First post, by gaula92
Hello there
I found a nice patch to use libfluidsynth as a MIDI device in Dosbox in the sourceforge project page. It's a simple patch, but I can't get it to compile with 0.74 sources (I had to manually apply it to some files).
I'm getting errors while compiling dosbox, but they have no sense to me. gcc seems to complain about undefined functions that are indeed defined in fluidsynth.h!
This is my src/gui/midi_synth.h
#include "mixer.h"
#include <fluidsynth.h>
extern "C" {
typedef struct _fluid_midi_parser_t fluid_midi_parser_t;
fluid_midi_parser_t *new_fluid_midi_parser(void);
fluid_midi_event_t *fluid_midi_parser_parse(fluid_midi_parser_t *parser, unsigned char c);
int delete_fluid_midi_parser(fluid_midi_parser_t* parser);
void fluid_log_config(void);
}
static MixerChannel *synthchan;
static fluid_synth_t *synth_soft;
static fluid_midi_parser_t *synth_parser;
static int synthsamplerate;
static void synth_CallBack (Bitu len) {
fluid_synth_write_s16(synth_soft, len, MixTemp, 0, 2, MixTemp, 1, 2);
synthchan->AddSamples_s16(len,(Bit16s *)MixTemp);
}
static void synth_log(int level, char *message, void *data) {
switch (level) {
case FLUID_PANIC:
case FLUID_ERR:
LOG(LOG_ALL,LOG_ERROR)(message);
break;
case FLUID_WARN:
LOG(LOG_ALL,LOG_WARN)(message);
break;
default:
LOG(LOG_ALL,LOG_NORMAL)(message);
break;
}
}
class MidiHandler_synth: public MidiHandler {
private:
fluid_settings_t *settings;
fluid_midi_router_t *router;
int sfont_id;
bool isOpen;
public:
MidiHandler_synth() : isOpen(false),MidiHandler() {};
char * GetName(void) { return "synth"; };
bool Open(const char *conf) {
/* Sound font file required */
if (!conf || (conf[0] == '\0')) {
LOG_MSG("SYNTH: Specify .SF2 sound font file with config=");
return false;
}
fluid_log_config();
fluid_set_log_function(FLUID_PANIC, synth_log, NULL);
fluid_set_log_function(FLUID_ERR, synth_log, NULL);
fluid_set_log_function(FLUID_WARN, synth_log, NULL);
fluid_set_log_function(FLUID_INFO, synth_log, NULL);
fluid_set_log_function(FLUID_DBG, synth_log, NULL);
/* Create the settings. */
settings = new_fluid_settings();
if (settings == NULL) {
LOG_MSG("SYNTH: Error allocating MIDI soft synth settings");
return false;
}
fluid_settings_setstr(settings, "audio.sample-format", "16bits");
if (synthsamplerate == 0) {
synthsamplerate = 44100;
}
fluid_settings_setnum(settings,
"synth.sample-rate", (double)synthsamplerate);
/* Create the synthesizer. */
synth_soft = new_fluid_synth(settings);
if (synth_soft == NULL) {
LOG_MSG("SYNTH: Error initialising MIDI soft synth");
delete_fluid_settings(settings);
return false;
}
/* Load a SoundFont */
sfont_id = fluid_synth_sfload(synth_soft, conf, 0);
if (sfont_id == -1) {
LOG_MSG("SYNTH: Failed to load MIDI sound font file \"%s\"",
conf);
delete_fluid_synth(synth_soft);
delete_fluid_settings(settings);
return false;
}
/* Allocate one event to store the input data */
synth_parser = new_fluid_midi_parser();
if (synth_parser == NULL) {
LOG_MSG("SYNTH: Failed to allocate MIDI parser");
delete_fluid_synth(synth_soft);
delete_fluid_settings(settings);
return false;
}
router = new_fluid_midi_router(settings,
fluid_synth_handle_midi_event,
(void*)synth_soft);
if (router == NULL) {
LOG_MSG("SYNTH: Failed to initialise MIDI router");
delete_fluid_midi_parser(synth_parser);
delete_fluid_synth(synth_soft);
delete_fluid_settings(settings);
return false;
}
synthchan=MIXER_AddChannel(synth_CallBack, synthsamplerate, "SYNTH");
synthchan->Enable(false);
isOpen = true;
return true;
};
void Close(void) {
if (!isOpen) return;
delete_fluid_midi_router(router);
delete_fluid_midi_parser(synth_parser);
delete_fluid_synth(synth_soft);
delete_fluid_settings(settings);
isOpen=false;
};
void PlayMsg(Bit8u *msg) {
fluid_midi_event_t *evt;
Bitu len;
int i;
len=MIDI_evt_len[*msg];
synthchan->Enable(true);
/* let the parser convert the data into events */
for (i = 0; i < len; i++) {
evt = fluid_midi_parser_parse(synth_parser, msg[i]);
if (evt != NULL) {
/* send the event to the next link in the chain */
fluid_midi_router_handle_midi_event(router, evt);
}
}
};
void PlaySysex(Bit8u *sysex, Bitu len) {
fluid_midi_event_t *evt;
int i;
/* let the parser convert the data into events */
for (i = 0; i < len; i++) {
evt = fluid_midi_parser_parse(synth_parser, sysex[i]);
if (evt != NULL) {
/* send the event to the next link in the chain */
fluid_midi_router_handle_midi_event(router, evt);
}
}
};
};
MidiHandler_synth Midi_synth;
And this is the kind of errors GCC is throwing at me:
make[3]: Entering directory `/usr/src/dos/dosbox-0.74-fluidsynth/src'
g++ -g -O2 -o dosbox dosbox.o cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a -lSDL_sound -lSDL -lpthread -lpng -lz -lSDL_net -lX11 -lGL
gui/libgui.a(midi.o): In function `synth_CallBack':
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:24: undefined reference to `fluid_synth_write_s16'
gui/libgui.a(midi.o): In function `MidiHandler_synth::PlaySysex(unsigned char*, unsigned int)':
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:163: undefined reference to `fluid_midi_parser_parse'
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:166: undefined reference to `fluid_midi_router_handle_midi_event'
gui/libgui.a(midi.o): In function `MidiHandler_synth::PlayMsg(unsigned char*)':
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:150: undefined reference to `fluid_midi_parser_parse'
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:153: undefined reference to `fluid_midi_router_handle_midi_event'
gui/libgui.a(midi.o): In function `MidiHandler_synth::Close()':
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:134: undefined reference to `delete_fluid_midi_router'
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:135: undefined reference to `delete_fluid_midi_parser'
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:136: undefined reference to `delete_fluid_synth'
/usr/src/dos/dosbox-0.74-fluidsynth/src/gui/midi_synth.h:137: undefined reference to `delete_fluid_settings'
Can someone please help me fixing my midi_synth.h file so it compiles and works?
regards