Home Web Audio API: Prevent momentary feedback sound on connect/disconnect
Reply: 0

Web Audio API: Prevent momentary feedback sound on connect/disconnect

user1808 Published in May 28, 2018, 5:04 am

I'm recreating the children's game "Simon" on Codepen and using the Web Audio API to create tones upon a user click or upon the machine generating a sequence.

When the program starts, I initialize an audio context, then initialize four different oscillators, one for each tone/color. I also start each tone.

let context = new AudioContext();

let audioblue = context.createOscillator();
audioblue.frequency.value = 329.63;
audioblue.type = "sine";
// I repeat same code as above for audiored, audiogreen, and audioyellow

I have the program generate a random number (0, 1, 2 or 3, correlating to each quadrant of the board), one number at a time, requiring the player to recreate the full sequence before the program generates the next random number. Every time a new number is added to the sequence, I use setInterval() to "play" the sequence. "Playing" the sequence means both lighting up the quadrant and playing the corresponding tone. For playing the tone, I have the following code (the same is true for audiored, audiogreen, and audioyellow):


I then use setInterval() to undo the lighting up and disconnect the audio.


(There's probably a better way to do this, but as a beginner this is how I was able to figure it out.)

Everything works. The problem is you can hear an unpleasant feedback sound on the connecting and disconnecting of the tone. Is it possible to eliminate this feedback sound so the tone is more pleasant and user-friendly?

Thanks for any help you can offer.

Here's a link to the Codepen: https://codepen.io/lieberscott/pen/aEqaNd

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336197 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO