From 65568afe2573b7ceeb403d2ad697ccd3b6e0a188 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 9 Oct 2011 12:29:49 +0000 Subject: [PATCH] improve logic for silent sound cutoff based on output buffer width git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11395 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_mix.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/snd_mix.c b/snd_mix.c index eab51a64..35add4ef 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -209,7 +209,7 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) float sample[3]; double posd; double speedd; - float sum; + float maxvol; qboolean looping; qboolean silent; @@ -246,10 +246,31 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) vol[i] = ch->volume[i]; // check total volume level, because we can skip some code on silent sounds but other code must still run (position updates mainly) - sum = 0; + maxvol = 0; for (i = 0;i < SND_LISTENERS;i++) - sum += vol[i]*vol[i]; - silent = sum < (1.0f / (65536.0f * 65536.0f)); // so silent it has zero effect + if(vol[i] > maxvol) + maxvol = vol[i]; + switch(snd_renderbuffer->format.width) + { + case 1: // 8bpp + silent = maxvol < (1.0f / (256.0f)); + // so silent it has zero effect + break; + case 2: // 16bpp + silent = maxvol < (1.0f / (65536.0f)); + // so silent it has zero effect + break; + default: // floating point + silent = maxvol < 1.0e-13f; + // 130 dB is difference between hearing + // threshold and a jackhammer from + // working distance. + // therefore, anyone who turns up + // volume so much they notice this + // cutoff, likely already has their + // ear-drums blown out anyway. + break; + } // when doing prologic mixing, some channels invert one side if (ch->prologic_invert == -1) -- 2.39.2