3. The Orchestra File

Understanding the header

The first part of the orchestra file is called the header file. The header consists of the sampling and control rate of the audio you wish to produce, as well as the number of output channels you wish to use. This header is optional, but highly recommended for the beginning and intermediate composer for reference purposes. The structure of a header file looks like this:
sr = 44100 ;sample rate of 44.1 kHz
kr = 4410 ;control rate of 4.41 kHz
ksmps = 10 ;samples per control cycle, or sr/kr.  ALWAYS do it this way.
nchnls = 1 ;1 = monophonic, 2 = stereo, 4 = quadraphonic, etc.

The semicolon (;) delineates code from comments.

The basics - make an instrument with the oscil opcode

Once you have your header file, you may begin creating instruments. Designing instruments in Csound is fairly straightforward. First, the instrument fits within a pair of identifying statements
instr # ;start here (# is an integer)
endin ;end that instrument

Let's create a simple instrument which produces a single sinewave tone:
instr 1
a1 oscil 10000, 440, 1
out a1

The a1 is just the handle for our audio signal, which here used an oscillator opcode oscil. You can call it afoo as long as it begins with an "a" (see further on why this is so.)

The next three numbers represent values for that opcode. The 10000 represents the amplitude (on a scale from +/-32768, the maximum values that can be stored in 16 bits), the 440 represents the frequency in Hertz (an A), and the 1 signifies the function table in the score file that stores the values for the sine wave. Instead of values, you can use variables which return the appropriate values. See below.

The next line tells Csound which signal to send the output. In this case we have a monophonic (as specified in the header) output signal of the unmodified oscillator.

You can't hear this instrument yet because you haven't written a score yet. If you are very impatient, you may skip ahead to the top of Section 4.


Using variables - the p-fields
P-fields are parameters which get their values in the score file and are used in the orchestra file. There they appear "raw" or disguised in meaningfully named variable, like foo, bar, ivanhoe.

Let's take our instrument from the previous section and make the amplitude and frequency fields adjustable parameters:
instr 2
a1 oscil p4, p5, 1
out a1

The first 3 p-fields in the score are fixed and always stand for instrument number, start time, and note duration. The composer can define additional instrument parameters starting with p4. In this case, the p4 field will represent a note’s amplitude, and p5 will represent its frequency. These p-fields are always given variables in the score file. (Next section!, if you're impatient.)

Csound syntax invites you to attach a memorable name to a p-field, and use it instead when feeding an instrument. Given the above insrument, let us modify the code to make p4 and p5 more easily identifiable:
instr 3
iamp = p4 ;amplitude
ifreq = p5 ;frequency
a1 oscil iamp, ifreq, 1  
out a1

The equals sign (‘=’) is an opcode just like ‘oscil’ or any other opcode we come across. You may have also noticed the ‘i’ in front of the amplitude and frequency definitions. In Csound, there are three different rates at which note parameters are refreshed.

- i-rate variables are updated at the start of each new note (i-statement in the score).
- k-rate variables are updated at the control rate (the kr value in the header). This is useful for when you are applying a glissando to a note, enveloping a sound, or changing any parameter at a slow to moderate rate over the course of the sound.
- a-rate variables are updated at the signal rate, sr in the header section.

Return to Table of Contents.