shithub: choc

Download patch

ref: 0e8395349f3dbcc4dc3db1502fcdb1377e632daa
parent: efdd44c17725cd89215b16cb054842f77b545343
author: Simon Howard <[email protected]>
date: Sat Sep 28 21:07:03 EDT 2013

Add config file variable for controlling libsamplerate conversion scale
factor. This is an alternative to the approach taken in the version on
the trunk version, where all sounds are pre-converted at startup and
adjusted based on the maximum value.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2690

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -88,6 +88,14 @@
 
 int use_libsamplerate = 0;
 
+// Scale factor used when converting libsamplerate floating point numbers
+// to integers. Too high means the sounds can clip; too low means they
+// will be too quiet. This is an amount that should avoid clipping most
+// of the time: with all the Doom IWAD sound effects, at least. If a PWAD
+// is used, clipping might occur.
+
+float libsamplerate_scale = 0.65;
+
 // Hook a sound into the linked list at the head.
 
 static void AllocatedSoundLink(allocated_sound_t *snd)
@@ -408,7 +416,8 @@
         // using INT16_MAX as the multiplier are not all that bad, but
         // artifacts are noticeable during the loudest parts.
 
-        float   cvtval_f = src_data.data_out[i] * 22265;
+        float cvtval_f =
+            src_data.data_out[i] * libsamplerate_scale * INT16_MAX;
         int32_t cvtval_i = cvtval_f + (cvtval_f < 0 ? -0.5 : 0.5);
 
         // Asymmetrical sound worries me, so we won't use -32768.
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -426,6 +426,7 @@
 void I_BindSoundVariables(void)
 {
     extern int use_libsamplerate;
+    extern float libsamplerate_scale;
 
     M_BindVariable("snd_musicdevice",   &snd_musicdevice);
     M_BindVariable("snd_sfxdevice",     &snd_sfxdevice);
@@ -442,7 +443,8 @@
     M_BindVariable("gus_ram_kb",        &gus_ram_kb);
 
 #ifdef FEATURE_SOUND
-    M_BindVariable("use_libsamplerate", &use_libsamplerate);
+    M_BindVariable("use_libsamplerate",   &use_libsamplerate);
+    M_BindVariable("libsamplerate_scale", &libsamplerate_scale);
 #endif
 
     // Before SDL_mixer version 1.2.11, MIDI music caused the game
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -985,6 +985,18 @@
     CONFIG_VARIABLE_INT(use_libsamplerate),
 
     //!
+    // Scaling factor used by libsamplerate. This is used when converting
+    // sounds internally back into integer form; normally it should not
+    // be necessary to change it from the default value. The only time
+    // it might be needed is if a PWAD file is loaded that contains very
+    // loud sounds, in which case the conversion may cause sound clipping
+    // and the scale factor should be reduced. The lower the value, the
+    // quieter the sound effects become, so it should be set as high as is
+    // possible without clipping occurring.
+
+    CONFIG_VARIABLE_FLOAT(libsamplerate_scale),
+
+    //!
     // Full path to a Timidity configuration file to use for MIDI
     // playback. The file will be evaluated from the directory where
     // it is evaluated, so there is no need to add "dir" commands