Skip to content

Commit

Permalink
add a fsynth_gain config key to fine tune the FluidSynth output level (
Browse files Browse the repository at this point in the history
…chocolate-doom#1631)

* add a fsynth_gain config key to fine tune the FluidSynth output level

Fixes ##1087

* lower fsynth_gain to 0.0f
  • Loading branch information
fabiangreffrath authored Oct 20, 2023
1 parent 7d44fa1 commit bd7be22
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/i_flmusic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/i_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
2 changes: 2 additions & 0 deletions src/setup/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit bd7be22

Please sign in to comment.