Path: blob/main/files/en-us/web/api/audioparam/setvalueattime/index.md
6567 views
------{{ APIRef("Web Audio API") }}
The setValueAtTime() method of the {{domxref("AudioParam")}} interface schedules an instant change to the AudioParam value at a precise time, as measured against {{domxref("BaseAudioContext/currentTime", "AudioContext.currentTime")}}. The new value is given in the value parameter.
Syntax
Parameters
value: A floating point number representing the value the AudioParam will change to at the given time.
startTime: A double representing the time (in seconds) after the {{domxref("AudioContext")}} was first created that the change in value will happen. If the time is less than {{domxref("BaseAudioContext/currentTime", "AudioContext.currentTime")}}, the change happens immediately. A {{jsxref("TypeError")}} is thrown if this value is negative.
Return value
A reference to this AudioParam object. In some browsers older implementations of this interface return {{jsxref('undefined')}}.
Examples
This simple example features a media element source with two control buttons (see our webaudio-examples repo for the source code, or view the example live). When the buttons are pressed, the currGain variable is incremented/decremented by 0.25, then the setValueAtTime() method is used to set the gain value equal to currGain, one second from now (audioCtx.currentTime + 1.)
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}