little "click" when playing/stopping wav file

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

I am working on a simple wav player. Let's say I have 2 buttons. The first is "Play my wav sample", and the second "Stop my wav sample". When I press stop, there is a little "click" sound. I can't get rid of it.

I use very basic code :
playSdRaw1.play("my_file.wav");
playSdRaw1.stop("my_file.wav");

I have tried to use a mixer device with a gain set to 0 to mute the sound. Still this little noise.

I use a teensy 3.2 with the audio shield.

Any suggestion ?
Thanks
Emmanuel
 
The click is caused when the sound level is abruptly dropped to zero. Instead of a mixer, try using an AudioEffectEnvelope with delay,attack,hold and decay all set to zero milliseconds. Set the sustain level to 1 and try setting the release time to 5 milliseconds. When you call noteOff, the release phase will ramp the audio level down to zero over 5 milliseconds which should remove the click. Just remember that when you call noteOff, the audio is still going to be playing for another 5 milliseconds. You may have to play with length of the release time to get an optimal value - I haven't tried this.

Pete
 
Hi Pete,
Your solution works. 2ms release+3ms delay do the trick.
I noticed there is a releaseNoteOn(milliseconds) function that is designed for this, but I didn't manage to make it work. Do you have any idea ?
Thanks
Emmanuel
 
Glad the envelope worked out.
I haven't used releaseNoteOn. I did a quick scan through the code and couldn't figure out how/what it really does. I'll try to have a more detailed look and maybe play with it soon.

Petee
 
Status
Not open for further replies.
Back
Top