Skip to content

Instantly share code, notes, and snippets.

@jacobjoaquin
Created April 29, 2012 14:02
Show Gist options
  • Save jacobjoaquin/2550583 to your computer and use it in GitHub Desktop.
Save jacobjoaquin/2550583 to your computer and use it in GitHub Desktop.
first Csound opcode
#include "csdl.h"
#include "jakesine.h"
int jakesine_init (CSOUND *csound, JAKESINE *p)
{
p->inc = *p->freq_in * csound->tpidsr;
p->phase = *p->phase_in * TWOPI;
return OK;
}
int jakesine_perf (CSOUND *csound, JAKESINE *p)
{
int n = csound->ksmps;
MYFLT *audio = p->audio_out;
MYFLT amp = *p->amp_in;
MYFLT *phase = &p->phase;
MYFLT inc = p->inc;
do {
*audio++ = amp * sin(*phase);
*phase += inc;
} while (--n);
return OK;
}
static OENTRY localops[] = {
{"jakesine", sizeof(JAKESINE), 5, "a", "iii", (SUBR)jakesine_init, (SUBR)NULL, (SUBR)jakesine_perf},
};
LINKAGE
#include "csdl.h"
typedef struct
{
OPDS h;
MYFLT *audio_out, *amp_in, *freq_in, *phase_in;
MYFLT inc, phase;
} JAKESINE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment