Cabbage Logo
Back to Cabbage Site

Envelope follower without opcode

Hi everyone,

Does anyone has some ideas how I could implement an envelope follower like rms or follow2 opcode but as csound code. I aim to have different shapes for the curves of attack and release, since the ones in those opcodes are pretty linear/standard.



I’m not too well versed in how they are implemented, but to access the amplitude values, it’s as simple as:

opcode AmpFollow, a,k
    setKsmps 1
    aSig zin
    xout k(aSig)

You can start with implementing the root mean square and applying some sort of simple smoothing filter. Augmentations thereafter might be flipping the filter cutoff value depending on whether the envelope is rising or falling. All values could then be mapped through a transfer function to create any attack/release shape you want.

form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
hslider bounds(10,10,300,10), range(0,1,0), channel("RMS")
-n -d
0dbfs = 1

instr 1
aIn inch 1
aRMS = tone:a(sqrt(aIn^2),2)
cabbageSetValue "RMS", k(aRMS)
    outs  aIn, aIn

i 1 0 z
1 Like