Cabbage Logo
Back to Cabbage Site

Iterative additive synth

Hello,

I recently moved from Csound to Cabbage (but still pretty new to Csound) and I’m trying to reproduce my additive synths using a master instr.

The problem is : the schedule opcode assigns a p3 value to the sub-instr and I can’t hold my notes anymore (like in the Cabbage synth template with vco2). How could I get rid of that fixed p3 ?
Thank you !

I tried using recursion (which is a solution), but I like to reschedule many two or three times the partial groups and I can’t imagine doing multiple loops in recursion.
Also, I don’t want to do additive synthesis manually because I’m generating a lot of partials.

Here is a very simplified version so that it is understandable :

form caption(“Untitled”) size(400, 300), guiMode(“queue”), pluginId(“def1”)
keyboard bounds(8, 158, 381, 95)

-n -d -+rtmidi=NULL -M0

ksmps = 1
nchnls = 2
0dbfs = 1

gisin = ftgen(0, 0, 16384, 10, 1)

instr 1

idur = 1 // fixed p3, can't hold my notes anymore

inum = 1
imax = 5
while inum < imax do
    schedule(10, 0, idur, inum)
    inum += 1
od

endin

instr 10

aamp = 0.125
afrq = 220 * p4

a0 poscil3 aamp, afrq, gisin, 0

chnmix a0, "m0"

endin

instr 9

a0 chnget "m0"
outs a0, a0
chnclear "m0"

endin

f 0 z
i 9 0 3600

(don’t know why blockquote hides the < … > parts, but it’s there)

I made some additions to your code. Here are the key points:
Schedule instr 10 to play really long notes but turn them off when the MIDI-triggered parent note is released.
You can use release to sense when a note has been released.
Using fractional p1 values for note events allows you to keep track of polyphonic voices.
turnoff2 allows you to turn off notes in other instruments that match a given fractional p1 value.

<Cabbage>
form caption(“Untitled”) size(400, 300), guiMode(“queue”), pluginId(“def1”)
keyboard bounds(8, 158, 381, 95)
</Cabbage>

<CsoundSynthesizer>
<CsOptions>
-n -dm0 -+rtmidi=NULL -M0
</CsOptions>

<CsInstruments>

ksmps = 1
nchnls = 2
0dbfs = 1

gisin = ftgen(0, 0, 16384, 10, 1)


instr 1

;idur = 1 // fixed p3, can't hold my notes anymore


iNotNum notnum
inum = 1
imax = 5
while inum < imax do
    schedule(10+(iNotNum*0.001), 0, 3600, cpsmidinn(iNotNum)*inum)

    inum += 1
od

    
    kflag release
    printk2 kflag
    if release:k()==1 then
    turnoff2 10+(iNotNum*0.001),4,1
    endif



endin

instr 10

aamp = 0.125
afrq = p4

a0 poscil3 aamp, afrq, gisin, 0

chnmix a0, "m0"
endin

instr 9
a0 chnget "m0"
outs a0, a0
chnclear "m0"
endin

</CsInstruments>

<CsScore>
f 0 z
i 9 0 3600
</CsScore>
</CsoundSynthesizer>

Ooooh I get it. Thanks a lot ! This is very helpful, I was stuck for a few days :pray: