DynamicsCompressorNode

DynamicsCompressorNode interface provides a compression effect, which lowers the volume of the loudest parts of the signal in order to help prevent clipping and distortion that can occur when multiple sounds are played and multiplexed together at once. This is often used in musical production and game audio. DynamicsCompressorNode is an AudioNode that has exactly one input and one output; it is created using the AudioContext.createDynamicsCompressor() 方法。

Number of inputs 1
Number of outputs 1
Channel count mode "clamped-max"
Channel count 2
Channel interpretation "speakers"

构造函数

DynamicsCompressorNode()
Creates a new instance of an DynamicsCompressorNode 对象。

特性

Inherits properties from its parent, AudioNode .

DynamicsCompressorNode.threshold 只读
k-rate AudioParam representing the decibel value above which the compression will start taking effect.
DynamicsCompressorNode.knee 只读
k-rate AudioParam containing a decibel value representing the range above the threshold where the curve smoothly transitions to the compressed portion.
DynamicsCompressorNode.ratio 只读
k-rate AudioParam representing the amount of change, in dB, needed in the input for a 1 dB change in the output.
DynamicsCompressorNode.reduction 只读
float representing the amount of gain reduction currently applied by the compressor to the signal.
DynamicsCompressorNode.attack 只读
k-rate AudioParam representing the amount of time, in seconds, required to reduce the gain by 10 dB.
DynamicsCompressorNode.release 只读
k-rate AudioParam representing the amount of time, in seconds, required to increase the gain by 10 dB.

方法

No specific methods; inherits methods from its parent, AudioNode .

范例

The below code demonstrates a simple usage of createDynamicsCompressor() to add compression to an audio track. For a more complete example, have a look at our basic Compressor example ( view the source code ).

// Create a MediaElementAudioSourceNode
// Feed the HTMLMediaElement into it
var source = audioCtx.createMediaElementSource(myAudio);
// Create a compressor node
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);
// connect the AudioBufferSourceNode to the destination
source.connect(audioCtx.destination);
button.onclick = function() {
  var active = button.getAttribute('data-active');
  if(active == 'false') {
    button.setAttribute('data-active', 'true');
    button.innerHTML = 'Remove compression';
    source.disconnect(audioCtx.destination);
    source.connect(compressor);
    compressor.connect(audioCtx.destination);
  } else if(active == 'true') {
    button.setAttribute('data-active', 'false');
    button.innerHTML = 'Add compression';
    source.disconnect(compressor);
    compressor.disconnect(audioCtx.destination);
    source.connect(audioCtx.destination);
  }
}
					

规范

规范 状态 Comment
Web 音频 API
The definition of 'DynamicsCompressorNode' 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
DynamicsCompressorNode 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
DynamicsCompressorNode() 构造函数 Chrome 55
注意事项
55
注意事项
Before Chrome 59, the default values were not supported.
Edge ≤79 Firefox 53 IE 不支持 No Opera 42 Safari ? WebView Android 55
注意事项
55
注意事项
Before version 59, the default values were not supported.
Chrome Android 55
注意事项
55
注意事项
Before Chrome 59, the default values were not supported.
Firefox Android 53 Opera Android 42 Safari iOS ? Samsung Internet Android 6.0
注意事项
6.0
注意事项
Before Samsung Internet 7.0, the default values were not supported.
attack 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
knee 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
ratio 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
reduction Chrome 14
注意事项
14
注意事项
Before version 52, this was an AudioParam. .
Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes
注意事项
Yes
注意事项
Before version 52, this was an AudioParam. .
Chrome Android 18
注意事项
18
注意事项
Before version 52, this was an AudioParam. .
Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0
注意事项
1.0
注意事项
Before Samsung Internet 6.0, this was an AudioParam. .
release 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
threshold 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

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。

另请参阅