distante
distante

Reputation: 7005

Does setValueAtTime has a specific duration?

In the docs says:

The setValueAtTime() method of the AudioParam interface schedules an instant change to the AudioParam value at a precise time, as measured against AudioContext.currentTime. The new value is given in the value parameter.

From what one can think it makes an instant change but when a run this code

...
biquadNode.gain.setValueAtTime(12, this._AudioContext.currentTime);
console.log("biquadNode.gain " + biquadNode.gain.value);
console.log("biquadNode.frequency " + biquadNode.frequency.value);
setTimeout(() => {
    console.log("biquadNode.gain " + biquadNode.gain.value);
    console.log("biquadNode.frequency " + biquadNode.frequency.value);
}, 100);
...

It outputs:

0
12

I am not sure why...

Upvotes: 1

Views: 255

Answers (1)

raina77ow
raina77ow

Reputation: 106365

It's instant, right, yet asynchronous (and is assumed to be a non-blocking op), as it's executed in a separate thread - note the word schedules in the description. That's why you won't see the change immediately.

Note that another method of updating value, via direct assignment to the corresponding property...

biquadNode.gain.value = 12;

... isn't synchronous either - and is basically equivalent to setValueAtTime(newValue, currentTime), as explained in this issue.

Upvotes: 1

Related Questions