fluidsynth
index
/home/nwhitehe/Projects/pygalaxy/pyfluidsynth/fluidsynth.py

pyFluidSynth
 
Python bindings for FluidSynth
 
Copyright 2008, Nathan Whitehead <nwhitehe@gmail.com>
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.

 
Modules
       
numpy
time

 
Classes
       
Synth

 
class Synth
    Synth represents a FluidSynth synthesizer
 
  Methods defined here:
__init__(self, gain=0.20000000000000001, samplerate=44100)
Create 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)
Choose a bank
cc(self, chan, ctrl, val)
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
delete(self)
get_samples(self, len=1024)
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)
Stop a note
noteon(self, chan, key, vel)
Play a note
pitch_bend(self, chan, val)
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)
Change the program
program_reset(self)
Reset the programs on all channels
program_select(self, chan, sfid, bank, preset)
Select a program
sfload(self, filename, update_midi_preset=0)
Load SoundFont and return its ID
sfont_select(self, chan, sfid)
Choose a SoundFont
sfunload(self, sfid, update_midi_preset=0)
Unload a SoundFont and free memory it used
start(self, driver=None)
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'
 
Not all drivers will be available for every platform, it
depends on which drivers were compiled into FluidSynth for
your platform.
system_reset(self)
Stop all notes and reset all programs

 
Functions
       
addressof(...)
addressof(C instance) -> integer
Return the address of the C instance internal buffer
alignment(...)
alignment(C type) -> integer
alignment(C instance) -> integer
Return the alignment requirements of a C instance
byref(...)
byref(C instance) -> byref-object
Return a pointer lookalike to a C instance, only usable
as function argument
cfunc(name, result, *args)
build and apply a ctypes prototype complete with parameter flags
fluid_synth_write_s16_stereo(synth, len)
Return generated samples in stereo 16-bit format
 
Return value is a Numpy array of samples.
raw_audio_string(data)
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).
resize(...)
Resize the memory buffer of a ctypes instance
set_conversion_mode(...)
set_conversion_mode(encoding, errors) -> (previous-encoding, previous-errors)
 
Set the encoding and error handling ctypes uses when converting
between unicode and strings.  Returns the previous values.
sizeof(...)
sizeof(C type) -> integer
sizeof(C instance) -> integer
Return the size in bytes of a C instance

 
Data
        DEFAULT_MODE = 0
RTLD_GLOBAL = 256
RTLD_LOCAL = 0
api_version = '1.2'
cdll = <ctypes.LibraryLoader object at 0xb70758ec>
delete_fluid_audio_driver = <CFunctionType object at 0xb7083304>
delete_fluid_settings = <CFunctionType object at 0xb70833d4>
delete_fluid_synth = <CFunctionType object at 0xb708336c>
fluid_settings_setint = <CFunctionType object at 0xb708329c>
fluid_settings_setnum = <CFunctionType object at 0xb7083234>
fluid_settings_setstr = <CFunctionType object at 0xb70831cc>
fluid_synth_bank_select = <CFunctionType object at 0xb708377c>
fluid_synth_cc = <CFunctionType object at 0xb70836ac>
fluid_synth_noteoff = <CFunctionType object at 0xb70835dc>
fluid_synth_noteon = <CFunctionType object at 0xb7083574>
fluid_synth_pitch_bend = <CFunctionType object at 0xb7083644>
fluid_synth_program_change = <CFunctionType object at 0xb7083714>
fluid_synth_program_reset = <CFunctionType object at 0xb708384c>
fluid_synth_program_select = <CFunctionType object at 0xb708350c>
fluid_synth_sfload = <CFunctionType object at 0xb708343c>
fluid_synth_sfont_select = <CFunctionType object at 0xb70837e4>
fluid_synth_sfunload = <CFunctionType object at 0xb70834a4>
fluid_synth_system_reset = <CFunctionType object at 0xb70838b4>
fluid_synth_write_s16 = <CFunctionType object at 0xb708391c>
memmove = <CFunctionType object at 0xb70d5bf4>
memset = <CFunctionType object at 0xb70d5c5c>
new_fluid_audio_driver = <CFunctionType object at 0xb7083164>
new_fluid_settings = <CFunctionType object at 0xb70d5b8c>
new_fluid_synth = <CFunctionType object at 0xb70830fc>
pydll = <ctypes.LibraryLoader object at 0xb707592c>
pythonapi = <PyDLL 'None', handle b7f58668 at b707594c>