|
>I' m porting some code from C to csound.
>Can anyone explain me the best way to perform with C array operations
>with zak ?
>I.e. Suppose I want translate a cycle of this kind:
>
>for(i=0;i<15;i++)
> for(j=0;j<15;j++)
> c[i][j]=a[i]*b[(i-j)%15]
>
Well, since I've done this extensivelly, maybe I can offer some help
a for loop translates to this:
ki=0
loop:
;inside the loop
;do what you gotta do
ki=ki+1
if (ki<15) kgoto loop
Of course you need a different label for each loop. For nested loops:
ki=0
loop1:
kj=0
loop2:
;inside nested loops
kj=kj+1
if (kj<15) kgoto loop2
ki=ki+1
if (ki<15) kgoto loop1
Now, arrays are more complicated. I deal with them like this:
Define start positions for each array. Careful, dont let them overlap
;float a[16], b[8], c[16][8];
iastart = 0
ibstart = iastart+16
icstart = ibstart+8
iend = icstart + 16*8
....then to read from a[5] use
kval zkr iastart+5
....and to read from c[7][3] use
kval zkr icstart+7*8+3
You have to multiply the 1st index -7- by the second dimension -8- and add
the 2nd index -3-
Now for the fearless, a 3 dimension array:
;float c[16][8][4];
(you have to set asside a 16*8*4 block in zak-space)
;reading from c[1][2][3]
kval zkr icstart+1*(8*4)+2*(4)+3
And so on...
(Note that this all assumes arrays starting at zero)
Finally the whole thing (I need to know the c array size, so assuming float
c[8][16]):
ki=0
loop1:
kj=0
loop2:
;c[i][j]=a[i]*b[(i-j)%15]
ka zkr iastart+ki
kndx=(ki-kj)-int((ki-kj)/15)*15
kb zkr ibstart+kndx
zkw ka*kb, icstart+ki*16+kj
kj=kj+1
if (kj<15) kgoto loop2
ki=ki+1
if (ki<15) kgoto loop1
(dis was just off the top of my head, hope I didnt miss any bugs)
>where the a[],b[] and c[][] are previosly declared as float.
there's only floats in csound
>How can I declare the variables and perform the task if a,b,c are
>at i_time?
use i-variables, igoto and zir/ziw
I do this kind of things 'ad nauseum' in my neural nets (the perceptron, the
back-prop morpher and the recurrent FIR network - this last one has
4-dimension arrays), and wavelet stuff. Its a drag, and must be debugged
thoroughly. I dont know how hard this array thing would be to implement, and
how useful it would be except for my useless designs
|