Is is possible to quickly fade out audio before an audio.seek(..) to avoid "popping" sounds?

Hello,

I’m working on a somewhat unique audio application where I very frequently (every few frames) do an audio.seek( ). The end result, which is on purpose, sounds like a skipping CD player. Because the audio is not necessarily going to repeat on a zero crossing, there are audible “popping” sounds.

Is there any way to quickly fade out the audio before an audio.seek(), then fade back in after the audio.seek()? It would have to be a VERY fast fade-out and fade-in for it to work for me.

I have tried doing it manually using audio.setVolume(), but it didn’t work. It still popped. For example:

audio.setVolume(.9)  
audio.setVolume(.8)  
... etc ...  
  
audio.seek(3000)  
  
audio.setVolume(.1)  
audio.setVolume(.2)  
.. etc...  

I’ve looked at audio.fade(), but it’s tricky for me to use since it doesn’t support a callback for when it’s done. For example, this didn’t work:

audio.fade({ time=50, volume=0.0 } )  
audio.seek(seek\_position, audio\_handle)  
audio.fade({ time=50, volume=1.0 } )  

I realize this might not be possible. Thanks,

  • Bret [import]uid: 168791 topic_id: 29755 reply_id: 329755[/import]

Hi Bret,

Since audio.fade doesn’t trigger a callback on completion, how about just starting a timer (of the same amount) at the exact same moment and using that to “delay” your seek? You could also pass the seek position along with the timer so you’d have it available when the timer’s triggered function executes.

What do you think? Would this solve your issue?
Brent [import]uid: 9747 topic_id: 29755 reply_id: 119410[/import]

Hi Brent,

That worked! Here’s the code:

function seekAfterFade()  
 audio.seek(seek\_position, audio\_handle)  
 audio.fade({ time=40, volume=1 } )  
end  
  
function seekAudio()  
 audio.fade({ time=40, volume=0 } )  
 timer.performWithDelay(40, seekAfterFade )  
end  

Oddly enough I liked the version with the “popping” more. Ha ha ha. Maybe there’s something about that clipping sound that’s more realistic to my ears. The version without the popping sounded too soft for me. But, it’s cool that it can be done, and thanks for the solution!

  • Bret [import]uid: 168791 topic_id: 29755 reply_id: 119449[/import]