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.

Converting Between Milliseconds and Bytes

The Sound Input Manager provides two routines that allow you to convert between millisecond and byte recording values.

SPBMilliSecondsToBytes

You can use the SPBMilliSecondsToBytes function to determine how many bytes a recording of a certain duration will use.

FUNCTION SPBMilliSecondsToBytes (inRefNum: LongInt;
                                                              VAR milliseconds: LongInt):
                     OSErr;

inRefNum

The device reference number of the sound input device, as obtained from the SPBOpenDevice function.

milliseconds

On entry, the duration of the recording in milliseconds. On exit, the number of bytes that sampled-sound data would occupy for a recording of the specified duration on the device specified by the inRefNum parameter.

DESCRIPTION

The SPBMilliSecondsToBytes function reports how many bytes are required to store a recording of duration milliseconds , given the input device's current sample rate, sample size, number of channels, and compression factor.

SPECIAL CONSIDERATIONS

You can call the SPBMilliSecondsToBytes function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the SPBMilliSecondsToBytes function are

Trap macro

Selector

_SoundDispatch

$04400014

RESULT CODES

noErr

0

No error

siBadSoundInDevice

-221

Invalid sound input device

SPBBytesToMilliSeconds

You can use the SPBBytesToMilliSeconds function to determine the maximum duration of a recording that can fit in a buffer of a certain size.

FUNCTION SPBBytesToMilliSeconds (inRefNum: LongInt;
                                                              VAR byteCount: LongInt): OSErr;

inRefNum

The device reference number of the sound input device, as obtained from the SPBOpenDevice function.

byteCount

On entry, a value in bytes. On exit, the number of milliseconds of recording on the device specified by the inRefNum parameter that would be necessary to fill a buffer of such a size.

DESCRIPTION

The SPBBytesToMilliSeconds function reports how many milliseconds of audio data can be recorded in a buffer that is byteCount bytes long, given the input device's current sample rate, sample size, number of channels, and compression factor.

SPECIAL CONSIDERATIONS

You can call the SPBBytesToMilliSeconds function at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the SPBBytesToMilliSeconds function are

Trap macro

Selector

_SoundDispatch

$04440014

RESULT CODES

noErr

0

No error

siBadSoundInDevice

-221

Invalid sound input device


© 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.