Cabbage Logo
Back to Cabbage Site

Trouble with global reverb in Cabbage?

Hi everyone, I’m doing some work with cabbage and I’m having trouble getting my reverb to work and cannot figure out what I’m missing/doing incorrectly.

I’ve instantiated my global variables and routed my sends, I think correctly… Yet I can’t get my reverb instrument to play? I can’t spot whatever I’m missing, or probably routing incorrectly.
So far, my audio plays correctly! But alas, no FX.

Maybe a second pair of eyes can help me out?

   <Cabbage> bounds(0, 0, 0, 0)
form caption("Simple Synth") size(650, 300), colour(255, 255, 255), guiMode("queue"), pluginID("def1")
keyboard bounds(18, 170, 568, 121)
rslider bounds(308, 82, 70, 70), channel("att"), range(0, 1, 0.01, 1, 0.01), text("Attack") textColour(0, 0, 0, 255)
rslider bounds(388, 82, 70, 70), channel("dec"), range(0, 1, 0.5, 1, 0.01), text("Decay") textColour(0, 0, 0, 255)
rslider bounds(458, 82, 70, 70), channel("sus"), range(0, 1, 0.5, 1, 0.01), text("Sustain") textColour(0, 0, 0, 255)
rslider bounds(530, 82, 70, 70), channel("rel"), range(0, 1, 0.7, 1, 0.01), text("Release") textColour(0, 0, 0, 255)
rslider bounds(462, 10, 70, 70), channel("cutoff"), range(0, 22000, 2000, 0.5, 0.01), text("Cut-Off") textColour(0, 0, 0, 255)
rslider bounds(532, 10, 70, 70), channel("res"), range(0, 1, 0.7, 1, 0.01), text("Resonance") textColour(0, 0, 0, 255)
rslider bounds(8, 84, 70, 70), channel("LFOFreq"), range(0, 10, 0, 1, 0.01), text("LFO Freq") textColour(0, 0, 0, 255)
rslider bounds(595, 215, 51, 59), channel("amp"), range(0, 1, 0.7, 1, 0.01), text("Gain") textColour(0, 0, 0, 255)
rslider bounds(4, 6, 60, 60) channel("RvbMix") range(0, 1, 0, 1, 0.001) text("Reverb") fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
rslider bounds(68, 6, 60, 60) channel("RvbSize") range(0, 1, 0, 1, 0.001) text("Size") fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)






;Preset Box
combobox bounds(208, 8, 100, 25), populate("*.snaps"), channel("combo1") channelType("string") value("0.0") automatable(0)
filebutton bounds(146, 8, 60, 25), text("Save", "Save"), populate("*.snaps"),mode("named preset") channel("filebutton1") 
filebutton bounds(312, 8, 60, 25), text("Remove", "Remove"), populate("*.snaps", "test"), mode("remove preset") channel("filebutton6")
;VU
vmeter bounds(610, 10, 12, 162) channel("vu1")  outlineColour(0, 0, 0, 255), overlayColour(0, 0, 0, 255) meterColour:0(255, 0, 0, 255) meterColour:1(255, 255, 0, 255) meterColour:2(0, 255, 0, 255)
vmeter bounds(628, 12, 12, 160) channel("vu2") value(0) outlineColour(0, 0, 0), overlayColour(0, 0, 0) meterColour:0(255, 0, 0) meterColour:1(255, 255, 0) meterColour:2(0, 255, 0) outlineThickness(1) 


</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>



; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

gaSendL, gaSendR    init      0 ; global reverb audio is init on start 

gkRvbMix chnget "RvbMix" ;Reverb Send Amount (0-1) obtaining value from chan. "RvbMix"

cabbageSetValue "RvbMix", 0.8
cabbageSetValue "RvbSize", 0.6
cabbageSetValue "amp", 0.5
;......................................... INIT Param values set.

;instrument will be triggered by keyboard widget
instr 1
iFreq = p4
iAmp = p5

gkAmp chnget "amp"

gkRvbSize    chnget    "RvbSize" 

iAtt chnget "att"
iDec chnget "dec"
iSus chnget "sus"
iRel chnget "rel"
kRes chnget "res"
kCutOff chnget "cutoff"
kLFOFreq chnget "LFOFreq"
;......................................... Obtaining values from channels


kEnv madsr iAtt, iDec, iSus, iRel 
aOut vco2 iAmp, iFreq
kLFO lfo 1, kLFOFreq, 5
aLP moogladder aOut, kLFO*kCutOff, kRes

asig = aLP*kEnv
aL = asig
aR = asig

outs aL * gkAmp, aR * gkAmp

  
   ;feeding meters starts here
   k1 rms asig * gkAmp, 30
   k2 rms asig * gkAmp , 30
    
    gaSendL        =         gaSendL + aL
    gaSendR        =         gaSendR + aR
   
    cabbageSetValue "vu1", portk(k1*10, .25), metro(10)
    cabbageSetValue "vu2", portk(k2*10, .25), metro(10)
    
    
endin

instr    99    ;reverb

  
    a2L, a2R    reverbsc    gaSendL, gaSendR, .8, 12000
        outs        a2L * gkRvbMix, a2R * gkRvbMix
        clear        gaSendL,gaSendR
endin




</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
i 99 0 60000

</CsoundSynthesizer>

That’s the problem. You’re not actually starting i99, because it’s not within the CsScore section. That took me some time :rofl Btw, I find it easier to use channels than global variables. I find it makes things a little easier to read. Here is your code again, but this time I use channels rather than global variables. Channels are more or less global as they can be accessed from any instrument.

   <Cabbage> bounds(0, 0, 0, 0)
form caption("Simple Synth") size(650, 300), colour(255, 255, 255), guiMode("queue"), pluginID("def1")
keyboard bounds(18, 170, 568, 121)
rslider bounds(308, 82, 70, 70), channel("att"), range(0, 1, 0.01, 1, 0.01), text("Attack") textColour(0, 0, 0, 255)
rslider bounds(388, 82, 70, 70), channel("dec"), range(0, 1, 0.5, 1, 0.01), text("Decay") textColour(0, 0, 0, 255)
rslider bounds(458, 82, 70, 70), channel("sus"), range(0, 1, 0.5, 1, 0.01), text("Sustain") textColour(0, 0, 0, 255)
rslider bounds(530, 82, 70, 70), channel("rel"), range(0, 1, 0.7, 1, 0.01), text("Release") textColour(0, 0, 0, 255)
rslider bounds(462, 10, 70, 70), channel("cutoff"), range(0, 22000, 2000, 0.5, 0.01), text("Cut-Off") textColour(0, 0, 0, 255)
rslider bounds(532, 10, 70, 70), channel("res"), range(0, 1, 0.7, 1, 0.01), text("Resonance") textColour(0, 0, 0, 255)
rslider bounds(8, 84, 70, 70), channel("LFOFreq"), range(0, 10, 0, 1, 0.01), text("LFO Freq") textColour(0, 0, 0, 255)
rslider bounds(595, 215, 51, 59), channel("amp"), range(0, 1, 0.7, 1, 0.01), text("Gain") textColour(0, 0, 0, 255)
rslider bounds(4, 6, 60, 60) channel("RvbMix") range(0, 1, 0, 1, 0.001) text("Reverb") fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
rslider bounds(68, 6, 60, 60) channel("RvbSize") range(0, 1, 0, 1, 0.001) text("Size") fontColour(0, 0, 0, 255) textColour(0, 0, 0, 255)
;Preset Box
combobox bounds(208, 8, 100, 25), populate("*.snaps"), channel("combo1") channelType("string") value("0.0") automatable(0)
filebutton bounds(146, 8, 60, 25), text("Save", "Save"), populate("*.snaps"),mode("named preset") channel("filebutton1") 
filebutton bounds(312, 8, 60, 25), text("Remove", "Remove"), populate("*.snaps", "test"), mode("remove preset") channel("filebutton6")
;VU
vmeter bounds(610, 10, 12, 162) channel("vu1")  outlineColour(0, 0, 0, 255), overlayColour(0, 0, 0, 255) meterColour:0(255, 0, 0, 255) meterColour:1(255, 255, 0, 255) meterColour:2(0, 255, 0, 255)
vmeter bounds(628, 12, 12, 160) channel("vu2") value(0) outlineColour(0, 0, 0), overlayColour(0, 0, 0) meterColour:0(255, 0, 0) meterColour:1(255, 255, 0) meterColour:2(0, 255, 0) outlineThickness(1) 

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

cabbageSetValue "RvbMix", 0.8
cabbageSetValue "RvbSize", 0.6
cabbageSetValue "amp", 0.5
;......................................... INIT Param values set.

;instrument will be triggered by keyboard widget
instr 1
    iFreq = p4
    iAmp = p5

    gkAmp chnget "amp"
    iAtt chnget "att"
    iDec chnget "dec"
    iSus chnget "sus"
    iRel chnget "rel"
    kRes chnget "res"
    kCutOff chnget "cutoff"
    kLFOFreq chnget "LFOFreq"
    ;......................................... Obtaining values from channels


    kEnv madsr iAtt, iDec, iSus, iRel 
    aOut vco2 iAmp, iFreq
    kLFO lfo 1, kLFOFreq, 5
    aLP moogladder aOut, kLFO*kCutOff, kRes

    asig = aLP*kEnv
    aL = asig
    aR = asig

    ;outs aL * gkAmp, aR * gkAmp
    chnset aL, "outL"
    chnset aR, "outR"
    
    ;feeding meters starts here
    k1 rms asig * gkAmp, 30
    k2 rms asig * gkAmp , 30

    cabbageSetValue "vu1", portk(k1*10, .25), metro(10)
    cabbageSetValue "vu2", portk(k2*10, .25), metro(10)    
endin


instr    99    ;reverb

    aL chnget "outL"
    aR chnget "outR"
    a2L, a2R    reverbsc    aL, aR, chnget:k("RvbSize"), 12000
    outs        a2L, a2R
    
    chnclear "outL"
    chnclear "outR"
endin


</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i 99 0 60000
</CsScore>
</CsoundSynthesizer>

Hm! oof, totally missed that it wasn’t in the score section.
Tried moving it and still doesn’t work unfortunately, makes me think it might be something about how I’m instantiating my glob variables??

I also tried your version with channels instead of globals and I’m not getting any audio out :c, meters are being fed tho! Which points to a signal definitely being there… and I’m SO puzzled :sweat_smile:

Thanks for all your help!

You need to increase the reverb size I think? Also, I commented out the main outputs for instr 1, you probably want to uncomment those.

Right, in your original code you have this:

gkRvbMix chnget "RvbMix" ;Reverb Send Amount (0-1) obtaining value from chan. "RvbMix"

There is no point in using k-rate opcodes in the header section. This is called instr 0 space in Csound parlance, and it’s for i-rate functions only. Just move this inside the reverb instrument. Here’s your code again with this change. Note that it’s easier to set the default value when declaring your widgets, rather than calling cabbageSetValue in the instr 0 space.

1 Like