Cabbage Logo
Back to Cabbage Site

Loop_lt in audio array

Just trying to work out how to multiplex (iterate) multiple oscillators into an array using loop_lt:

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

gaArr[]                     init        3 ;make global audio array

instr 1
kEnv                        madsr       .1, .2, .6, .4
iNdx                        init        0 
loop:
                            prints      "play instance %d\\n", int(iNdx)
gaArr[int(iNdx)]            oscil       p5, p4 + (1000*int(iNdx))
                    
                            loop_lt     iNdx,   1,  3,  loop

                            out (gaArr[0]+gaArr[1]+gaArr[2])/3*kEnv
                            endin

Currently I can only hear the last gaArr[2] oscillator?

Solved my own question:

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

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

                    opcode      synth, a, akkpp
                    
ain, kamp, kcps, idep, icnt    xin
                    if (icnt >= idep) goto skip1
                    increment = icnt + 1
ain                 synth       ain, kamp, kcps, idep, increment
skip1:
aout                oscil       kamp, kcps + increment *1000
aoutnew = aout + ain
                    xout aoutnew /2

                    
                    endop

instr 1

kamp                =           p5
kcps                =           p4

kEnv                madsr       .1, .2, .6, .4
a1 init 0
aout                  synth       a1, kamp, kcps, 3
                    

                    out aout*kEnv
                    endin

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

Apparently loop_lt can not iterate opcodes, and opcodes can’t be interated without using custom opcodes with an audio input.

If anyone can edit the syntax to make it better I would be really thankful! :slight_smile: