-W -o z.wav
;; Example instrument with tables
; table f1
f 1 0 131073 27 0 0 32768 1 98304 -1 131072 0
; table size: 131073 , gen routine 27 - construct functions from segments of straight lines in breakpoint fashion.
; triangle wave using:
; coords (0,0), (32768 ,1), (98304, -1), (131072,0)
; table f2
f 2 0 65536 31 1 1 0.3 0 2 1 0 3 0.5 0 4 0.25 0 5 0.125 0 6 0.6 0 7 0.3 0 8 0.15 0 9 0.07 0 10 0.04 0 11 0.02 0 13 0.01 0
; table size: 65536 , gen routine 31 - Mixes any waveform specified in an existing table - in this case, the triangle wave constructed in table 1.
; harmonic series of triangles
; table f3
f3 0 131073 8 0 16384 0.5 16384 1 16384 0.5 16384 0 16384 -0.5 16384 -1 16384 -0.5 16384 0
; table size: 131073 , GEN08 -- Generate a piecewise cubic spline curve
; cubic splines with maxima at (points of inflection in square brackets)
; 0 [0.5] 1 [0.5] 0 [-0.5] -1 [0.5] 0
; Has same area above and below so suitable for use as a waveform table.
;; These double ;; comments will get trimmed by the orchestra builder.
;; This makes it possible to add comments here about the format without confusing
;; a reader of the final auto build CSD files.
;; A few notes to play a test harmonic series so that user can hear
;; something if they render this instrument directly to an audio file in csound
;; The modifications here to make it suitable for orchestra building don't affect
;; it's integrity as a valid CSD file for normal use. They just add extra
;; sections to make it possible to use it for automatic orchestra building
;; as well, or add no op type statements that have no effect outside the
;; orchestra builder.
; Test the instrument with a short harmonic series
i1 0 1 3000 220 0.05 50 1
i1 1 1 3000 330 0.05 50 1
i1 2 1 3000 440 0.05 50 1
i1 3 1 3000 550 0.05 50 1
i1 4 1 3000 660 0.05 50 1
i1 5 1 3000 770 0.05 50 1
i1 6 1 3000 880 0.05 50 1
s
These Info sections are for comments, in this case for comments about the CsDurationInstruments section.
The CsDurationInstruments section lists the numbers of any
instruments that need to play a single note for the duration of the entire piece (usually for effects etc).
So for instance if instrument 11 needs to play for the duration,
put an 11 in the next section, and all the i instructions for instrument 11
in the header part of the score will get their duration fields updated to the
entire duration of the piece.
The next section has the instrument parameters, all on one line.
Volume parameters can be set to:
AMP or DB or VEL (for midi velocity)
Pitch parameters can be:
CPS, PCH, OCT, MIDI or eg. PCH31 (for 31-et notation)
If editing an example orchestra, one may not always be
sure what type the various parameters are. You can find
out by tracing through the way they are used in the orchestra
and looking up the op codes they are used for. But often
one can get a good idea already without needing to do that.
For a frst check - if it is a pitch parameter and
the numbers are large it is probably the frequency
in cycles per second, so the parameter should be
CPS.
The PCH format most often looks like this:
7.02 for two cents above the c in the 7th octave.
7.0386 for pure major third above the C and so on.
The volumes are usually either AMP (raw amplitude) or perhaps
DB - if the numbers are large then it is almost certainly
AMP. Some instruments designed for midi playing
may have midi note numbers and or / velocities so use
the MIDI and VEL parameters for those if appropriate.
VEL is in range 0 to 127 so rather hard to distinguish
from decibels.
Formulae can be used too, for instance VEL*10, CPS/2 etc. However
be sure to leave out spaces. Vel*10, not vel * 10. You can't currently use
PCH in formulae.
You need to identify any table parameters in the list so that they can be
automatically incremented when the tables are renumbered for
orchestra building. You mark the parameters as tables by prefixing
the number with F (all one symbol without spaces).
So for instance, if table 31 is used as a parameter, show it as
F31 rather than just 31.
You can add comment lines (starting with ;) after the parameter list
These are displayed to the user, so they can
can explain what the parameters do and any special considerations
about how they can be used.
You can also add a list of extra parameters to be added automatically
after all the user set ones like this:
EXTRA 0 1 2 1.3 4
In that example, every i instruction for this instrument will have
0 1 2 1.3 4 appended to it.
AMP CPS 0.05 50.0 F1; rise in seconds; decay as percentage of note length;
table to play - the tables available are 1 = triangle wave, 2 = a harmonic
series of triangle waves, 3 = a wave made out of cubic splines
You can include the full original orchestra from a CSound score here if you wish
so long as it includes the instrument you wish to play - and it should work.
However, if possible leave out any unneeded instruments (and leave out their
tables from the score section) as if you leave them in it will slow down the
rendering process
Most instruments convert automatically. Just include the whole
instrument from the instr instruction to the endin instruction
and you are done. If you want it to respond to pitch glides
in CSAV then read that section. The other points are needed
for some of the more complex instruments.
................A few special points...................
If you see a zakinit line in the orchestra and your instrument
is one of the ones that needs it, be sure to include it.
If unsure include it anyway; it does no harm and won't slow
things down noticeably.
This means that the instrument needs the zak patcher and
the zakinit line is needed so that it can be allocated
a suitably sized region of the zk space to work with.
Instruments with global variables are okay as the
globals will get renamed
to unique variables so won't conflict with
globals in other files used to build up the
orchestra. So if it needs a few globals, just
add those in as well just as they are in the original
orchestra.
If you need to set ksmps, e.g. ksmps = 1 then put that into the
CsGlobals section - most instruments
aren't particular about the ksmps rate - but some may
require it to be as fast as the audio rate.
See the CsInfoGlobals help below.
.................Pitch bend glides.......................
To make the instrument able to respond to pitch bend glides in
CSoundAV then first look to see if you can find the likes of this:
ifreq = p5
There ifreq is instruction rate so can't respond to pitch glides
in the middle of the note.
You need to assign it to a k (control) rate variable - any variable
name you like so long as it begins with a k
rather than an i. The way to do it though is to add an extra
line kp5 = p5 first.
Like this:
kp5 = p5
kfreq = kp5
then use kfreq everywhere instead of ifreq
Then, whenever the instrument is remade for CSoundAV
with pitch bend gliding enabled, your line kp5 = p5
will get removed and kp5 will get assigned to the control rate
pitch for the instrument instead of the instruction
rate p5. So it will glide in value. So kfreq will vary at the control rate
as desired. If you are interested in the techy details of how
it is done take a look at the CSD files that Tune Smithy
makes for CSoundAV.
When this instrument is used in normal scores,
kfreq will remain assigned to the
instruction rate p5 so will behave just as it
did before you made this change.
Some opcodes require the frequency to be
an instruction rate variable - in that case
set up both types of variable as in
this example:
kp5 = p5
kfreq = kp5
ifreq = p5
...
audio pluck kenvelope, kfreq , ifreq , 1, 3, 0
So wherever possible you use the k rate variable
in the code that follows, but if the op code requires
the instruction rate variable, use it instead.
Then the k rate variable will respond to pitch glides,
the instruction rate one won't - then try it out and see
what the effect is of this - you may find that the results are satisfactory.
After editing your instrument to respond to pitch bend glides,
you can indicate to the user that it does so. To do that,
add a new section CsPitchBendGlide and place an * within it
This can then be used by the automated orchestra builder
to indicate to the user which instruments in the list respond to pitch
bend glides
instr 1
; This instrument plays the function table set in parameter p8 with rise and decay
iduration = p3
iamplitude = p4
ifreq = p5
kfreq = ifreq
irise = p6
idecaypercent = p7
idecay = iduration*idecaypercent/100
kenvelope linen iamplitude, irise, iduration, idecay
audio pluck kenvelope, kfreq, ifreq , p8, 3, 0
; function table, pluck method 3, parameter 0 = plucked string effect
out audio
endin
*