A newer version of Max is available. Click here to access the latest documentation.
Tutorial 13: Recording and Playback
Open the tutorial.
Sound input: adc~
For getting sound from the ‘real world’ into MSP, there is an analog-to-digital conversion object called adc~. It recognizes all the same messages as the dac~ object, but instead of sending signal to the audio output jacks of the computer, adc~ receives signal from the audio input jacks, and sends the incoming signal out its outlets. Just as dac~ has a user interface version called ezdac~, there is an iconic version of adc~ called ezadc~.
adc~ and ezadc~ get sound from the audio input jacks and send it out as a signal
To use the adc~ object, you need to send sound from some source into the computer. The sound may come from the CD player of your computer, from any line level source such as a tape player, or from a microphone -- your computer might have a built-in microphone, or you can use a standard microphone via a preamplifer.
• Double click on the adc~ object to open the DSP Status window. Make sure that the Input Source popup menu displays the input device you want. Depending on your computer system, audio card and driver, you may not have a choice of input device-this is nothing to be concerned about.

• Click on the toggle above the adc~ object to turn audio on. If you want to hear the input sound played directly out the output jacks, adjust the number box marked Audio thruput level.
Adjust the audio throughput to a comfortable listening level
If your input source is a microphone, you'll need to be careful not to let the output sound from your computer feed back into the microphone.
Recording a sound: record~
To record a sample of the incoming sound (or any signal), you first need to designate a buffer in which the sound will be stored. Your patch should therefore include at least one buffer~ object. You also need a record~ object with the same name as the buffer~. The sound that you want to record must go in the inlet of the record~ object.
Record two seconds of stereo sound into the buffer~ named soundbite
When record~ receives a non-zero int in its left inlet, it begins recording the signals connected to its record inlets; 0 stops the recording. You can specify recording start and end points within the buffer~ by sending numbers in the two right inlets of record~. If you don't specify start and end points, recording will fill the entire buffer~. Notice that the length of the recording is limited by the length of the buffer~. If this were not the case, there would be the risk that record~ might be left on accidentally and fill the entire application memory.
In the tutorial patch, record~ will stop recording after 2 seconds (2000 ms). We have included a delayed bang to turn off the toggle after two seconds, but this is just to make the toggle accurately display the state of record~. It is not necessary to stop record~ explicitly, because it will stop automatically when it reaches its end point or the end of the buffer~.
A delayed bang turns off the toggle after two seconds so it will display correctly
• Make sure that you have sound coming into the computer, then click on the toggle to record two seconds of the incoming sound. If you want to, you can double-click on the buffer~ afterward to see the recorded signal.
Reading through a buffer~: index~
So far you have seen two ways to get sound into a buffer~. You can read in an existing audio file with the read message, and you can record sound into it with the record~ object. Once you get the sound into a buffer~, there are several things you can do with it. You can save it to an audio file by sending the write message to the buffer~. You can use 513 samples of it as a wavetable for cycle~, as demonstrated in Tutorial 3. You can use any section of it as a transfer function for lookup~, as demonstrated in Tutorial 14.

The index~ object receives a signal as its input, which represents a sample number. It looks up that sample in its associated buffer~, and sends the value of that sample out its outlet as a signal. The count~ object just sends out a signal value that increases by one with each sample. So, if you send the output of count~ -- a steady stream of increasing numbers -- to the input of index~ -- which will treat them as sample numbers -- index~ will read straight through the buffer~, playing it back at the current sampling rate.
Play the sound in a buffer~ by looking up each sample and sending it to the dac~
• Click on the button marked ‘Play’ to play the sound in the buffer~. You can change the starting sample number by sending a different starting number into count~.
This combination of count~ and index~ lets you specify a precise sample number in the buffer~ where you want to start playback. However, if you want to specify starting and ending points in the buffer~ in terms of milliseconds, and/or you want to play the sound back at a different speed -- or even backward -- then the play~ object is more appropriate.
Variable speed playback: play~
The play~ object receives a signal in its inlet which indicates a position, in milliseconds, in its associated buffer~; play~ sends out the signal value it finds at that point in the buffer~. Unlike index~, though, when play~ receives a position that falls between two samples in the buffer~ it interpolates between those two values. For this reason, you can read through a buffer~ at any speed by sending an increasing or decreasing signal to play~, and it will interpolate between samples as necessary. (Theoretically, you could use index~ in a similar manner, but it does not interpolate between samples so the sound fidelity would be considerably worse.)

The most obvious way to use the play~ object is to send it a linearly increasing (or decreasing) signal from a line~ object, as shown in the tutorial patch.
Read through a buffer~, from one position to another, in a given amount of time
Reading from 0 to 2000 (millisecond position in the buffer~) in a time of 2000 ms produces normal playback. Reading from 0 to 2000 in 4000 ms produces half-speed playback, and so on.
• Click on the different message box objects to hear the sound played in various speed/direction combinations. Turn audio off when you have finished.
Although not demonstrated in this tutorial patch, it's worth noting that you could use other signals as input to play~ in order to achieve accelerations and decelerations, such as an exponential curve from a curve~ object or even an appropriately scaled sinusoid from a cycle~ object.
Summary
Sound coming into the computer enters MSP via the adc~ object. The record~ object stores the incoming sound -- or any other signal -- in a buffer~. You can record into the entire buffer~, or you can record into any portion of it by specifying start and end buffer positions in the two rightmost inlets of record~. For simple normal-speed playback of the sound in a buffer~, you can use the count~ and index~ objects to read through it at the current sampling rate. Use the line~ and play~ objects for variable-speed playback and/or for reading through the buffer~ in both directions.

See Also

Name Description
adc~ Audio input and on/off
ezadc~ Audio input and on/off button
index~ Sample playback without interpolation
play~ Position-based sample playback
record~ Record sound into a buffer