Title Banner

Previous Book Contents Book Index Next

Newton Developer Technical Information: Newton Programmer's Guide: 2.1 OS Addendum /
Chapter 7 - Sound / Using Sound


Using the Built-in Sound Recorder Slip

The system includes a new built-in user interface object that lets the user control sound recording and playback. This floating slip (Figure 7-2 on page 7-3) exists as a child of the root view, and is named *soundRecorder. This slip incorporates all the code necessary to record and play sounds. You can use this slip to add sound recording and playback capabilities to any application.

Note that because the *soundRecorder slip is an independent floating view, you don't embed it in your application's view hierarchy, you simply send it a message to open it.

You can access the built-in sound recorder with code like this:

sr := GetRoot().soundRecorder;

To open this view to allow recording, use this call:

if sr then

sr:OpenRecord(callback);

This sets up the recorder slip to do recording and opens it on the screen. The callback parameter is a function that you supply and is called when the user closes the slip. When the user taps the close box to close the recorder, the callback function is called with a single argument, the array of sound frames that were allocated as a result of recording. You can store them or do whatever processing is required.

To play a sound using the sound recorder slip, use this call:

sr:OpenPlay(soundFrame);

This sets up the recorder to play the sound frame passed in soundFrame, and opens it on the screen.

After opening the recorder slip with either *OpenPlay or *OpenRecord, you can set several slots in the sound recorder base view to override values in the associated sound channel and sound frames created by it. The slots you can set are shown in Table 7-1.

Table 7-1 Sound recorder slots you can set
SlotDescription
fSoundFrameSlotsA frame that contains slots to be copied to the sound frames used for recording. This frame overrides the default values of the slots in any sound frames created by *soundRecorder. This frame can contain any slots that you want copied to the sound frames created by *soundRecorder.
fInputGainSets the inputGain slot in the sound channel.
fInputDeviceSets the inputDevice slot in the sound channel.
fOutputDeviceSets the outputDevice slot in the sound channel.
fCallbackA function that is called when the user taps the close box to close the recorder. It is passed a single argument, the array of sound frames that were allocated as a result of recording. Note that this slot is set by the *OpenRecord method (it's the argument you passed to *OpenRecord), so if you open the recorder by calling *OpenRecord, then you don't need to also set this slot.

Here's an example of setting the fSoundFrameSlots slot in the sound recorder base view to specify that IMA compression be used for recording:

sr.fSoundFrameSlots :=

{sndFrameType: 'codec, // use a codec codecName: "TIMACodec", // select IMA codec bufferSize: 12500, // size of codec buffers bufferCount: 4, // # of codec buffers compressionType: kSampleLinear, // for playback dataType: k16bit, // for playback samplingRate: 10000, // samples per second compressionRatio: 64/34, // for IMA }


Previous Book Contents Book Index Next

© Apple Computer, Inc.
26 APR 1997



Navigation graphic, see text links

Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help