I have a C code that creates a virtual synthesizer using FluidSynth. It loads a soundfont and connects the synthesizer to an external USB MIDI controller.
The code works perfectly on Debian. However, when I run it on a Raspberry Pi, the external MIDI controller fails to connect, and no error messages are displayed.
I’m using a Raspberry Pi Zero 2 W with Raspberry Pi OS 32-bit.
Note: If I manually connect the MIDI controller via shell using the command aconnect ‘Keystation Mini 32’:0 ‘fluid’:0, it works perfectly on the Raspberry Pi.
I can see the controller with aconnect -l and I add user to audio group with sudo usermod -a -G audio dimax
libasound2-dev libfluidsynth-dev, alsa-utils are installed.
Here’s the code:
#include <fluidsynth.h>
//to compile: gcc -o test test.c `pkg-config fluidsynth --libs` -lm//
/*function that set the handler for midi event and allows communication between external midi controller and virtual synth*/
int fluid_synth_handle_midi_event(void *data,fluid_midi_event_t *event);
/*function to manage the reverb of the synth*/
int main(int argc, char **argv){
/*define fluidsynth type to be used*/
fluid_settings_t *settings = NULL;
fluid_synth_t *synth = NULL;
fluid_audio_driver_t *adriver = NULL;
fluid_midi_driver_t* mdriver = NULL;
int sfont_id;
int err = 0;
/* Create the settings. */
settings = new_fluid_settings();
if(settings == NULL)
{
puts("Failed to create the settings!");
goto err;
}
/*set midi autoconnect to automatically connect virtual synth to available midi ports*/
fluid_settings_setint(settings,"midi.autoconnect",1);
/*create new synth instance*/
synth = new_fluid_synth(settings);
if(synth == NULL)
{
puts("Failed to create the synth!");
goto err;
}
/*create midi driver using fluid_synth_handle_midi_event as handler*/
mdriver = new_fluid_midi_driver(settings,fluid_synth_handle_midi_event, synth);
if(mdriver == NULL){
puts("Filed to create midi driver");
goto err;}
/* Create the audio driver. The synthesizer starts playing as soon
as the driver is created. */
adriver = new_fluid_audio_driver(settings, synth);
if(adriver == NULL)
{
puts("Failed to create the audio driver!");
goto err;
}
//INITIALIZE SOUNDFONTS//
sfont_id = fluid_synth_sfload(synth,"synth1.SF2", 1);
fluid_synth_noteon(synth, 0,60, 80);
printf("press any key");
getc(stdin);
err:
/*cleanup*/
delete_fluid_audio_driver(adriver);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
return 0;
}
Any ideas? Thank you in advance!
I’m trying to connect the external MIDI controller to the virtual synthesizer in FluidSynth with midi.autoconnect, but the connection fails.
Dimax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.