fosc
Files: fosc.h, fosc.c
FM oscilator pair with linear interpolation
sp_fosc_create(sp_fosc **fosc)
sp_fosc_init(sp_data *sp, sp_fosc *fosc, sp_ftbl *tbl)
sp_fosc_compute(sp_data *sp, sp_fosc *fosc, SPFLOAT *dummy, SPFLOAT *out)
sp_fosc_destroy(sp_fosc **fosc)
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.4)
car: Carrier frequency, expressed as a ratio number in C:M ratio. Typically an integer.
(Default value: 1)
mod: Modulator frequency, expressed as a ratio number in C:M ratio. Typically an integer.
(Default value: 1)
indx: Modulation index. Most commercial synthesizers have a range from 0-8, but there's nothing stopping you from going beyond that.
(Default value: 8)
Outputs
out: Signal out.
Example Code
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"
typedef struct {
sp_fosc *osc;
sp_ftbl *ft;
int counter;
} UserData;
void process(sp_data *sp, void *udata) {
UserData *ud = ud;
if(ud->counter == 0){
ud->osc->freq = 500 + rand() % 2000;
}
sp_fosc_compute(sp, ud->osc, 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, 2048);
sp_fosc_create(&ud.osc);
sp_gen_sine(sp, ud.ft);
sp_fosc_init(sp, ud.osc, ud.ft);
ud.osc->freq = 500;
sp->len = 44100 * 5;
sp_process(sp, &ud, process);
sp_ftbl_destroy(&ud.ft);
sp_fosc_destroy(&ud.osc);
sp_destroy(&sp);
return 0;
}