Question about working with audio

I want create a piano keyboard. I'm wondering if it is better to load all of the sounds one sound per key. Something like:

local c = audio.loadSound(c.m4a)
local d = audio.loadSound(d.m4a)
etc.

Or would it be better to load the sounds as needed. Something like:

local function playNote( whichNote )
local note = audio.loadSound(whichNote)
audio.play(note)
end

From my limited experience with Corona it seems that the first method would load a lot of audio up front. But would avoid loading lags and possibly avoid memory leaks.

The second method would only be loading one sound at a time and so might make better use of memory. Though you'd be loading more sounds over time. If these didn't get flushed out of memory you might be using more memory in the long term.

You are correct about loading lags. If the sound is going to be frequently used or you need very low latency, I recommend you load the sound early, say the beginning of a level or at start up.

If you are done with the sound, you should call audio.dispose(note) to free the memory.

Thanks for the reply.

My sounds are pretty small, about 53k each. I'm going to guess I'm probably good to load up 12 of these.

These are compressed AAC. Uncompressed the files 528k. Not sure what happens with this internally. Do the sounds take up their uncompressed size in RAM?

Either way I guess I can just give it a try and see what happens. Seems to work OK in the simulator so far.

Yeah files that small should be fine to load at once :)

views:1629 update:2011/11/14 9:16:56
corona forums © 2003-2011