LJ Archive

Real-time Linux Csound

A simple introduction to Linux Csound's real-time usage can be presented by defining an instrument (a simple oscillator), creating it in a text editor and saving it as my.orc:

sr=22050 ; sets sampling rate
kr=441 ; sets control rate for k-rate components
ksmps=50 ; sr/kr, number of samples per control
         ; period
nchnls=1 ; monaural output

instr 1
kamp = 10000 ; raw amplitude
kfreq = 440  ; an A at 440 cps
ifn = 1      ; stored function table 1
asig oscil kamp, kfreq, ifn ; an audio signal is
; created by an oscillator playing
; a stored sine wave at kamp and kfreq out asig
; the audio signal is sent out endin
Next, we write another file called my.sco. When compiled, the score will be played by the instrument:
f1 0 8192 10 1 ; stored sine wave
i1 0 3 ; instrument 1 plays for 3 seconds,
       ; start time
at 0
e
We then compile our orc/sco files into a sound file:
csound -omy.wav -W my.orc my.sco
; creates a WAV format sound file
Csound will create the sound file, the user can play it with vplay or any other WAV player and it can be edited by MiXViews, DAP, Snd or any other Linux sound file editor.

If we wish to send the sound output directly to the sound card DAC, we use this command:

csound -o devaudio -W -dm6 my.orc my.sco
where: With a full-duplex sound card, it is possible to have simultaneous audio input and output, allowing real-time signal processing. A command for such a setup (using the ALSA driver) would look like this:
csound -iADC -oDAC -W -dm6 inout.orc inout.sco
where:
LJ Archive