audio.fadeOut - what is the proper way of using this function?

Hi

I have a play/stop button with a audio clip (sound.wav), say, 10 seconds long.

When I press the button, it plays the clip.

[blockcode]
local channel
local file = “sound.wav”
sound = audio.loadSound(file)
channel = audio.play(sound, {loops=-1})
[/blockcode]

When I release the button, it stops the clip.
[blockcode]
audio.stop(channel)
[/blockcode]

Quite simple actually.

I tried to use fade or fadeOut to smooth out the sound when it is stopped. But the button does not play the sound any more when it is pressed again. Basically, there is no sound. I have checked the channel volume. It is still at 1.

[blockcode]
audio.fadeOut({channel=channel, time=1000})
[/blockcode]

I tried various combination of rewind, setVolume and stop etc but still could not get it to play properly.

I guess I don’t know how to use the fadeOut function properly. Can someone share a small sample code? Thank you.
Alternatively, how can I call audio.stop at the end of the fadeOut?

Looking forward for your help.

Cheers
ec0000

[import]uid: 29942 topic_id: 7761 reply_id: 307761[/import]

@ec0000, once you’ve faded out the sound on a specific channel, then that channel’s volume is now set to 0. If you want to play sound again on that channel, you need to change its volume to something loud enough to hear. Either do that with audio.setVolume

[lua]audio.setVolume( volume , { channel= channel } )[/lua]

or use the fade command to fade in to the correct volume:

[lua]audio.fade({ channel=channel, time=1000, volume=0.5 } )[/lua]
[import]uid: 9905 topic_id: 7761 reply_id: 28056[/import]

@DavidBFox, Thank you for your suggestion.

I tried to put the fadeOut and setVolume together. The sound can now be played multiple times. But fadeOut does not work any more.

fadeOut seems to be behaving like asynchronous call.

Can someone from the company confirm this, please?

Cheers
ec0000 [import]uid: 29942 topic_id: 7761 reply_id: 28352[/import]

@ec0000, not sure what’s happening for you. Maybe best to post a minimal code sample so we can take a look.

If you set the volume right after fadeOut, it probably wouldn’t do what you want since it’s going to take some time for fadeOut to do its thing.

Also, the main difference between fadeOut() and fade() is that when the sound level gets to 0, fadeOut() will actually turn it off and free up that channel while fade() leaves it playing, and the channel remains in use.

Check out this discussion on fadeOut()
http://developer.anscamobile.com/reference/index/audiofadeout#comment-28057 [import]uid: 9905 topic_id: 7761 reply_id: 28423[/import]