Music 733.1: Computer Music 1

Lab 1: Frequencies, Harmonics and Overtones

The csound oscillator is defined as a periodic waveform generator. It has arguments consisting of amplitude, frequency in Hz, and a waveform number (plus an optional phase argument, which is not necessary for the application we are discussing). It allows you to generate sounds consisting of harmonic partials of any combination of amplitudes and frequencies (integral partials). The only limitation of the oscillator principle is that it cannot vary the waveform over the course of time. Here is the way it appears in the csound manual:

ar	oscil	xamp, xcps, ifn[, iphs]
ar	oscili	xamp, xcps, ifn[, iphs]

These units produce audio signals by sampling the stored function ifn with an amplitude of xamp and a frequency of xcps. The function table, which is generated by Gen 9 or Gen10, is a wave table containing one or more harmonic partials. Only harmonic partials are possible to produce by this method; for inharmonic partials, separate oscillators must be used.

Xamp is the amplitude, specified in amplitude units (0-32767); the sum of all amplitudes mixed together in the output signal must not exceed 32767, or clipping (distortion) will be produced in the output signal. Xcps is the frequency, which can come from the output of a pitch converter. Both the amplitude and frequency can be changed during the course of the note, whereas the function must be set at the beginning and cannot be changed during the note.

Iphs is an optional input representing the initial phase, specified as a fraction of a cycle (0 to 1). To set the phase to 180 degrees, for example, you would use the value .5, which is at the midpoint of the cycle. The default value is 0, which should normally be used except on tied notes. A negative value causes phase resetting to be skipped. The internal phase is advanced on each sample of the note. The function table contains only a discrete number of locations where the wave table is stored. With oscil, only the integer value of the phase is used to retrieve the value sent to the output. With oscili, a linear interpolation is made between the values in adjacent locations of the function to adjust the output. While not perfect, oscili produces a better quality signal than oscil, but this is not significant if only a sine wave is being produced.

Waveforms for oscillators are produced by the csound generators gen09 and gen10. Gen09 has arguments listed in groups of three, where each successive group gives the partial number, amplitude and phase in degrees. Gen10 simply provides a resource for specifying each harmonic partial up to as high as you want to go, by placing the amplitude of each successive partial into successive fields beginning with p5. Phases are not specified, but a phase of 180 degrees may be specified by a negative amplitude. To skip a partial, you must specify zero as its amplitude. The series stops at the last partial you provide. The following two functions specify the first 5 partials of a sawtooth wave:

f1 0 512 10 1 .5 .333 .25 .2
f1 0 512  9 1 1 0 2 .5 0 3 .333 0 4 .25 0 5 .2 0

The csound program allows for two basic kinds of oscillators: oscil (truncating) and oscili (interpolating). In general, oscili should be used for these examples unless you are producing sine waves. For larger numbers of partials, it is best to use bigger wave tables (up to 8192 locations).

In all tone-generating units in csound, the frequency is specified in hertz (Hz), or cycles per second. The csound program has developed a method of pitch notation called octave point pitch class form (abbreviated 8ve.pc) which makes it very easy to transcribe notes in a score. In this method, the integer part of a number indicates the octave, where 8 is the octave of middle C, and the two-digit fractional part indicates the pitch class, where .00 represents C, .01 C-sharp or D-flat, ..., and .1 represents B. A value of .01 represents the semitone or half-step, and this number can be divided further for microtonal values (.005 for quarter-tones, for example). Thus 8.00 represents middle C, 9.07 G an octave and fifth higher, and 7.05 F a fifth below. The unit cpspch converts a number in 8ve.pc form to Hz, and it is used in the instrument shown below. (If you want to specify the frequency in Hz, leave out this unit.)


1. The following simple mono csound instrument produces a sound in which the note statement gives only the amplitude, pitch (in 8ve.pc), and timbre function number in p4, p5 and p6. The tone has a simple envelope with linear rise and decay times of .05 seconds. The timbre of the sound is changed by specifying a different function number in p6.

	instr	1
icps	=	cpspch(p5)
kenv	linen	p4,.05,p3,.05
asig	oscili	kenv,icps,p6
	out	asig

This instrument can be used for the following tests, which you are to run with your own data. Generate middle C (8.00) tones consisting of:

• a sine wave

• the first 10 partials of a sawtooth wave (*)

• the first 10 partials of a square wave (**)

• the reverse of the above two examples

• several waves (up to 16 partials) with diverse amplitudes, emphasizing various regions

• a wave consisting only of partials 4-8

• a wave consisting only of partials 5-12

(*) A sawtooth wave contains (theoretically) an infinite number of harmonic partials, each in the ratio of the reciprocal of the partial number. Thus, the fundamental (1) has an amplitude of 1, the second partial 1/2, the third 1/3, and the nth 1/n.

(**) A square wave contains (theoretically) an infinite number of harmonic partials, but only odd-numbered harmonics (1,3,5,7,...) The amplitudes are in the ratio of the reciprocal of the partial number, just as sawtooth waves. Thus, the fundamental (1) has an amplitude of 1, the third partial 1/3, the fifth 1/5, and the nth 1/n.

Next, try each of the above waves in several different octaves, at least two octaves below middle C and two octaves above middle C.

From these experiments, answer the following questions:

A. Are these waves useful in all octaves? If not, why not?

B. What happens when you specify very high partials on very high notes?

C. List at least three different waves (timbres) that you would find useful to use in a composition, in particular octaves (specify). Make sure that you have suitable tones for each octave present on a five-octave keyboard.

2. Older (pre-computer) books on musical acoustics often show bar graphs representing the timbre of musical instruments playing individual pitches. These show harmonic partials and a line representing the relative strength of the partial in the instrument's waveform. These graphs are misleading, for at least three important reasons: the timbre of other pitches played by the instrument may not be the same; no variations in the amplitudes of the different components are shown, and in most instruments there can be significant variations; and no transient or non-harmonic components are shown. Nevertheless, there is some truth to them.

Several excerpts from books on acoustics are shown in the following documents:

Select any two waves from these sources and try to produce waveforms corresponding to the graphs shown. How realistic are the timbres? What qualities of the instruments are not produced by these waveforms?

3. Generate a simple passage from a piece of instrumental music using oscillator timbres like these to differentiate the instruments.