1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<HTML>
<TITLE>THE_ORCHESTRA_FILE</TITLE>
<CENTER><P><A NAME="The_Orchestra_File"></A>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <B><A HREF="./TUTORIALS.html">Top of this section</A></B>
- <A HREF="./TUTORIALS.html">Previous</A> - <A HREF="../CONTENTS.html">Contents</A>
- <A HREF="../INDEX.html">Index</A> - <A HREF="./scofile.html">Next</A>
<HR></P></CENTER>
<H2>A Beginning Tutorial</H2>
<P>by Barry Vercoe, Massachusetts Institute of Technology</P>
<H3>The Orchestra File</H3>
<P><B>Csound</B> runs from two basic files: an <I>orchestra</I> file and
a <I><A HREF="./scofile.html">score file</A></I>. The orchestra file is
a set of <I>instruments</I> that tell the computer how to synthesize sound;
the score file tells the computer when. An instrument is a collection of
modular statements which either <I>generate</I> or <I>modify</I> a signal;
signals are represented by <I>symbols</I>, which can be "patched"
from one module to another. For example, the following two statements will
generate a 440 Hz sine tone and send it to an output channel:</P>
<PRE><TT> asig <B>oscil</B> 10000, 440, 1
<B>out</B> asig </TT>
</PRE>
<P>The first line sets up an oscillator whose controlling inputs are an
amplitude of 10000, a frequency of 440 Hz, and a waveform number, and whose
output is the audio signal <I>asig</I>. The second line takes the signal
<I>asig</I> and sends it to an (implicit) output channel. The two may be
encased in another pair of statements that identify the instrument as a
whole:</P>
<PRE><TT> instr 1
asig <B>oscil</B> 10000, 440, 1
<B>out</B> asig
endin </TT>
</PRE>
<P>In general, an orchestra statement in <B>Csound</B> consists of an action
symbol followed by a set of input variables and preceded by a result symbol.
Its <I>action</I> is to process the inputs and deposit the result where
told. The meaning of the input variables depends on the action requested.
The 10000 above is interpreted as an amplitude value because it occupies
the first input slot of an <B><A HREF="./../Generate/oscil.html">oscil</A></B>
unit; 440 signifies a frequency in Hertz because that is how an <B><A HREF="./../Generate/oscil.html">oscil</A></B>
unit interprets its second input argument; the waveform number is taken
to point indirectly to a stored function table, and before we invoke this
instrument in a score we must fill function table #1 with some waveform.
</P>
<P>The output of <B>Csound</B> computation is not a real audio signal,
but a stream of numbers which describe such a signal. When written onto
a sound file these can later be converted to sound by an independent program;
for now, we will think of variables such as asig as tangible audio signals.
</P>
<P>Let us now add some extra features to this instrument. First, we will
allow the pitch of the tone to be defined as a <I>parameter</I> in the
score. Score parameters can be represented by orchestra variables which
take on their different values on successive notes. These variables are
named sequentially: p1, p2, p3, ... The first three have a fixed meaning
(<A HREF="./scofile.html">see the Score File</A>), while the remainder
are assignable by the user. Those of significance here are: </P>
<P>p3 - duration of the current note (always in seconds).</P>
<P>p5 - pitch of the current note (in units agreed upon by score and orchestra).
</P>
<P>Thus in </P>
<PRE><TT> asig <B>oscil</B> 10000, p5, 1 </TT>
</PRE>
<P>the oscillator will take its pitch (presumably in cps) from score parameter
5.</P>
<P>If the score had forwarded pitch values in units other than cycles-per-second
(Hertz), then these must first be converted. One convenient score encoding,
for instance, combines <I>pitch class</I> representation (00 for C, 01
for C#, 02 for D, ... 11 for B) with <I>octave</I> representation (8. for
middle C, 9. for the C above, etc.) to give pitch values such as 8.00,
9.03, 7.11. The expression </P>
<PRE><TT> <B>cpspch</B>(8.09) </TT>
</PRE>
<P>will convert the pitch A (above middle C) to its cps equivalent (440
Hz). Likewise, the expression </P>
<PRE><TT> <B>cpspch</B>(p5) </TT>
</PRE>
<P>will first read a value from p5, then convert it from octave.pitch-class
units to cps. This expression could be imbedded in our orchestra statement
as </P>
<PRE><TT> asig <B>oscil</B> 10000, cpspch(p5), 1 </TT>
</PRE>
<P>to give the score-controlled frequency we sought. </P>
<P>Next, suppose we want to shape the amplitude of our tone with a linear
rise from 0 to 10000. This can be done with a new orchestra statement </P>
<PRE><TT> amp <B>line</B> 0, p3, 10000 </TT>
</PRE>
<P>Here, <I>amp</I> will take on values that move from 0 to 10000 over
time p3 (the duration of the note in seconds). The instrument will then
become </P>
<PRE><TT> instr 1
amp <B>line</B> 0, p3, 10000
asig <B>oscil</B> amp, cpspch(p5), 1
<B>out</B> asig
endin </TT>
</PRE>
<P>The signal <I>amp</I> is not something we would expect to listen to
directly. It is really a variable whose purpose is to control the amplitude
of the audio oscillator. Although audio output requires fine resolution
in time for good fidelity, a controlling signal often does not need that
much resolution. We could use another kind of signal for this amplitude
control</P>
<PRE><TT> kamp <B>line</B> 0, p3, 10000 </TT></PRE>
<P>in which the result is a new kind of signal kamp. Signal names up to
this point have always begun with the letter a (signifying an <I>audio</I>
signal); this one begins with <B>k</B> (for <I>control</I>). Control signals
are identical to audio signals, differing only in their resolution in time.
A control signal changes its value less often than an audio signal, and
is thus faster to generate. Using one of these, our instrument would then
become </P>
<PRE><TT> instr 1
kamp <B>line</B> 0, p3, 10000
asig <B>oscil</B> kamp, cpspch(p5), 1
<B>out</B> asig
endin </TT>
</PRE>
<P>This would likely be indistinguishable in sound from the first version,
but would run a little faster. In general, instruments take constants and
parameter values, and use calculations and signal processing to move first
towards the generation of control signals, then finally audio signals.
Remembering this flow will help you write efficient instruments with faster
execution times. </P>
<P>We are now ready to create our first orchestra file. Type in the following
orchestra using the system editor, and name it "intro.orc".</P>
<PRE> sr = 20000 ; audio sampling rate is 20 kHz
kr = 500 ; control rate is 500 Hz
ksmps = 40 ; number of samples in a control period (sr/kr)
nchnls = 1 ; number of channels of audio output
instr 1
kctrl <B>line</B> 0, p3, 10000 ; amplitude envelope
asig <B>oscil</B> kctrl, cpspch(p5), 1 ; audio oscillator
<B>out</B> asig ; send signal to channel 1
endin
</PRE>
<P>It is seen that comments may follow a semi-colon, and extend to the
end of a line. There can also be blank lines, or lines with just a comment.
Once you have saved your orchestra file on disk, we can <A HREF="./scofile.html">next
consider the score file</A> that will drive it.</P>
<CENTER><P>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <B><A HREF="./TUTORIALS.html">Top of this section</A></B>
- <A HREF="./TUTORIALS.html">Previous</A> - <A HREF="../CONTENTS.html">Contents</A>
- <A HREF="../INDEX.html">Index</A> - <A HREF="./scofile.html">Next</A>
<HR></P></CENTER>
<P><CENTER>
<B><I><FONT COLOR="#006600">HTML Csound Manual - <FONT SIZE=-1>©
Jean Piché & Peter J. Nix, 1994-97</FONT></FONT></I></B>
</CENTER>
</HTML>
|