The Alternative Csound Reference Manual
Previous | Syntax of the Orchestra | Next

# Constants and Variables

constants are floating point numbers, such as 1, 3.14159, or -73.45. They are available continuously and do not change in value.

variables are named cells containing numbers. They are available continuously and may be updated at one of the four update rates (setup only, i-rate, k-rate, or a-rate). i- and k-rate variables are scalars (i.e. they take on only one value at any given time) and are primarily used to store and recall controlling data, that is, data that changes at the note rate (for i-rate variables) or at the control rate (for k-rate variables). i- and k-variables are therefore useful for storing note parameter values, pitches, durations, slow-moving frequencies, vibratos, etc. a-rate variables, on the other hand, are arrays or vectors of information. Though renewed on the same perf-time control pass as k-rate variables, these array cells represent a finer resolution of time by dividing the control period into sample periods (see ksmps). a-rate variables are used to store and recall data changing at the audio sampling rate (e.g. output signals of oscillators, filters, etc.).

A further distinction is that between local and global variables. local variables are private to a particular instrument, and cannot be read from or written into by any other instrument. Their values are preserved, and they may carry information from pass to pass (e.g. from initialization time to performance time) within a single instrument. Local variable names begin with the letter p, i, k, or a. The same local variable name may appear in two or more different instrument blocks without conflict.

global variables are cells that are accessible by all instruments. The names are either like local names preceded by the letter g, or are special reserved symbols. Global variables are used for broadcasting general values, for communicating between instruments (semaphores), or for sending sound from one instrument to another (e.g. mixing prior to reverberation).

given these distinctions, there are eight forms of local and global variables:

Table 1. Types of Variables

Type | When Renewable | Local | Global
--- | --- | --- | ---
reserved symbols | permanent | -- | r symbol
score pfields | i-time | p number | --
v-set symbols | i-time | v number | gv number
init variables | i-time | i name | gi name
MIDI controllers | any time | c number | --
control signals | p-time, k-rate | k name | gk
audio signals | p-time, k-rate | a name | ga name
spectral data types | k-rate | w name | --

where rsymbol is a special reserved symbol (e.g. sr, kr), number is a positive integer referring to a score pfield or sequence number, and name is a string of letters and/or digits with local or global meaning. As might be apparent, score parameters are local i-rate variables whose values are copied from the invoking score statement just prior to the init pass through an instrument, while MIDI controllers are variables which can be updated asynchronously from a MIDI file or MIDI device.

Previous | Home | Next
Orchestra Statement Types | Up | Expressions