Constants and Variables
Prev | 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 3. Types of Variables

Type | When Renewable | Local | Global
--- | --- | --- | ---
reserved symbols | permanent | -- | rsymbol
score pfields | i-time | p number | --
init variables | i-time | i name | gi name
control signals | p-time, k-rate | k name | gk name
audio signals | p-time, k-rate (all audio samples in a k-pass) | a name | ga name
spectral data types | k-rate | w name | --
streaming spectral data types | k-rate | f name | gf name
string variables | i-time and optionally k-rate | S name | gS 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, the underscore character, 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.

### Variable Initialization

Opcodes that let one initialize variables are:

- assign

- divz

- init

- tival

#### Predefined Math Constant Macros

Csound defines several important math constants as Macros. You can see the full list here.

Prev | Up | Next
Ordinary Statements | Home | Expressions