12 #include "../stdafx.h" 13 #include "../openttd.h" 14 #include "../sound_type.h" 17 #include "midifile.hpp" 33 "/usr/share/sounds/sf2/FluidR3_GM.sf2",
36 "/usr/share/soundfonts/FluidR3_GM.sf2",
39 "/usr/share/sounds/sf2/TimGM6mb.sf2",
40 "/usr/share/sounds/sf2/FluidR3_GS.sf2",
45 static void RenderMusicStream(int16 *buffer,
size_t samples)
48 fluid_synth_write_s16(
_midi.synth, samples, buffer, 0, 2, buffer, 1, 2);
56 DEBUG(driver, 1,
"Fluidsynth: sf %s", sfont_name);
59 _midi.settings = new_fluid_settings();
60 if (!
_midi.settings)
return "Could not create midi settings";
64 if (!
_midi.synth)
return "Could not open synth";
70 sfont_id = FLUID_FAILED;
72 if (!fluid_is_soundfont(
default_sf[i]))
continue;
74 if (sfont_id != FLUID_FAILED)
break;
76 if (sfont_id == FLUID_FAILED)
return "Could not open any sound font";
78 sfont_id = fluid_synth_sfload(
_midi.synth, sfont_name, 1);
79 if (sfont_id == FLUID_FAILED)
return "Could not open sound font";
85 fluid_synth_set_sample_rate(
_midi.synth, samplerate);
86 DEBUG(driver, 1,
"Fluidsynth: samplerate %.0f", (
float)samplerate);
95 delete_fluid_synth(
_midi.synth);
96 delete_fluid_settings(
_midi.settings);
105 if (filename.empty()) {
111 DEBUG(driver, 0,
"Could not create midi player");
115 if (fluid_player_add(
_midi.player, filename.c_str()) != FLUID_OK) {
116 DEBUG(driver, 0,
"Could not open music file");
117 delete_fluid_player(
_midi.player);
121 if (fluid_player_play(
_midi.player) != FLUID_OK) {
122 DEBUG(driver, 0,
"Could not start midi player");
123 delete_fluid_player(
_midi.player);
131 if (!
_midi.player)
return;
133 fluid_player_stop(
_midi.player);
134 if (fluid_player_join(
_midi.player) != FLUID_OK) {
135 DEBUG(driver, 0,
"Could not join player");
137 delete_fluid_player(
_midi.player);
138 fluid_synth_system_reset(
_midi.synth);
144 if (!
_midi.player)
return false;
146 return fluid_player_get_status(
_midi.player) == FLUID_PLAYER_PLAYING;
155 double gain = (1.0 * vol) / (128.0 * 5.0);
156 if (fluid_settings_setnum(
_midi.settings,
"synth.gain", gain) != 1) {
157 DEBUG(driver, 0,
"Could not set volume");
const char * GetDriverParam(const char *const *parm, const char *name)
Get a string parameter the list of parameters.
Metadata about a music track.
bool IsSongPlaying()
Are we currently playing a song?
void StopSong()
Stop playing the current song.
fluid_settings_t * settings
FluidSynth settings handle.
void Stop()
Stop this driver.
Base for FluidSynth music playback.
uint32 MxSetMusicSource(MxStreamCallback music_callback)
Set source of PCM music.
#define DEBUG(name, level,...)
Output a line of debugging information.
fluid_synth_t * synth
FluidSynth synthesizer handle.
static FMusicDriver_FluidSynth iFMusicDriver_FluidSynth
Factory for the FluidSynth driver.
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
void PlaySong(const MusicSongInfo &song)
Play a particular song.
static struct @24 _midi
Metadata about the midi we're playing.
void SetVolume(byte vol)
Set the volume, if possible.
static const char * default_sf[]
List of sound fonts to try by default.
Factory for the fluidsynth driver.
const char * Start(const char *const *param)
Start this driver.
fluid_player_t * player
FluidSynth MIDI player handle.