Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 1 - Introduction to Sound on the Macintosh / Using Sound on Macintosh Computers


Legacy Documentclose button

Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.

Recording a Sound File

To record a sound directly into a file, you can call the SndRecordToFile function, which works exactly like SndRecord except that you pass it the file reference number of an open file instead of a handle to some memory. When SndRecordToFile exits successfully, that file contains the recorded audio data in AIFF or AIFF-C format. You can then play the recorded sound by passing that file reference number to the SndStartFilePlay function. (See Listing 1-2 on page 1-26 for a sample function that uses the SndStartFilePlay function.) Listing 1-6 defines a procedure that records a sound into a file using SndRecordToFile.

Listing 1-6 Recording a sound file

PROCEDURE MyRecordSoundFile (myFileRefNum: Integer);
VAR
   myErr:      OSErr;
   myCorner:   Point;
BEGIN
   MyGetTopLeftCorner(myCorner);
   myErr := SndRecordToFile(NIL, myCorner, siBestQuality, myFileRefNum);
   IF (myErr <> noErr) AND (myErr <> userCanceledErr) THEN
      DoError(myErr);
END;
The SndRecordToFile function records the sound in the file specified in its fourth parameter. You must open the file before calling the MyRecordSoundFile procedure, and you must close the file after calling it. For more information on creating, opening, and closing files, see the chapter "Introduction to File Management" in Inside Macintosh: Files.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996