int t_pitchamdf(sp_test *tst, sp_data *sp, const char *hash) { uint32_t n; int fail = 0; SPFLOAT freq = 0, amp = 0, blsaw = 0, randh = 0, osc = 0; sp_srand(sp, 1234567); UserData ud; sp_pitchamdf_create(&ud.pitchamdf); sp_osc_create(&ud.osc); sp_ftbl_create(sp, &ud.ft, 2048); sp_blsaw_create(&ud.blsaw); sp_randh_create(&ud.randh); sp_pitchamdf_init(sp, ud.pitchamdf, 200, 500); sp_randh_init(sp, ud.randh); ud.randh->max = 500; ud.randh->min = 200; ud.randh->freq = 6; sp_blsaw_init(sp, ud.blsaw); sp_gen_sine(sp, ud.ft); sp_osc_init(sp, ud.osc, ud.ft, 0); for(n = 0; n < tst->size; n++) { freq = 0, amp = 0, blsaw = 0, randh = 0, osc = 0; sp_randh_compute(sp, ud.randh, NULL, &randh); *ud.blsaw->freq = randh; sp_blsaw_compute(sp, ud.blsaw, NULL, &blsaw); sp_pitchamdf_compute(sp, ud.pitchamdf, &blsaw, &freq, &); ud.osc->freq = freq; sp_osc_compute(sp, ud.osc, NULL, &osc); sp_test_add_sample(tst, osc); } fail = sp_test_verify(tst, hash); sp_blsaw_destroy(&ud.blsaw); sp_randh_destroy(&ud.randh); sp_pitchamdf_destroy(&ud.pitchamdf); sp_ftbl_destroy(&ud.ft); sp_osc_destroy(&ud.osc); if(fail) return SP_NOT_OK; else return SP_OK; }
int chord_cloud_compute(sp_data *sp, chord_cloud *cc, SPFLOAT *in, SPFLOAT *out) { int i; SPFLOAT dust = 0, osc = 0, env = 0, tmp = 0, dummy; for(i = 0; i < cc->notes->size; i++) { chord_grain *grain = &cc->grains[i]; sp_dust_compute(sp, grain->dust, NULL, &dust); sp_tenv_compute(sp, grain->env, &dust, &env); sp_osc_compute(sp, grain->osc, NULL, &osc); sp_tevent_compute(sp, grain->retrig, &dust, &dummy); tmp += osc * env * cc->ampmax * grain->amp; } *out = tmp; return SP_OK; }
void write_clip(sp_data *sp, void *ud) { UserData *udp = ud; SPFLOAT out, osc, filt; if(sp->pos < (44100 * 2)) { sp_osc_compute(sp, udp->osc, NULL, &osc); sp_moogladder_compute(sp, udp->filt, &osc, &filt); sp->out[0] = filt; return; } else if(sp->pos >= (44100 * 2) && sp->pos < (44100 * 3)) { udp->clp->meth = 0; } else if(sp->pos >= (44100 * 3) && sp->pos < (44100 * 4)) { udp->clp->meth = 1; udp->clp->lim = 0.2; } else { udp->clp->meth = 2; udp->clp->lim = 0.03; } sp_osc_compute(sp, udp->osc, NULL, &osc); sp_moogladder_compute(sp, udp->filt, &osc, &filt); sp_clip_compute(sp, udp->clp, &filt, &out); sp->out[0] = out; }
void write_osc(sp_data *data, void *ud) { udata *udp = ud; SPFLOAT env = 0; SPFLOAT osc = 0; SPFLOAT rv = 0; SPFLOAT dry = 0; SPFLOAT trig; if(data->pos == 0){ trig = 1.0; }else{ trig = 0.0; } sp_tenv_compute(data, udp->tenv, &trig, &env); sp_osc_compute(data, udp->osc, NULL, &osc); dry = osc * env; sp_reverse_compute(data, udp->rv, &dry, &rv); data->out[0] = dry + rv; }
void write_osc(sp_data *sp, void *udata) { UserData *ud = udata; SPFLOAT env = 0; SPFLOAT osc = 0; SPFLOAT dry = 0; SPFLOAT trig; SPFLOAT dtrig = 0; SPFLOAT note = 0; if(sp->pos == 0){ trig = 1.0; }else{ trig = 0.0; } sp_dtrig_compute(sp, ud->dt, &trig, &dtrig); sp_tseq_compute(sp, ud->seq, &dtrig, ¬e); ud->osc->freq = sp_midi2cps(note + 24); env = 1.0; sp_tenv_compute(sp, ud->tenv, &dtrig, &env); sp_osc_compute(sp, ud->osc, NULL, &osc); sp->out[0] = osc * env; }
int t_tseg(sp_test *tst, sp_data *sp, const char *hash) { uint32_t n; int fail = 0; sp_srand(sp, 1234567); UserData ud; SPFLOAT osc = 0, tseg = 0; SPFLOAT trig = (sp->pos == 0); sp_tseg_create(&ud.tseg); sp_osc_create(&ud.osc); sp_ftbl_create(sp, &ud.ft, 2048); sp_tseg_init(sp, ud.tseg, 0.0001); ud.tseg->end = 1.0; ud.tseg->type = 3.0; ud.tseg->dur = 4.0; sp_gen_sine(sp, ud.ft); sp_osc_init(sp, ud.osc, ud.ft, 0); for(n = 0; n < tst->size; n++) { osc = 0; tseg = 0; trig = (sp->pos == 0); sp_tseg_compute(sp, ud.tseg, &trig, &tseg); ud.osc->freq = 100 + (tseg * 1000); sp_osc_compute(sp, ud.osc, NULL, &osc); sp_test_add_sample(tst, osc); } fail = sp_test_verify(tst, hash); sp_tseg_destroy(&ud.tseg); sp_ftbl_destroy(&ud.ft); sp_osc_destroy(&ud.osc); if(fail) return SP_NOT_OK; else return SP_OK; }
int t_tenv2(sp_test *tst, sp_data *sp, const char *hash) { uint32_t n; int fail = 0; sp_srand(sp, 1234567); UserData ud; SPFLOAT osc = 0, tenv2 = 0, tick = 0; sp_tenv2_create(&ud.tenv2); sp_osc_create(&ud.osc); sp_ftbl_create(sp, &ud.ft, 2048); sp_tenv2_init(sp, ud.tenv2); ud.tenv2->atk = 3; ud.tenv2->rel = 1; sp_gen_sine(sp, ud.ft); sp_osc_init(sp, ud.osc, ud.ft, 0); ud.osc->amp = 0.6; for(n = 0; n < tst->size; n++) { osc = 0, tenv2 = 0, tick = 0; if(sp->pos == 0 || sp->pos == sp->sr * 1) tick = 1; sp_osc_compute(sp, ud.osc, NULL, &osc); sp_tenv2_compute(sp, ud.tenv2, &tick, &tenv2); sp->out[0] = osc * tenv2; sp_test_add_sample(tst, sp->out[0]); } fail = sp_test_verify(tst, hash); sp_tenv2_destroy(&ud.tenv2); sp_ftbl_destroy(&ud.ft); sp_osc_destroy(&ud.osc); if(fail) return SP_NOT_OK; else return SP_OK; }
uint32_t compute_buffer(int16_t *pbuf, int bufsize) { int i, o; SPFLOAT fm = 0, lfo = 0; SPFLOAT tmp = 0; SPFLOAT r0, r1; for(i = 0; i < bufsize / 2; i+=2) { sp_osc_compute(sp, osc, NULL, &lfo); fm = 0; for(o = 0; o < NOSCS; o++) { tmp = 0; fosc[o]->indx = ((1.0 + lfo) * 0.5) * 6; sp_fosc_compute(sp, fosc[o], NULL, &tmp); fm += tmp; } sp_revsc_compute(sp, revsc, &fm, &fm, &r0, &r1); pbuf[i] = (fm * 0.8 + r0 * 0.1) * 32767; pbuf[i + 1] = (fm * 0.8 + r1 * 0.1) * 32767; } return 0; }
int t_line(sp_test *tst, sp_data *sp, const char *hash) { sp_srand(sp, 1234567); uint32_t n; int fail = 0; SPFLOAT osc = 0, line = 0; UserData ud; sp_line_create(&ud.line); sp_osc_create(&ud.osc); sp_ftbl_create(sp, &ud.ft, 2048); sp_line_init(sp, ud.line, 100, 3, 400); sp_gen_sine(sp, ud.ft); sp_osc_init(sp, ud.osc, ud.ft, 0); sp->len = 44100 * 5; for(n = 0; n < tst->size; n++) { sp_line_compute(sp, ud.line, NULL, &line); ud.osc->freq = line; sp_osc_compute(sp, ud.osc, NULL, &osc); sp->out[0] = osc; sp_test_add_sample(tst, sp->out[0]); } fail = sp_test_verify(tst, hash); sp_line_destroy(&ud.line); sp_ftbl_destroy(&ud.ft); sp_osc_destroy(&ud.osc); if(fail) return SP_NOT_OK; else return SP_OK; }
int t_tseq(sp_test *tst, sp_data *sp, const char *hash) { uint32_t n; int fail = 0; SPFLOAT env = 0; SPFLOAT osc = 0; SPFLOAT trig; SPFLOAT dtrig = 0; SPFLOAT note = 0; sp_srand(sp, 123456); UserData ud; sp_dtrig_create(&ud.dt); sp_tenv_create(&ud.tenv); sp_ftbl_create(sp, &ud.ft, 2048); sp_ftbl_create(sp, &ud.delta, 4); sp_ftbl_create(sp, &ud.nn, 1); sp_osc_create(&ud.osc); sp_gen_vals(sp, ud.delta, "0.2 0.2 0.2 0.1"); sp_gen_vals(sp, ud.nn, "60 62 64 67"); sp_tseq_create(&ud.seq); sp_tseq_init(sp, ud.seq, ud.nn); sp_dtrig_init(sp, ud.dt, ud.delta); ud.dt->loop = 1.0; sp_tenv_init(sp, ud.tenv); ud.tenv->atk = 0.01; ud.tenv->hold = 0.01; ud.tenv->rel = 0.05; sp_gen_sine(sp, ud.ft); sp_osc_init(sp, ud.osc, ud.ft, 0); ud.osc->freq = 1000; ud.osc->amp = 0.5; for(n = 0; n < tst->size; n++) { env = 0; osc = 0; dtrig = 0; note = 0; if(sp->pos == 0){ trig = 1.0; }else{ trig = 0.0; } sp_dtrig_compute(sp, ud.dt, &trig, &dtrig); sp_tseq_compute(sp, ud.seq, &dtrig, ¬e); ud.osc->freq = sp_midi2cps(note + 24); env = 1.0; sp_tenv_compute(sp, ud.tenv, &dtrig, &env); sp_osc_compute(sp, ud.osc, NULL, &osc); sp->out[0] = osc * env; sp_test_add_sample(tst, sp->out[0]); } fail = sp_test_verify(tst, hash); sp_dtrig_destroy(&ud.dt); sp_tseq_destroy(&ud.seq); sp_tenv_destroy(&ud.tenv); sp_ftbl_destroy(&ud.ft); sp_ftbl_destroy(&ud.nn); sp_ftbl_destroy(&ud.delta); sp_osc_destroy(&ud.osc); if(fail) return SP_NOT_OK; else return SP_OK; }
int sporth_osc(sporth_stack *stack, void *ud) { if(stack->error > 0) return PLUMBER_NOTOK; plumber_data *pd = ud; SPFLOAT out = 0, amp, freq, phs; char *ftname; sp_ftbl *ft; sp_osc *osc; switch(pd->mode){ case PLUMBER_CREATE: #ifdef DEBUGMODE fprintf(stderr, "Creating osc function... \n"); #endif sp_osc_create(&osc); plumber_add_module(pd, SPORTH_OSC, sizeof(sp_osc), osc); break; case PLUMBER_INIT: if(sporth_check_args(stack, "fffs") != SPORTH_OK) { stack->error++; fprintf(stderr,"Invalid arguments for osc.\n"); return PLUMBER_NOTOK; } osc = pd->last->ud; ftname = sporth_stack_pop_string(stack); phs = sporth_stack_pop_float(stack); amp = sporth_stack_pop_float(stack); freq = sporth_stack_pop_float(stack); if(plumber_ftmap_search(pd, ftname, &ft) == PLUMBER_NOTOK) { stack->error++; return PLUMBER_NOTOK; } sp_osc_init(pd->sp, osc, ft, phs); sporth_stack_push_float(stack, 0.0); free(ftname); break; case PLUMBER_COMPUTE: osc = pd->last->ud; phs = sporth_stack_pop_float(stack); amp = sporth_stack_pop_float(stack); freq = sporth_stack_pop_float(stack); osc->amp = amp; osc->freq = freq; sp_osc_compute(pd->sp, osc, NULL, &out); sporth_stack_push_float(stack, out); break; case PLUMBER_DESTROY: osc = pd->last->ud; sp_osc_destroy(&osc); break; default: fprintf(stderr,"Error: Unknown mode!"); stack->error++; return PLUMBER_NOTOK; break; } return PLUMBER_OK; }
void write_osc(sp_data *data, void *ud) { udata *udp = ud; sp_osc_compute(data, udp->osc, NULL, &data->out); }