From 9071f64f73575b05a153c231f01e26bf3e3b310f Mon Sep 17 00:00:00 2001 From: James O'Neill Date: Mon, 4 Mar 2024 12:24:07 +0900 Subject: [PATCH] Underwater sound filter: fix warning and code style, add function docstring --- snd_main.h | 2 ++ snd_mix.c | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/snd_main.h b/snd_main.h index 23541bcc..1ce9e169 100644 --- a/snd_main.h +++ b/snd_main.h @@ -153,6 +153,8 @@ extern qbool simsound; // Architecture-independent functions // ==================================================================== +void S_SetUnderwaterIntensity(void); + void S_MixToBuffer(void *stream, unsigned int frames); qbool S_LoadSound (struct sfx_s *sfx, qbool complain); diff --git a/snd_mix.c b/snd_mix.c index 499c16f4..b83c3ae7 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -309,19 +309,25 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p } } + + /* =============================================================================== UNDERWATER EFFECT +Muffles the intensity of sounds when the player is underwater + =============================================================================== */ -static struct { +static struct +{ float intensity; float alpha; float accum[SND_LISTENERS]; -} underwater = {0.f, 1.f, {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}}; +} +underwater = {0.f, 1.f, {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}}; void S_SetUnderwaterIntensity(void) { @@ -353,22 +359,25 @@ static void S_UnderwaterFilter(int endtime) { int i; int sl; - if (!underwater.intensity) { - if (endtime > 0) { - for (sl = 0; sl < SND_LISTENERS; sl++) { + + if (!underwater.intensity) + { + if (endtime > 0) + for (sl = 0; sl < SND_LISTENERS; sl++) underwater.accum[sl] = paintbuffer[endtime-1].sample[sl]; - } - } return; } - for (i = 0; i < endtime; i++) { - for (sl = 0; sl < SND_LISTENERS; sl++) { + + for (i = 0; i < endtime; i++) + for (sl = 0; sl < SND_LISTENERS; sl++) + { underwater.accum[sl] += underwater.alpha * (paintbuffer[i].sample[sl] - underwater.accum[sl]); paintbuffer[i].sample[sl] = underwater.accum[sl]; } - } } + + /* =============================================================================== -- 2.39.2