Plays a note at imidikey pitch and imidivel velocity on ichannelnum channel of number ienginenum fluidEngine.
ienginenum -- engine number assigned from fluidEngine
ichannelnum -- which channel number to play a note on in the given fluidEngine
imidikey -- MIDI key for note (0-127)
imidivel -- MIDI velocity for note (0-127)
Here is an example of the fluidsynth opcodes. It uses the file fluid.orc.
sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 0dbfs = 32767 ; LOAD SOUNDFONTS ienginenum1 fluidEngine ienginenum2 fluidEngine isfnum1 fluidLoad "Piano Steinway Grand Model C (21,738KB).sf2", ienginenum1, 1 fluidProgramSelect ienginenum1, 1, isfnum1, 0, 1 ; Bright Steinway, program 1, channel 1 fluidProgramSelect ienginenum1, 3, isfnum1, 0, 2 ; Concert Steinway with reverb, program 2, channel 3 isfnum2 fluidLoad "63.3mg The Sound Site Album Bank V1.0.SF2", ienginenum2, 1 fluidProgramSelect ienginenum2, 2, isfnum2, 0, 50 ; 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 = 1 ikey = p4 ivelocity = p5 istatus = 144 fluidControl ienginenum1, istatus, ichannel, ikey, ivelocity endin instr 2 ; GM soundfont ; 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 = 2 ikey = p4 ivelocity = p5 istatus = 144 fluidNote ienginenum2, ichannel, ikey, ivelocity endin instr 3 ; 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 fluidNote ienginenum1, ichannel, ikey, ivelocity endin ; COLLECT AUDIO FROM ALL SOUNDFONTS instr 100 ; Fluidsynth output ; INITIALIZATION ; Normalize so iamplitude for p5 of 80 == ampdb(80). iamplitude1 = ampdb(p5) * (10000.0 / 0.1) iamplitude2 = ampdb(p6) * (10000.0 / 0.1) ; AUDIO aleft1, aright1 fluidOut ienginenum1 aleft2, aright2 fluidOut ienginenum2 outs (aleft1 * iamplitude1) + (aleft2 * iamplitude2), (aright1 * iamplitude1) + (aright2 * iamplitude2) endin
Here is another more comples example of the fluidsynth opcodes written by Istvan Varga. It uses the file fluidcomplex.csd.
<CsoundSynthesizer> <CsOptions> -d -m229 -o dac -T -F midifile.mid </CsOptions> <CsInstruments> sr = 48000 ksmps = 32 nchnls = 2 0dbfs = 1 ; Example by Istvan Varga ; disable triggering of instruments by MIDI events ichn = 1 lp1: massign ichn, 0 loop_le ichn, 1, 16, lp1 pgmassign 0, 0 ; initialize FluidSynth gifld fluidEngine gisf2 fluidLoad "2gmgsmt.sf2", gifld, 1 ; k-rate version of fluidProgramSelect opcode fluidProgramSelect_k, 0, kkkkk keng, kchn, ksf2, kbnk, kpre xin igoto skipInit doInit: fluidProgramSelect i(keng), i(kchn), i(ksf2), i(kbnk), i(kpre) reinit doInit rireturn skipInit: endop instr 1 ; initialize channels kchn init 1 if (kchn == 1) then lp2: fluidControl gifld, 192, kchn - 1, 0, 0 fluidControl gifld, 176, kchn - 1, 7, 100 fluidControl gifld, 176, kchn - 1, 10, 64 loop_le kchn, 1, 16, lp2 endif ; send any MIDI events received to FluidSynth nxt: kst, kch, kd1, kd2 midiin if (kst != 0) then if (kst != 192 || kch != 10) then fluidControl gifld, kst, kch - 1, kd1, kd2 else fluidProgramSelect_k gifld, kch - 1, gisf2, 128, kd1 endif kgoto nxt endif ; get audio output from FluidSynth aL, aR fluidOut gifld outs aL, aR endin </CsInstruments> <CsScore> i 1 0 3600 e </CsScore> </CsoundSynthesizer>