shithub: choc

Download patch

ref: 46a5fbdc25282b0027bd4edd929b46e80546c70c
parent: 0910b7efe828717d47515118ba71529ba540181f
author: Simon Howard <[email protected]>
date: Tue Apr 15 17:40:33 EDT 2008

Make use_libsamplerate be an integer value that controls conversion
quality, rather than an on/off setting.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1112

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -39,6 +39,7 @@
 #endif
 
 #include "deh_main.h"
+#include "i_system.h"
 #include "s_sound.h"
 #include "m_argv.h"
 #include "w_wad.h"
@@ -93,6 +94,33 @@
 
 #ifdef HAVE_LIBSAMPLERATE
 
+// Returns the conversion mode for libsamplerate to use.
+
+static int SRC_ConversionMode(void)
+{
+    switch (use_libsamplerate)
+    {
+        // 0 = disabled
+
+        default:
+        case 0:
+            return -1;
+
+        // Ascending numbers give higher quality
+
+        case 1:
+            return SRC_LINEAR;
+        case 2:
+            return SRC_ZERO_ORDER_HOLD;
+        case 3:
+            return SRC_SINC_FASTEST;
+        case 4:
+            return SRC_SINC_MEDIUM_QUALITY;
+        case 5:
+            return SRC_SINC_BEST_QUALITY;
+    }
+}
+
 // libsamplerate-based generic sound expansion function for any sample rate
 //   unsigned 8 bits --> signed 16 bits
 //   mono --> stereo
@@ -132,7 +160,7 @@
 
     // Do the sound conversion
 
-    retn = src_simple(&src_data, SRC_SINC_BEST_QUALITY, 1);
+    retn = src_simple(&src_data, SRC_ConversionMode(), 1);
     assert(retn == 0);
 
     // Convert the result back into 16-bit integers.
@@ -614,14 +642,20 @@
     Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels);
 
 #ifdef HAVE_LIBSAMPLERATE
-    if (use_libsamplerate)
+    if (use_libsamplerate != 0)
     {
+        if (SRC_ConversionMode() < 0)
+        {
+            I_Error("I_SDL_InitSound: Invalid value for use_libsamplerate: %i",
+                    use_libsamplerate);
+        }
+
         ExpandSoundData = ExpandSoundData_SRC;
 
         I_PrecacheSounds();
     }
 #else
-    if (use_libsamplerate)
+    if (use_libsamplerate != 0)
     {
         fprintf(stderr, "I_SDL_InitSound: use_libsamplerate=%i, but "
                         "libsamplerate support not compiled in.\n",
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -697,9 +697,16 @@
     CONFIG_VARIABLE_INT(dclick_use,                dclick_use),
 
     //!
-    // If non-zero, libsamplerate is used to resample sound effects to
-    // the output sample rate.  This has no effect if libsamplerate
-    // support has not been compiled into the game.
+    // Controls whether libsamplerate support is used for performing
+    // sample rate conversions of sound effects.  Support for this
+    // must be compiled into the program.
+    //
+    // If zero, libsamplerate support is disabled.  If non-zero, 
+    // libsamplerate is enabled. Increasing values roughly correspond
+    // to higher quality conversion; the higher the quality, the 
+    // slower the conversion process.  Linear conversion = 1; 
+    // Zero order hold = 2; Fast Sinc filter = 3; Medium quality
+    // Sinc filter = 4; High quality Sinc filter = 5.
     //
 
     CONFIG_VARIABLE_INT(use_libsamplerate,         use_libsamplerate),