Keith Hamel's Csound Course

Week 13

In this tutorial:


Index Previous Week


Other Uses of Global Variables

We have used global variables for reverberation, but there are other places where global variables can be useful. Whenever you want a values to be calculated outside an individual note, you can create a global instrument, and access the global variables in that instrument from other instruments. As in the case of reverberation, the global instrument must be turned on in the score during the time you want to access it, but it need not necessarily generate any audio signal. In the example below, a panning instrument is set up to slowly pan from right to left in the instrument's p3.

instr 90                      ; global slow panning instrument
gkpan  line  0, p3, 1         ; ramp from 0 to 1
endin
instr 90 must be at the top of the orchestra, and must be turned on for the duration of the score. Now other instruments can access the gkpan variable to get the global panning value.

i90    0     5                ; pans right to left in 5 seconds
i1     0     .25     10000     8.00
i1     +     .
i1     +     .
i1     +     .
i1     +     .                ; ...etc
e

instr 1     ; instrument that accesses global pan
kenv  line     1, p3, .0001                           ; linear ramp
audio foscili  p4*kenv, cpspch(p5), 1, 3.001, 6, 1    ; fm oscillator
outs  audio*gkpan, audio*(1-gkpan)                    ; global panning
endin
Global variables can be used in a similar fashion to control any values that you want applied across multiple instruments.

goto top Index


Increasing the Fidelity of your Sound Files

There are a number of ways to increase the quality of your sound files - most of which also increase the computation time of your sound file. The more your piece deals with high frequencies, the more important it is to improve the fidelity.
  1. Increasing the sampling and control rates in your orchestra. We have been operating at a sampling rate of 22050 and control rate of 2205 - if you increase these to sr = 44100 and kr = 4410 you will double the fidelity of sound file. However, the file will take approximately twice as long to compute and will take up twice as much disk space. Only change to the higher sampling rate if there is sufficient free space on the hard drive. At this sampling rate, sound files take up approximately 10 MBytes per minute. You may want to wait until the final generation of your piece before making these changes.

    If you have been using soundins at 22050, you will not be able to change your sampling rate without affecting the soundin speed.

  2. Use interpolating oscillators and tables. In the manual you will notice that there are generators such as oscili, foscili and tablei (along with oscil, foscil and table). These use interpolation between table values to generate more accurate values. When using interpolation generators, use function tables with an extended guard-point (i.e. table size of 1025 rather than 1024). Alternatively, you can increase your table sizes for better resolution. If you have only a few tables, use a size of 4096 or 8192. Increasing table size takes up more internal memory during computation, but does not really slow down processing.

goto top Index


Score Sections

When working on a large project it is sometimes useful to divide your score into sections, and work on one section at a time. This works particularly well if there are clear breaks in your piece (much more difficult if the composition is continuous). A new section of your score begins after an S-statement in the score (a line beginning with s). In the new score section, you begin again at time 0, and the new section begins as soon as the previous section ends - the last note in the section is complete. If you want a space before the end of one section and the beginning of the next, use a dummy instrument (an instrument starting at he end of the section and having no duration, or use an f0 statement at the desired end time.

In the example below, the first section ends (and section section starts) at time 47.5:

...
i1    45.0  .5   10000  8.00
i1    46.0  .5   10000  8.00
i1    47.0  .5   10000  8.00

s1     ; end of section one

i1    0    .25    8000  10.01
i1    1    .25    8000  10.02
i1    2    .25    8000  10.03
...
In the next example, a dummy instrument causes the section boundary to be 48.0

...
i1    46.0  .5   10000  8.00
i1    47.0  .5   10000  8.00
i1    48.0  0    0      0       ; a dummy instrument - no duration

s1     ; end of section one

i1    0     .25   8000  10.01
i1    1     .25   8000  10.02
i1    2     .25   8000  10.03
...
Alternatively, f0 could be used:

f0    48.0     ; an f0 statement at time 48.0
...
i1    46.0  .5   10000  8.00
i1    47.0  .5   10000  8.00

s1     ; end of section one

i1    0     .25   8000  10.01
i1    1     .25   8000  10.02
...
In order to work on one section of the score at a time, you can either block comment out the other sections /* ...... */ or you can use the advance statements (see below).

It is possible to have instruments which play over section boundaries, by using negative durations. If you specify a duration as a negative value, the instrument will sound past the section boundary. However, the instrument's p3 (which is negative) must be changed to positive in the instrument with the line:

p3     =     abs(p3)     ; take the absolute value of p3
Now for the restrictions: The instrument will sound across the section boundary, but will be turned off automatically when it the same instrument is called again. If you are using different instruments in the next section, this will not be a problem; however, if you are using the same instrument, you can give the held instrument a decimal value (e.g. i 1.1) to distinguish it from the other copies. Because the held notes are crossing the section boundary, they will not turn off automatically. To turn off an instrument, use a negative instrument at the appropriate time. If you have more than one copy of the instrument handing over the section boundary, give each one a different decimal value. The example below should help clarify all of this:

f0    4.0               ; cause artificial section ending at 4.0

i1    0    .5    10000  8.00
i1    1    .5    10000  8.00
i1    2    .5    10000  8.00
i1.1  3    -5     2000  9.00     ; 1.1 copy of instrument 1
i1.2  3    -6     2000  9.07     ; 1.2 copy of instrument 1

s     1

/* section 2 starts at time 4.0 */

i1     0     .5    10000  8.00
i1     1     .5    10000  8.00
i1     2     .5    10000  8.00
i1     3     .5    10000  8.00
i1     4     .5    10000  8.00
i-1.1  4     0     ; turn off i 1.1
i-1.2  5     0     ; turn off i 1.2
i1     5     .5    10000  8.00

goto top Index


Advance statements

Advance statements causes the score to skip ahead a specified number of beats. This is useful if you are working on a small section in the middle of a large score, or if you want to advance through an entire score section. p2 refers to the starting beat of the advance, and p3 is the duration (in beat) of the advance.
A number usually 0 is required beside the a in the advance statement.

a0     0     25.0     ; advance 25.0 beats beginning at time 0.
OR

a0     12.0  24.0     ; skip from beat 12.0 to beat 24.0


goto top Index Previous Week