This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The value property of the AudioParam interface gets or sets the value of this AudioParam at the current time. Initially, the value is set to AudioParam.defaultValue.
Setting value has the same effect as calling AudioParam.setValueAtTime with the time returned by the AudioContext's currentTime property.
A floating-point Number indicating the parameter's value as of the current time. This value will be between the values specified by the minValue and maxValue properties.
The data type used internally to store value is a single-precision (32-bit) floating point number, while JavaScript uses 64-bit double-precision floating point numbers. As a result, the value you read from the value property may not always exactly equal what you set it to.
Consider this example:
const source = new AudioBufferSourceNode(/* … */); const rate = 5.3; source.playbackRate.value = rate; console.log(source.playbackRate.value === rate);
The log output will be false, because the playback rate parameter, rate, was converted to the 32-bit floating-point number closest to 5.3, which yields 5.300000190734863. One solution is to use the Math.fround() method, which returns the single-precision value equivalent to the 64-bit JavaScript value specified—when setting value, like this:
const source = new AudioBufferSourceNode(/* … */); const rate = Math.fround(5.3); source.playbackRate.value = rate; console.log(source.playbackRate.value === rate);
In this case, the log output will be true.
The value of an AudioParam can either be fixed or can vary over time. This is reflected by the value getter, which returns the value of the parameter as of the audio rendering engine's most recent render quantum, or moment at which audio buffers are processed and updated. In addition to processing audio buffers, each render quantum updates the value of each AudioParam as needed given the current time and any established time-based parameter value changes.
Upon first creating the parameter, its value is set to its default value, given by AudioParam.defaultValue. This is the parameter's value at a time of 0.0 seconds, and will remain the parameter's value until the first render quantum in which the value is altered.
During each render quantum, the browser does the following things related to managing the value of a parameter:
value setter has been used, the parameter's value is changed to the value given.setValueAtTime(), the value is changed to the value passed into setValueAtTime().linearRampToValueAtTime(), setTargetAtTime(), and setValueCurveAtTime().Thus, the value of a parameter is maintained to accurately reflect the state of the parameter over time.
This example instantly changes the volume of a GainNode to 40%.
const audioCtx = new AudioContext(); const gainNode = audioCtx.createGain(); gainNode.gain.value = 0.4; // which is identical to: gainNode.gain.setValueAtTime(0.4, audioCtx.currentTime);
| Specification |
|---|
| Web Audio API> # dom-audioparam-value> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
value |
14Before version 66, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
12 | 25["Before Firefox 134, settingvalue was ignored when done at the same time as scheduled automation events.", "Before Firefox 69, value did not take into account scheduled or gradiated changes to the parameter's value; instead, only explicitly set values were returned."] |
15Before version 53, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
6 | 18Before version 66, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
25Firefox for Android does not currently take into account scheduled or gradiated changes to the parameter's value; only the initial value or the most recent explicitly set value is returned. |
14Before version 47, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
6 | 1.0Before version 9.0, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
4.4Before version 66, the gain value of aGainNode would perform a smooth interpolation to prevent dezippering (instead of changing instantly). |
6 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioParam/value