Title: More on the Orchestra
1More on the Orchestra
- Csound is a high level programming language
- Optimized for synthesis and audio processing,
but - Shares many features with other text-based
languages - Csound provides numerous opcodes that perform
complex DSP functions - Allows users to design instruments quickly and
efficiently, working at a high level - Csound also provides a limited set of standard
programming functions - Allows users to make more flexible instruments
and/or to extend Csounds functionality, working
at a lower level
2Typical Programming Tasks
- Doing arithmetic
- Looking things up in tables
- Reading and writing files
- Printing messages/displaying data
- Making logical decisions
- Controlling execution order
3Csound Expressions
- Arithmetic Expressions
- A valid CSound Arithmetic Expression consists of
one or more terms (constants, variables,
function calls, or sub-expressions) connected by
arithmetic or logical operators, and producing a
result - Basic arithmetic operators ( and ) / -
- Operator Precedence is as listed above
- Some Csound functions sqrt, log, int, abs, sin,
and cos
4Example Arithmetic Expressions
irise idecay
p3 .5
- Functions evaluated first
- Next, expressions in parentheses
- Then and /
- Then and
- Finally, left to right order
5Logical Expressions
- For conditional operations
- May be part of a Csound arithmetic expression
- Produces a single numerical result
- Complete Syntax (condition ? expr1
expr2) - If condition is true, then return the result of
expr1, else return the result of expr2.
6Logical Operators
7Example Conditional Expressions
- In an assignment statement
- ival (sr 22050 ? icps/2 icps)
- ival (p16 gt 0 ? p16 sqrt(.5))
- In place of an argument to an opcode
- asig oscili kamp,cpspch(p5),(p6 0 ? p1 p6)
- In a conditional branching statement
- if (iamp gt 10000) goto continue
8Branching in Csound
9Sample Orchestra 2
sr 44100 kr 4410 ksmps 10 nchnls 2
stereo orchestra instr 1,2,3,4 identical
instruments initialization block if (p9 ! 0)
igoto pan i-time conditional branch ilfac
.707 if p9 is 0, default to mono irfac
.707 sqrt(.5) -- see note below igoto
continue unconditional branch pan get
here if p9 ! 0... ilfac sqrt(p9) p9 has
factor for left chan irfac sqrt(1-p9) send
the rest to right chan continue performance
block kgate linen p4, p6, p3, p7
amp,rise,dur,decay from score asig
oscili kgate, cpspch(p5), p8 p5 in pch, p8 has
fn outs asigilfac, asigirfac panning via
ilfac, irfac endin
10More on the Score
- Score is purposefully very simple, both in
function and in features - Instead of providing a extensive set of operators
to manipulate score data, Csound makes format
extremely simple - This encourages users to write their own external
utilities to generate and modify score data
11The Carry Feature Sections
- Values from the preceding i-statement carry to
any empty p-fields of the current card, if the
instrument number remains the same. - Applies only to i-statements
- Shuts off when instrument or opcode changes
- An empty p-field is indicated with a .
character. - After last entry in an i-statement, all
subsequent p-fields are assumed to be empty. - N.B., bug in some versions (f-card data may
carry)!
12Example (from the Primer)
13Sections in the Score
- An s-statement is used to mark the beginning of a
new section in the score. - Establishes a new (relative) time 0.0, from which
the subsequent start times are measured. - The new section (and new time 0.0) will begin
after the end of the last event of the previous
section (either the last f-statement or the
conclusion of the last i-statement).
14Extending a section with f0
- An f-statement with a funtion number (p1) of zero
can be used to extend a section after the last
note has finished. - Only p1 and p2 of the f-statement should be used.
- p1 (normally the function ) must be 0
- p2 specifies the time at which the non-event will
occur. The next section (begun with an
s-statement) will not begin until after this
time. - Example
- i1 0.0 6.0
- f0 8.0
- s
- i1 0.0 3.0
- results in a silence (rest) from beat 6.0 to
beat 8.0
15The Tempo Statement
- By default, Csound scores are assumed to be at a
tempo of 60 beats per minute (bpm), or one beat
per second. - This means that p2 and p3 of i-statements are
effectively the starting times and durations
on notes. Actually, however, they are values
expressed in beats. - A t-statement can be used to alter the tempo
within a particular section. - It is normally placed at the start of a section.
16Format of the Tempo Statement
- p1 must be zero p2 is initial tempo in bpm
- Starting with p3 p4, p-fields in pairs. Odd
p-fields contain a time in beats even p-fields
contain the tempo at that time. - All starting times and durations between two
successive tempi are altered appropriately (by
proportional interpolation) to effect a smooth
accelerando or ritardando.
17Tempo Statement Example
- T1 B2 T2 B3 T3 B4 T4
- t 0 90 2.0 120 8.5 120 10.0 40
- All notes from time 0 to time 2.0 will
accelerate from 90 bpm to 120 bpm - Notes from time 2.0 to 8.5 will remain at 120
- Notes from time 8.5 to 10 will decelerate
dramatically to 40 bpm. - Notes from time 10-on will remain at 40 bpm.
18Sample Score 2
Sample Score 2 This is a brief score for
Sample Orchestra 2, which calls for a tempo of
96... t00 96 ...and uses Gen10 to store a single
sine wave with octave overtone at one half
amplitude f01 0.0 512 10 1 .5 There are six
notes in section 1, with the following
P-fields insno start dur amp pch rise decay
fn panpos i01 0.0 0.5 20000 8.09 .1 .2
1 .5 i01 0.5 1.5 17500 8.10 i02
0.0 1.7 15000 8.00 .1 .2 1 .75 i02
1.7 0.3 22000 8.02 i03 0.2 0.8 19000
7.04 .1 .2 1 .25 i03 1.0 1.0
15000 7.04 ...then a 2-beat rest until time 4,
using an f-zero card f0 4.0 s ...then a
three-note chord in section 2 starting at total
time 4.0 i01 0.0 2.0 10000 9.05 .1 .2
1 .5 i02 0.0 2.0 10000 8.02 .1
.2 1 .75 i03 0.0 2.0 10000 7.00 .1
.2 1 .25 e
19The Csound .csd format
- Csound Structured Data (.csd) files
- Contain orchestra, score, and options
- Uses tags similar to html
- ltCsoundSynthesizergt
- ltCsoundOptionsgt
- Command line flags go here (optional)
- lt/CsoundOptionsgt
- ltCsoundInstrumentsgt
- Orchestra goes here
- lt/CsoundInstrumentsgt
- ltCsoundScoregt
- Score goes here
- lt/CsoundScoregt
- lt/CsoundSynthesizergt
20Assignments
- Read Primer Chapter 2
- Code and run Sample Orc/Sco 2
- Try converting to a .csd file
- PC Users - See Michael Gogins Tutorial