Csound TOOTS

From OLPC
Jump to: navigation, search

Introduction

Csound instruments are created in an orchestra file, and the list of notes to play is written in a separate score file, or, most currently, both can be combined in a CSD file[1] (these TOOTS use separate orchestra/score for sake of clarity, but see TOOT 14). Both are created using a standard text editor. When you run Csound on a specific orchestra and score, the score is sorted and ordered in time, the orchestra is translated and loaded, the wavetables are computed and filled, and then the score is performed. The score drives the orchestra by telling the specific instruments when and for how long to play, and what parameters to use during the course of each note event.

Unlike today's commercial hardware synthesizers, which have a limited set of oscillators, envelope generators, filters, and a fixed number of ways in which these can be interconnected, Csound's power is not limited. If you want an instrument with hundreds of oscillators, envelope generators, and filters you just type them in. More important is the freedom to interconnect the modules, and to interrelate the parameters which control them. Like acoustic instruments, Csound instruments can exhibit a sensitivity to the musical context, and display a level of "musical intelligence" to which hardware synthesizers can only aspire.

Because the intent of this tutorial is to familiarize the novice with the syntax of the language, we will design several simple instruments. You will find many instruments of the sophistication described above in The Csound Book or by following the links on the MIT Csound Front Page. A study of these will reveal Csound's real power. Still, hopefully you will find in these simple examples the building block you require and I encourage you to modify and extend each of them and recommend that you try to make each score more involved and more musical. Well, let's get started!

In Csound, the orchestra file has two main parts:

1. the header section - defining the sample rate, control rate, and number of output channels.

2. the instrument section - in which the instruments are designed.

The Header Section

A Csound orchestra generates signals at two rates - an audio sample rate and a control sample rate. Each can represent signals with frequencies no higher than half that rate, but the distinction between audio signals and sub-audio control signals is useful since it allows slower moving signals to require less compute time. In the header below, we have specified a sample rate of 44.1 kHz, a control rate of 4410 Hz, and then calculated the number of samples in each control period using the formula: ksmps = sr / kr

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

In Csound orchestras and scores, spacing is arbitrary. It is important to be consistent in laying out your files, and you can use spaces to help this. In the Tutorial Instruments shown below you will see we have adopted one convention. The reader can choose his or her own.

The Instrument Section

All instruments are numbered and are referenced thus in the score. Csound instruments are similar to patches on a hardware synthesizer. Each instrument consists of a set of "unit generators," or software "modules," which are "patched" together with "i/o" blocks — i-, k-, or a-rate variables. Unlike a hardware module, a software module has a number of variable "arguments" which the user sets to determine its behavior. The four types of variables are:

setup only i-rate variables, changed at the note rate k-rate variables, changed at the control signal rate a-rate variables, changed at the audio signal rate

Orchestra Statements

Each statement occupies a single line and has the same basic format:

result action arguments

To include an oscillator in our orchestra, you might specify it as follows:

a1 oscil 10000, 440, 1

The three "arguments" for this oscillator set its amplitude (10000), its frequency (440Hz), and its wave shape (1). The output is put in i/o block a1. This output symbol is significant in prescribing the rate at which the oscillator should generate output — here the audio rate. We could have named the result anything (e.g. asig) as long as it began with the letter "a".

Comments

To include text in the orchestra or score which will not be interpreted by the program, precede it with a semicolon. This allows you to fully comment your code. On each line, any text which follows a semicolon will be ignored by the orchestra and score translators.

The TOOTS themselves

1. TOOT 1: Play One Note

2. TOOT 2: P-fields

3. TOOT 3: Envelopes

4. TOOT 4: Chorusing

5. TOOT 5: Vibrato

6. TOOT 6: GENs

7. TOOT 7: Crossfade

8. TOOT 8: Soundin

9. TOOT 9: Global Stereo Reverb

10. TOOT 10: Filtered Noise

11. TOOT 11: Carry, Tempo & Sort

12. TOOT 12: Tables & Labels

13. TOOT 13: Spectral Fusion

14. TOOT 14: CSD files

When things go wrong

When you design your own Csound instruments you may occasionally be surprised by the results. There will be times when you've computed a file for hours and your playback is just silence, while at other times you may get error messages which prevent the score from running, or you may hang the computer and nothing happens at all

In general, Csound has a comprehensive error-checking facility that reports to your console at various stages of your run: at score sorting, orchestra translation, initializing each call of every instrument, and during performance. However, if your error was syntactically permissable, or it generated only a warning message, Csound could faithfully give you results you don't expect. Here is a list of the things you might check in your score and orchestra files:


1. You typed the letter ‘l’ instead of the number ‘1.’

2. You forgot to precede your comment with a semi-colon.

3. You forgot an opcode or a required parameter.

4. Your amplitudes are not loud enough, or they are too loud.

5. Your frequencies are not in the audio range - 20Hz to 20kHz.

6. You placed the value of one parameter in the p-field of another.

7. You left out some crucial information like a function definition.

8. You didn't meet the GEN specifications.

Suggestions for further study

Csound is such a powerful tool that we have touched on only a few of its many features and uses. You are encouraged to take apart the instruments in the tutorials, rebuild them, modify them, and integrate the features of one into the design of another. To understand their capabilities you should compose short etudes with each. You may be surprised to find yourself merging these little studies into the fabric of your first Csound compositions.

There are many sources of information on Csound and software synthesis. The ultimate sourcebook for Csound is The Csound Book: Perspectives in Software Synthesis, Sound Design, Signal Processing, and Programming [2], edited by Richard Boulanger, and published by MIT Press.

Nothing will increase your understanding more than actually making music with Csound. The best way to discover the full capability of these tools is to create your own music with them. As you negotiate the new and uncharted terrain you will make many discoveries. It is my hope that through Csound you discover as much about music as I have, and that this experience brings you great personal satisfaction and joy.

Acknowledgements

The 13 TOOTS were originally written by Richard Boulanger, Boston, Massachusetts USA March, 1991. The author has kindly agreed to allow for these to published in this Wiki.