From afcb3cf660f0ec3137f7edf470ddeff2ae546726 Mon Sep 17 00:00:00 2001 From: frosty Date: Sat, 16 May 2026 01:46:23 -0400 Subject: fix: pls work --- src/Main.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Main.c') diff --git a/src/Main.c b/src/Main.c index d83511a..71b2580 100644 --- a/src/Main.c +++ b/src/Main.c @@ -10,7 +10,25 @@ SDL_AtomicInt is_speaking; SDL_AtomicInt app_running; -float shared_rms = 0.0f; +SDL_AtomicInt shared_rms_bits; + +static inline void atomic_store_float(SDL_AtomicInt *a, float f) { + union { + float f; + int i; + } u; + u.f = f; + SDL_SetAtomicInt(a, u.i); +} + +static inline float atomic_load_float(SDL_AtomicInt *a) { + union { + float f; + int i; + } u; + u.i = SDL_GetAtomicInt(a); + return u.f; +} int SDLCALL audio_thread_func(void *data) { (void)data; @@ -34,7 +52,7 @@ int SDLCALL audio_thread_func(void *data) { for (int i = 0; i < BUFFER_SIZE; i++) sum_squares += (double)buffer[i] * buffer[i]; float rms = (float)sqrt(sum_squares / BUFFER_SIZE); - shared_rms = rms; + atomic_store_float(&shared_rms_bits, rms); SDL_SetAtomicInt(&is_speaking, rms > VOLUME_THRESHOLD ? 1 : 0); } pa_simple_free(s); @@ -61,7 +79,7 @@ int main(void) { if (event.type == SDL_EVENT_QUIT) SDL_SetAtomicInt(&app_running, 0); } - float target_rms = shared_rms; + float target_rms = atomic_load_float(&shared_rms_bits); if (target_rms < VOLUME_THRESHOLD) target_rms = 0.0f; visual_rms += (target_rms - visual_rms) * LERP_SPEED; -- cgit v1.3