Ensure oscillator step fits within lookup bounds

master
Peter Nelson 2010-01-13 13:57:41 +00:00
parent 864e4d1431
commit ba6cb260a4
1 changed files with 3 additions and 0 deletions

3
osc.c
View File

@ -28,5 +28,8 @@ void osc_setfreq(struct osc_t *osc, double freq)
{
osc->freq = freq;
osc->step = freq / _sample_rate * LOOKUP_SAMPLES;
/* Ensure step does not go out of bound */
while (osc->step > LOOKUP_SAMPLES) osc->step -= LOOKUP_SAMPLES;
}