NTNU · Department of Music
Csound Crash Course
Four days to get you reading, running, and writing Csound. The course will provide you with some basic knowledge you will need in the Ear Training for Digital Audio Production and the sensor-based work in the Electronic Music course.
Andreas Bergsland, teacher · Tore Talgø Roaldset, student assistant
Orientation
Why this course exists
Ear Training for Digital Audio Production asks you to read and modify existing Csound code across a wide range of DSP techniques — digital audio basics, modulated delay lines, distortion, reverb, spectral processing, convolution, and more. Furhtermore, in the second module of the Electronic Music course, you will build Csound instruments to communicate with motion sensors over OSC, treating that data, and mapping it to sound. In the last module of the course, some basic spatialization techniques for Csound will also be demonstrated.
The crash course will establish a shared vocabulary, a strategy for reading code you don't yet understand, and the ability to look up an unfamiliar opcode in the manual and work out what it does — the daily skill both courses assume you already have.
Before Day 1
Set up your system
Do this before the first lecture — lab time on Day 1 is for learning Csound, not troubleshooting installers.
- Install Csound 6.18 and CsoundQT (and Cabbage, if you don't already have it — you'll meet it briefly this week).
- Render the provided day1-starter.csd — both from CsoundQT and from a terminal / command line — and confirm you hear sound.
- Bring headphones, or make sure your machine's audio output works reliably in the lab room.
How to run Csound from the terminal
The minimal recipe — no need to type or remember a file path:
- Open a terminal (macOS) or Command Prompt (Windows).
- Type
csoundfollowed by a space — don't press Enter yet. - Drag the
.csdfile from Finder / Explorer and drop it into the terminal window. This types the full file path for you. - Press Enter.
csound /Users/you/Csound/day1-lecture-sketch.csd
Day 01
Getting oriented: how Csound works
The basic building blocks: how Csound's orchestra and score fit together, and how to read code you don't yet understand — including the manual entry for an opcode you've never seen.
Topics
- Orchestra vs. score, and the .csd container
- i-, k-, and a-rate variables — what they mean and why the rate matters
- Oscillators, envelopes, pitch conversion
- k-rate vs. a-rate envelopes — why a fast attack can audibly "step" at k-rate, heard directly
- Running Csound: CsoundQT vs. the terminal, offline vs. real-time
- Reading Csound's error messages
- The style guide - how to write readable and understandable code
- How to read a Csound manual entry: syntax lines, rate variants, required vs. optional arguments
You'll leave able to
- Explain how orchestra and score relate, and what an instrument / note event is
- Identify i-, k-, and a-rate variables in a piece of code
- Explain why amplitude envelopes default to a-rate in this course (house style #8)
- Diagnose a common error from the compiler error message alone
- Read an unfamiliar manual entry and extract its syntax, rates, and required arguments — without having seen the opcode before
- Build a simple oscillator + envelope instrument from a near-blank template
- Function tables: Use GEN10 to add harmonically related sine waves
- Read this .csd file to review the structure and functionality of the .csd-file format
- Run the provided example — break things on purpose, one line at a time, read the errors carefully and compare with those listed in "Common errors" at the boottom of this page
- Modify pitch, amplitude, and envelope shape of a given instrument
- Compare the k-rate and a-rate envelope instruments by ear — same envelope, different rate
- Build your own oscillator + envelope instrument from a skeleton template
- Explore the manual: look up three sound generating opcodes (see Signal Generators in the Csound manual) you've never seen before, and explore how they sound with different parameter settings
- Comment an instrument, line by line, in your own words
- Etude: using only what you built today, make a short (30–60s) miniature with a clear shape — a beginning, a middle, an end. Not a technical demo of oscillator+envelope, a small piece of music.
day1-starter.csd
Loading…Download day1-starter.csd
Why it matters: this is the shared vocabulary both follow-on courses assume — gDSP's code examples and Electronic Music's from-scratch instruments both rest on it.
Day 02
DSP with Csound: trying out some basic effects
The opcode vocabulary behind the DSP techniques you'll be asked to recognize by ear — and later read in code — in Ear Training for Digital Audio Production.
Topics
- Global variables and dry/wet mixing — separate dry and effect buses, combined at the end
- diskin2 to play a sound file, using a pitch ratio as its speed argument to transpose
- Named instruments (instr Source, instr Distortion...) instead of numbers
- Distortion: use clip or tanh to distort and balance to restore levels afterwards
- Filters: butterlp, and why balance matters again here too
- Comb filters with vcomb: delay with feedback — several effects depending on settings
- Modulated delay lines: vibrato / chorus using vdelay3 and an a-rate LFO
- Reverb: reverbsc
- A master instrument: dry/wet mixing with ntrpol, then clearing the buses with clear
- Simple score shortcuts such as repeat (.) and relative timing for p2 (^+)
You'll leave able to
- Identify and understand some basic DSP techniques
- Choose between two similar opcodes using only their manual entries — and justify the choice
- Modify DSP parameters in filters, delay, and distortion effects and estimate the audible result before rendering
- Explain why balance is useful after an effect that changes signal level, and use it correctly
- Build a simple send-effect chain with global parameters, and a dry/wet mix using two buses
- Read a score with relative timing shortcuts, not just absolute numbers
- Modify the settings of the effects in the .csd (filter cutoff/resonance, delay time/depth, distortion drive) — try to predict how it will sound, then listen
- Adjust the dry/wet balance in the Master instrument, and try swapping which effect feeds it
- Explore the manual: look up three sound effect opcodes (see Signal Modifiers in the Csound manual) you've never seen before, and explore how they sound with different parameter settings
- In pairs: choose a DSP effect and select static settings for it. Make your partner listen and guess the effect and settings
- Build a send-effect chain in stereo with some of the effect from today's example and/or the manual exploration assignment
- Manual comparison: compare two related opcodes, note down how they work and/or sound similarly or differently
- Etude: take one or several effects from today and use it expressively on a sound file of your choice — changing the settings gradually over time.
day2-starter.csd
Why it matters: this is the day aimed most directly at gDSP reading fluency — each topic maps onto a specific gDSP lesson.
Day 03
Control, trigger, and talking to the outside world
Where this course starts pointing toward Electronic Music: real-time triggering, and Csound listening to the outside world over OSC — using R-IoT sensors.
Topics
- Real-time triggering: metro, counters — use event as an alternative to score-triggering
- Use GEN10 to add harmonic partials and GEN02 to store sequencer events
- OSC in Csound: OSCinit, OSClisten — receiving a whole sensor message into a k-array in one call
- Use the -b and -B options to change buffer sizes
- Opcodes for smoothing: port, lineto and lagud
- Scaling sensor values with arithmatics and the scale opcode
- Mapping technique: use a function-table curve (GEN -5) for a non-linear response
- Mapping technique 2: Quantizing continuous sensor data to a small set of musical steps (mtof) for a more melodic mapping
You'll leave able to
- Know how and why to use score-triggered vs. real-time-triggered instrument calls
- Use table to read from an f-table and use raw, 0-based, indexing
- Build a metronome / sequencer using metro and conditional logic with if, then, and endif.
- Receive R-IoT sensor data as a k-rate array, and read from a 1D-array
- Choose between smoothing and mapping approaches depending on what the movement should feel like
- Map continuous sensor data onto a constrained, musical range rather than an unbounded one
- Build a sequencer / metronome-driven instrument
- Connect to a R-IoT sensor (see guide), set your own sensor number, and verify the array of incoming values updates with printk2
- Map one or several values from the sensor array to a synthesis parameter, choosing your own smoothing (portk/port) and mapping (linear/table) approach
- Compare portk and port, and linear vs. table-based mapping, on the same signal
- Etude: extend today's step sequencer into a short rhythmic/melodic pattern of your own — change the pattern table, tempo, or pitch mapping until it feels like an intentional musical idea, then use some sensor values to modify some of its parameters
day3-lecture-sketch.csd
Loading…Download day3-lecture-sketch.csd
How to connect to your R-IoT sensor
- Note the number of the sensor (A).
- Turn on the sensor with the small switch (B).
- Check that the light (C) is blinking rapidly in blue.
-
Look in the list of available wireless networks on your computer and select the one named
riot+ your sensor's number from step 1 (e.g.riot11). Connect to it — no password needed.
macOS: click the Wi-Fi icon in the menu bar, chooseriotXXfrom the list.
Windows: click the network icon in the taskbar, chooseriotXXfrom the list, click Connect. -
Go to your computer's Wi-Fi/network settings, open the
riotXXconnection's TCP/IP (IPv4) settings, and set it to Manual/Static with IP address192.168.1.100+ your sensor number, subnet mask255.255.255.0. Sensor 11 → IP192.168.1.111.
macOS: System Settings → Wi-Fi → Details (ⓘ) next toriotXX→ TCP/IP tab → Configure IPv4: Manually → enter the IP address and subnet mask.
Windows: Settings → Network & Internet → Wi-Fi → clickriotXX→ Edit (under IP settings) → change Automatic (DHCP) to Manual → turn on IPv4 → enter the IP address and subnet mask → Save. - Note the OSC port you'll listen on:
8000+ your sensor number. Sensor 11 → port8011.
riotXX replaces your normal Wi-Fi connection.Why it matters: this is the direct technical prerequisite for the sensor-based work in Electronic Music.
Day 04
Putting it together: analysis, spatialization, integration
Closing the loop: pulling features from audio, placing sound in space within what stereo playback allows, and combining the week into one working patch.
Topics
- Loading sound files into function table with GEN01
- Use temposcal for FFT-based playback of audio f-tables with transposition and time stretching
- Make UDOs of existing code to simplify reuse
- Use a change detector, changed2, to only recompute a value when its inputs actually change
- Use pan2 for stereo panning
- Integration: designing a full control-to-sound signal path
You'll leave able to
- Manipulate sound files by transposition and time stretching
- Enable easy reuse of code through UDOs
- Pan a mono source in a stereo field
- Combine control input, mapping, and sound generation into one working .csd
- Use one or several opcodes not covered in the course
- Download sound files for today's .csd here, or use your own, put in same folder as the .csd
- Mini integration project: combine techniques from the whole course: receive and modify sensor data, use mapping techniques to connect to sound-generating and effect instruments, output with panning
- Manual exploration: use at least one opcode not covered in the course
- Etude: make the mini integration project into a short piece. This is the week's closing statement: try to make it expressive and musical.
- Optional: a short 1–2 minute walk-through of your .csd for your peers at the end of session
day4-starter.csd
Loading…Download day4-starter.csd
Why it matters: a small-scale rehearsal of the kind of patch you'll build in Electronic Music — and manipulating effects similar to what you will do in the Ear Training for Digital Audio Production course.
Keep going
Resources
The crash course teaches you how to use these — it doesn't replace them. Come back to all four throughout both follow-on courses.
Reference
Style guide
This course uses a style that might deviate from what you see in the Floss manual. It should be pretty close to what you will meet in the Ear Training for Digital Audio Production and Electronic Music courses.
Csound 6.18 — not version 7, which is still in beta.
Nested conditional blocks are indented so the nesting depth is visible from indentation alone.
Function tables are built with ftgen, placed in instr 0.
Code sections are marked with blank lines and comment headers, not left as implicit groupings.
Instruments are triggered from the score (i statements) by default, not with opcodes like schedule — unless there's a specific reason to do otherwise (Day 3 has one, and flags it).
Variable naming: capitalize after the rate letter — aSound, kFreq, iAmp.
Amplitude envelopes are a-rate, not k-rate, unless there's a specific reason otherwise. A k-rate envelope with a fast attack/decay can step audibly — Day 1 demonstrates this directly.
Instruments can be named instead of numbered (instr Source, triggered as i "Source"...) — used from Day 2 onward once there are enough instruments that numbers get hard to track.
;=== INIT === instr 1 iAmp = p4 iFreq = p5 ;=== AUDIO === aSound poscil iAmp, iFreq outs aSound, aSound endin
Reference
Common errors & debugging
Seven errors account for most of what trips people up early on. Each one below shows the mistake and the compiler message it produces, so you can match what you're seeing to what's actually wrong.
1. Using a variable before it's defined
Variable 'iMin_variabel' used before defined
2. Referencing a function table that hasn't been created
INIT ERROR in instr 1 line 10: Invalid ftable no. 3.000000
3. Wrong argument type, or wrong number of arguments, for an opcode
Unable to find opcode entry for 'rand' with matching argument types: Found: a rand ck INIT ERROR in instr 1 line 9: incomplete number of input arguments
4. Forgetting instr or endin
error: syntax error, unexpected $end (token "") from file error: syntax error, unexpected INSTR_TOKEN (token "instr")
5. Forgetting a comma between arguments
error: syntax error, unexpected T_IDENT, expecting NEWLINE or ','
6. An argument with an illegal or unusable value
No fixed message for this one — it depends on which opcode is used. This is usually a value out of the range the opcode expects (e.g. a table number, a channel count, or a ratio that doesn't make sense for that argument).
7. Writing code outside <CsInstruments> or <CsScore>
Stopping on parser failure cannot compile orchestra
If you can't tell where in the code the error is:
- Comment out code to disable parts of the .csd file until it runs without an error message.
- Re-enable it line by line until you find where the error appears.
- Use
printandprintk2to check whether variable values are within the expected range. - If nothing helps, contact the teacher or student assistant, or post to the Csound mailing list (
CSOUND@LISTSERV.HEANET.IE— sign up via csound.com).