summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-02-03 18:20:20 -0800
committerVito Caputo <vcaputo@pengaru.com>2020-02-03 18:20:20 -0800
commit7d8a48bfa1ece4af9ad8cb22a992f5c09c08d7cb (patch)
tree3a7ba0303eedaeac6b6969dcc32dfe4ff51cc5aa /src
parent02111ff581e5c8f5c3df2dc0cbae4a5f09ae158a (diff)
libs/sig: remove ticks_ms modulo in sig_ops_sin
Seems broken, fix it correctly later.
Diffstat (limited to 'src')
-rw-r--r--src/libs/sig/ops_sin.c10
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;
}
© All Rights Reserved