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 theSndRecordToFilefunction, which works exactly likeSndRecordexcept that you pass it the file reference number of an open file instead of a handle to some memory. WhenSndRecordToFileexits 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 theSndStartFilePlayfunction. (See Listing 1-2 on page 1-26 for a sample function that uses theSndStartFilePlayfunction.) Listing 1-6 defines a procedure that records a sound into a file usingSndRecordToFile.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;TheSndRecordToFilefunction records the sound in the file specified in its fourth parameter. You must open the file before calling theMyRecordSoundFileprocedure, 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.