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
是
AudioNode
that has exactly one input and one output; it is created using the
AudioContext.createDynamicsCompressor()
方法。
| 输入数 |
1
|
|---|---|
| 输出数 |
1
|
| 通道计数模式 |
"clamped-max"
|
| 通道计数 |
2
|
| 通道解释 |
"speakers"
|
DynamicsCompressorNode()
DynamicsCompressorNode
对象。
继承的特性来自其父级,
AudioNode
.
DynamicsCompressorNode.threshold
只读
AudioParam
representing the decibel value above which the compression will start taking effect.
DynamicsCompressorNode.knee
只读
AudioParam
containing a decibel value representing the range above the threshold where the curve smoothly transitions to the compressed portion.
DynamicsCompressorNode.ratio
只读
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
只读
AudioParam
representing the amount of time, in seconds, required to reduce the gain by 10 dB.
DynamicsCompressorNode.release
只读
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);
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'DynamicsCompressorNode' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | Edge ≤79 | Firefox 53 | IE 不支持 No | Opera 42 | Safari ? |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 53 | Opera Android 42 | Safari iOS ? |
Samsung Internet Android
6.0
注意事项
|
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
注意事项
|
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
注意事项
|
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 |
完整支持
不支持
兼容性未知
见实现注意事项。
DynamicsCompressorNode
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode