cSounds.com - tutorials - An Instrument Design TOOTorial
Toot 11: Carry, Tempo & Sort

We now use a plucked string instrument to explore some of Csound's score preprocessing capabilities. Since the focus here is on the score, the instrument is presented without explanation.

 
Navi

[index] [prev] [next]


cSounds.com

[+] Home

Csound Manual

[+] Carry
[+] Sort
[+] Tempo

Listen

[+] Toot11.mp3 810k


 
Toot11.orc

          instr 6

ifunc     =         p11                                ; select the basic waveform

irel      =         0.01                               ; set vibrato release time

idel1     =         p3 - (p10 * p3)                    ; calculate initial delay (% of dur)

isus      =         p3 - (idel1- irel)                 ; calculate remaining duration

iamp      =         ampdb(p4)

iscale    =         iamp * .333                        ; p4=amp

inote     =         cpspch(p5)                         ; p5=freq

k3        linseg    0, idel1, p9, isus, p9, irel, 0    ; p6=attack time

k2        oscil     k3, p8, 1                          ; p7=release time

k1        linen     iscale, p6, p3, p7                 ; p8=vib rate

a3        oscil     k1, inote*.999+k2, ifunc           ; p9=vib depth

a2        oscil     k1, inote*1.001+k2, ifunc          ; p10=vib delay (0-1)

a1        oscil     k1, inote+k2, ifunc

          out       a1+a2+a3

          endin



		instr 11

asig1	pluck	ampdb(p4)/2, p5, p5, 0, 1

asig2	pluck	ampdb(p4)/2, p5*1.003, p5*1.003, 0, 1

		out		asig1 + asig2

		endin


 
The score can be divided into time-ordered sections by the s statement. Prior to performance, each section is processed by three routines: Carry, Tempo, and Sort. The score toot11.sco has multiple sections containing each of the examples below, in both of the forms listed.


Carry

The carry feature allows a dot ("." ) in a p-field to indicate that the value is the same as above, provided the instrument is the same. Thus the following two examples are identical:


;ins start dur amp freq | ;ins start dur amp freq

i11  0     1   90  200  | i11  0     1   90  200

i11  1     .   .   300  | i11  1     1   90  300

i11  2     .   .   400  | i11  2     1   90  400

A special form of the carry feature applies to p2 only. A "+" in p2 will be given the value of p2+p3 from the previous i statement. The "+" can also be carried with a dot:


;ins start dur amp freq | ;ins start dur amp freq

i11  0     1   90  200  | i11  0     1   90  200

i.   +     .   .   300  | i11  1     1   90  300

i.   .     .   .   500  | i11  2     1   90  500

The carrying dot may be omitted when there are no more explicit pfields on that line:


;ins start dur amp freq | ;ins start dur amp freq

i11  0     1   90  200  | i11  0     1   90  200

i11  +     2            | i11  1     2   90  200

i11                     | i11  3     2   90  200

Ramping

A variant of the carry feature is ramping, which substitutes a sequence of linearly interpolated values for a ramp symbol ( < ) spanning any two values of a pfield. Ramps work only on consecutive calls to the same instrument, and they cannot be applied to the first three p-fields.


;ins start dur amp freq | ;ins start dur amp freq

i11  0     1   90  200  | i11  0     1   90  200

i.   +     .   <   <    | i11  1     1   85  300

i.   .     .   <   400  | i11  2     1   80  400

i.   .     .   <   <    | i11  3     1   75  300

i.   .     4   70  200  | i11  4     4   70  200

Tempo

The unit of time in a Csound score is the beat - normally one beat per second. This can be modified by a tempo statement which enables the score to be arbitrarily time-warped. Beats are converted to their equivalent in seconds during score pre-processing of each Section. In the absence of a Tempo statement in any Section, the following tempo statement is inserted:


t 0 60

It means that at beat 0 the tempo of the Csound beat is 60 (1 beat per second). To hear the Section at twice the speed, we have two options: 1) cut all p2 and p3 in half and adjust the start times, or 2) insert the statement t 0 120 within the Section.


The tempo statement can also be used to move between different tempi during the score, thus enabling ritardandi and accelerandi. Changes are linear by beat size. The following statement will cause the score to begin at tempo 120, slow to tempo 80 by beat 4, then accelerate to 220 by beat 7:


t 0 120 4 80 7 220

The following will produce identical sound files:


t 0 120 ; Double-time via Tempo



;ins start dur amp freq | ;ins start dur amp freq

i11  0     .5  90  200  | i11  0     1   90  200

i.   +     .   <   <    | i.   +     .   <   <

i.   .     .   <   400  | i.   .     .   <   400

i.   .     .   <   <    | i.   .     .   <   <

i.   .     2   70  200  | i.   .     4   70  200

The following includes an accelerando and ritard. It should be noted, however, that the ramping feature is applied after time-warping, and is thus proportional to elapsed chronological time. While this is perfect for amplitude ramps, frequency ramps will not result in harmonically related pitches during tempo changes. The frequencies needed here are thus made explicit.


t 0 60 4 400 8 60 ; Time-warping via Tempo



;ins start dur amp freq

i11  0     1   70  200

i.   +     .   <   500

i.   .     .   90  800

i.   .     .   <   500

i.   .     .   70  200

i.   .     .   90  1000

i.   .     .   <   600

i.   .     .   70  200

i.   .     8   90  100

Score Sections

Three additional score features are extremely useful in Csound. The s statement was used above to divide a score into Sections for individual pre-processing. Since each s statement establishes a new relative time of 0, and all actions within a section are relative to that, it is convenient to develop the score one section at a time, then link the sections into a whole later.


Suppose we wish to combine the six above examples (call them toot11a - toot11f) into one score. One way is to start with toot11a.sco, calculate its total duration and add that value to every starting time of toot11b.sco, then add the composite duration to the start times of toot11c.sco, etc. Alternatively, we could insert an s statement between each of the sections and run the entire score. The file toot11.sco, which contains a sequence of all of the above score examples, did just that.


Adding Extra Time

The f0 statement, which creates an "action time" with no associated action, is useful in extending the duration of a section. Two seconds of silence are added to the first two sections below.


;ins start dur amp freq

i11 0 2 90 100



f 0 4   ; The f0 Statement

s       ; The Section Statement



i11 0 1 90 800

i.  + . .  400

i.  . . .  100



f 0 5

s



i11 0 4 90 50



e

Sort

During preprocessing of a score section, all action-time statements are sorted into chronological order by p2 value. This means that notes can be entered in any order, that you can merge files, or work on instruments as temporarily separate sections, then have them sorted automatically when you run Csound on the file.


The file below contains excerpts from this section of the rehearsal chapter and from instr6 of the tutorial, and combines them as follows:


;ins start dur amp freq

i11  0     1   70  100            ; Score Sorting

i.   +     .   <   <

i.   .     .   <   <

i.   .     .   90  800

i.   .     .   <   <

i.   .     .   <   <

i.   .     .   70  100

i.   .     .   90  1000

i.   .     .   <   <

i.   .     .   <   <

i.   .     .   <   <

i.   .     .   70  <

i.   .     8   90  50



f1 0 2048 10 1                                  ; Sine

f2 0 2048 10 1 .5 .3 .25 .2 .167 .14 .125 .111  ; Sawtooth

f3 0 2048 10 1 0 .3 0 .2 0 .14 0 .111           ; Square

f4 0 2048 10 1 1 1 1 .7 .5 .3 .1                ; Pulse



;ins strt dur amp frq  atk rel vibr vibdpth vibdel waveform

i6   0    2   86  9.00 .03 .1  6    5       .4     1

i6   2    2   86  9.02 .03 .1  6    5       .4     2

i6   4    2   86  9.04 .03 .1  6    5       .4     3

i6   6    4   86  9.05 .05 .1  6    5       .4     4

 
Figure 11: Carry, Tempo, and Sort


[+] Any questions, comments or suggestions? please let us know:
support@csounds.com