Csound Csound-dev Csound-tekno Search About

[Csnd] Opcode Development - working with arrays for internal data use

Date2025-01-04 18:22
FromPhilipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE>
Subject[Csnd] Opcode Development - working with arrays for internal data use
Hello everybody,

i’m sitting at a project where i need arrays for saving data inside the performance function.
I also need these arrays inside my opcode struct for saving the data between performance cycles.
These arrays don’t need to change size during the performance.
So i guess i need to set the size in the init function.

My first thought was to use ARRAYDAT types for this and allocate memory with tabinit in the init function.
But tabinit expects a pointer. But inside the struct pointers are reserved for input and output variables.

I need some help what i need for this.

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

Date2025-01-04 18:39
FromEduardo Moguillansky
SubjectRe: [Csnd] Opcode Development - working with arrays for internal data use
If you just need an internal vector to store information, csound has what's called an AUXCH, which is for such cases. The idea behind it is that you should delegate memory allocation to csound, so this takes care of such allocations

typedef struct {
    OPDS h;
    MYFLT *out;
    MYFLT *in;
    ...   
    AUXCH vec;

} MYOPCODE;

Then inside your init func:

static int32_t myopcode_init(CSOUND *csound, MYOPCODE *p) {
    size_t numitems = 2048;
    csound->AuxAlloc(csound, sizeof(MYFLT)*numitems, &(p->vec));
    memset(p->vec.auxp, 0, sizeof(MYFLT)*numitems);
    ...   
    return OK;
}

Grep for AUXCH or AuxAlloc within the csound source for more examples

On Sat, Jan 4, 2025 at 7:23 PM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote:
Hello everybody,

i’m sitting at a project where i need arrays for saving data inside the performance function.
I also need these arrays inside my opcode struct for saving the data between performance cycles.
These arrays don’t need to change size during the performance.
So i guess i need to set the size in the init function.

My first thought was to use ARRAYDAT types for this and allocate memory with tabinit in the init function.
But tabinit expects a pointer. But inside the struct pointers are reserved for input and output variables.

I need some help what i need for this.

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

Date2025-01-04 19:09
FromPhilipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Opcode Development - working with arrays for internal data use
Thanks Eduardo! This helps a lot!

I searched a little bit in the source code and i guess, i can work after init the vector like this in the process function:

MYFLT *process_vec =  (MYFLT*) p->init_vec.auxp;
process_vec[0] = my_value;

Is this right?

And a second question:
i need to set the first value of the vector to a specific value in the init function.
How can i do this?

- Philipp

> Am 04.01.2025 um 19:39 schrieb Eduardo Moguillansky :
> 
> If you just need an internal vector to store information, csound has what's called an AUXCH, which is for such cases. The idea behind it is that you should delegate memory allocation to csound, so this takes care of such allocations
> 
> typedef struct {
>     OPDS h;
>     MYFLT *out;
>     MYFLT *in;
>     ...    
>     AUXCH vec;
> 
> } MYOPCODE;
> 
> Then inside your init func:
> 
> static int32_t myopcode_init(CSOUND *csound, MYOPCODE *p) {
>     size_t numitems = 2048;
>     csound->AuxAlloc(csound, sizeof(MYFLT)*numitems, &(p->vec));
>     memset(p->vec.auxp, 0, sizeof(MYFLT)*numitems);
>     ...    
>     return OK;
> }
> 
> Grep for AUXCH or AuxAlloc within the csound source for more examples
> 
> On Sat, Jan 4, 2025 at 7:23 PM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote:
> Hello everybody,
> 
> i’m sitting at a project where i need arrays for saving data inside the performance function.
> I also need these arrays inside my opcode struct for saving the data between performance cycles.
> These arrays don’t need to change size during the performance.
> So i guess i need to set the size in the init function.
> 
> My first thought was to use ARRAYDAT types for this and allocate memory with tabinit in the init function.
> But tabinit expects a pointer. But inside the struct pointers are reserved for input and output variables.
> 
> I need some help what i need for this.
> 
> - Philipp
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

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

Date2025-01-04 19:59
FromPhilipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Opcode Development - working with arrays for internal data use
ah, i think i found the solution.

i can do a cast to a MYFLT and just handle it like a MYFLT vector

> Am 04.01.2025 um 20:09 schrieb Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE>:
> 
> Thanks Eduardo! This helps a lot!
> 
> I searched a little bit in the source code and i guess, i can work after init the vector like this in the process function:
> 
> MYFLT *process_vec =  (MYFLT*) p->init_vec.auxp;
> process_vec[0] = my_value;
> 
> Is this right?
> 
> And a second question:
> i need to set the first value of the vector to a specific value in the init function.
> How can i do this?
> 
> - Philipp
> 
>> Am 04.01.2025 um 19:39 schrieb Eduardo Moguillansky :
>> 
>> If you just need an internal vector to store information, csound has what's called an AUXCH, which is for such cases. The idea behind it is that you should delegate memory allocation to csound, so this takes care of such allocations
>> 
>> typedef struct {
>>    OPDS h;
>>    MYFLT *out;
>>    MYFLT *in;
>>    ...    
>>    AUXCH vec;
>> 
>> } MYOPCODE;
>> 
>> Then inside your init func:
>> 
>> static int32_t myopcode_init(CSOUND *csound, MYOPCODE *p) {
>>    size_t numitems = 2048;
>>    csound->AuxAlloc(csound, sizeof(MYFLT)*numitems, &(p->vec));
>>    memset(p->vec.auxp, 0, sizeof(MYFLT)*numitems);
>>    ...    
>>    return OK;
>> }
>> 
>> Grep for AUXCH or AuxAlloc within the csound source for more examples
>> 
>> On Sat, Jan 4, 2025 at 7:23 PM Philipp Neumann <0000119f78f3a4f9-dmarc-request@listserv.heanet.ie> wrote:
>> Hello everybody,
>> 
>> i’m sitting at a project where i need arrays for saving data inside the performance function.
>> I also need these arrays inside my opcode struct for saving the data between performance cycles.
>> These arrays don’t need to change size during the performance.
>> So i guess i need to set the size in the init function.
>> 
>> My first thought was to use ARRAYDAT types for this and allocate memory with tabinit in the init function.
>> But tabinit expects a pointer. But inside the struct pointers are reserved for input and output variables.
>> 
>> I need some help what i need for this.
>> 
>> - Philipp
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>        https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> 

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