/*================================================================================================== File: CoreAudio/CoreAudioTypes.h Contains: Definitions types common to the Core Audio APIs Version: Technology: Mac OS X Release: Mac OS X Copyright: (c) 1985-2007 by Apple Inc., all rights reserved. Bugs?: For bug reports, consult the following page on the World Wide Web: http://developer.apple.com/bugreporter/ ==================================================================================================*/ #if !defined(__CoreAudioTypes_h__) #define __CoreAudioTypes_h__ /*! @header CoreAudioTypes This header defines the types and constants that all the CoreAudio APIs have in common. */ //================================================================================================== #define COREAUDIOTYPES_VERSION 1050 #include "TargetConditionals.h" #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) #include "CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h" #else #include "MacTypes.h" #endif #if defined(__cplusplus) #include "string.h" #endif //================================================================================================== #if PRAGMA_ENUM_ALWAYSINT #pragma enumsalwaysint off #endif #if defined(__cplusplus) extern "C" { #endif //================================================================================================== /*! @struct AudioValueRange @abstract This structure holds a pair of numbers that represent a continuous range of values. @field mMinimum The minimum value. @field mMaximum The maximum value. */ struct AudioValueRange { Float64 mMinimum; Float64 mMaximum; }; typedef struct AudioValueRange AudioValueRange; /*! @struct AudioValueTranslation @abstract This stucture holds the buffers necessary for translation operations. @field mInputData The buffer containing the data to be translated. @field mInputDataSize The number of bytes in the buffer pointed at by mInputData. @field mOutputData The buffer to hold the result of the translation. @field mOutputDataSize The number of bytes in the buffer pointed at by mOutputData. */ struct AudioValueTranslation { void* mInputData; UInt32 mInputDataSize; void* mOutputData; UInt32 mOutputDataSize; }; typedef struct AudioValueTranslation AudioValueTranslation; /*! @struct AudioBuffer @abstract A structure to hold a buffer of audio data. @field mNumberChannels The number of interleaved channels in the buffer. @field mDataByteSize The number of bytes in the buffer pointed at by mData. @field mData A pointer to the buffer of audio data. */ struct AudioBuffer { UInt32 mNumberChannels; UInt32 mDataByteSize; void* mData; }; typedef struct AudioBuffer AudioBuffer; /*! @struct AudioBufferList @abstract A variable length array of AudioBuffer structures. @field mNumberBuffers The number of AudioBuffers in the mBuffers array. @field mBuffers A variable length array of AudioBuffers. */ struct AudioBufferList { UInt32 mNumberBuffers; AudioBuffer mBuffers[kVariableLengthArray]; }; typedef struct AudioBufferList AudioBufferList; /*! @typedef AudioSampleType @abstract The canonical audio sample type used by the various CoreAudio APIs */ typedef Float32 AudioSampleType; /*! @struct AudioStreamBasicDescription @abstract This structure encapsulates all the information for describing the basic format properties of a stream of audio data. @discussion This structure is sufficient to describe any constant bit rate format that has channels that are the same size. Extensions are required for variable bit rate data and for constant bit rate data where the channels have unequal sizes. However, where applicable, the appropriate fields will be filled out correctly for these kinds of formats (the extra data is provided via separate properties). In all fields, a value of 0 indicates that the field is either unknown, not applicable or otherwise is inapproprate for the format and should be ignored. Note that 0 is still a valid value for most formats in the mFormatFlags field. In audio data a frame is one sample across all channels. In non-interleaved audio, the per frame fields identify one channel. In interleaved audio, the per frame fields identify the set of n channels. In uncompressed audio, a Packet is one frame, (mFramesPerPacket == 1). In compressed audio, a Packet is an indivisible chunk of compressed data, for example an AAC packet will contain 1024 sample frames. @field mSampleRate The number of sample frames per second of the data in the stream. @field mFormatID A four char code indicating the general kind of data in the stream. @field mFormatFlags Flags specific to each format. @field mBytesPerPacket The number of bytes in a packet of data. @field mFramesPerPacket The number of sample frames in each packet of data. @field mBytesPerFrame The number of bytes in a single sample frame of data. @field mChannelsPerFrame The number of channels in each frame of data. @field mBitsPerChannel The number of bits of sample data for each channel in a frame of data. @field mReserved Pads the structure out to force an even 8 byte alignment. */ struct AudioStreamBasicDescription { Float64 mSampleRate; UInt32 mFormatID; UInt32 mFormatFlags; UInt32 mBytesPerPacket; UInt32 mFramesPerPacket; UInt32 mBytesPerFrame; UInt32 mChannelsPerFrame; UInt32 mBitsPerChannel; UInt32 mReserved; }; typedef struct AudioStreamBasicDescription AudioStreamBasicDescription; /*! @enum AudioStreamBasicDescription Constants @abstract Constants for use with AudioStreamBasicDescription @constant kAudioStreamAnyRate The format can use any sample rate. Note that this constant can only appear in listings of supported formats. It will never appear in a current format. */ enum { kAudioStreamAnyRate = 0 }; /*! @enum Format IDs @abstract The four char code IDs used to identify individual formats of audio data. @constant kAudioFormatLinearPCM Linear PCM, uses the standard flags. @constant kAudioFormatAC3 AC-3, has no flags. @constant kAudioFormat60958AC3 AC-3 packaged for transport over an IEC 60958 compliant digital audio interface. Uses the standard flags. @constant kAudioFormatAppleIMA4 Apples implementation of IMA 4:1 ADPCM, has no flags. @constant kAudioFormatMPEG4AAC MPEG-4 Low Complexity AAC audio object, has no flags. @constant kAudioFormatMPEG4CELP MPEG-4 CELP audio object, has no flags. @constant kAudioFormatMPEG4HVXC MPEG-4 HVXC audio object, has no flags. @constant kAudioFormatMPEG4TwinVQ MPEG-4 TwinVQ audio object type, has no flags. @constant kAudioFormatMACE3 MACE 3:1, has no flags. @constant kAudioFormatMACE6 MACE 6:1, has no flags. @constant kAudioFormatULaw µLaw 2:1, has no flags. @constant kAudioFormatALaw aLaw 2:1, has no flags. @constant kAudioFormatQDesign QDesign music, has no flags @constant kAudioFormatQDesign2 QDesign2 music, has no flags @constant kAudioFormatQUALCOMM QUALCOMM PureVoice, has no flags @constant kAudioFormatMPEGLayer1 MPEG-1/2, Layer 1 audio, has no flags @constant kAudioFormatMPEGLayer2 MPEG-1/2, Layer 2 audio, has no flags @constant kAudioFormatMPEGLayer3 MPEG-1/2, Layer 3 audio, has no flags @constant kAudioFormatTimeCode A stream of IOAudioTimeStamps, uses the IOAudioTimeStamp flags (see IOKit/audio/IOAudioTypes.h). @constant kAudioFormatMIDIStream A stream of MIDIPacketLists where the time stamps in the MIDIPacketList are sample offsets in the stream. The mSampleRate field is used to describe how time is passed in this kind of stream and an AudioUnit that receives or generates this stream can use this sample rate, the number of frames it is rendering and the sample offsets within the MIDIPacketList to define the time for any MIDI event within this list. It has no flags. @constant kAudioFormatParameterValueStream A "side-chain" of Float32 data that can be fed or generated by an AudioUnit and is used to send a high density of parameter value control information. An AU will typically run a ParameterValueStream at either the sample rate of the AudioUnit's audio data, or some integer divisor of this (say a half or a third of the sample rate of the audio). The Sample Rate of the ASBD describes this relationship. It has no flags. @constant kAudioFormatAppleLossless Apple Lossless, the flags indicate the bit depth of the source material. @constant kAudioFormatMPEG4AAC_HE MPEG-4 High Efficiency AAC audio object, has no flags. @constant kAudioFormatMPEG4AAC_LD MPEG-4 AAC Low Delay audio object, has no flags. @constant kAudioFormatMPEG4AAC_HE_V2 MPEG-4 High Efficiency AAC Version 2 audio object, has no flags. @constant kAudioFormatMPEG4AAC_Spatial MPEG-4 Spatial Audio audio object, has no flags. @constant kAudioFormatAMR The AMR Narrow Band speech codec. */ enum { kAudioFormatLinearPCM = 'lpcm', kAudioFormatAC3 = 'ac-3', kAudioFormat60958AC3 = 'cac3', kAudioFormatAppleIMA4 = 'ima4', kAudioFormatMPEG4AAC = 'aac ', kAudioFormatMPEG4CELP = 'celp', kAudioFormatMPEG4HVXC = 'hvxc', kAudioFormatMPEG4TwinVQ = 'twvq', kAudioFormatMACE3 = 'MAC3', kAudioFormatMACE6 = 'MAC6', kAudioFormatULaw = 'ulaw', kAudioFormatALaw = 'alaw', kAudioFormatQDesign = 'QDMC', kAudioFormatQDesign2 = 'QDM2', kAudioFormatQUALCOMM = 'Qclp', kAudioFormatMPEGLayer1 = '.mp1', kAudioFormatMPEGLayer2 = '.mp2', kAudioFormatMPEGLayer3 = '.mp3', kAudioFormatTimeCode = 'time', kAudioFormatMIDIStream = 'midi', kAudioFormatParameterValueStream = 'apvs', kAudioFormatAppleLossless = 'alac', kAudioFormatMPEG4AAC_HE = 'aach', kAudioFormatMPEG4AAC_LD = 'aacl', kAudioFormatMPEG4AAC_HE_V2 = 'aacp', kAudioFormatMPEG4AAC_Spatial = 'aacs', kAudioFormatAMR = 'samr' }; /*! @enum Standard Flag Values for AudioStreamBasicDescription @abstract These are the standard flags for use in the mFormatFlags field of the AudioStreamBasicDescription structure. @discussion Typically, when an ASBD is being used, the fields describe the complete layout of the sample data in the buffers that are represented by this description - where typically those buffers are represented by an AudioBuffer that is contained in an AudioBufferList. However, when an ASBD has the kAudioFormatFlagIsNonInterleaved flag, the AudioBufferList has a different structure and semantic. In this case, the ASBD fields will describe the format of ONE of the AudioBuffers that are contained in the list, AND each AudioBuffer in the list is determined to have a single (mono) channel of audio data. Then, the ASBD's mChannelsPerFrame will indicate the total number of AudioBuffers that are contained within the AudioBufferList - where each buffer contains one channel. This is used primarily with the AudioUnit (and AudioConverter) representation of this list - and won't be found in the AudioHardware usage of this structure. @constant kAudioFormatFlagIsFloat Set for floating point, clear for integer. @constant kAudioFormatFlagIsBigEndian Set for big endian, clear for little endian. @constant kAudioFormatFlagIsSignedInteger Set for signed integer, clear for unsigned integer. This is only valid if kAudioFormatFlagIsFloat is clear. @constant kAudioFormatFlagIsPacked Set if the sample bits occupy the entire available bits for the channel, clear if they are high or low aligned within the channel. @constant kAudioFormatFlagIsAlignedHigh Set if the sample bits are placed into the high bits of the channel, clear for low bit placement. This is only valid if kAudioFormatFlagIsPacked is clear. @constant kAudioFormatFlagIsNonInterleaved Set if the samples for each channel are located contiguously and the channels are layed out end to end, clear if the samples for each frame are layed out contiguously and the frames layed out end to end. @constant kAudioFormatFlagIsNonMixable Set to indicate when a format is non-mixable. Note that this flag is only used when interacting with the HAL's stream format information. It is not a valid flag for any other uses. @constant kAudioFormatFlagsAreAllClear Set if all the flags would be clear in order to preserve 0 as the wild card value. @constant kLinearPCMFormatFlagIsFloat Synonym for kAudioFormatFlagIsFloat. @constant kLinearPCMFormatFlagIsBigEndian Synonym for kAudioFormatFlagIsBigEndian. @constant kLinearPCMFormatFlagIsSignedInteger Synonym for kAudioFormatFlagIsSignedInteger. @constant kLinearPCMFormatFlagIsPacked Synonym for kAudioFormatFlagIsPacked. @constant kLinearPCMFormatFlagIsAlignedHigh Synonym for kAudioFormatFlagIsAlignedHigh. @constant kLinearPCMFormatFlagIsNonInterleaved Synonym for kAudioFormatFlagIsNonInterleaved. @constant kLinearPCMFormatFlagIsNonMixable Synonym for kAudioFormatFlagIsNonMixable. @constant kLinearPCMFormatFlagsAreAllClear Synonym for kAudioFormatFlagsAreAllClear. @constant kAppleLosslessFormatFlag_16BitSourceData This flag is set for Apple Lossless data that was sourced from 16 bit native endian signed integer data. @constant kAppleLosslessFormatFlag_20BitSourceData This flag is set for Apple Lossless data that was sourced from 20 bit native endian signed integer data aligned high in 24 bits. @constant kAppleLosslessFormatFlag_24BitSourceData This flag is set for Apple Lossless data that was sourced from 24 bit native endian signed integer data. @constant kAppleLosslessFormatFlag_32BitSourceData This flag is set for Apple Lossless data that was sourced from 32 bit native endian signed integer data. */ enum { kAudioFormatFlagIsFloat = (1L << 0), kAudioFormatFlagIsBigEndian = (1L << 1), kAudioFormatFlagIsSignedInteger = (1L << 2), kAudioFormatFlagIsPacked = (1L << 3), kAudioFormatFlagIsAlignedHigh = (1L << 4), kAudioFormatFlagIsNonInterleaved = (1L << 5), kAudioFormatFlagIsNonMixable = (1L << 6), kAudioFormatFlagsAreAllClear = (1L << 31), kLinearPCMFormatFlagIsFloat = kAudioFormatFlagIsFloat, kLinearPCMFormatFlagIsBigEndian = kAudioFormatFlagIsBigEndian, kLinearPCMFormatFlagIsSignedInteger = kAudioFormatFlagIsSignedInteger, kLinearPCMFormatFlagIsPacked = kAudioFormatFlagIsPacked, kLinearPCMFormatFlagIsAlignedHigh = kAudioFormatFlagIsAlignedHigh, kLinearPCMFormatFlagIsNonInterleaved = kAudioFormatFlagIsNonInterleaved, kLinearPCMFormatFlagIsNonMixable = kAudioFormatFlagIsNonMixable, kLinearPCMFormatFlagsAreAllClear = kAudioFormatFlagsAreAllClear, kAppleLosslessFormatFlag_16BitSourceData = 1, kAppleLosslessFormatFlag_20BitSourceData = 2, kAppleLosslessFormatFlag_24BitSourceData = 3, kAppleLosslessFormatFlag_32BitSourceData = 4 }; /*! @enum Commonly Used Combinations of ASBD Flags @abstract Some commonly used combinations of flags for AudioStreamBasicDescriptions. @constant kAudioFormatFlagsNativeEndian Defined to set or clear kAudioFormatFlagIsBigEndian depending on the endianness of the processor at build time. @constant kAudioFormatFlagsCanonical The flags for the canonical audio sample type @constant kAudioFormatFlagsNativeFloatPacked The flags for fully packed, native endian floating point data. */ enum { #if TARGET_RT_BIG_ENDIAN kAudioFormatFlagsNativeEndian = kAudioFormatFlagIsBigEndian, #else kAudioFormatFlagsNativeEndian = 0, #endif kAudioFormatFlagsCanonical = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked, kAudioFormatFlagsNativeFloatPacked = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked }; /*! @defined TestAudioFormatNativeEndian @abstract A macro for checking if an ASBD indicates native endian linear PCM data. */ #define TestAudioFormatNativeEndian(f) ((f.mFormatID == kAudioFormatLinearPCM) && ((f.mFormatFlags & kAudioFormatFlagIsBigEndian) == kAudioFormatFlagsNativeEndian)) /*! @function IsAudioFormatNativeEndian @abstract A C++ inline function for checking if an ASBD indicates native endian linear PCM data. @param f The AudioStreamBasicDescription to examine. @result Whether or not the ASBD indicates native endian linear PCM data. */ #if defined(__cplusplus) inline bool IsAudioFormatNativeEndian(const AudioStreamBasicDescription& f) { return (f.mFormatID == kAudioFormatLinearPCM) && ((f.mFormatFlags & kAudioFormatFlagIsBigEndian) == kAudioFormatFlagsNativeEndian); } #endif /*! @function CalculateLPCMFlags @abstract A C++ inline function for calculating the mFormatFlags for linear PCM data. Note that this function does not support specifying sample formats that are either unsigned integer or low-aligned. @param inSampleRate @param inValidBitsPerChannel The number of valid bits in each sample. @param inTotalBitsPerChannel The total number of bits in each sample. @param inIsFloat Whether or not the samples are represented with floating point numbers. @param isIsBigEndian Whether the samples are big endian or little endian. @result A UInt32 containing the format flags. */ #if defined(__cplusplus) inline UInt32 CalculateLPCMFlags(UInt32 inValidBitsPerChannel, UInt32 inTotalBitsPerChannel, bool inIsFloat, bool inIsBigEndian, bool inIsNonInterleaved = false) { return (inIsFloat ? kAudioFormatFlagIsFloat : kAudioFormatFlagIsSignedInteger) | (inIsBigEndian ? ((UInt32)kAudioFormatFlagIsBigEndian) : 0) | ((!inIsFloat && (inValidBitsPerChannel == inTotalBitsPerChannel)) ? kAudioFormatFlagIsPacked : kAudioFormatFlagIsAlignedHigh) | (inIsNonInterleaved ? ((UInt32)kAudioFormatFlagIsNonInterleaved) : 0); } #endif /*! @function FillOutASBDForLPCM @abstract A C++ inline function for filling out an AudioStreamBasicDescription to describe linear PCM data. Note that this function does not support specifying sample formats that are either unsigned integer or low-aligned. @param outASBD The AudioStreamBasicDescription to fill out. @param inSampleRate The number of sample frames per second of the data in the stream. @param inChannelsPerFrame The number of channels in each frame of data. @param inValidBitsPerChannel The number of valid bits in each sample. @param inTotalBitsPerChannel The total number of bits in each sample. @param inIsFloat Whether or not the samples are represented with floating point numbers. @param isIsBigEndian Whether the samples are big endian or little endian. */ #if defined(__cplusplus) inline void FillOutASBDForLPCM(AudioStreamBasicDescription& outASBD, Float64 inSampleRate, UInt32 inChannelsPerFrame, UInt32 inValidBitsPerChannel, UInt32 inTotalBitsPerChannel, bool inIsFloat, bool inIsBigEndian, bool inIsNonInterleaved = false) { outASBD.mSampleRate = inSampleRate; outASBD.mFormatID = kAudioFormatLinearPCM; outASBD.mFormatFlags = CalculateLPCMFlags(inValidBitsPerChannel, inTotalBitsPerChannel, inIsFloat, inIsBigEndian, inIsNonInterleaved); outASBD.mBytesPerPacket = inChannelsPerFrame * (inTotalBitsPerChannel / 8); outASBD.mFramesPerPacket = 1; outASBD.mBytesPerFrame = inChannelsPerFrame * (inTotalBitsPerChannel / 8); outASBD.mChannelsPerFrame = inChannelsPerFrame; outASBD.mBitsPerChannel = inValidBitsPerChannel; } #endif /*! @struct AudioStreamPacketDescription @abstract This structure describes the packet layout of a buffer of data where the size of each packet may not be the same or where there is extraneous data between packets. @field mStartOffset The number of bytes from the start of the buffer to the beginning of the packet. @field mVariableFramesInPacket The number of sample frames of data in the packet. For formats with a constant number of frames per packet, this field is set to 0. @field mDataByteSize The number of bytes in the packet. */ struct AudioStreamPacketDescription { SInt64 mStartOffset; UInt32 mVariableFramesInPacket; UInt32 mDataByteSize; }; typedef struct AudioStreamPacketDescription AudioStreamPacketDescription; // SMPTETime is also defined in the CoreVideo headers. #if !defined(__SMPTETime__) #define __SMPTETime__ /*! @struct SMPTETime @abstract A structure for holding a SMPTE time. @field mSubframes The number of subframes in the full message. @field mSubframeDivisor The number of subframes per frame (typically 80). @field mCounter The total number of messages received. @field mType The kind of SMPTE time using the SMPTE time type constants. @field mFlags A set of flags that indicate the SMPTE state. @field mHours The number of hourse in the full message. @field mMinutes The number of minutes in the full message. @field mSeconds The number of seconds in the full message. @field mFrames The number of frames in the full message. */ struct SMPTETime { SInt16 mSubframes; SInt16 mSubframeDivisor; UInt32 mCounter; UInt32 mType; UInt32 mFlags; SInt16 mHours; SInt16 mMinutes; SInt16 mSeconds; SInt16 mFrames; }; typedef struct SMPTETime SMPTETime; /*! @enum SMPTE Time Types @abstract Constants that describe the type of SMPTE time. @constant kSMPTETimeType24 24 Frame @constant kSMPTETimeType25 25 Frame @constant kSMPTETimeType30Drop 30 Drop Frame @constant kSMPTETimeType30 30 Frame @constant kSMPTETimeType2997 29.97 Frame @constant kSMPTETimeType2997Drop 29.97 Drop Frame @constant kSMPTETimeType60 60 Frame @constant kSMPTETimeType5994 59.94 Frame @constant kSMPTETimeType60Drop 60 Drop Frame @constant kSMPTETimeType5994Drop 59.94 Drop Frame @constant kSMPTETimeType50 50 Frame @constant kSMPTETimeType2398 23.98 Frame */ enum { kSMPTETimeType24 = 0, kSMPTETimeType25 = 1, kSMPTETimeType30Drop = 2, kSMPTETimeType30 = 3, kSMPTETimeType2997 = 4, kSMPTETimeType2997Drop = 5, kSMPTETimeType60 = 6, kSMPTETimeType5994 = 7, kSMPTETimeType60Drop = 8, kSMPTETimeType5994Drop = 9, kSMPTETimeType50 = 10, kSMPTETimeType2398 = 11 }; /*! @enum SMPTE State Flags @abstract Flags that describe the SMPTE time state. @constant kSMPTETimeValid The full time is valid. @constant kSMPTETimeRunning Time is running. */ enum { kSMPTETimeValid = (1L << 0), kSMPTETimeRunning = (1L << 1) }; #endif /*! @struct AudioTimeStamp @abstract A strucutre that holds different representations of the same point in time. @field mSampleTime The absolute sample frame time. @field mHostTime The host machine's time base (see