fluidload - Loads a SoundFont, assigns a MIDI channel to a
SoundFont preset.
fluidcontrol - Sends MIDI note on, note off, and
other messages to a SoundFont preset.
fluidout - Receives sound
from all loaded SoundFonts.
These opcodes provide a simple Csound opcode wrapper around Peter Hanappe's Fluidsynth SoundFont2 synthesizer. This implementation accepts any MIDI note on, note off, controller, pitch bend, or program change message at k-rate. Maximum polyphony is 4096 simultaneously sounding voices.Any number of SoundFonts may be loaded and played simultaneously.
fluidload soundfont, iprogram, ichannel [, olistprograms]
fluidcontrol kstatus, kchannel, kdata1, data2
aleft, aright fluidout
aleft - Left channel audio output.
aright - Right channel audio output.
soundfont - String specifying a SoundFont filename. Note that any number of SoundFonts may be loaded (obviously, by different invocations of fluidload).
iprogram - Number of the Fluidsynth program to be assigned to a MIDI channel.
kstatus - MIDI channel message status byte: 128 for note off, 144 for note on, 176 for control change, 192 for program change, or 224 for pitch bend. Note off messages need not be specified, as one is automatically generated when each Csound note expires or is released.
ichannel, kchannel - MIDI channel number to which the Fluidsynth program is assigned: from 0 to 255. MIDI channels numbered 16 or higher are virtual channels.
kdata1 - For note on, MIDI key number: from 0 (lowest) to 127 (highest), where 60 is middle C. For continuous controller messages, controller number.
kdata2 - For note on, MIDI key velocity: from 0 (no sound) to 127 (loudest). For continous controller messages, controller value.
olistprograms - If specified, lists all Fluidsynth programs for the just-loaded SoundFont. A Fluidsynth program is a combination of SoundFont ID, bank number, and preset number that is assigned to a MIDI channel.
Invoke fluidload in the orchestra header, any number of times. The same SoundFont may be invoked to assign programs to MIDI channels any number of times; the SoundFont is only loaded the first time.
Invoke fluidcontrol in instrument definitions that actually play notes and send control messages. Each instrument definition must consistently use one MIDI channel that was assigned to a Fluidsynth program using fluidload.
Invoke fluidout in an instrument definition numbered higher than any fluidcontrol instrument definitions. All SoundFonts send their audio output to this one opcode. Send a note with a long duration to this instrument to turn the SoundFonts on for as long as required.
In this implementation, SoundFont effects such as chorus or reverb are used if and only if they are defaults for the preset. There is no means of turning such effects on or off, or of changing their parameters, from Csound.
sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 0dbfs = 32767 ; LOAD SOUNDFONTS fluidload "Piano Steinway Grand Model C (21,738KB).sf2", 1, 1, 1 ; Bright Steinway, program 1, channel 1 fluidload "Piano Steinway Grand Model C (21,738KB).sf2", 2, 3, 1 ; Concert Steinway with reverb, program 2, channel 3 fluidload "63.3mg The Sound Site Album Bank V1.0.SF2", 50, 2, 1 ; General MIDI, program 50, channel 2 ; SEND NOTES TO STEINWAY SOUNDFONT instr 1 ; FluidSynth Steinway Rev ; INITIALIZATION mididefault 60, p3 ; Default duration of 60 -- overridden by score. midinoteonkey p4, p5 ; Channels MIDI input to pfields. ; Use channel assigned in fluidload. ichannel = 3 ikey = p4 ivelocity = p5 istatus = 144 fluidcontrol istatus, ichannel, ikey, ivelocity endin ; COLLECT AUDIO FROM ALL SOUNDFONTS instr 100 ; Fluidsynth output ; INITIALIZATION ; Normalize so iamplitude for p5 of 80 == ampdb(80). iamplitude = ampdb(p5) * (10000.0 / 0.1) ; AUDIO aleft, aright fluidout outs aleft * iamplitude, aright * iamplitude endin
Opcodes by Michael Gogins (gogins at pipeline dot com). Thanks to Peter Hanappe for Fluidsynth, and to Steven Yi for seeing that it is necessary to break up the Fluidsynth into several different Csound opcodes.