audio - How can I avoid this 'clicking' sound when I stop playing a sound? -


i hope question stays programming question , not end sound mechanics question... here goes...

i doing experiments in order figure out how web audio api works. trying simple "hang phone" sound playing in loop. problem when sound ends, can hear quite annoying 'clicking' sound. cannot explain better, can hear if test code.

is there way avoid this? filter apply or anything?

var audiocontext = new (audiocontext || webkitaudiocontext)();            var frequencyoffset = 0      function boop(){        // our sound source simple triangle oscillator        var oscillator = audiocontext.createoscillator(); // create sound source          oscillator.type = 'triangle';                // adding gain node lower volume bit , make        // sound less ear-piercing        var gain = audiocontext.creategain();        oscillator.connect(gain);        gain.connect(audiocontext.destination);                gain.gain.value = 0.1;        // fun let frequency increase on each itteration        oscillator.frequency.value = 200 + frequencyoffset;        oscillator.start(0);                // sound should last 250ms        settimeout(function(){          oscillator.disconnect();           oscillator.stop();          gain.disconnect();        }, 250);        frequencyoffset += 1;      }        setinterval(boop, 500);

this audio issue, not programming problem. click hear occurs when waveform stopped/cut in middle of wave, rather @ zero-crossing.

the best simple solution audio paradigm fade-out, instead of stopping playback.

a more complex solution find next zero-crossing , stop playback @ precisely point.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -