The sound disappears, but does not disappear - why?

I think I understand the basic concept of the web audio API, as well as how sounds work in general. And although I managed to make the sound “fade”, I can’t understand why it doesn’t “fade” in the following fragment that I wrote to present the problem:

(function ()
{
    'use strict';
    var context = new AudioContext(),
        wave = context.createOscillator(),
        gain = context.createGain(),
        ZERO = 0.000001;

    wave.connect(gain);
    gain.connect(context.destination);

    wave.type = 'sine';
    wave.frequency.value = 200;
    gain.gain.value = ZERO;

    wave.start(context.currentTime);

    gain.gain.exponentialRampToValueAtTime(1.00, 1.0);
    gain.gain.exponentialRampToValueAtTime(ZERO, 3.0);
})();
Run codeHide result

NOTE. . A similar problem arose in Firefox (Linux) and Chrome (Windows).

+4
source share
2 answers

Replacing the line gain.gain.value = ZEROwith:

gain.gain.setValueAtTime(ZERO, 0);

fix the problem.

The rationale is in the actual specification of the function exponentialRampToValueAtTime():

, ( ), . linearRampToValueAtTime.

MDN:

AudioParam.value... , , - , AudioParam, , .

+4

gain.gain.setValueAtTime(ZERO, 0); 

gain.gain.value = ZERO;

AudioParam - ( 1 = 0). . ; 75%, , .

+3

All Articles