Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lots of Comments (lots of comments)
Jacob Joaquin
September 27, 2010
jacobjoaquin@gmail.com
csoundblog.com
A Csound block begins with the CsoundSynthesizer tag. Everything outside of this tag is ignored by Csound:
<CsoundSynthesizer>
<CsInstruments>
; The orchestra block begins with the CsInstruments tag
; Header
;
; The header sets up the conditions of a Csound file.
sr = 44100 ; Sampling rate
kr = 4410 ; Control rate
ksmps = 10 ; 10 samples per k-block. sr / kr = 10
nchnls = 1 ; 1 output channel (mono)
0dbfs = 1 ; The range of the signal is -1 to 1
; A new instrument begins with the keyword instr, followed by a number or name
; for the instrument. In this case, we have assigned it the number 1. In the
; score, we will refer to this instrument with 1.
instr 1
; P-field input
;
; The following block of code reads in parameter field values (p) passed
; into the instrument from the score and assigns them to init type
; variables (i-type.) Though you can use p-field values directly in your
; instrument, assigning i-type variables to them at the top of your
; instrument will make your code easier to read for you and others.
idur = p3 ; Duration
iamp = p4 ; Amplitude
ipch = cpspch(p5) ; Pitch. cpspch converts octave point pitch-class
; notation (8ve.pc) to frequency in hertz.
ifn = p6 ; Function number of the look up table used by the audio
; oscillator. There are four defined in this
; example, created in the score. The table shapes
; are defined as:
; 1 - Sine wave
; 2 - Triangle wave
; 3 - Saw wave (down)
; 4 - Square wave
; Envelope
;
; The line opcode is a 1-segment envelope generator.
;
; It takes 3 arguments:
; starting value
; duration in seconds
; ending value
;
; The output of line is assigned to kenv. The first letter "k" designates
; the signal as being a control rate signal. The value of the signal is
; only updated once every 10 times in this example. Why? Because "ksmps" is
; set to 10 in the header.
;
; This signal will be fed to the oscillator in the next line of code.
kenv line iamp, idur, 0
; Audio oscillator
;
; The oscil opcode is an oscillator that creates a signal by cycling
; through values stored in a look up table. These look up tables are
; created using the GEN routines. In this example, they are created in the
; score using the "f" statement.
;
; It requires 3 arguments, and takes 1 additional optional argument (not
; shown here):
; amplitude
; frequency in hertz
; function table number
; starting phase (optional)
;
; The amplitude is being modulated by the envelope. Over the duration of an
; instance of the instrument, the amplitude will go from the value stored
; in iamp (p4) to 0.
;
; The output in this case is an audio rate signal , designated by the first
; letter "a" in "a1." Though a k-rate signal updates once every ksmps value,
; an a-rate signal is updated for every sample.
a1 oscil kenv, ipch, ifn ; Amp modulated table oscillator
; Output
;
; This last step sends the audio from "a1" to either the digital audio
; converter (DAC), or to a soundfile, depending on your command-line
; settings.
;
; The out opcode is for mono renders. "nchnls" in the header is set to 1.
; If this example was designed for stereo, "nchnls" would be set to 2 and
; instead of using out, you would use the outs opcode instead.
out a1 ; Output signal
; The instrument block ends with endin.
endin
; The orchestra block ends with /CsInstruments
</CsInstruments>
<CsScore>
; The score block begins with the CsScore tag.
; Tables
;
; The "f" statement in the score allows users to create function tables. The
; data generated depends on the GEN routine used. Two GEN types are used in
; this example: 7 and 10. GEN 10 "Generate composite waveforms made up of
; weighted sums of simple sinusoids." Gen 7 "Constructs functions from segments
; of straight lines."
;
; The first 5 parameters for every f-statement are:
; f
; table number
; when the table is created
; the size of the table
; the GEN routine to use
;
; Any additional paramenters are depend on the GEN routine used.
f 1 0 8192 10 1 ; Sine
f 2 0 8192 7 -1 4096 1 4096 -1 ; Triangle
f 3 0 8192 7 1 8192 -1 ; Saw (down)
f 4 0 8192 7 1 4096 1 0 -1 4096 -1 ; Square
; Tempo
;
; The score works in beat time. It defaults to 60 beats-per-minutes (BPM),
; which is the same as working in seconds. This example sets the BPM to 120.
t 0 120
; Instrument events
;
; i-events is what starts, and some times stops, instruments from the
; orchestra. Each of the following four i-events starts a new instance
; of instr 1.
;p0 p1 p2 p3 p4 p5 p6
; instr start_time duration amplitude pitch function_table
i 1 0 4 0.707 7.07 1
i 1 4 4 0.4 7.09 2
i 1 8 4 0.2 7.03 3
i 1 12 4 0.1 7.00 4
; The score block ends with the /CsScore tag
</CsScore>
</CsoundSynthesizer>
The Csound block ends with the /CsoundSynthesizer tag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.