Cabbage Logo
Back to Cabbage Site

Attack, release shapes compressor

Hi everyone,

Do you see a possibility to add custom attack and release curves to a compressor opcode or any other way to realise that?

I want to match curves from different compressors.

Thanks!

//Rootnote

sorry @rootnote, I’ve no idea as I’ve never used any of the compressors in Csound. Maybe you can roll your own compressor to do this?

Hi.
If you use follow as the envelope follower, you can roll your own compressor with separate control of attack and release times. Then, to control the shape of each segment, you can run it through a pow opcode. Writing this on my phone, so I don’t have full examples from my teaching at hand. Can supply those later if you need them :wink:
Øyvind

1 Like

Meant follow2 due envelope follower. Autocorrect ate the '2’:joy:

@Oeyvind that would be fantastic!!! Thanks

Here’s a compressor that uses follow2 as the envelope follower. I have not used shaping on the envelope, but IIRC follow2 is roughly exponential. I think you will get most things done with just adjusting the attack and release times.

<CsoundSynthesizer>
<CsOptions>
;-odac0 -b1024 -B2048    ; realtime audio out
-ocompressor3.wav      ; output to audio file
</CsOptions>
<CsInstruments>

  sr = 48000
  ksmps = 64
  nchnls = 2
  0dbfs = 1

;***************************************************
;ftables
;***************************************************

  giSample2  ftgen  0, 0, 0, 1, "MoodySlide2_110.wav", 0, 0, 0

;***************************************************
; Simple Compressor, ratio expressed in dB,
; lookahead time in milliseconds.
; Using envelope follower instead of simple amplitude tracking, so we can adjust attack and release time separately
;***************************************************
instr 2

 iamp = ampdbfs(p4) ; Amp in -dB
 kthresh = p5 ; compression threshold
 kratio = p6 ; compression ratio
 kattack = p7 ; attack time
 krelease = p8 ; release time

; audio generator
 aenv linseg 0,0.0001, 1, 1, 1, 0.1, 0.2, 1, 0.2, 1, 0
 a1 loscil iamp, 1, giSample2, 1 ; test sample

; compressor
 arms follow2 a1, kattack/1000, krelease/1000 ; envelope follower
 karms downsamp arms ; workaround for dbfsamp (should take a-rate input)
 arms_dB = upsamp(dbfsamp(karms)) ; convert to dB scale and upsample
 aovershoot = arms_dB - kthresh ; how much over the threshold are we?
 atarget = kthresh + (aovershoot*(1/kratio)) ; target output level (with current input level, threshold and ratio)
 ampMod_dB = atarget - arms_dB ; difference from target = adjust amount
 ampMod_dB limit ampMod_dB, -150, 0 ; do not adjust unless negative
 ampMod = ampdbfs(ampMod_dB) ; convert back to normalized scale
 acomp = a1*ampMod ; apply amplitude modification

; audio out
 outs acomp, acomp
endin
;***************************************************


</CsInstruments>
<CsScore>

;compression
;   start  dur  amp  thresh  ratio   attack  release
i2  0  3  0  -20  8  60  100
i2  ^+4  3  0  -20  8  15  100
i2  ^+4  3  0  -20  8  2  20
i2  ^+4  3  0  -20  8  30  20
i2  ^+4  3  0  -20  8  60  20
</CsScore>
</CsoundSynthesizer>
1 Like

@Oeyvind thank you very very much for that!!