Pyfluidsynth - Python bindings for FluidSynth

  •        0

pyFluidSynthPython bindings for FluidSynthCopyright 2008, Nathan Whitehead , maintained by Bart Spaans Released under the LGPL This module contains 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. REQUIREMENTSFluidSynth 1.0.7 (or later version) (earlier versions probably work, untested) NumPy 1.0 or later DOWNLOADpyFluidSynth is available as a source distribution from PyPI. INSTALLATIONpyFluidSynth is packaged as Python source using distutils. To install, run the following command as root: python install For more information and options about using distutils, read: EXAMPLEHere is a program that plays a chord for a second. import timeimport fluidsynthfs = fluidsynth.Synth()fs.start()sfid = fs.sfload("example.sf2")fs.program_select(0, sfid, 0, 0)fs.noteon(0, 60, 30)fs.noteon(0, 67, 30)fs.noteon(0, 76, 30)time.sleep(1.0)fs.noteoff(0, 60)fs.noteoff(0, 67)fs.noteoff(0, 76)time.sleep(1.0)fs.delete()First a Synth object is created to control playback. The start() method starts audio output in a separate thread. To get sound, you need to choose an instrument. First load a SoundFont with sfload(), then select a bank and preset with program_select(). program_select(track, soundfontid, banknum, presetnum) To start a note, use the noteon() method. noteon(track, midinum, velocity) To stop a note, use noteoff(). noteoff(track, midinum) MANAGING AUDIOYou can also manage audio IO yourself and just use FluidSynth to calculate the samples for the music. You might do this, for example, in a game with WAV sound effects and algorithmically generated music. To do this, create the Synth object but don't call start(). To generate the next chunk of audio, call get_samples(). get_samples(len) The length you pass will be the number of audio samples. Unless specified otherwise, FluidSynth assumes an output rate of 44100 Hz. The return value will be a Numpy array of samples. By default FluidSynth generates stereo sound, so the return array will be length 2 len. To join arrays together, use numpy.append(). To convert an array of samples into a string of bytes suitable for sending to the soundcard, use fluidsynth.raw_audio_string(samples). Here is an example that generates a chord then plays the data using PyAudio. import timeimport numpyimport pyaudioimport fluidsynthpa = pyaudio.PyAudio()strm = format = pyaudio.paInt16, channels = 2, rate = 44100, output = True)s = []fl = fluidsynth.Synth()# Initial silence is 1 seconds = numpy.append(s, fl.get_samples(44100 * 1))sfid = fl.sfload("example.sf2")fl.program_select(0, sfid, 0, 0)fl.noteon(0, 60, 30)fl.noteon(0, 67, 30)fl.noteon(0, 76, 30)# Chord is held for 2 secondss = numpy.append(s, fl.get_samples(44100 * 2))fl.noteoff(0, 60)fl.noteoff(0, 67)fl.noteoff(0, 76)# Decay of chord is held for 1 seconds = numpy.append(s, fl.get_samples(44100 * 1))fl.delete()samps = fluidsynth.raw_audio_string(s)print len(samps)print 'Starting playback'strm.write(samps)BUGS AND LIMITATIONSNot all functions in FluidSynth are bound. Not much error checking, FluidSynth will segfault/crash if you call the functions incorrectly sometimes.



Related Projects

MuseScore - MuseScore Free music composition and notation software

MuseScore is a free music composition and notation software. It is easy to use and makes beautiful sheet music. MuseScore is often praised as a cost effective alternative for Sibelius and Finale. It is easy and fast note entry with mouse, keyboard or MIDI. It supports playback with integrated sequencer and FluidSynth software synthesizer.


AlsaModularSynth is a MIDI controlled realtime modular synthesizer and effect processor with support for LADSPA and JACK.

GR FloorBoard

midi editing software for use with the Roland GR-55 guitar synthesizer, to allow graphical representation of the internal settings and parameters of the GR-55. Realtime editing and patch data backups, bulk patch editing.


PyDAW is a complete solution for producing electronic music in Linux. PyDAW consists of a full featured DAW with built-in sampler, synthesizers and effects. PyDAW features ultra-tight, sample accurate audio and MIDI timing, and high quality plugin DSP.


SoundHelix is a free versatile Java framework for algorithmic random music composition. SoundHelix can generate random songs, play them (for example, on any number of MIDI devices or MIDI-capable software synthesizers) and is highly customizable using XML configuration. SoundHelix produces music that is actually enjoyable to listen to.


LMMS is a free cross-platform software which allows you to produce music with your computer. This covers creating melodies and beats, synthesizing and mixing sounds and arranging samples. You can have fun with your MIDI keyboard and much more – all in a user-friendly and modern interface. Furthermore LMMS comes with many ready-to-use instrument and effect plugins, presets and samples.


A modular VST instrument software synthesizer.


MIDI and audio sequencer and notation editor for Linux


Midi hardware editor.


MidiShare is a real-time musical MIDI operating system. Result of many years of research and development undertaken by Computer Music Research Laboratory of Grame, MidiShare provides high level services to the field of computer music and MIDI applications

We have large collection of open source products. Follow the tags from Tag Cloud >>