Python bindings for FluidSynth.

FluidSynth is a software synthesizer for generating music. It works like a MIDI synthesizer.

You load patches, set parameters, then send NOTEON and NOTEOFF events to play notes.

Instruments are defined in SoundFonts, generally files with the extension SF2.

FluidSynth can either be used to play audio itself, or you can call a function that returns chunks of audio data and output the data to the soundcard yourself.

FluidSynth works on all major platforms, so pyFluidSynth should also.

class mingus.midi.pyfluidsynth.Synth[source]
__init__(self, gain=0.2, samplerate=44100)[source]

Create a new synthesizer object to control sound generation.

Optional keyword arguments:
gain: scale factor for audio output, default is 0.2
lower values are quieter, allow more simultaneous notes

samplerate: output samplerate in Hz, default is 44100 Hz

bank_select(self, chan, bank)[source]

Choose a bank.

cc(self, chan, ctrl, val)[source]

Send control change value.

The controls that are recognized are dependent on the SoundFont. Values are always 0 to 127. Typical controls include:

1: vibrato 7: volume 10: pan (left to right) 11: expression (soft to loud) 64: sustain 91: reverb 93: chorus
get_samples(self, len=1024)[source]

Generate audio samples.

The return value will be a NumPy array containing the given length of audio samples. If the synth is set to stereo output (the default) the array will be size 2 * len.

noteoff(self, chan, key)[source]

Stop a note.

noteon(self, chan, key, vel)[source]

Play a note.

pitch_bend(self, chan, val)[source]

Adjust pitch of a playing channel by small amounts.

A pitch bend value of 0 is no pitch change from default. A value of -2048 is 1 semitone down. A value of 2048 is 1 semitone up. Maximum values are -8192 to +8192 (transposing by 4 semitones).

program_change(self, chan, prg)[source]

Change the program.


Reset the programs on all channels.

program_select(self, chan, sfid, bank, preset)[source]

Select a program.

sfload(self, filename, update_midi_preset=0)[source]

Load SoundFont and return its IDi.

sfont_select(self, chan, sfid)[source]

Choose a SoundFont.

sfunload(self, sfid, update_midi_preset=0)[source]

Unload a SoundFont and free memory it used.

start(self, driver=None)[source]

Start audio output driver in separate background thread.

Call this function any time after creating the Synth object. If you don’t call this function, use get_samples() to generate samples.

Optional keyword argument:
driver: which audio driver to use for output
Possible choices:
‘alsa’, ‘oss’, ‘jack’, ‘portaudio’ ‘sndmgr’, ‘coreaudio’, ‘Direct Sound’, ‘dsound’, ‘pulseaudio’

Not all drivers will be available for every platform, it depends on which drivers were compiled into FluidSynth for your platform.


Stop all notes and reset all programs.


Attribute of type: int 0


Attribute of type: int 256


Attribute of type: int 0


Attribute of type: str '1.2'


Attribute of type: ctypes.LibraryLoader <ctypes.LibraryLoader object at 0x7f9066868810>


Attribute of type: str 'libfluidsynth.so.1'


Attribute of type: ctypes.LibraryLoader <ctypes.LibraryLoader object at 0x7f9066868850>


Attribute of type: ctypes.PyDLL <PyDLL 'None', handle 7f9069f84188 at 7f9066868890>

mingus.midi.pyfluidsynth.ARRAY(typ, len)[source]

CFUNCTYPE(restype, *argtypes,
use_errno=False, use_last_error=False) -> function prototype.

restype: the result type argtypes: a sequence specifying the argument types

The function prototype can be called in different ways to create a callable object:

prototype(integer address) -> foreign function prototype(callable) -> create and return a C callable function from callable prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal prototype((function name, dll object)[, paramflags]) -> foreign function exported by name


mingus.midi.pyfluidsynth.SetPointerType(pointer, cls)[source]

mingus.midi.pyfluidsynth.c_buffer(init, size=None)[source]

mingus.midi.pyfluidsynth.cast(obj, typ)[source]

mingus.midi.pyfluidsynth.cfunc(name, result)[source]

Build and apply a ctypes prototype complete with parameter flags.

mingus.midi.pyfluidsynth.create_string_buffer(init, size=None)[source]

create_string_buffer(aString) -> character array create_string_buffer(anInteger) -> character array create_string_buffer(aString, anInteger) -> character array

mingus.midi.pyfluidsynth.create_unicode_buffer(init, size=None)[source]

create_unicode_buffer(aString) -> character array create_unicode_buffer(anInteger) -> character array create_unicode_buffer(aString, anInteger) -> character array


mingus.midi.pyfluidsynth.fluid_synth_write_s16_stereo(synth, len)[source]

Return generated samples in stereo 16-bit format.

Return value is a Numpy array of samples.


Return a string of bytes to send to soundcard.

Input is a numpy array of samples. Default output format is 16-bit signed (other formats not currently supported).

mingus.midi.pyfluidsynth.string_at(ptr, size=-1)[source]

string_at(addr[, size]) -> string

Return the string at addr.

mingus.midi.pyfluidsynth.wstring_at(ptr, size=-1)[source]

wstring_at(addr[, size]) -> string

Return the string at addr.

Back to Index