posc3
Files: posc3.h, posc3.c
High-precision table-lookup posc3ilator with cubic interpolation
sp_posc3_create(sp_posc3 **posc3)
sp_posc3_init(sp_data *sp, sp_posc3 *posc3, sp_ftbl *tbl)
sp_posc3_compute(sp_data *sp, sp_posc3 *posc3, SPFLOAT *dummy, SPFLOAT *out)
sp_posc3_destroy(sp_posc3 **posc3)
Mandatory Parameters
tbl: Wavetable to read from. Note: the size of this table must be a power of 2.
(Recommended value: N/A)
Optional Parameters
freq: Frequency (in Hz)
(Default value: 440)
amp: Amplitude (typically a value between 0 and 1).
(Default value: 0.2)
Outputs
out: Signal out.
Example Code
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"
typedef struct {
sp_posc3 *posc3;
sp_ftbl *ft;
int counter;
} UserData;
void write_posc3(sp_data *sp, void *udata) {
UserData *ud = udata;
if(ud->counter == 0){
ud->posc3->freq = 500 + rand() % 2000;
}
sp_posc3_compute(sp, ud->posc3, NULL, &sp->out[0]);
ud->counter = (ud->counter + 1) % 4410;
}
int main() {
srand(time(NULL));
UserData ud;
ud.counter = 0;
sp_data *sp;
sp_create(&sp);
sp_ftbl_create(sp, &ud.ft, 1024);
sp_posc3_create(&ud.posc3);
sp_gen_sine(sp, ud.ft);
sp_posc3_init(sp, ud.posc3, ud.ft);
ud.posc3->freq = 500;
sp->len = 44100 * 5;
sp_process(sp, &ud, write_posc3);
sp_ftbl_destroy(&ud.ft);
sp_posc3_destroy(&ud.posc3);
sp_destroy(&sp);
return 0;
}