Inside Macintosh: Sound Manager

| Previous | Chapter contents | Chapter top | Section top | Next |

Legacy Documentclose button

Important: Sound Input Manager 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.

Opening and Closing Sound Input Devices

You can use the SPBOpenDevice function to open the default sound input device that the user has selected in the Sound In control panel or to open a specific sound input device. You must open a device before you can record from it by using SPBRecord , but the Sound Input Manager's high-level routines automatically open the default sound input device. You can close a sound input device by calling the SPBCloseDevice function.

SPBOpenDevice

You can use the SPBOpenDevice function to open a sound input device.

FUNCTION SPBOpenDevice (deviceName: Str255; permission: Integer;
                                                              VAR inRefNum: LongInt): OSErr;

deviceName

The name of the sound input device to open, or the empty string if the default sound input device is to be opened.

permission

A flag that indicates whether subsequent operations with that device are to be read/write or read-only.

inRefNum

On exit, if the function is successful, a device reference number for the open sound input device.

DESCRIPTION

The SPBOpenDevice function attempts to open a sound input device having the name indicated by the deviceName parameter. If SPBOpenDevice succeeds, it returns a device reference number in the inRefNum parameter. The permission parameter indicates whether subsequent operations with that device are to be read/write or read-only. If the device is not already in use, read/write permission is granted; otherwise, only read-only operations are allowed. To make any recording requests or to call the SPBSetDeviceInfo function, read/write permission must be available. Use these constants to request the appropriate permission:

CONST
    siReadPermission            = 0;        {open device for reading}
    siWritePermission           = 1;        {open device for reading/writing}

You can request that the current default sound input device be opened by passing either a zero-length string or a NIL string as the deviceName parameter. If only one sound input device is installed, that device is used. Generally you should open the default device unless you specifically want to use some other device. You can get a list of the available devices by calling the SPBGetIndexedDevice function.

SPECIAL CONSIDERATIONS

Because the SPBOpenDevice function allocates memory, you should not call it at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the SPBOpenDevice function are

Trap macro

Selector

_SoundDispatch

$05180014

RESULT CODES

noErr

0

No error

permErr

-54

Device already open for writing

siBadDeviceName

-228

Invalid device name

SPBCloseDevice

You can use the SPBCloseDevice function to close a sound input device.

FUNCTION SPBCloseDevice (inRefNum: LongInt): OSErr;

inRefNum

The device reference number of the sound input device to close.

DESCRIPTION

The SPBCloseDevice function closes a device that was previously opened by SPBOpenDevice and whose device reference number is specified in the inRefNum  parameter.

SPECIAL CONSIDERATIONS

Because the SPBCloseDevice function moves or purges memory, you should not call it at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the SPBCloseDevice function are

Trap macro

Selector

_SoundDispatch

$021C0014

RESULT CODES

noErr

0

No error

siBadRefNum

-229

Invalid reference number


© 1999 Apple Computer, Inc.

Inside Macintosh: Sound Manager

| Previous | Chapter contents | Chapter top | Section top | Next |

Legacy Documentclose button

Important: Sound Input Manager 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.