foxygit / doom Log in
commit c354b6967e137c17919b2f203939f133b3630b95
Author:     Michael Day <contact@michaelcday.com>
AuthorDate: Tue Mar 14 15:58:21 2023 -0400
Commit:     Michael Day <contact@michaelcday.com>
CommitDate: Tue Mar 21 13:59:22 2023 -0400

    fluidsynth: Add more config variables

    Expose synth.polyphony and synth.midi-bank-select.
---
 src/i_flmusic.c   |  5 +++++
 src/i_sound.c     |  2 ++
 src/i_sound.h     |  2 ++
 src/m_config.c    | 14 ++++++++++++++
 src/setup/sound.c |  7 +++++--
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/i_flmusic.c b/src/i_flmusic.c
index aaa01f01..a9e94c57 100644
--- a/src/i_flmusic.c
+++ b/src/i_flmusic.c
@@ -48,6 +48,8 @@ float fsynth_chorus_depth = 5.0;
 float fsynth_chorus_level = 0.35;
 int fsynth_chorus_nr = 3;
 float fsynth_chorus_speed = 0.3;
+char *fsynth_midibankselect = "gs";
+int fsynth_polyphony = 256;
 int fsynth_reverb_active = 1;
 float fsynth_reverb_damp = 0.4;
 float fsynth_reverb_level = 0.15;
@@ -89,6 +91,9 @@ static boolean I_FL_InitMusic(void)
     settings = new_fluid_settings();

     fluid_settings_setnum(settings, "synth.sample-rate", snd_samplerate);
+    fluid_settings_setstr(settings, "synth.midi-bank-select",
+                          fsynth_midibankselect);
+    fluid_settings_setint(settings, "synth.polyphony", fsynth_polyphony);

     fluid_settings_setint(settings, "synth.chorus.active",
                           fsynth_chorus_active);
diff --git a/src/i_sound.c b/src/i_sound.c
index 0ed329e7..34b02cfe 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -520,6 +520,8 @@ void I_BindSoundVariables(void)
     M_BindFloatVariable("fsynth_chorus_level",      &fsynth_chorus_level);
     M_BindIntVariable("fsynth_chorus_nr",           &fsynth_chorus_nr);
     M_BindFloatVariable("fsynth_chorus_speed",      &fsynth_chorus_speed);
+    M_BindStringVariable("fsynth_midibankselect",   &fsynth_midibankselect);
+    M_BindIntVariable("fsynth_polyphony",           &fsynth_polyphony);
     M_BindIntVariable("fsynth_reverb_active",       &fsynth_reverb_active);
     M_BindFloatVariable("fsynth_reverb_damp",       &fsynth_reverb_damp);
     M_BindFloatVariable("fsynth_reverb_level",      &fsynth_reverb_level);
diff --git a/src/i_sound.h b/src/i_sound.h
index 5fde4783..1c2066d1 100644
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -287,6 +287,8 @@ extern float fsynth_chorus_depth;
 extern float fsynth_chorus_level;
 extern int fsynth_chorus_nr;
 extern float fsynth_chorus_speed;
+extern char *fsynth_midibankselect;
+extern int fsynth_polyphony;
 extern int fsynth_reverb_active;
 extern float fsynth_reverb_damp;
 extern float fsynth_reverb_level;
diff --git a/src/m_config.c b/src/m_config.c
index 06d0200e..ea7f51ec 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -972,6 +972,20 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_FLOAT(fsynth_chorus_speed),

+    //!
+    // This setting defines how FluidSynth interprets Bank Select messages. The
+    // default is "gs". Other possible values are "gm", "xg" and "mma".
+    //
+
+    CONFIG_VARIABLE_STRING(fsynth_midibankselect),
+
+    //!
+    // Sets the number of FluidSynth voices that can be played in parallel.
+    // Default is 256, range is 1 - 65535.
+    //
+
+    CONFIG_VARIABLE_INT(fsynth_polyphony),
+
     //!
     // If 1, activate the FluidSynth reverb effects module. If 0, no reverb
     // will be added to the output signal.
diff --git a/src/setup/sound.c b/src/setup/sound.c
index 90933342..281c4f71 100644
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -88,12 +88,14 @@ int winmm_chorus_level = -1;
 #endif

 #if HAVE_FLUIDSYNTH
-char *fsynth_sf_path = NULL;
+char *fsynth_sf_path = "";
 int fsynth_chorus_active = 1;
 float fsynth_chorus_depth = 5.0;
 float fsynth_chorus_level = 0.35;
 int fsynth_chorus_nr = 3;
 float fsynth_chorus_speed = 0.3;
+char *fsynth_midibankselect = "gs";
+int fsynth_polyphony = 256;
 int fsynth_reverb_active = 1;
 float fsynth_reverb_damp = 0.4;
 float fsynth_reverb_level = 0.15;
@@ -366,6 +368,8 @@ void BindSoundVariables(void)
     M_BindFloatVariable("fsynth_chorus_level",    &fsynth_chorus_level);
     M_BindIntVariable("fsynth_chorus_nr",         &fsynth_chorus_nr);
     M_BindFloatVariable("fsynth_chorus_speed",    &fsynth_chorus_speed);
+    M_BindStringVariable("fsynth_midibankselect", &fsynth_midibankselect);
+    M_BindIntVariable("fsynth_polyphony",         &fsynth_polyphony);
     M_BindIntVariable("fsynth_reverb_active",     &fsynth_reverb_active);
     M_BindFloatVariable("fsynth_reverb_damp",     &fsynth_reverb_damp);
     M_BindFloatVariable("fsynth_reverb_level",    &fsynth_reverb_level);
@@ -396,7 +400,6 @@ void BindSoundVariables(void)
     music_pack_path = M_StringDuplicate("");
     timidity_cfg_path = M_StringDuplicate("");
     gus_patch_path = M_StringDuplicate("");
-    fsynth_sf_path = M_StringDuplicate("");

     // All versions of Heretic and Hexen did pitch-shifting.
     // Most versions of Doom did not and Strife never did.