I want to write a custom opcode that takes in frequency input via the cpsmidi opcode. Assuming I’m just producing a sine wave for example how would I set up the opcode to retrieve real-time midi input via cpsmidi?
If we were to strip it down to just the lines to retrieve and use the frequency info from cpsmidi (disregarding all the other things youd need to set up such as sample rate, period, etc etc) would those lines look as simple as:
// declare output var, input var for frequency, internal frequency var in data //structure
typedef struct _newopc {
OPDS h;
MYFLT *out;
MYFLT *in1;
MYFLT freq;
}newopc;
//initialize time set internal frequency var to value of input var
int new_opc_init(CSOUND *csound, newopc *p){
p->freq = *p->in1;
return OK;
}
//at performance time use frequency input to calculate and output //sinewave
int new_opc_process_audio(CSOUND *csound, newopc *p){
MYFLT freq = *p->freq;
//Now use freq in calculating sinewave output
return OK;
}
//register opcode
static OENTRY localops[] = {
{“newopc”, sizeof(newopc), 0, 7, “a”, “i”,
(SUBR) new_opc_init, (SUBR) new_opc_process_audio,}
};
LINKAGE
I ask because it seems like you would need to be continuously taking in input at performance time but I’m confused because to call cpsmidi you use an i-time variable. I want the implementation in csound to look like:
instr1
icps cpsmidi
asig myopc icps
outs asig, asig
endin
At it’s most basic level…