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 |
浏览器兼容性
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
DynamicsCompressorNode | Chrome Full support 14 | Edge Full support Yes | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
DynamicsCompressorNode() constructor | Chrome
Full support
55
| Edge ? | Firefox Full support 53 | IE No support No | Opera Full support 42 | Safari ? | WebView Android
Full support
55
| Chrome Android
Full support
55
| Firefox Android Full support 53 | Opera Android Full support 42 | Safari iOS ? | Samsung Internet Android Full support 6.0 |
attack | Chrome Full support 14 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
knee | Chrome Full support 14 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
ratio | Chrome Full support 14 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
reduction | Chrome
Full support
14
| Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android
Full support
Yes
| Chrome Android
Full support
18
| Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
release | Chrome Full support 14 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
threshold | Chrome Full support 14 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support 15 | Safari Full support 6 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 26 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.