DynamicsCompressorNode

DynamicsCompressorNode 接口提供了一个压缩效果器,用以降低信号中最响部分的音量,来协助避免在多个声音同时播放并叠加在一起的时候产生的削波失真。通常用于音乐创作和游戏音效中。DynamicsCompressorNode 是一个 AudioNode ,只有一路输入和一路输出,使用 AudioContext.createDynamicsCompressor() 方法创建。

Number of inputs 1
Number of outputs 1
Channel count mode "explicit"
Channel count 2
Channel interpretation "speakers"

构造方法

DynamicsCompressorNode()
创建一个新的 DynamicsCompressorNode 对象实例。

属性

由父类 AudioNode 派生

DynamicsCompressorNode.threshold 只读
比例系数 AudioParam 型。分贝高于此值时,将会进行压缩。
DynamicsCompressorNode.knee 只读
比例系数 AudioParam 型。当超出 threshold 设置的值之后,曲线在哪个点开始朝着 ratio 设置的部分平滑变换。
DynamicsCompressorNode.ratio 只读
比例系数 AudioParam 型。输入增益变化多少来产生 1 dB 的输出。
DynamicsCompressorNode.reduction 只读
float 型。表示当前压缩器使用的增益压缩值。
DynamicsCompressorNode.attack 只读
比例系数 AudioParam 型。降低增益 10 dB 的时间(单位为秒)。
DynamicsCompressorNode.release 只读
比例系数 AudioParam 型。提升增益 10 dB 的时间(单位为秒)。

方法

没有自定义的方法,继承父类 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);
  }
}

Specifications

Specification Status Comment
Web Audio API
DynamicsCompressorNode
Working Draft  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
DynamicsCompressorNodeChrome Full support 14Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
DynamicsCompressorNode() constructorChrome Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Edge ? Firefox Full support 53IE No support NoOpera Full support 42Safari ? WebView Android Full support 55
Notes
Full support 55
Notes
Notes Before version 59, the default values were not supported.
Chrome Android Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Firefox Android Full support 53Opera Android Full support 42Safari iOS ? Samsung Internet Android Full support 6.0
attackChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
kneeChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
ratioChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
reductionChrome Full support 14
Notes
Full support 14
Notes
Notes Before version 52, this was an AudioParam..
Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Before version 52, this was an AudioParam..
Chrome Android Full support 18
Notes
Full support 18
Notes
Notes Before version 52, this was an AudioParam..
Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
releaseChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
thresholdChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

参见