The Web Audio API's AudioParam interface represents an audio-related parameter, usually a parameter of an AudioNode (such as GainNode.gain). An AudioParam can be set to a specific value or a change in value, and can be scheduled to happen at a specific time and following a specific pattern.
There are two kinds of AudioParam, a-rate and k-rate parameters:
- An a-rate
AudioParamtakes the current audio parameter value for each sample frame of the audio signal. - A k-rate
AudioParamuses the same initial audio parameter value for the whole block processed, that is 128 sample frames. In other words, the same value applies to every frame in the audio as it's processed by the node.
Each AudioNode defines which of its parameters are a-rate or k-rate in the spec.
Each AudioParam has a list of events, initially empty, that define when and how values change. When this list is not empty, changes using the AudioParam.value attributes are ignored. This list of events allows us to schedule changes that have to happen at very precise times, using arbitrary timelime-based automation curves. The time used is the one defined in AudioContext.currentTime.
Properties
AudioParam.defaultValueRead only- Represents the initial volume of the attribute as defined by the specific
AudioNodecreating theAudioParam. AudioParam.maxValueRead only- Represents the maximum possible value for the parameter's nominal (effective) range.
AudioParam.minValueRead only- Represents the minimum possible value for the parameter's nominal (effective) range.
AudioParam.value- Represents the parameter's current value as of the current time; initially set to the value of
defaultValue.
Methods
AudioParam.setValueAtTime()- Schedules an instant change to the value of the
AudioParamat a precise time, as measured againstAudioContext.currentTime. The new value is given by thevalueparameter. AudioParam.linearRampToValueAtTime()- Schedules a gradual linear change in the value of the
AudioParam. The change starts at the time specified for the previous event, follows a linear ramp to the new value given in thevalueparameter, and reaches the new value at the time given in theendTimeparameter. AudioParam.exponentialRampToValueAtTime()- Schedules a gradual exponential change in the value of the
AudioParam. The change starts at the time specified for the previous event, follows an exponential ramp to the new value given in thevalueparameter, and reaches the new value at the time given in theendTimeparameter. AudioParam.setTargetAtTime()- Schedules the start of a change to the value of the
AudioParam. The change starts at the time specified instartTimeand exponentially moves towards the value given by thetargetparameter. The exponential decay rate is defined by thetimeConstantparameter, which is a time measured in seconds. AudioParam.setValueCurveAtTime()- Schedules the values of the
AudioParamto follow a set of values, defined by an array of floating-point numbers scaled to fit into the given interval, starting at a given start time and spanning a given duration of time. AudioParam.cancelScheduledValues()- Cancels all scheduled future changes to the
AudioParam. AudioParam.cancelAndHoldAtTime()- Cancels all scheduled future changes to the
AudioParambut holds its value at a given time until further changes are made using other methods.
Examples
First, a basic example showing a GainNode having its gain value set. gain is an example of an a-rate AudioParam, as the value can potentially be set differently for each sample frame of the audio.
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
var gainNode = audioCtx.createGain();
gainNode.gain.value = 0;
Next, an example showing a DynamicsCompressorNode having some param values maniuplated. These are examples of k-rate AudioParam's, as the values are set for the entire audio block at once.
var compressor = audioCtx.createDynamicsCompressor();
compressor.threshold.setValueAtTime(-50, audioCtx.currentTime);
compressor.knee.setValueAtTime(40, audioCtx.currentTime);
compressor.ratio.setValueAtTime(12, audioCtx.currentTime);
compressor.attack.setValueAtTime(0, audioCtx.currentTime);
compressor.release.setValueAtTime(0.25, audioCtx.currentTime);
Specifications
| Specification | Status | Comment |
| Web Audio APIThe definition of 'AudioParam' in that specification. | Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioParam
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
automationRate
|
Chrome
Full support 68 |
Edge
Full support ≤79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 55 |
Safari
No support No |
WebView Android
Full support 68 |
Chrome Android
Full support 68 |
Firefox Android
No support No |
Opera Android
Full support 48 |
Safari iOS
No support No |
Samsung Internet Android
Full support 10.0 |
cancelAndHoldAtTime
|
Chrome
Full support 57 |
Edge
Full support ≤79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
No support No |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
cancelScheduledValues
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
defaultValue
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
exponentialRampToValueAtTime
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox Partial support 25 Partial support 25 Notes' Does not work (see bug 1171438 and bug 1567777). |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android Partial support 18 Partial support 18 Notes' This sets the target volume at the specified time, but it doesn’t ramp to it, causing this function to behave like |
Firefox Android Partial support 26 Partial support 26 Notes' Does not work (see bug 1171438 and bug 1567777). |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
linearRampToValueAtTime
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox Partial support 25 Partial support 25 Notes' Does not work (see bug 1171438 and bug 1567777). |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android Partial support 18 Partial support 18 Notes' This sets the target volume at the specified time, but it doesn’t ramp to it, causing this function to behave like |
Firefox Android Partial support 26 Partial support 26 Notes' Does not work (see bug 1171438 and bug 1567777). |
Opera Android
Full support 14 |
Safari iOS
? |
Samsung Internet Android
Full support 1.0 |
maxValue
|
Chrome
Full support 52 |
Edge
Full support ≤18 |
Firefox
Full support 53 |
IE
No support No |
Opera
Full support 39 |
Safari
Full support 6 |
WebView Android
Full support 52 |
Chrome Android
Full support 52 |
Firefox Android
Full support 53 |
Opera Android
Full support 41 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 6.0 |
minValue
|
Chrome
Full support 52 |
Edge
Full support ≤18 |
Firefox
Full support 53 |
IE
No support No |
Opera
Full support 39 |
Safari
Full support 6 |
WebView Android
Full support 52 |
Chrome Android
Full support 52 |
Firefox Android
Full support 53 |
Opera Android
Full support 41 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 6.0 |
setTargetAtTime
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
setValueAtTime
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
setValueCurveAtTime
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android
Full support 26 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
value
|
Chrome
Full support 14 |
Edge
Full support 12 |
Firefox Full support 25 Full support 25 Notes' Prior to Firefox 69, |
IE
No support No |
Opera
Full support 15 |
Safari
Full support 6 |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android Full support 26 Full support 26 Notes' Firefox 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. |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.'
- See implementation notes.
See also
AudioParam by Mozilla Contributors is licensed under CC-BY-SA 2.5.