Let’s look again at the code presented on page 45 of The Technology of Computer Music:
INS 0 1 ;
OSC P5 P6 B2 F2 P30 ;
OUT B2 B1 ;
GEN 0 1 2 0 0 .999 50 .999 205 -.999 306 -.999 461 0 511 ;
NOT 0 1 .50 125 8.45 ;
NOT .75 1 .17 250 8.45 ;
NOT 1.00 1 .50 500 8.45 ;
NOT 1.75 1 .17 1000 8.93 ;
NOT 2.00 1 .95 2000 10.04 ;
NOT 3.00 1 .95 1000 8.45 ;
NOT 4.00 1 .50 500 8.93 ;
NOT 4.75 1 .17 500 8.93 ;
NOT 5.00 1 .50 700 8.93 ;
NOT 5.75 1 .17 1000 13.39 ;
NOT 6.00 1 1.95 2000 12.65 ;
TER 8.00 ;
The following list compares Music V mneumonics to their Csound opcode equivalents in the order in which they appear the previous example:
INS => instr
OSC => oscil
OUT => out
END => endin
GEN => f
NOT => i
TER => e
A Music V instrument definition begins with INS and and is terminated with END. This is nearly identical to Csound’s instr and endin. Music V does allow one capability that Csound lacks, as instrument defininitions in Music V have a parameter that lets users specify the time in which they come into being. Hopefully someday, Csound will include a more mature version of this feature, where users can dynamically create and destroy instruments in the middle of a score or performance. *crosses fingers*
Though OSC and oscil are similar, there are some noticeable differences in their implementations. In part 3, I mentioned that Csound supports control signals, and Music V does not. The oscil opcode is an example of a unit generator that can output both audio rate and control rate signals.
Both support a simple amplitude value, but diverge on frequency. Instead of a frequency paramenter, Music V has an increment parameter that determines the frequency of the unit generator. The increment parameter is used to specify the number of samples that are sequentially skipped in a stored function for each pass. The following equation is used to convert increment values to frequencies (Mathews, pg. 127):
frequency = sampling rate * increment / (function length in samples - 1)
The first note played in the example specifies an increment value of 8.45. Let’s do the math:
330.72407045009783 = 20000 * 8.45 / (512 - 1)
An increment value of 8.45 translates to roughly 330Hz. Provided that the sampling rate is 20kHz and the table size is 512.
The problem with Music V’s method is that any changes made to the size of the stored function table or the sampling rate greatly affects the frequencies of the oscillators. The reason why I modified my copy of Music V is because the examples in the book were designed to render with a sampling rate of 20kHz, not 44.1kHz. Thus, frequencies were higher than they were supposed to be, and the LFOs were right out.
This is where Csound is much more user-friendly as users specify a frequency, and all the increment calculations are done automatically, making life a little easier for us Csounders.
Thanks for reading this first Csound Blog mini series. Hopefully you’ll stay tuned. A lot of great topics are coming up, including coding techniques, composition, sound design, etc..