aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/midi
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-01-17 00:58:47 -0800
committerChris Robinson <[email protected]>2014-01-17 00:58:47 -0800
commit50c8d9181a5e99163274bfe6fdbaaf63aceb04b2 (patch)
tree309dffa1fadafcfc58676f8d2a6a47bbd7a5aa87 /Alc/midi
parent08ba5d9dba798c3985bad425906564431b4f6c0d (diff)
Add a config option to specify the extra MIDI volume scaling
The value specified is in decibels.
Diffstat (limited to 'Alc/midi')
-rw-r--r--Alc/midi/fluidsynth.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c
index be3c0da7..fea40058 100644
--- a/Alc/midi/fluidsynth.c
+++ b/Alc/midi/fluidsynth.c
@@ -462,6 +462,7 @@ typedef struct FSynth {
ALsizei NumFontIDs;
ALboolean ForceGM2BankSelect;
+ ALfloat GainScale;
} FSynth;
static void FSynth_Construct(FSynth *self, ALCdevice *device);
@@ -495,6 +496,7 @@ static void FSynth_Construct(FSynth *self, ALCdevice *device)
self->FontIDs = NULL;
self->NumFontIDs = 0;
self->ForceGM2BankSelect = AL_FALSE;
+ self->GainScale = 0.2f;
}
static void FSynth_Destruct(FSynth *self)
@@ -520,6 +522,18 @@ static void FSynth_Destruct(FSynth *self)
static ALboolean FSynth_init(FSynth *self, ALCdevice *device)
{
+ ALfloat vol;
+
+ if(ConfigValueFloat("midi", "volume", &vol))
+ {
+ if(!(vol <= 0.0f))
+ {
+ ERR("MIDI volume %f clamped to 0\n", vol);
+ vol = 0.0f;
+ }
+ self->GainScale = powf(10.0f, vol / 20.0f);
+ }
+
self->Settings = new_fluid_settings();
if(!self->Settings)
{
@@ -528,6 +542,7 @@ static ALboolean FSynth_init(FSynth *self, ALCdevice *device)
}
fluid_settings_setint(self->Settings, "synth.polyphony", 256);
+ fluid_settings_setnum(self->Settings, "synth.gain", self->GainScale);
fluid_settings_setnum(self->Settings, "synth.sample-rate", device->Frequency);
self->Synth = new_fluid_synth(self->Settings);
@@ -611,9 +626,8 @@ static ALenum FSynth_selectSoundfonts(FSynth *self, ALCcontext *context, ALsizei
static void FSynth_setGain(FSynth *self, ALfloat gain)
{
- /* Scale gain by an additional 0.2 (-14dB), to help keep the mix from clipping. */
- fluid_settings_setnum(self->Settings, "synth.gain", 0.2 * gain);
- fluid_synth_set_gain(self->Synth, 0.2f * gain);
+ fluid_settings_setnum(self->Settings, "synth.gain", self->GainScale * gain);
+ fluid_synth_set_gain(self->Synth, self->GainScale * gain);
MidiSynth_setGain(STATIC_CAST(MidiSynth, self), gain);
}