How-To Control Csound with a Custom Midi Controller: Introduction (1 of 2)
Csound is a free language for sound synthesis and processing. It has a rich history and is still used today by musicians, composers and sound designers including Brian Eno, Richard James (aka Aphex Twin), NIN, DJ Spooky, and many more. Why is Csound still in existence today? It is a simple language which veers quickly to complex auditory experiences. This coupled with a quick learning curve has kept Csound a popular audio synthesis language since its creation in 1985 by Barry Vercoe.
This How-To is one of a two part installment. Part One is an introductory leap into Csound. Part Two next week will have you building a physical interface to control a Csound environment via Midi. Please note that this intro is a small daub of paint in the universe that is Csound creation. Many books, entire webpages, and courses have been taught on Csound. This introduction is meant to offer a glimpse into the rich world of audio creation and to hopefully inspire the reader to invest more time in Csound.
You will need for this How-To: a computer with an audio card, and a Mac (OS X or OS 9), Windows, or Linux operating
system. This How-To will focus on the lastest Mac OS X version of Csound, but should allow extrapolation to your
OS.
Find and install Csound for your OS of choice:
Mac OS X
Mac OS 9
Windows
Linux (also
here)
If you are in doubt about which version to grab go to the Csound front page and
choose "Execs" and navigate to the download for your operating system or alternatively see the
sourceforge page for Csound.
Launch the Csound application. Notice you have "orc" and "sco" tabs at the top of the main window. Orc
stands for orchestra which is the area where you will define what your instruments will sound like. Sco stands
for Score, the section in which you will define the notes and durations and parameters for each instrument.
Delete the text in the "orc" window and cut and paste this text to replace it (or download both orc and score files
from here):
COPY AND PASTE THE TEXT BELOW THIS LINE
=======================================
;Fabienne Serriere
;engadget.com
;23rd August 2005
;feel free to redistribute! please use me and re-use me.
sr = 44100
kr = 44100
ksmps = 1
nchnls = 1
instr 10
idur = p3
iamp = ampdb(p4)
ifrq = cpspch(p5)
ifun = p6
iatk = p7
irel = p8
iatkfun = p9
index1 = p10
index2 = p11
kenv envlpx iamp, iatk, idur, irel, iatkfun, .7, .01
kmodswp expon index1, idur, index2
kbuzswp expon 20, idur, 1
afab grain 10000, ifrq*.04, 55, 10000, 10, .05, 1, 1, 1
asig3 foscil kenv, ifrq, 1, 1, kmodswp, ifun
asig2 buzz kenv, ifrq*.99, kbuzswp+1, ifun
asig1 pluck iamp, ifrq*.5, ifrq, 0, 1
amix = asig1+asig2+asig3+afab
out amix*.5
endin
instr 20
idur = p3
iamp = ampdb(p4)
ifrq = cpspch(p5)
iatk = p6
irel = p7
ivibdel = p8
imoddpt = p9
imodfrq = p10
iharm = p11
kenv linen iamp, iatk, idur, irel
kvibenv linseg 0, ivibdel, 1, idur-ivibdel, .3
klfo oscil kvibenv*imoddpt, imodfrq, 2
asig buzz kenv, ifrq+klfo, iharm, 2
out asig
endin
instr 30 ; 3D Sample Wave Terrain
ilevl =
p4*32767
; Output level
ipitch = (p5 < 10 ? cpspch(p5) : p5) ; Pitch in cpspch or Hz
iposx1 =
p6
; X position start
iposx2 =
p7
; X position finish
iposy1 =
p8
; Y position start
iposy2 =
p9
; Y position finish
iradi1 =
p10/1000
; Radius start (scaled)
iradi2 =
p11/1000
; Radius end (scaled)
iratex =
p12
; X random rate
iratey =
p13
; Y random rate
idpth =
p14/1000
; Random depth (scaled)
kx line iposx1, p3, iposx2 ; X position
ky line iposy1, p3, iposy2 ; Y position
krad line iradi1, p3, iradi2 ; Radius
krndx randi idpth, iratex ; X random
position modulation
krndy randi idpth, iratey ; Y random
position modulation
ksin oscili krad, ipitch, 40 ; X indexing osc
(sine)
kcos oscili krad, ipitch, 40, .25 ; Y indexing osc (cosine)
kindx = kx + ksin + krndx ; Add X
indexes together
kindy = ky + kcos + krndy ; Add Y
indexes together
ax tablei kindx, 20, 1, 0, 1 ; X indexing
ay tablei kindy, 30, 1, 0, 1 ; Y indexing
out
ax*ay*ilevl
; Output
endin
instr 40
idur = p3
iamp = ampdb(p4)
ifrq = cpspch(p5)
ifun = p6
iatk = p7
irel = p8
iatkfun = p9
index1 = p10
index2 = p11
kenv envlpx iamp, iatk, idur, irel, iatkfun, .7, .01
kmodswp expon index1, idur, index2
kbuzswp expon 20, idur, 1
afab grain 10000, ifrq*.5, 55, 10000, 10, .05, 1, 1, 1
asig3 foscil kenv, ifrq, 1, 1, kmodswp, ifun
asig2 buzz kenv, ifrq*.99, kbuzswp+1, ifun
asig1 pluck iamp, ifrq*.5, ifrq, 0, 1
amix = asig1+asig2+asig3+afab
out amix*.5
endin
==========================
COPY AND PASTE THE TEXT ABOVE THIS LINE
Next do the same for the "sco" section. Delete the existing text and cut and paste this in its place (or
download both orc and score files from here):
COPY AND PASTE THE TEXT BELOW THIS LINE
==========================
;Fabienne Serriere
;engadget.com
;23rd August 2005
;feel free to redistribute! please use me and re-use me.
;Function 1 uses the GEN15 subroutine to compute a sine wave
;Function 2 uses the GEN10 subroutine to compute a sine wave
;Function 9 uses the GEN05 subroutine to compute an exponential Attack for use with envlpx
;Function 10 uses the GEN05 subroutine to compute an exponential Attack for use with envlpx
;Function 20 terrain table
;Function 30 terrain table
;Function 40 index table
f 1 0 4096 15 1
f 2 0 4096 10 1
f 9 0 513 5 .001 128 .8 128 .6 256 1
f 10 0 513 5 .01 64 1 64 .5 64 .99
64 .6 64 .98 64 .7 64 .97 32 .8 32 1
f 20 0 32768 1 "sample.wav" 0 4 0 ; X Sample1
f 30 0 65536 1 "sample.wav" 0 4 0 ; Y Sample1
f 40 0 8193 10 1 ; Sine
;ins st dur amp frq
fun atk rel atkfun indx1 indx2
;===========================================
i 10 0 .4 58 4.00
1 .5 1 9 3
100
i 10 + .4 59 4.00 1
.5 1 9 3
100
i 10 . .4 60 4.00
1 .5 1 9 3
100
i 10 . .4 62 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .2 75 4.00
1 .5 1 9 3
100
i 10 . .2 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .133 75 4.00 1
.5 1 9 3
100
i 10 . .133 75 4.00 1
.5 1 9 3
100
i 10 . .133 75 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 75 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00 1
.5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . .4 66 4.00
1 .5 1 9 3
100
i 10 . 4 75 4.00
1 .5 5 9 3
100
;ins st dur amp frq
atk rel lfodel lfodpth
lfofrq harm1
;=================================================
i 20 4 2 74 6.02
.2 .4 .5
5 6 9
i 20 + 1 74
6.02 .1 .5
.8 4
5 12
i 20 . .1 76 6.04
.2 .4 .5
5 6 9
i 20 . .1 74
6.03 .1 .5
.8 4
5 12
i 20 . 2 75 6.02
.3 .3 1.6
7 7
6
i 20 . 1 75 6.04
.5 .3 1
6 4.7 8
i 20 . 1 80 6.02
.9 .4 1.5
5 6
11
i 20 . .1 82 5.11
.2 .4 .5
5 6 9
i 20 . .1 82
6.0 .1 .5
.8 4
5 12
i 20 . 3 80 6.02
.1 .3
1 4 5
5
==========
; Strt Leng Levl Pitch Xpos1 Xpos2 Ypos1 Ypos2 Radi1 Radi2 Xrate Yrate Depth
i 30 16 20.0 1.00 300.0 0.25 0.35 0.10 0.75 0.00
0.35 2.35 1.11 0.10
i 30 . . 0.05 220.5 0.10 0.33 1.00 0.33
0.00 0.25 1.25 0.77 0.10
i 30 . . 1.00 480.3 0.50 0.77 0.80 0.74
0.01 0.08 2.23 3.14 0.10
; Strt Leng Levl Pitch Xpos1 Xpos2 Ypos1 Ypos2 Radi1 Radi2 Xrate Yrate Depth
i 30 30 25.0 1.00 330.0 0.25 0.35 0.10 0.75 0.00
0.05 2.35 1.11 0.10
i 30 . . 0.05 80.5 0.10 0.93 1.00
0.33 0.00 0.25 1.25 0.77 0.10
i 30 . . 1.00 480.3 0.50 0.77 0.80 0.74
0.01 0.98 2.23 3.14 0.10
; Strt Leng Levl Pitch Xpos1 Xpos2 Ypos1 Ypos2 Radi1 Radi2 Xrate Yrate Depth
i 30 50 32.0 1.00 300.0 0.01 0.03 0.80 0.75 0.09
0.35 2.35 1.11 0.10
i 30 . . 0.05 220.5 0.10 0.33 1.00 0.33
0.00 0.25 1.25 0.77 0.10
i 30 . . 1.00 480.3 0.50 0.98 0.80 0.04
0.01 0.08 2.23 3.14 0.10
=========
;=============================================
i 40 72.4 .4 75 6.00 1
.5 1 9 3
100
i 40 + .6 66 6
1 .5 1 9 3
100
i 40 . .2 66 5.09
1 .5 1 9 3
100
i 40 . .4 66 5.09
1 .5 1 9 3
100
i 40 . .4 75 6
1 .5 1 9 3
100
i 40 . .6 66 6
1 .5 1 9 3
100
i 40 . .2 66 5.07
1 .5 1 9 3
100
i 40 . .4 66 5.07
1 .5 1 9 3
100
i 40 . .4 75 5.09
1 .5 1 9 3
100
i 40 . .4 66 5.10 1
.5 1 9 3
100
i 40 . .4 66 6.0
1 .5 1 9 3
100
i 40 . .4 66 6.02
1 .5 1 9 3
100
i 40 . .4 75 5.09
1 .5 1 9 3
100
i 40 . .4 66 5.10 1
.5 1 9 3
100
i 40 . .4 66 6.0
1 .5 1 9 3
100
i 40 . .4 66 6.02
1 .5 1 9 3
100
i 40 . .4 62 5.04
1 .5 1 9 3
100
i 40 . .4 62 5.05 1
.5 1 9 3
100
i 40 . .4 62 5.06
1 .5 1 9 3
100
i 40 . .4 62 5.07
1 .5 1 9 3
100
i 40 . .4 62 5.04
1 .5 1 9 3
100
i 40 . .4 62 5.05 1
.5 1 9 3
100
i 40 . .4 62 5.06
1 .5 1 9 3
100
i 40 . .4 62 5.07
1 .5 1 9 3
100
i 40 . .4 < 5.02
1 .5 1 9 3
100
i 40 . .4 . 5.021 1
.5 1 9 3
100
i 40 . .4 . 5.022
1 .5 1 9 3
100
i 40 . .4 . 5.023
1 .5 1 9 3
100
i 40 . .1 50 5.06
1 .5 1 9 3
100
i 40 . .1 50 5.07 1
.5 1 9 3
100
i 40 . .1 50 5.06
1 .5 1 9 3
100
i 40 . .1 50 5.06 1
.5 1 9 3
100
i 40 . .1 50 5.07 1
.5 1 9 3
100
i 40 . .1 50 5.05
1 .5 1 9 3
100
i 40 . .1 50 5.07
1 .5 1 9 3
100
i 40 . .1 50 5.06 1
.5 1 9 3
100
i 40 . .1 50 5.06
1 .5 1 9 3
100
i 40 . .1 50 5.08
1 .5 1 9 3
100
i 40 . .1 50 5.07 1
.5 1 9 3
100
i 40 . .1 50 5.05
1 .5 1 9 3
100
i 40 . .1 < 5.06
1 .5 1 9 3
100
i 40 . .1 . 5.07 1
.5 1 9 3
100
i 40 . .1 . 5.06
1 .5 1 9 3
100
i 40 . .1 . 5.06 1
.5 1 9 3
100
i 40 . .1 . 5.07 1
.5 1 9 3
100
i 40 . .1 . 5.05
1 .5 1 9 3
100
i 40 . .1 . 5.07
1 .5 1 9 3
100
i 40 . .1 . 5.06 1
.5 1 9 3
100
i 40 . .1 . 5.06
1 .5 1 9 3
100
i 40 . .1 . 5.08
1 .5 1 9 3
100
i 40 . .1 . 5.07 1
.5 1 9 3
100
i 40 . .1 . 5.05
1 .5 1 9 3
100
i 40 . .1 . 5.06
1 .5 1 9 3
100
i 40 . .1 . 5.07 1
.5 1 9 3
100
i 40 . .1 40 5.06
1 .5 1 9 3
100
i 40 . .1 . 5.06 1
.5 1 9 3
100
i 40
















Reader Comments (Page 1 of 1)
mike @ Dec 19th 2005 2:47AM
Why is the entire article up on the home page?
carpespasm @ Dec 19th 2005 2:47AM
is it just me, or does this article seem to not be posted right? i know one of my buddies that would probably get into csound, he is already into both programming and music.
s8ist @ Dec 19th 2005 2:47AM
awesome tutorial.. always wanted to know what richard james was using... although i'm sure it's just a small piece of the puzzle, i'm glad to see this stuff. keep it coming. and as for the question, "why is the whole article up on the homepage?" i'm sure you can scroll down. people need to stop complaining about the content they're not interested in. you have the option to either visit the site or not. i know the effort involved is painful and excrutiating. put the bacon-butter-mayo sandwich down, and move the damn mouse.
brandon @ Dec 19th 2005 2:47AM
the space and tab formatting seems to be incorrect, ive had to go back and re-space everything. maybe due to html formatting?
roleo hibachi @ Dec 19th 2005 2:47AM
Hey, the engadget '85 link gave me a thought... why not have a Hackaday MUD session? just a concept...
Brandon @ Dec 19th 2005 2:47AM
I like mud. Mud in my jeep. Check out my jeep.
http://www.cardomain.com/ride/2094780/1
Nathan @ Dec 19th 2005 2:47AM
I did a whole semester of Csound in college. It was a blast. I still have a few of my orc's and sco's around somewhere. Will have to drag em out and try them with the new real-time renderer and see how it goes. I used to have to wait for a LONG time to get some of the granular synthesis stuff to render on those old G3's.
Injulen @ Dec 19th 2005 2:47AM
Oooh. Spiffy.
I just realized, Hackaday's first post is Sept 5 2004. That means, that the 1 year anniversary of Hackaday is coming up!
fabienne @ Dec 19th 2005 2:47AM
4. brandon: there are text versions of the files if you so wish for the spacing/tab issues:
http://www.engadget.com/misc/text_files.zip
also, csound doesn't care about the number of spaces (or tab size) as long as there is at least one space between fields. the files should still render even if the spacing is messy.
---fabienne
forest @ Dec 19th 2005 2:47AM
w00t! I use Csound and this tutorial is great...thanx!
Peter Kirn @ Dec 19th 2005 2:47AM
Okay, I was skeptical of the choice of Csound here, but later in the day talked to electronica master BT. He takes weekly courses on Csound and swears by it:
http://createdigitalmusic.com/index.php?option=com_content&task=view&id=824&Itemid=44
Max/MSP and Reaktor may remain my tools of choice (or Pd for a free alternative), but I'm increasingly respecting Csound in the modern age. Maybe I should play with that tool for bring Pd into Max.
wow . . . my caps are gone! This site is like a copy editor's worse nightmare. ;-)
forest @ Dec 19th 2005 2:47AM
peter: I use both Pd and Csound and I swear by csound. I wanted to build a simple FM Synth in Pd and what I got was a cluttered mess of boxes and lines. The same synth in csound is a mere 3 lines:
kmod oscili p6, p7, 1
aout oscili p4, p5 + kmod, 1
outs aout, aout
quaeler @ Dec 19th 2005 2:47AM
am i on crack or do the score lines featuring a row of uncommented equals signs cause compile errors (like line 111 in the score)?