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.

Thanks!

//Rootnote

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)
endop
2 Likes

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.

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
hslider bounds(10,10,300,10), range(0,1,0), channel("RMS")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
0dbfs = 1

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

</CsInstruments>
<CsScore>
i 1 0 z
</CsScore>
</CsoundSynthesizer>
1 Like