From 7d8a48bfa1ece4af9ad8cb22a992f5c09c08d7cb Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 3 Feb 2020 18:20:20 -0800 Subject: libs/sig: remove ticks_ms modulo in sig_ops_sin Seems broken, fix it correctly later. --- src/libs/sig/ops_sin.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libs/sig/ops_sin.c b/src/libs/sig/ops_sin.c index 87f16da..555a682 100644 --- a/src/libs/sig/ops_sin.c +++ b/src/libs/sig/ops_sin.c @@ -39,7 +39,6 @@ static float ops_sin_output(void *context, unsigned ticks_ms) { ops_sin_ctxt_t *ctxt = context; float rads_per_ms, rads, hz; - unsigned ms_per_cycle; assert(ctxt); assert(ctxt->hz); @@ -48,9 +47,14 @@ static float ops_sin_output(void *context, unsigned ticks_ms) if (hz < .001f) return 0.f; - ms_per_cycle = hz * 1000.f; + /* TODO FIXME: wrap ticks_ms into the current cycle + * so rads can be as small as possible for precision reasons. + * I had some code here which attempted it but the results were + * clearly broken, so it's removed for now. As ticks_ms grows, + * the precision here will suffer. + */ rads_per_ms = (M_PI * 2.f) * hz * .001f; - rads = (float)(ticks_ms % ms_per_cycle) * rads_per_ms; + rads = (float)ticks_ms * rads_per_ms; return sinf(rads) * .5f + .5f; } -- cgit v1.2.3