From ba6cb260a4de3df71a02db6f2a3fe099db36f7d6 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 13 Jan 2010 13:57:41 +0000 Subject: [PATCH] Ensure oscillator step fits within lookup bounds --- osc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osc.c b/osc.c index 218cac9..92ca612 100644 --- a/osc.c +++ b/osc.c @@ -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; }