From 12b32acb2bd4e1eb9e8760b8971e92f79ac68dac Mon Sep 17 00:00:00 2001 From: veclav talica Date: Sat, 15 Jun 2024 14:30:50 +0500 Subject: [PATCH] oscillators: fix --- articles/oscillators/page.mmd | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/articles/oscillators/page.mmd b/articles/oscillators/page.mmd index 5e46542..bf23c9e 100644 --- a/articles/oscillators/page.mmd +++ b/articles/oscillators/page.mmd @@ -51,12 +51,16 @@ struct sqrtwave { uint32_t u; } v; } init_sqrtwave(float frequency, float phase, float amplitude) { - struct sqrtwave r; - r.w = init_sinewave(frequency, phase, 1.f); - v.f = r.w.s; - a.f = amplitude; - r.v.u = (a.u & 0x7fffffff) | (v.u & 0x80000000); - return r; + struct sqrtwave r; + union { + float f; + uint32_t u; + } v, a; + r.w = init_sinewave(frequency, phase, 1.f); + v.f = r.w.s; + a.f = amplitude; + r.v.u = (a.u & 0x7fffffff) | (v.u & 0x80000000); + return r; } /* Use floating point bit representation to infer sign, all other bits are set to amplitude */