Apr 99 Getting Started
Volume Number: 15
Issue Number: 4
Column Tag: Getting Started
Sound Recording and Playback
by Dan Parks Sydow
How a Mac program records and plays back
user-entered sounds
In the last two Getting Started columns we covered sound-playing basics and
asynchronous sound playing (the playing of sound while other action takes place).
Getting Started has a wealth of other topics to cover, but before moving on we'll wrap
up our study of sound by exploring how a Mac program can easily allow a user to
record a sound and then make that sound a part of the program.
Mac users aren't a passive bunch - they want to interact with applications. Giving the
user the ability to record something (such as a short clip of music from a CD or the
user's own voice) provides the user with a feeling of power. It's also just plain cool!
Giving the user the ability to then play back that sound at any time furthers the user's
feeling of control. In this article you'll see how a single Toolbox call makes sound
recording possible, and how a few dozen lines of code make it possible to save the
user's sound to a resource and then play that sound back on demand.
Sound Recording and the User
Interface consistency across applications has been important to the success of the
Macintosh. When a user wants to open a file, he knows that choosing the Open item in
the File menu results in the appearance of the very familiar standard Open dialog box.
The same holds true for sound recording. If the user of a program wants to record a
sound, choosing a Record menu item or clicking on a Record button should result in the
appearance of the standard Sound Recording dialog box - the dialog box shown in
Figure 1.
Figure 1. The standard Sound Recording dialog box.
Whatever sound input device is active serves as the supplier of the sound to the Sound
Recording dialog box. Usually that device is a microphone (like the one supplied with
current Mac models) that's plugged into the Mac's sound input port - but it can be a
different device, such as a CD drive. Using this dialog box is intuitive and
straightforward. Clicking the Record button starts sound recording. Clicking the Pause
button temporarily halts recording, while clicking the Stop button ends recording. The
Play button is used to listen to the just-recorded sound. When it comes time to dismiss
the Sound Recording dialog box, a click on the Cancel button does the job - without
saving whatever was just recorded. Clicking the Save button also dismisses the dialog
box, but not until the last recorded sound is saved (more on that later).
Because adding sound recording to a program is easy, you'll want to play around with
the code in this column just to have a little fun. When it comes time to incorporate
sound recording into your own program, though, you'll want to give some thought to
the matter. Your own application may not have a need for this feature, but your
program may find that it's a useful option. Consider recent versions of the word
processor Microsoft Word.
Microsoft Word allows a user to add comments to a document. Typically a person who is
reviewing a document written by someone else uses this feature. When the original
author of the document gets the reviewed copy back, he can choose to view the
comments to get the reviewer's input. In Microsoft Word, the author can read what the
reviewer wrote or, if the reviewer chose the voice comments option, the author can
actually hear what the reviewer said. Figure 2 shows a Word document after a
comment that includes both text and voice has been added to it.