Tutorial 3: Wavetable Oscillator
Open the tutorial.
Audio on/off switch: ezdac~
In this tutorial patch, the dac~ object which was used in earlier examples has been replaced by a button with a speaker icon. This is the ezdac~ object, a user interface object available in the object palette.
ezdac~ is an on/off button for audio, available in the object palette
The ezdac~ works much like dac~, except that clicking on it turns the audio on or off. It can also respond to start and stop messages in its left inlet, like dac~. (Unlike dac~, however, it is appropriate only for output channels 1 and 2.) The ezdac~ button is highlighted when audio is on.
A stored sound: buffer~
In the previous examples, the cycle~ object was used to read repeatedly through 512 values describing a cycle of a cosine wave. In fact, though, cycle~ can read through any 512 values, treating them as a single cycle of a waveform. These 512 numbers must be stored in an object called buffer~. (A buffer means a holding place for data.)
A buffer~ object requires a unique name typed in as an argument. A cycle~ object can then be made to read from that buffer by typing the same name in as its argument. (The initial frequency value for cycle~, just before the buffer name, is optional.)
cycle~ reads its waveform from a buffer~ of the same name
To get the sound into the buffer~, send it a read message. That opens an Open Document dialog box, allowing you to select an audio file to load. The word read can optionally be followed by a specific file name, to read a file in without selecting it from the dialog box, provided that the audio file is in Max's search path.
Read in a specific sound immediately
Regardless of the length of the sound in the buffer~, cycle~ uses only 512 samples from it for its waveform. (You can specify a starting point in the buffer~ for cycle~ to begin its waveform, either with an additional argument to cycle~ or with a set message to cycle~.) In the example patch, we use an audio file that contains exactly 512 samples.
• Click on the message box that says read gtr512.aiff. This loads in the audio file. Then click on the ezdac~ object to turn the audio on. (There will be no sound at first. Can you explain why?) Next, click on the message box marked B3 to listen to 1 second of the cycle~ object.
Create a breakpoint line segment function with line~
If we want to, we can send line~ a longer list containing many value-time pairs of numbers (up to 64 pairs of numbers). In this way, we can make line~ perform a more elaborate function composed of many adjoining line segments. After completing the first line segment, line~ proceeds immediately toward the next target value in the list, taking the specified amount of time to get there.
A function made up of line segments
Synthesizer users are familiar with using this type of function to generate an ‘ADSR’ amplitude envelope. That is what we're doing in this example patch, although we can choose how many line segments we wish to use for the envelope.
Other signal generators: phasor~ and noise~
The phasor~ object produces a signal that ramps repeatedly from 0 to 1.
Signal produced by phasor~
The frequency with which it repeats this ramp can be specified as an argument or can be provided in the left inlet, in Hertz, just as with cycle~. This type of function is useful at sub-audio frequencies to generate periodically recurring events (a crescendo, a filter sweep, etc.). At a sufficiently high frequency, of course, it is audible as a sawtooth waveform.

In the example patch, the phasor~ is pitched an octave above cycle~, and its output is scaled and offset so that it ramps from -1 to +1.
220 Hz sawtooth wave
The noise~ object produces white noise: a signal that consists of a completely random stream of samples. In this example patch, it is used to add a short burst of noise to the attack of a composite sound.
• Click on the message box marked B1 to hear white noise. Click on the message box marked B2 to hear a sawtooth wave.
Add signals to produce a composite sound
Multiple signals are added (mixed) in a signal inlet
In the example patch, white noise, a 220 Hz sawtooth wave, and a 110 Hz tone using the waveform in buffer~ are all mixed together to produce a composite instrument sound.
Three signals mixed to make a composite instrument sound
Each of the three tones has a different amplitude envelope, causing the timbre of the note to evolve over the course of its 1-second duration. The three tones combine to form a note that begins with noise, quickly becomes electric-guitar-like, and gets a boost in its overtones from the sawtooth wave toward the end. Even though the three signals crossfade, their amplitudes are such that there is no possibility of clipping (except, possibly, in the very earliest milliseconds of the note, which are very noisy anyway).
• Click on the button to play all three signals simultaneously. To hear each of the individual parts that comprise the note, click on the message boxes marked A1, A2, and A3. If you want to hear how each of the three signals sound sustained at full volume, click on the message boxes marked B1, B2, and B3. When you have finished, click on ezdac~ to turn the audio off.
The ezdac~ object is a button for switching the audio on and off. The buffer~ object stores a sound. You can load an audio file into buffer~ with a read message, which opens an Open Document dialog box for choosing the file to load in. If a cycle~ object has a typed-in argument which gives it the same name as a buffer~ object has, the cycle~ will use 512 samples from that buffered sound as its waveform, instead of the default cosine wave.
The phasor~ object generates a signal that increases linearly from 0 to 1. This ramp from 0 to 1 can be generated repeatedly at a specific frequency to produce a sawtooth wave. For generating white noise, the noise~ object sends out a signal consisting of random samples.
Whenever you connect more than one signal to a given signal inlet, the receiving object adds those signals together and uses the sum as its input in that inlet. Exercise care when mixing (adding) audio signals, to avoid distortion caused by sending a signal with amplitude greater than 1 to the DAC; signals must be kept in the range -1 to +1 when sent to dac~ or ezdac~.

See Also

Name Description
buffer~ Store audio samples
ezdac~ Audio output and on/off button
phasor~ Sawtooth wave generator
noise~ White noise generator