Simple Csound orchestra

BP2 makes it pos­si­ble to use Csound orches­tra instruc­tions such as

kr tablei kndx, ifn

to make con­tin­u­ous para­me­ters vary accord­ing to a func­tion table (indexed 'ifn') that BP2 pro­duces and insert in the Csound score when necessary.

Below is a typ­i­cal instru­ment in which vol­ume and pitch­bend are con­trolled either by lin­ear inter­po­la­tion, using start and end val­ues, or by func­tion tables.

  • p5 and p6 are the start and end val­ues of volume
  • p8 and p9 are the start and end val­ues of pitchbend
  • p7 con­tains the index of the vol­ume func­tion table. If it is 0, then vol­ume varies by lin­ear interpolation.
  • p10 con­tains the index of the pitch­bend func­tion table. If it is 0, then pitch­bend varies by lin­ear interpolation.

Indexes of func­tion tables are assigned auto­mat­i­cal­ly by BP2, and each table is stored in the score as a 'f' state­ment just pre­ced­ing the 'i' state­ment relat­ing to an instru­ment using the table. BP2 takes care of not over­writ­ing tables that might be ref­ered by Csound instru­ment and enlist­ed in the Csound instru­ment descrip­tion file.

In any case, it starts index­ing from 100 onwards.

sr = 22050
kr = 2205
ksmps = 10
nchnls = 1

instr 1

ik1 = 32767. / 127.
ik2 = log(2.) / 1200.

ifvol = p7
ifcents = p10

kvol line p5, p3, p6
if (vol <= 0) goto vol­umelin
ilen­vol = ftlen(ifvol)
kndxvol line 0, p3, ilen­vol
kvol tablei kndxvol, ifvol

vol­umelin: kcents line p8, p3, p9
if (ifcents <= 0) goto pitch­bendlin
ilen­cents = ftlen(ifcents)
kndx­cents line 0, p3, ilen­cents
kcents tablei kndx­cents, ifcents

pitch­bendlin: kpitch = cpspch(p4) * exp(kcents * ik2)
kamp = kvol * ik1

a1 oscil kamp, kpitch, 1
out a1
endin

This instru­ment is cur­rent­ly saved as "BP2test.orc".

Function tables might invoke either GEN07 (straight lines, p.62) or GEN08 (cubic spline, p.64).

If for instance the func­tion table index is 102, and GEN07 is used, the fol­low­ing instruc­tion will be insert­ed by BP2 into the score:

f102 time size -7 v1 n1 v2 n2 v3 n3 … vmax

with n1 + n2 + … + n(max-1) = maxpoints

'size' is a pow­er of two equal to or greater than the actu­al num­ber of points 'max­points'.
'time' is exact­ly para­me­ter p2 of the fol­low­ing 'i' state­ment which makes actu­al use of the table.

Writing '-7' instead of '7' after 'size' inhibits rescaling.

GEN08 looks bet­ter in terms of smooth­ing the table, but it has the draw­back of set­ting first deriv­a­tives to 0 on the first and last points of the table. It also slows down Csound's sound file generation.

One Reply to “Simple Csound orchestra”

Leave a Reply

Your email address will not be published. Required fields are marked *