[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[fluid-dev] Sustain pedal not working on compiled program using libfluid

From: Eric Gagnon
Subject: [fluid-dev] Sustain pedal not working on compiled program using libfluidsynth
Date: Wed, 6 Nov 2013 19:43:12 -0500



I have compiled a standalone C program using libfluidsynth 1.1.6.  This program is running on a small Intel Atom motherboard with Ubuntu server 12.04LTS.  Using a M-Audio standard USB-to-MIDI adapter, I interface to this motherboard to a standard Yamaha MIDI keyboard which also has a sustain pedal.  The MIDI device (port 20) is connected to the fluidsynth server (port 128) using the command “aconnect 20:0 128:0”.  Once done, I can play on the MIDI keyboard and hear sounds from the application synthesized by fluidsynth.  Everything works very well except for one problem.  The behaviour of the sustain pedal doesn’t appear to work correctly.  If I let go of the sustain pedal and strike a key, the sound fades quickly (as expected).  However, if I hold down the sustain pedal and strike a key, the sound does NOT fade any slower.  It fact, it fades exactly as quickly as when the sustain pedal is released.  It seems like the pedal has no effect.  I have checked and can confirm that the sustain pedal is sending midi message 176-64-127 (when on) and 176-64-0 (when off).  I am also using the standard Fluid R3 GM MIDI soundfont.


In order to eliminate some variables, I ran a completely separate test.  This time, instead of using my compile C program, I simply ran the fluidsynth server as a command-line utility:  


>jackd –R –t2500 –P81 –dalsa –p128 –n3 –r44100

>fluidsynth  -s  -a  jack  –j  -g0.2 –i  -r 44100 –o synth.polyphony=64 /usr/share/sounds/sf2/FluidR3_GM.sf2

>aconnect 20:0 128:0


When I do that and connect the MIDI output, it actually WORKS exactly as expected!  When I hold down the pedal, the notes take longer to fade.  This confirms that fluidsynth is able to respond to the signal and the the midi sustain pedal is sending the correct MIDI message across.  The remaining question is what is different about my C program using the libfluidsynth library that would prevent the sustain function from working?  I am not doing anything special and most of the settings are kept as defaults.  I checked all the command-line options of the command line fluidsynth utility and have all the same values selected in my program.  Any ideas why the default behaviour is different?  See code snippet below.


Secondly, in the fluidsynth API I cannot find any message that allows me to enable or disable sustain function.  The only references to sustain are the “overflow” settings below.  What is the proper fluidsynth API function call used to enable and disable sustain? 


Thanks for your help!



Here is a snippet of code of how I initialize the synth in my program:


synth_t *new_synth(int argc, char **argv)


                synth_t* synth_ptr = NULL;                                        // Temporary variables

                int err = 0, i;

                                                                                                                // Allocate mem for synth structure

                synth_ptr = (synth_t *) malloc(sizeof(synth_t));

                                                                                                                // On error, return immediately

                if (synth_ptr == NULL) return (NULL);

                                                                                                                // Allocate fluidsynth settings

                synth_ptr->settings = new_fluid_settings();


                if (synth_ptr->settings == NULL)                                               // On allocation error


                                err++;                                                                   // Increment err

                                goto synth_cleanup;                                      // Jump to cleanup


                else                                                                                        // If allocation successful, set

                {                                                                                              // desired parameters in settings

                                                                                                                // structure.  Polyphony = 64 prevents

                                                                                                                // system crash and distortion due to

                                                                                                                // limited Intel Atom processing power.

                                                                                                                // The synth assumes that the JACK

                                                                                                                // server is already running.

                                                                                                                // 44.1kHz sample rate.  Default

                                                                                                                // fluidsynth gain is nominally 0.2

                                fluid_settings_setint(synth_ptr->settings, "synth.polyphony", 64);

                                fluid_settings_setint(synth_ptr->settings, "synth.chorus.active", 1);

                                fluid_settings_setint(synth_ptr->settings, "synth.reverb.active", 1);


// The following values are simply experiments to try and get the sustain pedal to work.  No success yet…                           

//                            fluid_settings_setnum(synth_ptr->settings, "synth.overflow.age", 1000.0);

//                            fluid_settings_setnum(synth_ptr->settings, "synth.overflow.percussion", 4000.0);

//                            fluid_settings_setnum(synth_ptr->settings, "synth.overflow.released", -2000.0);

//                            fluid_settings_setnum(synth_ptr->settings, "synth.overflow.sustained", -1000.0);

//                            fluid_settings_setnum(synth_ptr->settings, "synth.overflow.volume", 500.0); 


                                fluid_settings_setnum(synth_ptr->settings, "synth.sample-rate", 44100.0);

                                fluid_settings_setint(synth_ptr->settings, "audio.jack.autoconnect", 1);

                                fluid_settings_setnum(synth_ptr->settings, "synth.gain", DEFAULT_SYNTH_GAIN);








reply via email to

[Prev in Thread] Current Thread [Next in Thread]