FX INTRODUCTION / 10 / DRAFT
Compressor: reduce loud sections
Unlike a gate, a compressor continuously controls how much loud sounds are reduced.
This article is a work in progress. The examples will be refined through listening. Run starts playback; Stop ends it. Use Apply after editing values. Stop the playing iframe before trying another one.
Listen with the built-in FX
| Setting | Meaning |
|---|---|
| threshold | Threshold (dBFS) |
| ratio | Compression ratio above the threshold |
| attack / release | Response times (seconds) |
| makeup | Output compensation (dB) |
Select none in FX Monitor to see the waveform after the built-in FX. This pass-through effect makes input and output overlap; it does not compare the signal before and after the built-in FX.
How the PCM is processed
Divide the number of decibels above the threshold by Ratio. For an input 12 dB above threshold at 4:1, the target output is 3 dB above threshold: a 9 dB gain reduction. Attack and Release mean the instantaneous output does not always match this target.
input[ch][i] is one input sample. ch identifies a left or right audio channel, not a physical FM voice. Store values carried between blocks in state. Since process cannot access outer variables, put settings in context.
Try it with liveFx
The 48000 in context.sampleRate is a placeholder. Match it to the actual output rate shown in FX Monitor. It is used to calculate times and frequencies; it does not change the browser's output sample rate.
Open in a separate Playground tab ↗
Select compressor-lab in FX Monitor to compare the input and output of this process.
- Keep makeupDb at 0 and change ratio from 1 to 4.
- Compare the input/output difference at the loud beginning and during decay.
- Compare attackMs at 1 and 80. Finally, raise makeupDb slightly to match loudness.
Scope of this example
This learning example uses simple peak detection and a hard knee. Its detection and gain smoothing do not exactly match the built-in version. It is neither a lookahead nor a brickwall limiter, so it does not guarantee peaks below the threshold.
The waveform shows changes over time; Spectrum shows the strength of frequency components. A short display window or smoothing can hide some changes. Listen while changing one setting at a time.