COURSE NOTES
Introduction to Computer Music Programming and Csound

Introduction to Csound

The Orchestra File

An Example Instrument

    instr 1
a1  oscil 10000, 440, 1
    out a1
    endin

The Complete Orchestra File

sr = 20000		; audio sampling rate
kr = 400		; control rate
ksmps = 50		; samples/control period
nchnls = 1		; number of audio channels
    instr 1
a1  oscil 10000, 440, 1
    out a1
    endin

The Score File

The Function Table

Csound Function GEN10: Sum of Sine Waves

Function Table Examples

f1 0 256 10 1
f2 0 256 10 1 0 0.33 0 0.2
f3 0 512 10 1 0.25 0.111 0.06 0.04

Tempo and Beats

The Note Statement

Example Note Statements
(The period "." indicates the carry feature, where the value is the same value as the same parameter in the previous statement.)

t 0 120
i1 0 0.5
i1 0.5 .
i1 1.0 .
i1 1.5 .
i1 2.0 1.0

The Complete Score File

; a sine wave function table
f1 0 256 10 1
; five notes played by instrument 1
i1 0 0.5
i1 0.5 .
i1 1.0 .
i1 1.5 .
i1 2.0 1.0
e

Optional Note Parameters

Second Example (Use of Optional Parameters)

; Orchestra File
sr = 20000
kr = 400
ksmps = 50
nchnls = 1

instr 1
a1  oscil p4, p5, 1
    out a1
endin
====================================
; Score File
f1 0 256 10 1

i1 0 0.5 10000 440
i1 0.5 . 5000 660
i1 1.0 . 10000 440
i1 1.5 . 20000 200
i1 2.0 1.0 15000 440

e

Introduction to Control (k) Orchestra Variables

Third Example (Use of Control Variable)

; Orchestra File
sr = 20000
kr = 400
ksmps = 50
nchnls = 1

instr 1
k1  line 0, p3, p4
a1  oscil k1, p5, 1
    out a1
endin
====================================
; Score File
f1 0 256 10 1

i1 0 0.5 10000 440
i1 0.5 . 5000 660
i1 1.0 . 10000 440
i1 1.5 . 20000 200
i1 2.0 1.0 15000 440

e

Oscillator Algorithm

Formulas

Sampling Increment Examples

Non-integral Increments

General Oscillator Algorithm

Initialize table[] with periodic waveform
index = 0, j = 0, incr = f0*L/R
buf[j] = table[index]
S = D * R
for j = 1 to (S-1)
begin
    index = (index + incr) mod L
    buf[j] = table[index]
end

Csound Signal Generators

kr line ia, idur1, ib		; kr = control var.
ar line ia, idur1, ib		; ar = audio var.
kr linseg ia, idur1, ib [, idur2, ic [, ...]]
ar linseg ia, idur1, ib [, idur2, ic [, ...]]
examples:
	k4 line p4, p3, 0
	a3 linseg 0, p3/3, p4, 2*p3/3, 0
kr expon ia, idur1, ib
ar expon ia, idur1, ib
kr expseg ia, idur1, ib [, idur2, ic [, ...]]
ar expseg ia, idur1, ib [, idur2, ic [, ...]]
examples:
	k4 expon p4, p3, 0.0001
	a4 expseg 0.0001, p3/3, p4, 2*p3/3, 0.0001
kr oscil xamp, xcps, ifn[, iphs]
ar oscil xamp, xcps, ifn[, iphs]
kr oscili xamp, xcps, ifn[, iphs]
ar oscili xamp, xcps, ifn[, iphs]
ifn: function table number (stored in score)
iphs: initial phase (fractional value between 0 and 1)

Csound Signal Modifiers

kr linen xamp, irise, idur, idec
ar linen xamp, irise, idur, idec
irise = rise time in seconds
idec = decay time in seconds
idur = overall duration of envelope in seconds
example:
	k5 linen p4, p3/10, p3, p3/4
	a1 oscil k5, p5, 1

Csound Example: Amplitude Control

sr = 22000				; ORCHESTRA
kr = 1100
ksmps = 20
nchnls = 1
; p3 = duration, p4 = amplitude, p5 = pitch
instr 1
k1  linen p4, p3/8, p3, p3/2
a1  oscil k1, p5, 1
    out a1
endin
===========================
f1 0 256 10 1 0 0.33 0 0.2		; SCORE
i1 0 1.0 25000 440
e

Csound Function GEN07 & GEN05: Linear and Exponential Segments

Using Oscillator Algorithm for Amplitude Envelope

Csound Example: Amplitude Control (Again) using Oscillator for Amplitude Envelope

sr = 22000				; ORCHESTRA
kr = 1100
ksmps = 20
nchnls = 1
; p3 = duration, p4 = amplitude, p5 = pitch
instr 1
k1  oscil p4, 1/p3, 2
a1  oscil k1, p5, 1
    out a1
endin
===========================
f1 0 256 10 1 0 0.33 0 0.2		; SCORE
f2 0 256 7 0 32 1 96 1 128 0
i1 0 1.0 25000 440
e

Csound Signal Display and Audio Output

display xsig, iprd
	iprd - the period of display (in seconds)
	examples:
	k1 linen p4, p3/8, p3, p3/2
	   display k1, p3
	a1 oscil p4, p5, 1
	   display a1, p3    ; bad display
	a2 oscil p4, p5, 1
 	   display a2, 1/p5  ; good display - one cycle
out asig		; output for one channel (monophonic)
outs asig1, asig2	; output for two channels (stereophonic)

COURSE INFORMATION | HOMEWORK ASSIGNMENTS
COURSE PROJECT | CS240 HELP DESK