Audio Problems

Hi, I’m back to working on the rhythm game mentioned all the way in my very first post, hoping the new builds have the problem fixed. This is getting very frustrating.

Check out the code below:
[lua]local counter = 10
local function endcheck(event)
print(event.time)
end
local ppptime = 0
local sound1ID = media.newEventSound( “sound1.mp3” )
local function playBeep(event)
if counter == 0 then
media.playEventSound( sound1ID, endcheck )
print(event.time - ppptime)
ppptime = event.time
print(sound1ID)
counter = 10
end
counter = counter - 1
end
Runtime:addEventListener(“enterFrame”, playBeep)[/lua]

I require sound feedback from user touch input and was using audio.play() which worked but had massive latency between the user tapping and the sound actually playing. This screws with the player mind of the tempo. Some on the forums have suggested switching back to media.playEventSound to get rid of the latency.

The code above was a test to see what was going on. The sound was made to play every 10 frames and the time between the sounds were printed.

But the sound refused to play. I tried .wav and .mp3 and .ogg. Neither worked. However, when I shifted the line
[lua]local sound1ID = media.newEventSound( “sound1.mp3” )[/lua]
to within the Runtime loop such that we get this:

[lua]local counter = 10
local function endcheck(event)
print(event.time)
end
local ppptime = 0

local function playBeep(event)
– SHIFTED HERE –
local sound1ID = media.newEventSound( “sound1.mp3” )
if counter == 0 then
media.playEventSound( sound1ID, endcheck )
print(event.time - ppptime)
ppptime = event.time
print(sound1ID)
counter = 10
end
counter = counter - 1
end
Runtime:addEventListener(“enterFrame”, playBeep)[/lua]

This time we have a new soundID declared every frame, and miraculously the sound starts to play, but with 800ms lag in between due to the loading of the sound.

May I know what is going on? So far the general forum responses are:

  1. Oh you’re using media.playEventSound()? Try audio.play()
  2. Oh you’re using audio.play()? Try media.playEventSound()
    [import]uid: 108204 topic_id: 19736 reply_id: 319736[/import]

By the way, the endcheck completion listener is never accessed. [import]uid: 108204 topic_id: 19736 reply_id: 76392[/import]

If your target device is Android then there’s unfortunately nothing that can be done from a Corona standpoint. Audio lag is an Android problem.
[import]uid: 70847 topic_id: 19736 reply_id: 76403[/import]

I created a small WAV with a short beep and tested your code (first snippet) on my iPad and it works well.

I also tested on my Android device (Galaxy Player, Android 2.2) and I get sound to play, but the timing is not steady. [import]uid: 70847 topic_id: 19736 reply_id: 76407[/import]

The problem now is that it’s not working in the simulator for me, which is really frustrating. [import]uid: 108204 topic_id: 19736 reply_id: 76417[/import]

For me it’s OK on the simulator as well. I’m on a Mac, OSX Lion, Corona 2011.715. [import]uid: 70847 topic_id: 19736 reply_id: 76421[/import]