mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-25 08:22:17 +00:00
This commit is contained in:
@@ -26,6 +26,7 @@ static struct {
|
||||
fluid_synth_t *synth; ///< FluidSynth synthesizer handle
|
||||
fluid_player_t *player; ///< FluidSynth MIDI player handle
|
||||
std::mutex synth_mutex; ///< Guard mutex for synth access
|
||||
double max_gain; ///< Default max gain.
|
||||
} _midi; ///< Metadata about the midi we're playing.
|
||||
|
||||
/** Factory for the FluidSynth driver. */
|
||||
@@ -137,6 +138,14 @@ std::optional<std::string_view> MusicDriver_FluidSynth::Start(const StringList &
|
||||
if (sfont_id == FLUID_FAILED) return "Could not open sound font";
|
||||
}
|
||||
|
||||
/* Treat a configured synth gain as the maximum gain to use. */
|
||||
if (fluid_settings_getnum(_midi.settings, "synth.gain", &_midi.max_gain) != FLUID_OK) {
|
||||
if (fluid_settings_getnum_default(_midi.settings, "synth.gain", &_midi.max_gain) != FLUID_OK) {
|
||||
/* No synth.gain value present for some reason, use FluidSynth's default value. */
|
||||
_midi.max_gain = 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
_midi.player = nullptr;
|
||||
|
||||
return std::nullopt;
|
||||
@@ -217,11 +226,8 @@ void MusicDriver_FluidSynth::SetVolume(uint8_t vol)
|
||||
std::lock_guard<std::mutex> lock{_midi.synth_mutex};
|
||||
if (_midi.settings == nullptr) return;
|
||||
|
||||
/* Allowed range of synth.gain is 0.0 to 10.0 */
|
||||
/* fluidsynth's default gain is 0.2, so use this as "full
|
||||
* volume". Set gain using OpenTTD's volume, as a number between 0
|
||||
* and 0.2. */
|
||||
double gain = (1.0 * vol) / (128.0 * 5.0);
|
||||
/* Set gain using OpenTTD's volume, as a number between 0 and max_gain. */
|
||||
double gain = (1.0 * vol) / 128.0 * _midi.max_gain;
|
||||
if (fluid_settings_setnum(_midi.settings, "synth.gain", gain) != FLUID_OK) {
|
||||
Debug(driver, 0, "Could not set volume");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user