commit bd7be2212c4c0520cd6e5721a0d0cae32eb09c24
Author: Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Fri Oct 20 16:45:43 2023 +0200
Commit: GitHub <noreply@github.com>
CommitDate: Fri Oct 20 16:45:43 2023 +0200
add a fsynth_gain config key to fine tune the FluidSynth output level (#1631)
* add a fsynth_gain config key to fine tune the FluidSynth output level
Fixes #https://github.com/fabiangreffrath/crispy-doom/issues/1087
* lower fsynth_gain to 0.0f
---
src/i_flmusic.c | 12 +++++++++++-
src/i_sound.c | 1 +
src/i_sound.h | 1 +
src/m_config.c | 7 +++++++
src/setup/sound.c | 2 ++
5 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/i_flmusic.c b/src/i_flmusic.c
index 7ea7653d..1ea9999b 100644
--- a/src/i_flmusic.c
+++ b/src/i_flmusic.c
@@ -55,6 +55,7 @@ float fsynth_reverb_damp = 0.4f;
float fsynth_reverb_level = 0.15f;
float fsynth_reverb_roomsize = 0.6f;
float fsynth_reverb_width = 4.0f;
+float fsynth_gain = 1.0f;
static fluid_synth_t *synth = NULL;
static fluid_settings_t *settings = NULL;
@@ -119,6 +120,15 @@ static boolean I_FL_InitMusic(void)
fsynth_chorus_speed);
}
+ if (fsynth_gain < 0.0f)
+ {
+ fsynth_gain = 0.0f;
+ }
+ if (fsynth_gain > 10.0f)
+ {
+ fsynth_gain = 10.0f;
+ }
+
synth = new_fluid_synth(settings);
if (synth == NULL)
@@ -154,7 +164,7 @@ static void I_FL_SetMusicVolume(int volume)
}
// FluidSynth's default is 0.2. Make 1.0 the maximum.
// 0 -- 0.2 -- 10.0
- fluid_synth_set_gain(synth, (float) volume / 127);
+ fluid_synth_set_gain(synth, ((float) volume / 127) * fsynth_gain);
}
static void I_FL_PauseSong(void)
diff --git a/src/i_sound.c b/src/i_sound.c
index a892b86a..90709662 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -525,6 +525,7 @@ void I_BindSoundVariables(void)
M_BindFloatVariable("fsynth_reverb_level", &fsynth_reverb_level);
M_BindFloatVariable("fsynth_reverb_roomsize", &fsynth_reverb_roomsize);
M_BindFloatVariable("fsynth_reverb_width", &fsynth_reverb_width);
+ M_BindFloatVariable("fsynth_gain", &fsynth_gain);
M_BindStringVariable("fsynth_sf_path", &fsynth_sf_path);
#endif // HAVE_FLUIDSYNTH
diff --git a/src/i_sound.h b/src/i_sound.h
index 7674a6b7..21dc8cb1 100644
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -293,6 +293,7 @@ extern float fsynth_reverb_damp;
extern float fsynth_reverb_level;
extern float fsynth_reverb_roomsize;
extern float fsynth_reverb_width;
+extern float fsynth_gain;
#endif // HAVE_FLUIDSYNTH
#endif
diff --git a/src/m_config.c b/src/m_config.c
index 7c3e0e8a..c5ddcbbf 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1021,6 +1021,13 @@ static default_t extra_defaults_list[] =
CONFIG_VARIABLE_FLOAT(fsynth_reverb_width),
+ //!
+ // Fine tune the FluidSynth output level. Default is 1.0,
+ // range is 0.0 - 10.0.
+ //
+
+ CONFIG_VARIABLE_FLOAT(fsynth_gain),
+
//!
// Full path to a soundfont file to use with FluidSynth MIDI playback.
//
diff --git a/src/setup/sound.c b/src/setup/sound.c
index 77d9c162..6f5de1f7 100644
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -103,6 +103,7 @@ float fsynth_reverb_damp = 0.4f;
float fsynth_reverb_level = 0.15f;
float fsynth_reverb_roomsize = 0.6f;
float fsynth_reverb_width = 4.0f;
+float fsynth_gain = 1.0f;
#endif // HAVE_FLUIDSYNTH
// DOS specific variables: these are unused but should be maintained
@@ -376,6 +377,7 @@ void BindSoundVariables(void)
M_BindFloatVariable("fsynth_reverb_level", &fsynth_reverb_level);
M_BindFloatVariable("fsynth_reverb_roomsize", &fsynth_reverb_roomsize);
M_BindFloatVariable("fsynth_reverb_width", &fsynth_reverb_width);
+ M_BindFloatVariable("fsynth_gain", &fsynth_gain);
M_BindStringVariable("fsynth_sf_path", &fsynth_sf_path);
#endif // HAVE_FLUIDSYNTH