AudioParam

The Web Audio API's AudioParam interface represents an audio-related parameter, usually a parameter of an AudioNode (譬如 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. In other words, the same value applies to every frame in the audio as it's processed by the node.

AudioNode defines which of its parameters are a-rate or k-rate in the spec.

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 .

特性

AudioParam.defaultValue 只读
Represents the initial volume of the attribute as defined by the specific AudioNode creating the AudioParam .
AudioParam.maxValue 只读
Represents the maximum possible value for the parameter's nominal (effective) range.
AudioParam.minValue 只读
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 .

方法

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 by the value 参数。
AudioParam.linearRampToValueAtTime()
Schedules a gradual linear change in the value of the AudioParam . The change starts at the time specified for the 上一 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 参数。
AudioParam.exponentialRampToValueAtTime()
Schedules a gradual exponential change in the value of the AudioParam . The change starts at the time specified for the 上一 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 参数。
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 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 AudioParam but holds its value at a given time until further changes are made using other methods.

范例

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);
					

规范

规范 状态 Comment
Web 音频 API
The definition of 'AudioParam' in that specification.
工作草案

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
AudioParam Chrome 14 Edge ≤18 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
automationRate Chrome 68 Edge ≤79 Firefox ? IE 不支持 No Opera Yes Safari ? WebView Android 68 Chrome Android 68 Firefox Android ? Opera Android Yes Safari iOS Yes Samsung Internet Android 10.0
cancelAndHoldAtTime Chrome 57
57
? — 56
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
Edge ≤79 Firefox 不支持 No IE 不支持 No Opera 44
44
? — 43
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
Safari 不支持 No WebView Android 57
57
? — 56
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
Chrome Android 57
57
? — 56
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
Firefox Android 不支持 No Opera Android 43
43
? — 43
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
Safari iOS 不支持 No Samsung Internet Android 7.0
7.0
? — 6.0
Alternate Name
Alternate Name Uses the non-standard name: cancelValuesAndHoldAtTime()
cancelScheduledValues Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
defaultValue Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
exponentialRampToValueAtTime Chrome 14 Edge 12 Firefox 部分支持 25
注意事项
部分支持 25
注意事项
Does not work (see bug 1171438 and bug 1567777 ).
IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 部分支持 18
注意事项
部分支持 18
注意事项
This sets the target volume at the specified time, but it doesn’t ramp to it, causing this function to behave like setValueAtTime() .
Firefox Android 部分支持 26
注意事项
部分支持 26
注意事项
Does not work (see bug 1171438 and bug 1567777 ).
Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
linearRampToValueAtTime Chrome 14 Edge 12 Firefox 部分支持 25
注意事项
部分支持 25
注意事项
Does not work (see bug 1171438 and bug 1567777 ).
IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 部分支持 18
注意事项
部分支持 18
注意事项
This sets the target volume at the specified time, but it doesn’t ramp to it, causing this function to behave like setValueAtTime() .
Firefox Android 部分支持 26
注意事项
部分支持 26
注意事项
Does not work (see bug 1171438 and bug 1567777 ).
Opera Android 14 Safari iOS ? Samsung Internet Android 1.0
maxValue Chrome 52 Edge ≤18 Firefox 53 IE 不支持 No Opera 39 Safari 6 WebView Android 52 Chrome Android 52 Firefox Android 53 Opera Android 41 Safari iOS Yes Samsung Internet Android 6.0
minValue Chrome 52 Edge ≤18 Firefox 53 IE 不支持 No Opera 39 Safari 6 WebView Android 52 Chrome Android 52 Firefox Android 53 Opera Android 41 Safari iOS Yes Samsung Internet Android 6.0
setTargetAtTime Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
setValueAtTime Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
setValueCurveAtTime Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
value Chrome 14 Edge 12 Firefox 25
注意事项
25
注意事项
Prior to Firefox 69, value did not take into account scheduled or gradiated changes to the parameter's value; instead, only explicitly set values were returned.
IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26
注意事项
26
注意事项
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 14 Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持
完整支持
部分支持
部分支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
使用非标名称。
使用非标名称。

另请参阅