Live Flute Synthesis with Linux and Csound5
by Brian Redfern
Brian Redfern is a Los Angeles based musician who first talked to Mstation when we were a little baby e-zine, almost ten years ago. There, he talked about what he was doing then with references to the Drum n bass scene. Here he is talking about something made possible by newer more powerful computers which enable realtime alteration of sound parameters. He uses
csound to do this, and
some knowledge of it will be helpful to understand what's going on. On the other
hand, it might inspire people who don't know it to give it a try - it's free for one
Csound is my favorite software synthesizer. Its nearly infinite in its capabilities, only limited by processing power and ram. Now I don't have the greatest machine on the planet, it cost under $200 and only has a 1.8ghz single core processor. So its not necessary to have some quad-core mega-box. It's possible to play with realtime csound under linux with a fairly modest machine.
So how to get started? Its all up to you, if you're just getting started though, I would recommend the Jacklab Open Suse based Linux Audio distribution, as it comes with all the pieces needed to do
csound5 in real-time all built into the distribution, so you don't need to compile anything from source yourself. If you do, you can take advantage of 64 bit processing power to use more ram and resources than are available with a 32 bit Linux distribution.
Ok, so now you have a distribution, lets examine a csound file that will allow me to control its pitch with my usb midi keyboard. Now normally with csound you use a score file to set the pitches and parameter controls, but nowadays even entry level PCs are powerful enough to run at least one csound instrument in real-time. In my case I can only run one at a time, so I don't use a midi sequencer to compose, instead I use
ardour2 when I want to multitrack multiple csound instruments.
In this example I use the waveguide flute model to create a haunting synthetic flute. I'm using a combination of three real-time controllers and some randomness to give it a fresh and lively sound. Now the first part to note is the set of flags I'm using to setup my real-time control. First I set audio output to
rtaudio=jack so that I can use
jack to playback and also record, so I could pipe
ardour2, or I could even use
jackrack to process my instrument further with my
ladspa plugins. Then I set the realtime midi to
alsa, in this case using midi hardware #1, which corresponds to my usb midi keyboard.
Now the score part of this instrument just sets up an f0 table that runs for a few hours, long enough that it could still keep going even after I fall asleep!
The first part of the instrument captures the action of my pitch bend. If you have knobs on your keyboard, you could also capture them here using a generic midi controller. But for now I'm just capturing the key note, the velocity and pitch bend. The
ikoct is set to a 4 octave range, and the
kfratio connects to midic7 to capture the pitch bend. Then I use
cpsmidi to convert the midi note to a standard pitch. To use the pitch bend I then multiply i1 by the
kfratio. I use an envelope to shape the attack and sustain, and you can get crazy effects by extending the sustain, which I set here to 3 seconds. You could also randomize the sustain for some weird looping effects.
; Select audio/midi flags here according to platform -+rtaudio=jack -i adc -o dac -+rtmidi=alsa -M hw:1 ; Initialize the global variables. sr = 44100 ksmps = 128 nchnls = 2 ; Instrument #1. instr 1 ikoct = 8 ;4 octave range kfratio midic7 1, 1, ikoct ;mod.wheel controls transposition ifscale = 2 ifn = 1 i1 cpsmidi ivel veloc kamp = ivel*500 kfreq = i1*kfratio kjet = rnd(0.5) iatt = 0.1 idetk = 0.1 kngain = rnd(0.05) kvibf = kfratio kvamp = 0.05 kenv linsegr 0,0.001,ivel/128, 3, 0 a1 wgflute kamp, kfreq, kjet, iatt, idetk, kngain, kvibf, kvamp, ifn outs a1*kenv,a1*kenv endin ; Table #1, a sine wave. f 1 0 16384 10 1 ; f table to keep running without score f 0 120000 e
Now lets see how we can microtune our instrument, to go beyond the standard western pitches.
ftgen to generate a table of pitch values that sets up our micro-tuned scale, in this case instead of the normal 12 tones of the western scale, we have a 14 tone scale developed by the microtonal composer Kraig Grady. Instead of
cpsmid, which converts the midi input into a standard western tuning, we use
cpstmid, which allows us to convert the midi input pitches into the microtuned scale set by
gitemp. I'm using the same midi controls as before, but this time I have my own custom scale so that I'm not limited to the western tuning.
; Select audio/midi flags here according to platform ; Audio out Audio in No messages ;-odac -iadc -d ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o wgflute.wav -W ;;; for file output any platform -+rtaudio=jack -i adc -o dac -+rtmidi=alsa -M hw:1 ; Initialize the global variables. sr = 44100 ksmps = 128 nchnls = 2 ; Table #1 Kraig Grady's 14 tone mictotuned scale ; numgrades = 14 (fourteen tones) ; interval = 2 (one octave) ; basefreq = 261.659 (Middle C) ; basekeymidi = 60 (Middle C) gitemp ftgen 2, 0, 64, -2, 14, 2, 261.659, 60, 1.05, 1.125, 1.166666666666666667, 1.25, 1.3125, 1.333333333333333333, 1.4, \ 1.5, 1.575, 1.6875, 1.75, 1.875, 1.96875, 2 ; Instrument #1. instr 1 ikoct = 8 ;4 octave range kfratio midic7 1, 1, ikoct ;mod.wheel controls transposition ifscale = 2 ifn = 2 i1 cpstmid ifn ivel veloc kamp = ivel*200 kfreq = i1*kfratio kjet = rnd(0.5) iatt = 0.1 idetk = 0.1 kngain = 0.15 kvibf = kfratio kvamp = 0.05 kenv linsegr 0,0.001,ivel/128, 3, 0 a1 wgflute kamp, kfreq, kjet, iatt, idetk, kngain, kvibf, kvamp, ifn outs a1*kenv,a1*kenv endin ; Table #1, a sine wave. f 1 0 16384 10 1 ; f table to keep running without score f 0 120000 e
Bookmark:post to Delicious Digg Reddit Facebook StumbleUpon
Recent on Mstation: music: Vivian Girls, America's Cup, music: Too Young to Fall..., music: Pains of Being Pure At Heart, Berlin Lakes, music: Atarah Valentine, Travel - Copenhagen, House in the Desert