The MTCoreAudio framework is a Cocoa-flavored Objective-C wrapping around the Hardware Abstraction Layer (HAL) of Apple's CoreAudio library.
Download MTCoreAudio.framework, its source code, and two example programs with source as either a disk image or a compressed tar file.
MTCoreAudio provides one main class, MTCoreAudioDevice, which abstracts the global audio hardware environment and the individual audio devices attached to the system. The class includes methods for finding the system's default input and output devices, all of the devices attached to the system, or a particular device based on its unique identifier (a persistent address which can identify an audio device across reboots and reconfiguration). The class can accomodate a delegate for global hardware events. Device instances accomodate a delegate for device-specific events.
A device instance may have a single AudioDeviceIOProc (a C function, the same as with CoreAudio HAL), or a target/selector for the IO cycle. Multiple device instances may refer to the same physical device, and each instance may have its own AudioDeviceIOProc (or target/selector), which may be different from, or the same as, other instances' AudioDeviceIOProcs (or targets/selectors). Note that the earlier limitation that the AudioDeviceIOProcs not be the same for instances referring to the same physical device has been removed. For example:
... MTCoreAudioDevice * theInputDevice = [MTCoreAudioDevice defaultInputDevice]; MTCoreAudioDevice * theOutputDevice = [MTCoreAudioDevice defaultOutputDevice]; MTCoreAudioDevice * theSysOutputDevice = [MTCoreAudioDevice defaultSystemOutputDevice]; [theInputDevice setIOProc:myInputIOProc withClientData:self]; [theOutputDevice setIOProc:myOutputIOProc withClientData:self]; [theSysOutputDevice setIOProc:myOutputIOProc withClientData:other]; ...will work, even if the default input, output, and system output devices are the same physical device.
An MTCoreAudioDevice instance lets you query and control most of a device's properties, such as a channel's volume, mute, or play-through settings, input or output sources (such as internal microphone, line in, et cetera), buffer size, sample rate, channel configuration, and clock sources.
In the CoreAudio HAL, devices consist of one or more audio streams, which have an implicit direction (either record or playback). MTCoreAudioStream encapsulates a stream. An instance of this class is always associated with an MTCoreAudioDevice instance. Using MTCoreAudioStreams gives you most of the same controls over a device's channels, and is convenient for dealing with audio devices in your code in a manner more analogous to how the device is laid out. MTCoreAudioStreams also provide the only means to modify the hardware data format of the device (such as sample bit depth). This is because, in the HAL, a stream is the only way to modify those parameters. MTCoreAudioStreams can accomodate a delegate for stream-related notification events; however, if an instance does not have a delegate, the delegate of the associated MTCoreAudioDevice instance will be used.
The MTCoreAudioStreamDescription class is just a simple wrapper around the HAL's AudioStreamBasicDescription, which is used for describing both the logical and physical data formats of audio data in a device and its streams. This structure is encapsulated in an Objective-C class to simplify memory management (especially when working with arrays of supported formats), and to provide a simple text description of a format.
Some services of MTCoreAudio require initialization before use.
hardware notifications and
value transformers. These services are
initialized when you send the first message to class
MTCoreAudioDevice. This is usually
accomplished by sending
main() function, but may be accomplished by sending any message to
the class before attempting to use those services.
Many types are defined in CoreAudio's header files. Please see
for their definitions.