Sound Memory Issue

Hi,

I am using audio.load() and audio.play() to play sounds in game. But I am unable to free the memory occupied by any sound. And, I am not able to keep track of memory occupied by sounds.
Can somebody help in releasing the sound memory? Or any other better way to use sounds?

Thanks, [import]uid: 68306 topic_id: 14695 reply_id: 314695[/import]

If you are using audio.loadSound() or audio.loadStream() then you can use audio.dispose() to free up the memory. I don’t know of any audio.load() method.

As for tracking memory used by audio, I don’t think there is a way to do that. Maybe a Corona Staffer could say? It doesn’t appear to be stored in texture memory, but I could be wrong…

system.getInfo(“textureMemoryUsed”) doesn’t seem affected by audio.loadSound() or audio.loadStream()…

Hope that helps. [import]uid: 10818 topic_id: 14695 reply_id: 54357[/import]

Hey Thanks for reply. And sorry for misprint, I am using audio.loadSound().

I am using audio.dispose() only to release memory. But, I don’t think so it’s working. I am getting some crash issues because of this memory problem.

and system.getInfo() doesn’t work for sound memory.

Thanks. [import]uid: 68306 topic_id: 14695 reply_id: 54363[/import]

if you dispose a handler, every further call to that handler will fail. also you can’t dispose a sound that is playing or paused.

I never use audio.dispose(), btw.
I prefetch all sounds inside a table and call the identifier inside that table to play a sound.

Here, I took this snippet from somewhere on this site:

GameSounds= {  
 ["laserSound"] = audio.loadSound( "laser1.wav" ),  
 ["secLaserSound"] = audio.loadSound( "laser2.wav" )  
}  
  
function playSnd(sndKey)  
 local sndChanFree = audio.findFreeChannel()  
 audio.play( GameSounds[sndKey], { channel = sndChanFree } )  
 return;  
end  
  
-- usage:  
playSnd("laserSound") -- plays laser1.wav  

As long as you don’t use tons of megabytes of sounds, this should work without any crashes…

-finefin [import]uid: 70635 topic_id: 14695 reply_id: 54385[/import]

also if your using audio.dispose make sure to nil out your handle and stop the audio before disposing :

[code]

local mySound = audio.loadSound(“sound.wav”)

audio.play(mySound)

–When disposing
audio.stop(mySound)
audio.dispose(mySound)
mySound = nil
[/code] [import]uid: 84637 topic_id: 14695 reply_id: 54388[/import]

@Canupa & @Danny:

Hey… Over time, I have noticed a few issues when using sounds. I do use the protocols you mention, Danny…
audio.stop()
audio.dispose()
and then nil out the handle (tho in some cases I don’t do this because I instead immediately fill the same var with a new handle.)

Canupa… if you aren’t having any problems and you aren’t using audio.dispose(), then I’m thinking of doing the same. The real question is, how precious is the memory associated with audio playback? I try to keep my apps to the 20MB App Store limit, so audio won’t likely ever go beyond 15MB… but if this is texture memory or something similar, then I want to know. Can either of you clarify this for me? Thanks!

[import]uid: 10818 topic_id: 14695 reply_id: 54467[/import]