void process(AUAudioFrameCount frameCount, AUAudioFrameCount bufferOffset) override { // For each sample. for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { int frameOffset = int(frameIndex + bufferOffset); frequency = double(frequencyRamper.getStep()); amplitude = double(amplitudeRamper.getStep()); detuningOffset = double(detuningOffsetRamper.getStep()); detuningMultiplier = double(detuningMultiplierRamper.getStep()); *blsaw->freq = frequency * detuningMultiplier + detuningOffset; *blsaw->amp = amplitude; float temp = 0; for (int channel = 0; channel < channels; ++channel) { float *out = (float *)outBufferListPtr->mBuffers[channel].mData + frameOffset; if (started) { if (channel == 0) { sp_blsaw_compute(sp, blsaw, nil, &temp); } *out = temp; } else { *out = 0.0; } } } }
int t_blsaw(sp_test *tst, sp_data *sp, const char *hash) { uint32_t n; int fail = 0; SPFLOAT blsaw; sp_blsaw *blsaw_d; sp_blsaw_create(&blsaw_d); sp_blsaw_init(sp, blsaw_d); *blsaw_d->freq = 500; sp->len = 44100 * 5; for(n = 0; n < tst->size; n++) { blsaw = 0; sp_blsaw_compute(sp, blsaw_d, NULL, &blsaw); sp_out(sp, 0, blsaw); sp_test_add_sample(tst, sp->out[0]); } fail = sp_test_verify(tst, hash); sp_blsaw_destroy(&blsaw_d); if(fail) return SP_NOT_OK; else return SP_OK; }
int main() { sp_data *sp; sp_create(&sp); sp_srand(sp, 12345); sp->sr = SR; sp->len = sp->sr * LEN; uint32_t t, u; SPFLOAT in = 0, out = 0; sp_blsaw *unit[NUM]; for(u = 0; u < NUM; u++) { sp_blsaw_create(&unit[u]); sp_blsaw_init(sp, unit[u]); } for(t = 0; t < sp->len; t++) { for(u = 0; u < NUM; u++) sp_blsaw_compute(sp, unit[u], &in, &out); } for(u = 0; u < NUM; u++) sp_blsaw_destroy(&unit[u]); sp_destroy(&sp); return 0; }
int sporth_blsaw(sporth_stack *stack, void *ud) { plumber_data *pd = ud; SPFLOAT out; SPFLOAT freq; SPFLOAT amp; sp_blsaw *blsaw; switch(pd->mode) { case PLUMBER_CREATE: #ifdef DEBUG_MODE fprintf(stderr, "blsaw: Creating\n"); #endif sp_blsaw_create(&blsaw); plumber_add_ugen(pd, SPORTH_SAW, blsaw); if(sporth_check_args(stack, "ff") != SPORTH_OK) { fprintf(stderr,"Not enough arguments for blsaw\n"); stack->error++; return PLUMBER_NOTOK; } amp = sporth_stack_pop_float(stack); freq = sporth_stack_pop_float(stack); sporth_stack_push_float(stack, 0); break; case PLUMBER_INIT: #ifdef DEBUG_MODE fprintf(stderr, "blsaw: Initialising\n"); #endif amp = sporth_stack_pop_float(stack); freq = sporth_stack_pop_float(stack); blsaw = pd->last->ud; sp_blsaw_init(pd->sp, blsaw); sporth_stack_push_float(stack, 0); break; case PLUMBER_COMPUTE: amp = sporth_stack_pop_float(stack); freq = sporth_stack_pop_float(stack); blsaw = pd->last->ud; *blsaw->freq = freq; *blsaw->amp = amp; sp_blsaw_compute(pd->sp, blsaw, NULL, &out); sporth_stack_push_float(stack, out); break; case PLUMBER_DESTROY: blsaw = pd->last->ud; sp_blsaw_destroy(&blsaw); break; default: fprintf(stderr, "blsaw: Unknown mode!\n"); break; } return PLUMBER_OK; }
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; }