Sound Recording
Sound Recording Saving and storing sounds
The Sound Manager provides your application with the ability to record and
digitally store sounds in a device-independent manner. Your applications can
create a resource or a file containing a recorded sound simply by calling
SndRecord or SndRecordToFile. In cases where you need very fine control
over the recording process, you can call various low-level sound input
routines. You can then use the recorded sound in any way appropriate to your
application.
The sound input and storage routines can be used with any available sound
input hard-ware for which there is an appropriate device driver. To allow the
user to select from among multiple possible input devices, the Sound control
panel lists the available sound input devices, as illustrated in the Figure below.
The Sound control panel
Devices are listed if their drivers have previously registered themselves
with the Sound Manager and provided a name and device icon. In the Figure
above, two sound input devices are available, a device named Built-in and a
device named HackRecorder. The user has selected Built-in. The selected device
is the current sound input device.
The new Sound control panel also includes three new buttons, Add, Remove,
and Options. These buttons allow the user to add sounds to and remove sounds
from the list of available system alert sounds and to set any device-specific
recording options. The Add button is used to record a new alert sound and add it
to the list. Clicking the Add button causes the
Sound Manager to put up a sound recording dialog box. Clicking the
Remove button causes the Sound Manager to remove the selected alert
sound from the list. The user can achieve the same effect by selecting a sound
and then choosing the Clear command in the Edit menu. If no sound input
drivers are installed in the system, then these three buttons do not appear.
If the sound recording dialog box was called up by clicking the Add button of
the Sound control panel, then the recorded sound is saved as a resource of type
'snd ' in the System file. That sound then appears in the list of available alert
sounds. Note that the standard Edit menu commands can be used on sounds
stored in the System file. The Cut command copies the selected sound to the
Clipboard and removes it from the list of system alert sounds. The Copy
command just copies the selected sound to the Clipboard. The Paste command
copies a sound from the Clipboard and places it in the list of available alert
sounds. However, the Undo command does not work with sound-related editing
ope rations.
The Sound Manager provides two high-level routines that allow your
application to record sounds from the user and store them in memory or in a
file. When you call either SndRecord or SndRecordToFile, the
Sound Manager presents a sound recording dialog box to the user,
illustrated in the Figure below.
The sound recording dialog box
Using the controls in this dialog box, the user can start, pause, resume, and
stop recording on the currently selected sound input device. The user can also
play back the recorded sound. The time indicator bar provides an indication of
the current length of the recorded sound. When the user clicks the Save
button, another dialog box appears asking the user to give the sound a name.
Unless the user cancels the save ope ration at that point, the recorded sound is
saved into a file (if SndRecordToFile was called) or into RAM (if
SndRecord was called).
The Sound Manager also provides a set of low-level routines that are of
interest to you only if your application needs to intervene in the normal
sound-recording process or if you are writing a driver to support a sound
input device. If you simply want a resource (or a file) that contains a recorded
sound, you can get that most easily by calling SndRecord (or
SndRecordToFile). If you need to modify the features or ope ration of the
sound recording dialog box, you can usually do so by defining a custom filter
procedure.
In instances where you need to gain greater control over the recording
process, you can use a set of routines that manipulate the incoming sound data
by using sound parameter blocks. The parameter blocks contain information
about the current recording device, the length recorded, a routine to call on
completion of the recording, and so forth. You can call SPBRecord (or
SPBRecordToFile) to begin a recording. Then you can use the functions
SPBPauseRecording, SPBResumeRecording, and SPBStopRecording
to control the recording. Note that you need to open a device ( using
SPBOpenDevice) before you can record from it. On completion of the
recording, you should close the device (using SPBCloseDevice).
There are also several routines intended for use by sound input device
drivers. Sound input drivers need to register with the Sound Manager by
calling SPBSignInDevice. This makes that device visible in the Sound
control panel for possible selection as the current input device. You can
remove a device from that panel by calling SPBSignOutDevice.
Two functions-SPBGetDeviceInfo and SPBSetDeviceInfo-allow you to
examine and change certain settings in a sound input device. For example, you
can set the recording quality by passing the appropriate selector code and
setting to SPBSetDeviceInfo.