I hope to learn something here since I was not able to find info in the books.
I can reinit
i-rate variables just fine, e.g. i1, i2
. However, when I’m using for example products of those i1*i2
later on, it seems those are only calculated at the init
pass and if I’m not using for example i3 = i1*i2
in the reinit
block (rather than just i1*i2
), I’m not getting an updated product. I was surprised by this since I though i-rate variables are still used at k-rate to calculate k-rate variables like k1 = i1*i2*k0
. Even more peculiar I find the behaviour of constants (C
) in k-rate calculations. The code below has 6 cases:
- no calculations with
i1
andi2
- all good (updates oni1
&i2
) - calculation
k(C)*i1*i2
- updates oni1
&i2
(why? not expected!) - calculation
C*k(i1)*i2
- updates only oni2
(not oni1
?) - calculation
C*k(i2)*i1
- updates only oni1
(does conversion prevent updates?) - calculation
C*i1*i2
- no update (almost expected) - calculation
C*i1*k(i2)
- no update (the order seems to matter?)
I’m confused by this. I hope you could help me sort this logic out. Thank you!
Change the horizontal slider to check the different cases and Freq1/Freq1
sliders to set new values to be updated in the reinit
block after pushing the Trigger
button.
bounds(0, 0, 0, 0)
<Cabbage>
form caption("Test Reinit") size(365, 125), pluginId("tri1")
rslider bounds(56, 56, 60, 60) range(1, 2, 1, 1, 0.01) channel("Freq1") text("Freq1")
rslider bounds(246, 56, 60, 60) range(1, 2, 1, 1, 0.01) channel("Freq2") text("Freq2")
hslider bounds(8, 14, 323, 30) range(1, 6, 1, 1, 1) channel("Choose")
label bounds(-12, 4, 380, 12) text("i1/i2 k(C)*i1*i2 C*k(i1)*i2 C*k(i2)*i1 C*i1*i2 C*i1*k(i2)") fontColour(255, 255, 150, 255) channel("ChooseLabel")
button bounds(142, 66, 80, 40) channel("reTrigger") latched(0) text("Re-init")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=null -M0 -m0d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 16
nchnls = 2
0dbfs = 1
instr 1
if cabbageGetValue:k("reTrigger") == 1 then
reinit reTRIGGER
endif
reTRIGGER:
iFreq1 = cabbageGetValue:i("Freq1")
iFreq2 = cabbageGetValue:i("Freq2")
iFreqOut1 = 440 * iFreq1
iFreqOut2 = 440 * iFreq2
rireturn
if cabbageGetValue:k("Choose") == 1 then
a1 poscil .01, iFreqOut1 // updates on Freq1 & Freq2
a2 poscil .01, iFreqOut2
elseif cabbageGetValue:k("Choose") == 2 then
a1 poscil .01, k(440) * iFreq1 * iFreq2 // updates on Freq1 & Freq2
a2 = a1
elseif cabbageGetValue:k("Choose") == 3 then
a1 poscil .01, 440 * k(iFreq1) * iFreq2 // updates only on Freq2
a2 = a1
elseif cabbageGetValue:k("Choose") == 4 then
a1 poscil .01, 440 * k(iFreq2) * iFreq1 // updates only on Freq1
a2 = a1
elseif cabbageGetValue:k("Choose") == 5 then
a1 poscil .01, 440 * iFreq1 * iFreq2 // no update
a2 = a1
else
a1 poscil .01, 440 * iFreq1 * k(iFreq2) // no update
a2 = a1
endif
outs a1, a2
endin
</CsInstruments>
<CsScore>
f0 z
i 1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>