Toot 9

In the previous example you may have noticed the soundin source being "cut off" at ends of notes, because the reverb was inside the instrument itself. It is better to create a companion instrument, a global reverb instrument, to which the source signal can be sent. Let's also make this stereo (two channel).

Variables are named cells which store numbers. In Csound, they can be either local or global, are available continuously, and can be updated at one of four rates - setup, i-rate, k-rate, or a-rate.

Local variables (which begin with the letters p, i, k, or a) are private to a particular instrument. They cannot be read from, or written to, by any other instrument or by other notes from the same instrument.

Global Variables are cells which are accessible by all instruments. Three of the same four variable types are supported (i, k, and a), but these letters are preceded by the letter "g" to identify them as "global." Global variables are used for "broadcasting" general values, for communicating between instruments, and for sending sound from one instrument to another.

The reverb instr 99 below, receives input from instr 9 via the global a-rate variable garvbsig. Since instr 9 adds into this global, several copies of instr 9 can do this without losing any data. The addition requires garvbsig to be cleared before each k-rate pass through any active instruments. This is accomplished first with an init statement in the orchestra header, giving the reverb instrument a higher number than any other (instruments are performed in numerical order), and then clearing garvbsig within instr 99 once its data has been placed into the reverb.

In the score we turn the global reverb on at time 0 and keep it on until irvbtime after the last note.

[TOOT 9 Schematic]

TOOT 9 Schematic

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

nchnls    =         2                        ; stereo output

garvbsig  init      0                        ; global "a" variable initialized to 0

          instr 9

idur      =         p3
iamp      =         p4
iskiptime =         p5
iattack   =         p6
irelease  =         p7
ibalance  =         p8                       ; 1 = left, .5 = center, 0 = right
irvbgain  =         p9

kamp      linen     iamp, iattack, idur, irelease
asig      soundin   "fox.wav", iskiptime
arampsig  =         kamp * asig

          outs      arampsig * ibalance, arampsig * (1 - ibalance)

garvbsig  =         garvbsig + arampsig * irvbgain

          endin

          instr 99

irvbtime  =         p4

asig      reverb    garvbsig,  irvbtime      ; put global sig into reverb

          outs      asig, asig

garvbsig  =         0                        ; then clear it

          endin

</CsInstruments>
<CsScore>

;ins strt dur  rvbtime
i99  0    15   2.2

;ins strt dur  amp  skip atk  rel  blnce(0-1)     rvbsend
i9   0    1.2  .5   0    .02  .1   1              .2
i9   2    1.4  .5   0    .03  .1   0              .3
i9   3.5  2.28 .5   0    .9   .1   .5             .1
i9   4.5  2.28 .5   0    1.2  .1   0              .2
i9   5    2.28 .5   0    .2   .1   1              .3
i9   9    2.28 .7   0    .1   .1   .5             .03

e
</CsScore>
</CsoundSynthesizer>