33 lines
598 B
C
33 lines
598 B
C
|
|
#define LOOKUP_SAMPLES 360
|
|
|
|
extern double _sin_table[LOOKUP_SAMPLES + 1];
|
|
extern double _saw_table[LOOKUP_SAMPLES + 1];
|
|
extern double _tri_table[LOOKUP_SAMPLES + 1];
|
|
|
|
struct osc_t
|
|
{
|
|
double freq;
|
|
double step;
|
|
double ramp;
|
|
|
|
double sin;
|
|
double saw;
|
|
double tri;
|
|
};
|
|
|
|
void osc_init();
|
|
void osc_setfreq(struct osc_t *osc, double freq);
|
|
|
|
static inline void osc_tick(struct osc_t *osc)
|
|
{
|
|
osc->ramp += osc->step;
|
|
if (osc->ramp > LOOKUP_SAMPLES) osc->ramp -= LOOKUP_SAMPLES;
|
|
|
|
uint32_t pos = floor(osc->ramp);
|
|
|
|
osc->sin = _sin_table[pos];
|
|
osc->saw = _saw_table[pos];
|
|
osc->tri = _tri_table[pos];
|
|
}
|