]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
improve logic for silent sound cutoff based on output buffer width
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 9 Oct 2011 12:29:49 +0000 (12:29 +0000)
committerRudolf Polzer <divverent@xonotic.org>
Fri, 14 Oct 2011 18:51:50 +0000 (20:51 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11395 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=65568afe2573b7ceeb403d2ad697ccd3b6e0a188

snd_mix.c

index eab51a6474002d58d98266edb9609ead2907a4fb..35add4ef72a2570598d38932765f383cc51ecb4a 100644 (file)
--- 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)