will audio.fadeOut() call audio.dispose() ?

I’m using

audio.fadeOut()

to “remove” my sound in a storyboard scene in the listener function scene:exitScene()

Now I wonder if this is enough to free the memory and if audio.fadeOut() is calling audio.dispose() and setting audio to nil automatically?

With the fadeOut my sound will end while the new scene already has started… so it would be difficult to add the audio.dispose() for this sound.

Thank you for your help!

Daniela

Hi Daniela,

Nope, “fadeOut()” won’t automatically remove/unload the sound. It will free up the channel when it completes, but that doesn’t remove the sound file from memory.

Since your sound will “overlap” into a new scene, you’ll have to build some kind of removal function in your project core, outside of the Storyboard scenes. The “fadeOut()” API features an “onComplete” call which you can use for this.

In general, I suggest you build some kind of sound management table in your project core, independent of the scenes. It will just be safer, defensive programming. Then you can add/remove/dispose of sounds in that table, so there won’t be memory leaks from sounds called/played individually from scenes that are being swapped around.

Hope this helps,

Brent Sorrentino

Thank you Brent for your fast answer!

Can you please tell me how I can use the onComplete call with fadeOut()… I don’t know how to access it and can’t find a sample!?

Thanks again!

Daniela

Hi Daniela,

Did you ever solve this? I actually informed you incorrectly: the “onComplete” callback is available from the audio.play() API, not from the audio.fadeOut() API. So, I think you’ll need to play the sound as normal, do a fadeOut (separately), then put the onComplete argument in the play call, like this:

[lua]

local sparkleSound = audio.loadSound( “sparkle.wav” )

local function disposeSound( event )

    audio.stop( event.channel )

    audio.dispose( event.handle )

    sparkleSound = nil

end

local sound = audio.play( sparkleSound, { onComplete=disposeSound } )

audio.fadeOut( { channel=sound, time=1000 } )

[/lua]

Notice that in the fadeOut() call, “channel=sound” is used because “sound” (the local variable set to play the sound) is equal to the channel it plays on… you need that because fadeOut() requires the channel to fade, but you might not know which channel it’s on unless you specify a channel… and since you probably don’t want to do that, “sound” gives you the channel to use with fadeOut().

Hope this helps!

Brent

Hi Brent,

thank you for your detailed answer!

I did a workaround for the problem but will look into your code asap.

Thanks again! Much appreciated ! :slight_smile:

Daniela

Hi Daniela,

Nope, “fadeOut()” won’t automatically remove/unload the sound. It will free up the channel when it completes, but that doesn’t remove the sound file from memory.

Since your sound will “overlap” into a new scene, you’ll have to build some kind of removal function in your project core, outside of the Storyboard scenes. The “fadeOut()” API features an “onComplete” call which you can use for this.

In general, I suggest you build some kind of sound management table in your project core, independent of the scenes. It will just be safer, defensive programming. Then you can add/remove/dispose of sounds in that table, so there won’t be memory leaks from sounds called/played individually from scenes that are being swapped around.

Hope this helps,

Brent Sorrentino

Thank you Brent for your fast answer!

Can you please tell me how I can use the onComplete call with fadeOut()… I don’t know how to access it and can’t find a sample!?

Thanks again!

Daniela

Hi Daniela,

Did you ever solve this? I actually informed you incorrectly: the “onComplete” callback is available from the audio.play() API, not from the audio.fadeOut() API. So, I think you’ll need to play the sound as normal, do a fadeOut (separately), then put the onComplete argument in the play call, like this:

[lua]

local sparkleSound = audio.loadSound( “sparkle.wav” )

local function disposeSound( event )

    audio.stop( event.channel )

    audio.dispose( event.handle )

    sparkleSound = nil

end

local sound = audio.play( sparkleSound, { onComplete=disposeSound } )

audio.fadeOut( { channel=sound, time=1000 } )

[/lua]

Notice that in the fadeOut() call, “channel=sound” is used because “sound” (the local variable set to play the sound) is equal to the channel it plays on… you need that because fadeOut() requires the channel to fade, but you might not know which channel it’s on unless you specify a channel… and since you probably don’t want to do that, “sound” gives you the channel to use with fadeOut().

Hope this helps!

Brent

Hi Brent,

thank you for your detailed answer!

I did a workaround for the problem but will look into your code asap.

Thanks again! Much appreciated ! :slight_smile:

Daniela

I having memory leak troubles, I was under the impression that the audio cleaned itself up from scene to scene. Must we dispose every single file we use when changing to new scene with something like director. 

As I know you have to do this with something like director and even when using storyboard because it is not a graphics file in storyboards scenegroup.
 

Daniela

Hi @Beloudest,

Audio definitely needs to be disposed of… not necessarily between scenes, but at some point it does need to be. Logically though, if you are leaving a scene and don’t need any of the audio used in that scene, you should dispose of it for memory reasons.

Brent

I having memory leak troubles, I was under the impression that the audio cleaned itself up from scene to scene. Must we dispose every single file we use when changing to new scene with something like director. 

As I know you have to do this with something like director and even when using storyboard because it is not a graphics file in storyboards scenegroup.
 

Daniela

Hi @Beloudest,

Audio definitely needs to be disposed of… not necessarily between scenes, but at some point it does need to be. Logically though, if you are leaving a scene and don’t need any of the audio used in that scene, you should dispose of it for memory reasons.

Brent