The 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.
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 Inherits properties from its parent, AudioNode.
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 volume as a floating point value; initially set to the value of
AudioParam.defaultValue. Though it can be set, any modifications happening while there are automation events scheduled — that is events scheduled using the methods of theAudioParam— are ignored, without raising any exception.
Methods
AudioParam Inherits methods from its parent, AudioNode.
AudioParam.setValueAtTime()- Schedules an instant change to the value of the
AudioParamat a precise time, as measured againstAudioContext.currentTime. The new value is given in 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 thevaluesFloat32Arrayscaled to fit into the given interval, starting atstartTime, and having a specificduration. 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. The new value is given in thevalueparameter.
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 BiquadFilterNode having some values set. These are examples of k-rate AudioParam's, as the values are set for the entire audio block at once.
var AudioContext = window.AudioContext || window.webkitAudioContext; var audioCtx = new AudioContext(); var biquadFilter = audioCtx.createBiquadFilter(); biquadFilter.type = "lowshelf"; biquadFilter.frequency.value = 1000; biquadFilter.gain.value = 25;
Specifications
| Specification | Status | Comment |
|---|---|---|
| Web Audio API The definition of 'AudioParam' in that specification. |
Working Draft |
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | 14 webkit | (Yes) | 23 (23) | No support | 15 webkit 22 (unprefixed) |
6 webkit |
| Unprefixed | (Yes) | (Yes) | (Yes) | No support | (Yes) | No support |
minValue and maxValue |
52 | No support | (Yes) | No support | 39 | No support |
cancelAndHoldAtTime() |
57 | No support | No support | No support | No support | No support |
| Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | (Yes) | 28 webkit | (Yes) | 25.0 (25) | No support | No support | 6 webkit |
| Unprefixed | (Yes) | (Yes) | (Yes) | (Yes) | No support | (Yes) | No support |
minValue and maxValue |
52 | 52 | No support | (Yes) | No support | 39 | No support |
cancelAndHoldAtTime() |
57 | 57 | No support | No support | No support | No support | No support |