W3cubDocs

/DOM

AudioParam

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 AudioParam takes the current audio parameter value for each sample frame of the audio signal.
  • A k-rate AudioParam uses 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.defaultValue Read only
Represents the initial volume of the attribute as defined by the specific AudioNode creating the AudioParam.
AudioParam.maxValue Read only
Represents the maximum possible value for the parameter's nominal (effective) range.
AudioParam.minValue Read 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 the AudioParam — 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 AudioParam at a precise time, as measured against AudioContext.currentTime. The new value is given in the value parameter.
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 the value parameter, and reaches the new value at the time given in the endTime parameter.
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 the value parameter, and reaches the new value at the time given in the endTime parameter.
AudioParam.setTargetAtTime()
Schedules the start of a change to the value of the AudioParam. The change starts at the time specified in startTime and exponentially moves towards the value given by the target parameter. The exponential decay rate is defined by the timeConstant parameter, which is a time measured in seconds.
AudioParam.setValueCurveAtTime()
Schedules the values of the AudioParam to follow a set of values, defined by the values Float32Array scaled to fit into the given interval, starting at startTime, and having a specific duration.
AudioParam.cancelScheduledValues()
Cancels all scheduled future changes to the AudioParam.
AudioParam.cancelAndHoldAtTime()
Cancels all scheduled future changes to the AudioParam but holds its value at a given time until further changes are made using other methods. The new value is given in the value parameter.

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 Internet Explorer Opera Safari
Basic support 14 Yes 25 No 15 6
defaultValue 14 Yes 25 No 15 6
maxValue 52 Yes 53 No 39 No
minValue 52 Yes 53 No 39 No
value 14 Yes 25 No 15 6
cancelAndHoldAtTime

57

Yes — 561

? No No

44

Yes — 431

No
cancelScheduledValues 14 Yes 25 No 15 6
exponentialRampToValueAtTime 14 Yes 25 No 15 6
linearRampToValueAtTime 14 Yes 25 No 15 6
setTargetAtTime 14 Yes 25 No 15 6
setValueAtTime 14 Yes 25 No 15 6
setValueCurveAtTime 14 Yes 25 No 15 6
Feature Android webview Chrome for Android Edge mobile Firefox for Android IE mobile Opera Android iOS Safari
Basic support Yes 14 Yes 26 No 15 ?
defaultValue Yes 14 Yes 26 No 15 ?
maxValue 52 52 Yes 53 No 39 ?
minValue 52 52 Yes 53 No 39 ?
value Yes 14 Yes 26 No 15 ?
cancelAndHoldAtTime

57

Yes — 561

57

Yes — 561

Yes No No

44

Yes — 431

No
cancelScheduledValues Yes 14 Yes 26 No 15 ?
exponentialRampToValueAtTime Yes 14 Yes 26 No 15 ?
linearRampToValueAtTime Yes 14 Yes 26 No 15 ?
setTargetAtTime Yes 14 Yes 26 No 15 ?
setValueAtTime Yes 14 Yes 26 No 15 ?
setValueCurveAtTime Yes 14 Yes 26 No 15 ?

1. Supported as cancelValuesAndHoldAtTime().

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioParam