41 #ifndef __CAAudioUnit_h__
42 #define __CAAudioUnit_h__
44 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
45 #include <CoreAudio/CoreAudio.h>
46 #include <AudioUnit/AudioUnit.h>
48 #include <AudioUnit/MusicDevice.h>
50 #include <AudioToolbox/AUGraph.h>
52 #include <ConditionalMacros.h>
53 #include <CoreAudioTypes.h>
54 #include <AudioUnit.h>
55 #include <MusicDevice.h>
57 #include <MusicDevice.h>
61 #include "CAStreamBasicDescription.h"
62 #include "CAComponent.h"
63 #include "CAAudioChannelLayout.h"
81 badComponentSelector = (long)0x80008002
84 typedef std::vector<AudioChannelLayoutTag> ChannelTagVector;
85 typedef ChannelTagVector::iterator ChannelTagVectorIter;
91 CAAudioUnit (
const AudioUnit& inUnit);
93 CAAudioUnit (
const AUNode &inNode,
const AudioUnit& inUnit);
95 CAAudioUnit (
const CAAudioUnit& y)
96 : mDataPtr(0) { *
this = y; }
98 static OSStatus Open (
const CAComponent& inComp, CAAudioUnit &outUnit);
105 CAAudioUnit& operator= (
const CAAudioUnit& y);
111 #pragma mark __State Management
112 bool IsValid ()
const;
114 AudioUnit AU()
const;
115 operator AudioUnit ()
const {
return AU(); }
117 const CAComponent& Comp()
const {
return mComp; }
119 bool FromAUGraph ()
const {
return GetAUNode() != 0 && GetAUNode() != kCAAU_DoNotKnowIfAUNode; }
121 AUNode GetAUNode ()
const;
122 operator AUNode ()
const {
return GetAUNode(); }
124 #pragma mark __API Wrapper
125 OSStatus Initialize()
const {
126 return AudioUnitInitialize(AU());
128 OSStatus Uninitialize()
const {
129 return AudioUnitUninitialize(AU());
131 OSStatus GetPropertyInfo(AudioUnitPropertyID propID, AudioUnitScope scope, AudioUnitElement element,
132 UInt32 *outDataSize, Boolean *outWritable)
const
134 return AudioUnitGetPropertyInfo(AU(), propID, scope, element, outDataSize, outWritable);
136 OSStatus GetProperty(AudioUnitPropertyID propID, AudioUnitScope scope, AudioUnitElement element,
137 void *outData, UInt32 *ioDataSize)
const
139 return AudioUnitGetProperty(AU(), propID, scope, element, outData, ioDataSize);
141 OSStatus SetProperty(AudioUnitPropertyID propID, AudioUnitScope scope, AudioUnitElement element,
142 const void *inData, UInt32 inDataSize)
144 return AudioUnitSetProperty(AU(), propID, scope, element, inData, inDataSize);
146 OSStatus SetParameter(AudioUnitParameterID inID, AudioUnitScope scope, AudioUnitElement element,
147 Float32 value, UInt32 bufferOffsetFrames=0);
149 OSStatus GetParameter(AudioUnitParameterID inID, AudioUnitScope scope, AudioUnitElement element,
150 Float32 &outValue)
const;
152 OSStatus Render (AudioUnitRenderActionFlags * ioActionFlags,
153 const AudioTimeStamp * inTimeStamp,
154 UInt32 inOutputBusNumber,
155 UInt32 inNumberFrames,
156 AudioBufferList * ioData);
158 OSStatus Reset (AudioUnitScope scope, AudioUnitElement element)
160 return AudioUnitReset (AU(), scope, element);
162 OSStatus GlobalReset ()
164 return AudioUnitReset (AU(), kAudioUnitScope_Global, 0);
167 OSStatus AddRenderNotify (AURenderCallback inProc,
void *inProcRefCon)
169 return AudioUnitAddRenderNotify (AU(), inProc, inProcRefCon);
172 OSStatus RemoveRenderNotify (AURenderCallback inProc,
void *inProcRefCon)
174 return AudioUnitRemoveRenderNotify (AU(), inProc, inProcRefCon);
177 OSStatus AddPropertyListener (AudioUnitPropertyID inID,
178 AudioUnitPropertyListenerProc inProc,
181 return AudioUnitAddPropertyListener (AU(), inID, inProc, inProcRefCon);
184 OSStatus RemovePropertyListener (AudioUnitPropertyID inID,
185 AudioUnitPropertyListenerProc inProc,
186 void * inProcUserData);
188 #if !TARGET_OS_IPHONE
190 OSStatus MIDIEvent (UInt32 inStatus,
193 UInt32 inOffsetSampleFrame);
196 OSStatus StartNote (MusicDeviceGroupID inGroupID,
197 NoteInstanceID * outNoteInstanceID,
198 UInt32 inOffsetSampleFrame,
199 const MusicDeviceNoteParams * inParams)
201 return StartNote (kMusicNoteEvent_UseGroupInstrument,
202 inGroupID, outNoteInstanceID,
203 inOffsetSampleFrame, inParams);
206 OSStatus StartNote (MusicDeviceInstrumentID inInstrument,
207 MusicDeviceGroupID inGroupID,
208 NoteInstanceID * outNoteInstanceID,
209 UInt32 inOffsetSampleFrame,
210 const MusicDeviceNoteParams * inParams);
212 OSStatus StopNote (MusicDeviceGroupID inGroupID,
213 NoteInstanceID inNoteInstanceID,
214 UInt32 inOffsetSampleFrame);
217 #pragma mark __Format Utilities
223 bool CanDo (
int inChannelsInOut)
const
225 return CanDo (inChannelsInOut, inChannelsInOut);
228 bool CanDo (
int inChannelsIn,
229 int inChannelsOut)
const;
234 bool CanDo (
const CAAUChanHelper &input,
235 const CAAUChanHelper &output)
const;
237 bool SupportsNumChannels ()
const;
239 bool HasChannelLayouts (AudioUnitScope inScope,
240 AudioUnitElement inEl)
const;
242 OSStatus GetChannelLayoutTags (AudioUnitScope inScope,
243 AudioUnitElement inEl,
244 ChannelTagVector &outChannelVector)
const;
246 bool HasChannelLayout (AudioUnitScope inScope,
247 AudioUnitElement inEl)
const;
249 OSStatus GetChannelLayout (AudioUnitScope inScope,
250 AudioUnitElement inEl,
251 CAAudioChannelLayout &outLayout)
const;
253 OSStatus SetChannelLayout (AudioUnitScope inScope,
254 AudioUnitElement inEl,
255 const CAAudioChannelLayout &inLayout);
257 OSStatus SetChannelLayout (AudioUnitScope inScope,
258 AudioUnitElement inEl,
259 const AudioChannelLayout &inLayout,
262 OSStatus ClearChannelLayout (AudioUnitScope inScope,
263 AudioUnitElement inEl);
265 OSStatus GetFormat (AudioUnitScope inScope,
266 AudioUnitElement inEl,
267 AudioStreamBasicDescription &outFormat)
const;
270 OSStatus SetFormat (AudioUnitScope inScope,
271 AudioUnitElement inEl,
272 const AudioStreamBasicDescription &inFormat);
274 OSStatus GetSampleRate (AudioUnitScope inScope,
275 AudioUnitElement inEl,
276 Float64 &outRate)
const;
277 OSStatus SetSampleRate (AudioUnitScope inScope,
278 AudioUnitElement inEl,
282 OSStatus SetSampleRate (Float64 inSampleRate);
284 OSStatus NumberChannels (AudioUnitScope inScope,
285 AudioUnitElement inEl,
286 UInt32 &outChans)
const;
288 OSStatus GetNumberChannels (AudioUnitScope inScope,
289 AudioUnitElement inEl,
290 UInt32 &outChans)
const
292 return NumberChannels (inScope, inEl, outChans);
295 OSStatus SetNumberChannels (AudioUnitScope inScope,
296 AudioUnitElement inEl,
299 OSStatus IsElementCountWritable (AudioUnitScope inScope,
bool &outWritable)
const;
301 OSStatus GetElementCount (AudioUnitScope inScope, UInt32 &outCount)
const;
303 OSStatus SetElementCount (AudioUnitScope inScope, UInt32 inCount);
309 bool HasDynamicInputs (SInt32 &outTotalNumChannels)
const
311 return HasDynamicScope (kAudioUnitScope_Input, outTotalNumChannels);
314 bool HasDynamicOutputs (SInt32 &outTotalNumChannels)
const
316 return HasDynamicScope (kAudioUnitScope_Output, outTotalNumChannels);
321 OSStatus ConfigureDynamicInput (UInt32 inNumElements, UInt32 *inChannelsPerElement, Float64 inSampleRate)
323 return ConfigureDynamicScope (kAudioUnitScope_Input, inNumElements, inChannelsPerElement, inSampleRate);
326 OSStatus ConfigureDynamicOutput (UInt32 inNumElements, UInt32 *inChannelsPerElement, Float64 inSampleRate)
328 return ConfigureDynamicScope (kAudioUnitScope_Output, inNumElements, inChannelsPerElement, inSampleRate);
331 bool CanBypass ()
const;
333 bool GetBypass ()
const;
335 OSStatus SetBypass (
bool inBypass)
const;
337 Float64 Latency ()
const;
341 OSStatus GetAUPreset (CFPropertyListRef &outData)
const;
343 OSStatus SetAUPreset (CFPropertyListRef &inData);
345 OSStatus SetAUPresetFromDocument (CFPropertyListRef &inData);
347 OSStatus GetPresentPreset (AUPreset &outData)
const;
349 OSStatus SetPresentPreset (AUPreset &inData);
351 bool HasCustomView ()
const;
354 void Print ()
const { Print (stdout); }
355 void Print (FILE* file)
const;
364 CAAudioUnit (
const CAComponent& inComp);
366 bool HasDynamicScope (AudioUnitScope inScope, SInt32 &outTotalNumChannels)
const;
367 OSStatus ConfigureDynamicScope (AudioUnitScope inScope,
368 UInt32 inNumElements,
369 UInt32 *inChannelsPerElement,
370 Float64 inSampleRate);
371 bool ValidateChannelPair (
int inChannelsIn,
373 const AUChannelInfo * info,
374 UInt32 numChanInfo)
const;
376 bool ValidateDynamicScope (AudioUnitScope inScope,
377 SInt32 &outTotalNumChannels,
378 const AUChannelInfo * info,
379 UInt32 numInfo)
const;
380 bool CheckOneSide (
const CAAUChanHelper &inHelper,
382 const AUChannelInfo *info,
383 UInt32 numInfo)
const;
385 kCAAU_DoNotKnowIfAUNode = -1
389 class CAAUChanHelper {
392 : mChans(mStaticChans), mNumEls(0), mDidAllocate(false)
394 memset (mChans, 0,
sizeof(UInt32) * kStaticElCount);
396 CAAUChanHelper(UInt32 inMaxElems);
397 CAAUChanHelper(
const CAAudioUnit &inAU, AudioUnitScope inScope);
398 CAAUChanHelper (
const CAAUChanHelper &c)
399 : mChans(mStaticChans), mNumEls(0), mDidAllocate(false)
404 CAAUChanHelper& operator= (
const CAAUChanHelper &c);
413 UInt32 mStaticChans[kStaticElCount];
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.