media.PlaySound memory leak

Hi, 

I found memory leak in my code. I startded to cut it to pin leak source, and I finished with… 6 lines of code.

I work in Windows 7. Corona Simulator get additional about 1 MB (!) memory at every tap and finally crashes.

local button = display.newRect( 100, 100, 50, 50 ) local function onTap() media.playSound( "jump1.wav" ) return true end button:addEventListener( "tap", onTap )

The sound is about 1 second and takes 32 KB.

Anyone knows, what’s wrong?

Regards,

Gudicus

Gudicus,

For a sound so short (basically a sound effect) I believe the recommendation is to use    

audio.loadSound() & audio.play()

Near the top of your code put this line:

local jumpSound = audio.loadSound(“jump1.wav”)

and then in the onTap function replace the media.playSound with this :

audio.play(jumpSound)

I have never used media.playSound … so I can not tell you why you are accumulating the memory usage so quickly.  But, try the audio.loadSound and audio.play and see if that works for you.

It might be helpful to checkout the corona docs on media.playSound and audio.playSound, where you can see the differences between them, and find the one that will work best.  I have never used the media module so I really have little knowledge about it.

Good luck!

Bob

That is really odd. Bob is right with the audio.playSound suggestion. The only thing you may run into is that audio.playSound has latency issues with some versions of Android. Since you are on Windows, I assume you are developing for Android?

I cannot use audio beacase of sound latency (on Android). This sound I use for jump and I need it instantly. I like audio lib and I use it for backround music.

Audio latency problem touches Android, on iOS there is no problems.

Anyway - I observed problem on Windows using Corona Simulator. How to check it on device?

Regards,

Gudicus

Out of curiousity, I tested with your exact code, plus printing memory usage for each tap. No leaks, issues, or otherwise. What version of corona are you running?

Since you’re using wav, the latency isn’t as bad as mp3, should you decide to use the audio library.

Version 2015.2731, system Windows 7 64 bit. Latency with audio is not acceptable in platform game :slight_smile:

What environment have you tested?

Regards,

Gudicus

Agreed my friend, agreed. Windows 10 x64, Corona Simulator 2015.2781

EDIT: Forgot to ask you, is this only on simulator or on device as well? If you’re only seeing it on the sim, it might be something with your sound card drivers.

I observed it on simulator. How to check memory on device?

I work on MSI notebook with preinstalled system - drivers should be correect :slight_smile:

@csavalas

Thanks for the information about audio latency on android.  I have only done iOS, but am getting ready to do android now… I now may have to change my original code to deal with that latency issue …

What is the best work around to deal with that latency issue on android, in your experience?

I will search the forum for answers to this as well, but if you have some insight on this, I thank you in advance for your sharing of knowledge.

Thanks

Bob

As for now, as I know, there is no way to avoid latency using audio.library.

I use media.playSound for instant sounds and audio for background music and asynchronous sounds.

For instant sounds I have simple function with priority check, so more important sound stops sound with lower priority (if played), but less important will not stop more important one during play.

In addition, media library cannot control properly volume level (audio can). So I have only sound on/off, and user sets volume by phone settings.

I was surprised, yes.

:slight_smile:

Gudicus,

Good to know. Thanks

Bob

Gudicus,

For a sound so short (basically a sound effect) I believe the recommendation is to use    

audio.loadSound() & audio.play()

Near the top of your code put this line:

local jumpSound = audio.loadSound(“jump1.wav”)

and then in the onTap function replace the media.playSound with this :

audio.play(jumpSound)

I have never used media.playSound … so I can not tell you why you are accumulating the memory usage so quickly.  But, try the audio.loadSound and audio.play and see if that works for you.

It might be helpful to checkout the corona docs on media.playSound and audio.playSound, where you can see the differences between them, and find the one that will work best.  I have never used the media module so I really have little knowledge about it.

Good luck!

Bob

That is really odd. Bob is right with the audio.playSound suggestion. The only thing you may run into is that audio.playSound has latency issues with some versions of Android. Since you are on Windows, I assume you are developing for Android?

I cannot use audio beacase of sound latency (on Android). This sound I use for jump and I need it instantly. I like audio lib and I use it for backround music.

Audio latency problem touches Android, on iOS there is no problems.

Anyway - I observed problem on Windows using Corona Simulator. How to check it on device?

Regards,

Gudicus

Out of curiousity, I tested with your exact code, plus printing memory usage for each tap. No leaks, issues, or otherwise. What version of corona are you running?

Since you’re using wav, the latency isn’t as bad as mp3, should you decide to use the audio library.

Version 2015.2731, system Windows 7 64 bit. Latency with audio is not acceptable in platform game :slight_smile:

What environment have you tested?

Regards,

Gudicus

Agreed my friend, agreed. Windows 10 x64, Corona Simulator 2015.2781

EDIT: Forgot to ask you, is this only on simulator or on device as well? If you’re only seeing it on the sim, it might be something with your sound card drivers.

I observed it on simulator. How to check memory on device?

I work on MSI notebook with preinstalled system - drivers should be correect :slight_smile:

@csavalas

Thanks for the information about audio latency on android.  I have only done iOS, but am getting ready to do android now… I now may have to change my original code to deal with that latency issue …

What is the best work around to deal with that latency issue on android, in your experience?

I will search the forum for answers to this as well, but if you have some insight on this, I thank you in advance for your sharing of knowledge.

Thanks

Bob

As for now, as I know, there is no way to avoid latency using audio.library.

I use media.playSound for instant sounds and audio for background music and asynchronous sounds.

For instant sounds I have simple function with priority check, so more important sound stops sound with lower priority (if played), but less important will not stop more important one during play.

In addition, media library cannot control properly volume level (audio can). So I have only sound on/off, and user sets volume by phone settings.

I was surprised, yes.

:slight_smile: