[Csnd] Question about accumulation of audio variables

Hello everyone,

Probably I am doing a very trivial mistake, but I cannot spot it.

What's wrong with the accumulation in the following code? I am trying to do some modal synthesis by accumulating the outputs of several resonators in parallel.

instr 1

    // some init
    aIn1 inch 1 // input left
    aIn2 inch 2 // input right

    aOut1 init 0 // output left
    aOut2 init 0 // output right

    iCount = some value (the number of modal resonances)

    iFreq[] init iCount // the vector holding the resonance frequencies

    // the iFreq array is then instantiated (omitted here)

    .

    .

    kBw = some value...

    // then the filter bank is calculated

    index = 0

    loop:
            aTmpL resonz aIn1, iFreq[index], kBw
            aOut1 += aTmpL
          
            aTmpR resonz aIn2, iFreq[index], kBw
            aOut2 += aTmpR
   
    loop_lt index, 1, iCount, loop
       
    outs aOut1, aOut2

endin

The calculated output is only the last resonance plus a fixed signal, unrelated with the requested resonances.

I also tried using global variables gaOut1 and gaOut2, initializing them outside the instrument definition, and clearing them after the output assignment, but with the same result. If I avoid to use the loop, by explicitly adding the resonator outputs, everything is working (but it is not what I am looking for, since I need the number of resonances to be parametric).

Thank you in advance for your help.
Massimiliano

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

The issue is using i-rate variables for your loop_lt, so the loop only
runs during init-time. Try changing to a k-rate kindex. You might also
look at using while-loops instead of loop_lt.