From 0e8395349f3dbcc4dc3db1502fcdb1377e632daa Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 29 Sep 2013 01:07:03 +0000 Subject: 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 --- src/i_sdlsound.c | 11 ++++++++++- src/i_sound.c | 4 +++- src/m_config.c | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index 4169a921..c8ec6853 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -88,6 +88,14 @@ static int allocated_sounds_size = 0; 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 @@ static boolean ExpandSoundData_SRC(sfxinfo_t *sfxinfo, // 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. diff --git a/src/i_sound.c b/src/i_sound.c index 47cae682..19a697d8 100644 --- a/src/i_sound.c +++ b/src/i_sound.c @@ -426,6 +426,7 @@ boolean I_MusicIsPlaying(void) 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 @@ void I_BindSoundVariables(void) 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 diff --git a/src/m_config.c b/src/m_config.c index cce90579..9d421d3f 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -984,6 +984,18 @@ static default_t extra_defaults_list[] = 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 -- cgit v1.2.3