diff options
Diffstat (limited to 'src/libs/sig')
-rw-r--r-- | src/libs/sig/ops_sin.c | 10 |
1 files changed, 7 insertions, 3 deletions
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; } |