Audio fade out not working correctly.

I am trying to get a looping sound to stop at a precise moment. However, the audio.fadeOut is allowing the sound to continue on past the “stop” point.

Things to note:

The looping .wav sound I am using is slightly less than 1000 milliseconds so the fade only takes 3ish frames.  

The second audio.stop works as intended, stoping the audio at the precise moment.

Any ideas what I am doing wrong?

 --soundfx are preloaded in another function but here for clarity --duration = x, is passed through the function call local soundfx = { rockButtonDown = audio.loadSound( "audio/buttonDown\_05.wav" ), rockButtonUp = audio.loadSound( "audio/buttonUp\_05.wav" ), rockSliding = audio.loadSound( "audio/rockSliding\_01.wav" ), } local clipDuration = { audio.getDuration( soundfx.rockButtonDown ), audio.getDuration( soundfx.rockButtonUp ), timeDelay = 0,--.5 timeFadeLength = .2, } timer.performWithDelay( clipDuration.timeDelay \* clipDuration[1], function() audio.play( soundfx.rockSliding, { channel = 3, loops = -1, fadein = clipDuration.timeFadeLength\*clipDuration[1], } ) end ) --THIS: timer.performWithDelay( duration - (clipDuration.timeFadeLength\*clipDuration[2]), function() audio.fadeOut( { 3, clipDuration.timeFadeLength \* clipDuration[2] } ) end ) --VS. THIS: timer.performWithDelay( duration, function() audio.stop( 3 ) end )

TTT!

If the duration is very short, could the problem be related to how quickly the sound must fade after starting?

Crickets?

Hi @gullie667,

My guess is that there’s some minor imprecision going on with the timers and the fade(s) and so forth. There will always be some minor accuracy issues with timers, and they can’t always be relied upon to start/end at the exact millisecond you want them to. If you absolutely need these sound effects to fade out with precision, you should probably just edit the original sound files if possible, using a basic sound editor program (there should be something with this basic capability for free).

Take care,

Brent

Yup. You need to remember that audio in Corona is always done on a “best effort” basis. It is never rock-solid as timing is concerned.

Ok… Thanks for the info!

No problem! For your information - I have found that the first few microseconds of a sound are often truncated, which becomes noticeable when you use very very short sounds like ticks etc.

TTT!

If the duration is very short, could the problem be related to how quickly the sound must fade after starting?

Crickets?

Hi @gullie667,

My guess is that there’s some minor imprecision going on with the timers and the fade(s) and so forth. There will always be some minor accuracy issues with timers, and they can’t always be relied upon to start/end at the exact millisecond you want them to. If you absolutely need these sound effects to fade out with precision, you should probably just edit the original sound files if possible, using a basic sound editor program (there should be something with this basic capability for free).

Take care,

Brent

Yup. You need to remember that audio in Corona is always done on a “best effort” basis. It is never rock-solid as timing is concerned.

Ok… Thanks for the info!

No problem! For your information - I have found that the first few microseconds of a sound are often truncated, which becomes noticeable when you use very very short sounds like ticks etc.