ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


IOAudioStream

Inherits from:
Declared In:

Overview

This class wraps a single sample buffer in an audio driver.

Discussion

An IOAudioStream represents one hardware sample buffer as well as the direction of that buffer, the mix buffer that multiple clients mix into as well as a list of all of the formats to which this buffer can be set.

When an IOAudioEngine is created during init time in the driver, an IOAudioStream must be created for each sample buffer in the device. Typically, the sample buffer will be interleaved (or single channel), as a non-interleaved buffer should be divided into multiple single-channel buffers (and multiple IOAudioStreams).

Additionally, when an IOAudioStream is created it must have all of the possible formats (and allowed sample rates for each format) set and must have the currently set format specified (addAvailableFormat() and setFormat()).



Groups

group2

Group members:

audioEngine
audioIOFunctions
availableFormatDictionaries
availableFormats
clientBufferListEnd
clientBufferListStart
clippedPosition
commandGate
createDictionaryFromFormat
createFormatFromDictionary
defaultAudioControls
direction
format
maxNumChannels
mixBuffer
mixBufferSize
numAvailableFormats
numClients
numIOFunctions
sampleBuffer
sampleBufferSize
startingChannelID
startingPosition
streamAllocatedMixBuffer
streamAvailable
streamIOLock
workLoop

 

group3

Group members:

addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)
addClient
addDefaultAudioControl
clearAvailableFormats
clearSampleBuffer
clipIfNecessary
clipOutputSamples
free
getDirection
getFormat
getFormatExtension
getMaxNumChannels
getMixBuffer
getMixBufferSize
getNumClients
getNumSampleFramesRead
getSampleBuffer
getSampleBufferSize
getStartingChannelID
getStreamAvailable
getWorkLoop
hardwareFormatChanged
initWithAudioEngine
lockStreamForIO
mixOutputSamples
numSampleFramesPerBufferChanged
processOutputSamples
readInputSamples
removeClient
removeDefaultAudioControls
resetClipInfo
setDefaultNumSampleFramesRead
setFormat
setFormat(const IOAudioStreamFormat *, bool)
setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, bool)
setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, OSDictionary *, bool)
setFormat(OSDictionary *)
setFormatAction
setIOFunction
setIOFunctionList
setMixBuffer
setProperties
setSampleBuffer
setSampleLatency
setStartingChannelNumber
setStreamAvailable
setTerminalType
stop
unlockStreamForIO
updateNumClients
userClientList
validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatDesc *)
validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatExtension *, IOAudioStreamFormatDesc *)

Functions

addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)
addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)
addClient
addDefaultAudioControl
clearAvailableFormats
clearSampleBuffer
clipIfNecessary
clipOutputSamples
createDictionaryFromFormat
createFormatFromDictionary
free
getDirection
getFormat
getFormatExtension
getMaxNumChannels
getMixBuffer
getMixBufferSize
getNumClients
getNumSampleFramesRead
getSampleBuffer
getSampleBufferSize
getStartingChannelID
getStreamAvailable
getWorkLoop
hardwareFormatChanged
initKeys
initWithAudioEngine
lockStreamForIO
mixOutputSamples
numSampleFramesPerBufferChanged
processOutputSamples
readInputSamples
removeClient
removeDefaultAudioControls
resetClipInfo
setDefaultNumSampleFramesRead
setFormat
setFormat(const IOAudioStreamFormat *, bool)
setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, bool)
setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, OSDictionary *, bool)
setFormat(OSDictionary *)
setFormatAction
setIOFunction
setIOFunctionList
setMixBuffer
setProperties
setSampleBuffer
setSampleLatency
setStartingChannelNumber
setStreamAvailable
setTerminalType
stop
unlockStreamForIO
updateNumClients
validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatDesc *)
validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatExtension *, IOAudioStreamFormatDesc *)

addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)


public

virtual void addAvailableFormat( const IOAudioStreamFormat *streamFormat, const IOAudioSampleRate *minRate, const IOAudioSampleRate *maxRate, AudioIOFunction ioFunction);
Discussion

Adds a single available sample format to an audio stream.


addAvailableFormat(const IOAudioStreamFormat *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)


public

virtual void addAvailableFormat( const IOAudioStreamFormat *streamFormat, const IOAudioSampleRate *minRate, const IOAudioSampleRate *maxRate, const AudioIOFunction *ioFunctionList = NULL, UInt32 numFunctions = 0);
Discussion

Adds a list of available sample formats to an audio stream.


addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, AudioIOFunction)


public

virtual void addAvailableFormat( const IOAudioStreamFormat *streamFormat, const IOAudioStreamFormatExtension *formatExtension, const IOAudioSampleRate *minRate, const IOAudioSampleRate *maxRate, AudioIOFunction ioFunction);
Discussion

Adds a single available format to the list of supported formats.


addAvailableFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, const IOAudioSampleRate *, const IOAudioSampleRate *, const AudioIOFunction *, UInt32)


public

virtual void addAvailableFormat( const IOAudioStreamFormat *streamFormat, const IOAudioStreamFormatExtension *formatExtension, const IOAudioSampleRate *minRate, const IOAudioSampleRate *maxRate, const AudioIOFunction *ioFunctionList = NULL, UInt32 numFunctions = 0);
Discussion

Adds multiple available formats to the list of supported formats in a single call.


addClient


protected

virtual IOReturn addClient( IOAudioClientBuffer *clientBuffer);
Discussion

Adds a new client to this stream..


addDefaultAudioControl


public

virtual IOReturn addDefaultAudioControl( IOAudioControl *defaultAudioControl);
Discussion

Adds a default audio control.


clearAvailableFormats


public

virtual void clearAvailableFormats();
Discussion

Clears the list of available formats.


clearSampleBuffer


public

virtual void clearSampleBuffer();
Discussion

This function zeroes the sample buffer. You should call this prior to starting the audio engine.


clipIfNecessary


protected

virtual void clipIfNecessary();
Discussion

Calls clipOutputSamples if there are frames in the mix buffer that have not been clipped.


clipOutputSamples


protected

virtual void clipOutputSamples( UInt32 startingSampleFrame, UInt32 numSampleFrames);
Discussion

Generally, this function calls the audio engine's clipOutputSamples function. This can, however, be overridden on a per-stream basis.


createDictionaryFromFormat


public

static OSDictionary *createDictionaryFromFormat( const IOAudioStreamFormat *streamFormat, const IOAudioStreamFormatExtension *formatExtension, OSDictionary *formatDict = 0);
Discussion

Creates an OSDictionary object from audio format values.


createFormatFromDictionary


public

static IOAudioStreamFormat *createFormatFromDictionary( const OSDictionary *formatDict, IOAudioStreamFormat *streamFormat = 0, IOAudioStreamFormatExtension *formatExtension = 0);
Discussion

Creates an audio format value from an OSDictionary object.


free


public

virtual void free();
Discussion

Frees a stream object and its instance variables.


getDirection


public

virtual IOAudioStreamDirection getDirection();
Discussion

Gets the direction of a stream.


getFormat


public

virtual const IOAudioStreamFormat *getFormat();
Discussion

Returns the current audio stream format.


getFormatExtension


public

virtual const IOAudioStreamFormatExtension *getFormatExtension();
Discussion

Gets the current format extension.


getMaxNumChannels


public

virtual UInt32 getMaxNumChannels();
Discussion

Returns the maximum number of channels for any format that this stream supports. The next audio stream created should start at getStartingChannelID() + getMaxNumChannels().


getMixBuffer


public

virtual void *getMixBuffer();
Discussion

Returns the current mix buffer.


getMixBufferSize


public

virtual UInt32 getMixBufferSize();
Discussion

Returns the size of the current mix buffer.


getNumClients


protected

virtual UInt32 getNumClients();
Discussion

Returns the current number of clients of this stream..


getNumSampleFramesRead


public

virtual UInt32 getNumSampleFramesRead();
Discussion

Returns the number of sample frames read.


getSampleBuffer


public

virtual void *getSampleBuffer();
Discussion

Returns the current sample buffer.


getSampleBufferSize


public

virtual UInt32 getSampleBufferSize();
Discussion

Returns the size of the current sample buffer.


getStartingChannelID


public

virtual UInt32 getStartingChannelID();
Discussion

Returns the first channel ID for this stream. Each successive channel has an ID that is one higher than the last, up to getStartingChannelID() + getMaxNumChannels() - 1.


getStreamAvailable


public

virtual bool getStreamAvailable();
Discussion

Returns the stream's availability as set by setStreamAvailable.


getWorkLoop


public

virtual IOWorkLoop *getWorkLoop() const;
Discussion

Returns the workloop associated with the stream.


hardwareFormatChanged


public

virtual IOReturn hardwareFormatChanged( const IOAudioStreamFormat *streamFormat);
Discussion

Notifies the Audio HAL that the hardware has requested an audio format change (such as when an external clock source changes rates).


initKeys


public

static void initKeys();
Discussion

Initializes keys to default values.


initWithAudioEngine


public

virtual bool initWithAudioEngine( IOAudioEngine *engine, IOAudioStreamDirection dir, UInt32 startChannelID, const char *streamDescription = NULL, OSDictionary *properties = 0);
Discussion

Initializes a stream object.


lockStreamForIO


protected

virtual void lockStreamForIO();
Discussion

Locks the stream for I/O.


mixOutputSamples


public

virtual IOReturn mixOutputSamples( const void *sourceBuf, void *mixBuf, UInt32 firstSampleFrame, UInt32 numSampleFrames, const IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream);
Discussion

Calls the Audio Engine's mixOutputSamples function. This may be overridden on a stream-by-stream basis by subclassing IOAudioStream.


numSampleFramesPerBufferChanged


public

virtual void numSampleFramesPerBufferChanged();
Discussion

This function should be called if you change the number of sample frames in the buffer.


processOutputSamples


protected

virtual IOReturn processOutputSamples( IOAudioClientBuffer *clientBuffer, UInt32 firstSampleFrame, UInt32 loopCount, bool samplesAvailable);
Discussion

Calls functions to mix source material into the mix buffer and, if necessary, clip the results.


readInputSamples


protected

virtual IOReturn readInputSamples( IOAudioClientBuffer *clientBuffer, UInt32 firstSampleFrame);
Discussion

Calls I/O functions to read input samples from hardware.


removeClient


protected

virtual void removeClient( IOAudioClientBuffer *clientBuffer);
Discussion

Removes a client of this stream.


removeDefaultAudioControls


public

virtual void removeDefaultAudioControls();
Discussion

Removes all default audio controls.


resetClipInfo


protected

virtual void resetClipInfo();
Discussion

Resets clip position information to zero.


setDefaultNumSampleFramesRead


public

virtual void setDefaultNumSampleFramesRead( UInt32);
Discussion

Sets the default number of sample frames read.


setFormat


public

virtual IOReturn setFormat( const IOAudioStreamFormat *streamFormat, OSDictionary *formatDict, bool callDriver = true);
Discussion

Sets the current stream format and stream format dictionary.


setFormat(const IOAudioStreamFormat *, bool)


public

virtual IOReturn setFormat( const IOAudioStreamFormat *streamFormat, bool callDriver = true);
Discussion

Sets the current stream format.


setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, bool)


public

virtual IOReturn setFormat( const IOAudioStreamFormat *streamFormat, const IOAudioStreamFormatExtension *formatExtension, bool callDriver = true);
Discussion

Sets the current audio format.


setFormat(const IOAudioStreamFormat *, const IOAudioStreamFormatExtension *, OSDictionary *, bool)


public

virtual IOReturn setFormat( const IOAudioStreamFormat *streamFormat, const IOAudioStreamFormatExtension *formatExtension, OSDictionary *formatDict, bool callDriver = true);
Discussion

Sets the current audio format using a format dictionary.


setFormat(OSDictionary *)


public

virtual IOReturn setFormat( OSDictionary *formatDict);
Discussion

Sets the current stream format dictionary.


setFormatAction


public

static IOReturn setFormatAction( OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
Discussion

Assigns a format action callback. This function will be called when a format change occurs.


setIOFunction


public

virtual void setIOFunction( AudioIOFunction ioFunction);
Discussion

Assigns an I/O function to the stream.


setIOFunctionList


public

virtual void setIOFunctionList( const AudioIOFunction *ioFunctionList, UInt32 numFunctions);
Discussion

Assigns a list of I/O functions to the stream.


setMixBuffer


public

virtual void setMixBuffer( void *buffer, UInt32 size);
Discussion

Assigns a mix buffer of a given size to the stream.


setProperties


public

virtual IOReturn setProperties( OSObject *properties);
Discussion

Sets properties on a stream.


setSampleBuffer


public

virtual void setSampleBuffer( void *buffer, UInt32 size);
Discussion

Assigns a sample buffer of a given size to the stream.


setSampleLatency


public

virtual void setSampleLatency( UInt32 numSamples);
Discussion

Calls the Audio Engine's setSampleLatency function. This may be overridden on a stream-by-stream basis by subclassing IOAudioStream.


setStartingChannelNumber


protected

virtual void setStartingChannelNumber( UInt32 channelNumber);
Discussion

Sets the starting channel number for this stream.


setStreamAvailable


public

virtual void setStreamAvailable( bool available);
Discussion

Marks a stream as available or unavailable for use.


setTerminalType


public

virtual void setTerminalType( const UInt32 terminalType);
Discussion

Sets the terminal type of the current stream.


stop


public

virtual void stop( IOService *provider);
Discussion

Stops an audio stream.


unlockStreamForIO


protected

virtual void unlockStreamForIO();
Discussion

Unlocks the stream for I/O.


updateNumClients


protected

virtual void updateNumClients();
Discussion

Iterates the stream's client list and updates the current count of clients.


validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatDesc *)


public

virtual bool validateFormat( IOAudioStreamFormat *streamFormat, IOAudioStreamFormatDesc *formatDesc);
Discussion

Validates an audio format.


validateFormat(IOAudioStreamFormat *, IOAudioStreamFormatExtension *, IOAudioStreamFormatDesc *)


public

virtual bool validateFormat( IOAudioStreamFormat *streamFormat, IOAudioStreamFormatExtension *formatExtension, IOAudioStreamFormatDesc *formatDesc);
Discussion

Validates an audio format format (with format extension).

Typedefs


AudioIOFunction


public

typedef IOReturn ( *AudioIOFunction)( const void *mixBuf, void *sampleBuf, UInt32 firstSampleFrame, UInt32 numSampleFrames, const IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream);
Discussion

The audio IO function pointer is the standard function prototype for various Audio I/O-related callbacks into device drivers from the Core Audio HAL.

Member Data


audioEngine


public

IOAudioEngine *audioEngine;
Discussion

The audio engine associated with this stream.


audioIOFunctions


public

AudioIOFunction *audioIOFunctions;
Discussion

An array of audio IO function callbacks.


availableFormatDictionaries


public

OSArray *availableFormatDictionaries;
Discussion

An OSArray of available format dictionaries.


availableFormats


public

IOAudioStreamFormatDesc *availableFormats;
Discussion

A list of available stream formats.


clientBufferListEnd


public

IOAudioClientBuffer *clientBufferListEnd;
Discussion

The tail of a list of audio client buffers.


clientBufferListStart


public

IOAudioClientBuffer *clientBufferListStart;
Discussion

The head of a list of audio client buffers.


clippedPosition


public

IOAudioEnginePosition clippedPosition;
Discussion

The position in the sample buffer which has been clipped and is thus available for playback.


commandGate


public

IOCommandGate *commandGate;
Discussion

The command gate associated with this stream.


defaultAudioControls


public

OSSet *defaultAudioControls;
Discussion

A set of audion controls.


direction


public

IOAudioStreamDirection direction;
Discussion

The direction of the audio stream.


format


public

IOAudioStreamFormat format;
Discussion

An IOAudioStreamFormat object containing the stream's current format.


gAlignmentKey


public

static const OSSymbol *gAlignmentKey;
Discussion

Alignment value for streams that contain padding. Possible values are described in IOAudioStreamAlignments.


gBitDepthKey


public

static const OSSymbol *gBitDepthKey;
Discussion

Bit depth of samples.


gBitWidthKey


public

static const OSSymbol *gBitWidthKey;
Discussion

Bit width of samples (including padding).


gByteOrderKey


public

static const OSSymbol *gByteOrderKey;
Discussion

Byte order of samples within an audio stream. Possible values are described in IOAudioStreamByteOrder.


gDirectionKey


public

static const OSSymbol *gDirectionKey;
Discussion

Audio stream direction (possible values are "Output" and "Input").


gDriverTagKey


public

static const OSSymbol *gDriverTagKey;
Discussion

Driver tag key.


gIsMixableKey


public

static const OSSymbol *gIsMixableKey;
Discussion

Indicates whether the current format of the audio buffer is mixable. Examples of non-mixable formats include encoded formats such as AC-3.


gMaximumSampleRateKey


public

static const OSSymbol *gMaximumSampleRateKey;
Discussion

Maximum sample rate.


gMinimumSampleRateKey


public

static const OSSymbol *gMinimumSampleRateKey;
Discussion

Minimum sample rate.


gNumChannelsKey


public

static const OSSymbol *gNumChannelsKey;
Discussion

The number of channels in this stream.


gNumericRepresentationKey


public

static const OSSymbol *gNumericRepresentationKey;
Discussion

The numberic representation. Possible values are described in IOAudioStreamNumericRepresentations.


gSampleFormatKey


public

static const OSSymbol *gSampleFormatKey;
Discussion

The current sample format for this stream.


maxNumChannels


public

UInt32 maxNumChannels;
Discussion

The maximum number of channels of any format provided by this stream.


mixBuffer


public

void *mixBuffer;
Discussion

A pointer to the mix buffer


mixBufferSize


public

UInt32 mixBufferSize;
Discussion

The size of the mix buffer (in bytes)


numAvailableFormats


public

UInt32 numAvailableFormats;
Discussion

The number of available formats.


numClients


public

UInt32 numClients;
Discussion

The current number of clients utilizing this stream.


numIOFunctions


public

UInt32 numIOFunctions;
Discussion

The number of functions in the audioIOFunctions array.


sampleBuffer


public

void *sampleBuffer;
Discussion

A pointer to the raw sample buffer


sampleBufferSize


public

UInt32 sampleBufferSize;
Discussion

The size of the sample buffer (in bytes)


startingChannelID


public

UInt32 startingChannelID;
Discussion

The starting channel ID.


startingPosition


public

IOAudioEnginePosition startingPosition;
Discussion

The starting position in the sample buffer.


streamAllocatedMixBuffer


public

bool streamAllocatedMixBuffer;
Discussion

Set to true if the audio stream contains a mix buffer that needs to be freed.


streamAvailable


public

bool streamAvailable;
Discussion

True if this stream is available.


streamIOLock


public

IORecursiveLock *streamIOLock;
Discussion

A stream-specific lock.


userClientList


public

IOAudioClientBuffer *userClientList;
Discussion

A list of user clients.


workLoop


public

IOWorkLoop *workLoop;
Discussion

The workloop associated with this stream.


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19