Cabbage Logo
Back to Cabbage Site

Delay effect feedback

I have some code below to create an echo ping pong delay the effect I’ve generated creates a stereo ping pong delay but only while the midi note is on how do I change this to get the delay to gradually fade away even after the note has been released :thinking: the effect seems to provide some sort of stereo widening which although I do want in the future is not the exact effect I am looking to get now I am looking to get a standard vst delay type effect that you would find on most vst subtractive synths in the effect mods am I possibly missing something in the score :face_with_monocle:

instr 1

aEnv     expon   1, 0.2, 0.001

aIn      poscil  aEnv, 440



kTime    =       0.2    ; delay time



kFB      =       0.8    ; feedback ratio

iMaxTime =       4



aInDel   vdelay  aIn, a(kTime)*1000, iMaxTime*1000



aBufL    delayr  iMaxTime

aTapL    deltapi a(kTime) * 2 ; n.b. delay time doubled

         delayw  aIn + (aTapL * kFB)



aBufR    delayr  iMaxTime

aTapR    deltapi a(kTime) * 2

         delayw  aInDel + (aTapR * kFB)

         

         outs    aIn + aTapL, aIn + aTapR + aInDel

endin

In my code the variable aIn is nowhere as simple it’s a modified vco2 it passed through a gain then a moogladder followed by butterhp then that signal aIn is used in this delay code I’m trying to create :+1:

One way to do it is with a madsr opcode. It’s kind of a hack, but if you add the following line of code you your instrument it will cause it to take 10 second before it’s fully released, thus giving your delay enough time to fade out.

kDummy madsr 1, 1, 1, 10

It’s kind of a hack because you’re not actually using the envelope for anything other than extending the note.

Oh, I just thought of a more Csound-esque way to do this. I should really delete my previous advice, but hey. So just use the xtratim opcode. Simply add the following line of code to your instrument block:

xtratim 10

You can replace the 10 with however long you want your synth to play for.

Alternatively you can put the delay in a separate, always on, instrument so that echoes will always decay to silence. Audio is sent from instr 1 to instr 2 using channels. Here’s the complete code for a Cabbage synth:

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
aEnv     expon   1, 0.2, 0.001
aIn      poscil  aEnv*p5, p4
         chnmix  aIn, "Send"
endin

instr 2
aIn      chnget  "Send"
         chnclear "Send"
kTime    =       0.2    ; delay time
kFB      =       0.8    ; feedback ratio
iMaxTime =       4

aInDel   vdelay  aIn, a(kTime)*1000, iMaxTime*1000

aBufL    delayr  iMaxTime
aTapL    deltapi a(kTime) * 2 ; n.b. delay time doubled
         delayw  aIn + (aTapL * kFB)

aBufR    delayr  iMaxTime
aTapR    deltapi a(kTime) * 2
         delayw  aInDel + (aTapR * kFB)

         outs    aIn + aTapL, aIn + aTapR + aInDel
endin

</CsInstruments>
<CsScore>
i 2 0 z
</CsScore>
</CsoundSynthesizer>

Absolutely brilliant exactly what I was hoping for :+1: to toggle from zero feedback to max which parameters would I need to control with a widget

I’ve had ago with both k variables but there is still one buffer of feedback

Here is the same code with some controls added. I’m not sure if this is exactly what way you want this to work but here is my suggestion. Changes to delay time have a lag applied so you get pitch warping effects when it is altered. There is a special switch so that when feedback is zero you get a single echo in the left and the right channels according to the ping-pong effect.

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
rslider bounds(5,5,50,70), channel("InGain"), text("In Gain"), range(0,1,1)
rslider bounds(65,5,50,70), channel("DelayTime"), text("Time"), range(0.1,2,0.2)
rslider bounds(125,5,50,70), channel("Feedback"), text("Feedback"), range(0, 1, 0.8)
rslider bounds(185,5,50,70), channel("FXLevel"), text("FX Level"), range(0, 1, 1)
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
aEnv     expon   1, 0.2, 0.001
aIn      poscil  aEnv*p5, p4
         chnmix  aIn, "Send"
endin

instr 2
aIn      chnget  "Send"
         chnclear "Send"
kTime    chnget  "DelayTime" ; delay time
kPortTime linseg   0, 0.01, 0.1
kTime    portk   kTime, kPortTime
kFB      chnget  "Feedback"  ; feedback ratio
iMaxTime =       4

aInDel   vdelay  aIn, a(kTime)*1000, iMaxTime*1000

aBufL    delayr  iMaxTime
aTapL    deltapi a(kTime) * 2 ; n.b. delay time doubled
         delayw  aIn + (aTapL * kFB)

aBufR    delayr  iMaxTime
aTapR    deltapi a(kTime) * 2
         delayw  aInDel + (aTapR * kFB)

kFXLevel chnget "FXLevel"

         outs    aIn + (aTapL * kFXLevel), aIn + (((aTapR * ceil(kFB)) + aInDel) * kFXLevel) 
endin

</CsInstruments>
<CsScore>
i 2 0 z
</CsScore>
</CsoundSynthesizer>