[Csnd] Need some help with array data opcodes

Hello everybody!

I’m still having troubles with developing a Opcode that generates a-array output and is handling it’s internal data with arrays. I can’t get my seg-faults to solve.
I’m still on Csound 6, because these opcodes need to run at a few systems where it’s not possible yet to update these do Csound7.

This is the link to the file:

I can’t get this to work:
- writing to a-array output
- handle tem data inside the opcode with arrays

Maybe someone has the time and patients to help me through this and can check what i do wrong there? I would be endlessly greatfull.

All the best,
Philipp
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        GitHub · Where software is built
Discussions of bugs and features can be posted here

- Audio Arrays:

The data is organised as blocks of ksmps MYFLTs, instead of single MYFLTs in k- and i- arrays. So you
just have to navigate the array memory with the proper offsets.

I’m not quite sure about what you want to know in your second question.

So, no ARRAYDAT involved for this?

I also thought i have to init these output arrays like this:

  /* init output arrays */
  p->n_voices = *p->n_particles;
  tabinit(csound, p->aout_x, p->n_voices);
  tabinit(csound, p->aout_y, p->n_voices);
  tabinit(csound, p->aout_z, p->n_voices);

To my second point:
i have sine parallel computation in this opcode, why i thought about saving these values for the next process cycle in a array.

I thought i need AUXCH for this and did the init like this:

  /* init value arrays */
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->x_in));
  memset(p->x_in.auxp, 0, sizeof(MYFLT)*p->n_voices);
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->y_in));
  memset(p->y_in.auxp, 0, sizeof(MYFLT)*p->n_voices);
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->z_in));
  memset(p->z_in.auxp, 0, sizeof(MYFLT)*p->n_voices);
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->x_vals));
  memset(p->x_vals.auxp, 0, sizeof(MYFLT)*p->n_voices);
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->y_vals));
  memset(p->y_vals.auxp, 0, sizeof(MYFLT)*p->n_voices);
  csound->AuxAlloc(csound, sizeof(MYFLT) * p->n_voices, &(p->z_vals));
  memset(p->z_vals.auxp, 0, sizeof(MYFLT)*p->n_voices);

But i can’t get the data correctly saved after the processing loop.

What I mean is that the data field in ARRAYDAT holds ksmps blocks for each array item, if you are using
an audio array.

If you want to put data in the AUXCH memory you’ve allocated, just use the pointer, e.g. p->x_in.auxp
to access that memory. You can then use memcpy or assignment in a loop, depending on the source
of the data. Does that make sense?

So in my struct i declare `ARRAYDAT *my_out_array;`

In my init function i allocate memory for this via
`tabinit(csound, p->my_out_array, array_size);`

In my processing function i declaring, initilizing and casting to MYFLT like this
`MYFLT my_out_array = (MYFLT*)p->my_out_array->data;

And after this i just can write to it with the right offset?

Or am i doing something wrong there?

yes, something like that:

ARRAYDAT *array;

...
tabinit(csound, p->array, size); // size in items, tabinit allocates enough memory for the array type used

...
MYFLT *array = (MYFLT *) p->array;

then

for(k = 0 ; k < size; k++) { // for each elem in array
    for(n = offset; n < nsmps; n++) { // ksmps loop
        array[k*ksmps + n] = …
    }
}

See for example how diskin does it when scaling the output (diskin2.c:1979):

    /* apply 0dBFS scale */
    for (chn = 0; chn < p->nChannels; chn++)
      for (nn = offset; nn < nsmps; nn++)
        aOut[chn*ksmps+nn] *= csound->e0dbfs;

Thanks Victor. This is clear now.

Is my take on AUXCH right?

in my struct:
AUXCH arraydata;

in my init function:
csound->AuxAlloc(csound, sizeof(MYFLT) * size_of_array, &(p->arraydata));
memset(p->arraydara.auxp, 0, sizeof(MYFLT) * size_of_array);

writing data to the array in my processing function:
MYFLT *array = (MYFLT *) p->arraydata;
for (int i = 0; i < size_of_array; i++){
   array[i] = my_value;
    }

Just a small change

MYFLT *array = (MYFLT *) p->arraydata.auxp;

Prof. Victor Lazzarini
Maynooth University
Ireland

Thanks Victor again.
But i can’t solve it. I double checked it twice, but something i am missing.
My processing function isn’t even starting. My init function is starting and finishing. hmmm. maybe someone has time to check my code?

All the best,
Philipp