From: James O'Neill Date: Mon, 4 Mar 2024 03:24:07 +0000 (+0900) Subject: Underwater sound filter: fix warning and code style, add function docstring X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=9071f64f73575b05a153c231f01e26bf3e3b310f;hp=b134a4aeee8f2cabaef8f6bea8c23393b3159d49;p=xonotic%2Fdarkplaces.git Underwater sound filter: fix warning and code style, add function docstring --- 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]; } - } } + + /* ===============================================================================