Compressor
#struct CompressorHow hard to squeeze a signal and how fast to react.
| Name | Type | Description |
|---|---|---|
threshold | f64 = -20 | The level in decibels above which the squeezing starts. |
ratio | f64 = 4 | How much of the excess to keep. A ratio of 4 lets a quarter of it through. |
attack | f64 = 0.005 | How many seconds to take hold once the signal goes over. |
release | f64 = 0.1 | How many seconds to let go once it comes back under. |
makeup | f64 = 0 | Decibels of gain added afterwards, to win back what the squeezing cost. |
import audio
import audio.dsp
import audio.synth
import math
func main:
mut src := synth.Tone(440.0, 0.1, 22050, synth.WaveSine)
println src.frames, src.rate
mut e := dsp.Echo(src, 0.02, 2, 0.5)
println e.frames, e.frames == src.frames + 2 * 441
println math.Abs(
audio.Sample(e, 451, 0) - (audio.Sample(src, 451, 0) + audio.Sample(src, 10, 0) * 0.5)
) < 0.001
mut rv := dsp.Reverb(src, 0.5, 0.3)
println rv.frames, audio.Peak(rv) <= 1.0
mut dry := dsp.Reverb(src, 0.5, 0.0)
println math.Abs(audio.Sample(dry, 50, 0) - audio.Sample(src, 50, 0)) < 0.0001
mut ch := dsp.Chorus(src, 0.5, 2.0, 0.5)
mut fl := dsp.Flanger(src, 0.5, 1.0, 0.5)
println ch.frames, fl.frames
println dsp.Correlation(src, ch) < 0.999, dsp.Correlation(src, fl) < 0.9999
mut tr := audio.Clone(src)
dsp.Tremolo(tr, 10.0, 1.0)
println audio.RMS(tr) < audio.RMS(src), audio.Peak(tr) <= audio.Peak(src) + 0.0001
mut dl := audio.Clone(src)
dsp.Delay(dl, 0.01, 0.5, 0.5)
println dl.frames == src.frames
k := dsp.Compressor {
threshold = -20.0,
ratio = 8.0,
attack = 0.001,
release = 0.05
}
mut hard := audio.Clone(src)
dsp.CompressorProcess(k, hard)
println audio.RMSDb(hard) < audio.RMSDb(src) - 6.0
mut hot := audio.Clone(src)
audio.Scale(hot, 4.0)
dsp.LimiterProcess(hot, -1.0)
println audio.PeakDb(hot) <= -1.0 + 0.001
mut gated := audio.Clone(src)
audio.Gain(gated, -60.0)
dsp.GateProcess(gated, -40.0, 0.001)
println audio.Peak(gated) < 0.0001
mut longer := dsp.TimeStretch(src, 2.0)
println longer.frames == src.frames * 2, longer.rate
mut up := dsp.PitchShift(src, 12.0)
println up.frames, up.rate
println dsp.DetectPitch(up, 0, 2048) > 700.0
audio.Free(src)
audio.Free(e)
audio.Free(rv)
audio.Free(dry)
audio.Free(ch)
audio.Free(fl)
audio.Free(tr)
audio.Free(dl)
audio.Free(hard)
audio.Free(hot)
audio.Free(gated)
audio.Free(longer)
audio.Free(up)
end2205 22050 3087 true true 2205 true true 2205 2205 true true true true true true true true true 22050 2205 22050 true