42 #include "CAXException.h"
49 #define PARAM(_typ, _name, _index, _nparams) \
50 _typ _name = *(_typ *)¶ms->params[_index + 1];
53 #define PARAM(_typ, _name, _index, _nparams) \
54 _typ _name = *(_typ *)¶ms->params[_nparams - 1 - _index];
58 #define PARAM(_typ, _name, _index, _nparams) \
59 _typ _name = *(_typ *)¶ms->params[_index];
63 #if AU_DEBUG_DISPATCHER
64 #include "AUDebugDispatcher.h"
66 #define INIT_DEBUG_DISPATCHER(This) \
68 if (This->mDebugDispatcher != NULL) \
69 nowTime = CAHostTimeBase::GetTheCurrentTime();
72 OSStatus AUBase::ComponentEntryDispatch(ComponentParameters *params, AUBase *This)
74 if (This == NULL)
return paramErr;
76 #if AU_DEBUG_DISPATCHER
77 INIT_DEBUG_DISPATCHER(This)
80 OSStatus result = noErr;
82 switch (params->what) {
83 case kComponentCanDoSelect:
84 switch (params->params[0]) {
86 case kAudioUnitInitializeSelect:
87 case kAudioUnitUninitializeSelect:
88 case kAudioUnitGetPropertyInfoSelect:
89 case kAudioUnitGetPropertySelect:
90 case kAudioUnitSetPropertySelect:
91 case kAudioUnitAddPropertyListenerSelect:
93 case kAudioUnitRemovePropertyListenerSelect:
95 case kAudioUnitGetParameterSelect:
96 case kAudioUnitSetParameterSelect:
97 case kAudioUnitResetSelect:
103 case kAudioUnitRemovePropertyListenerWithUserDataSelect:
104 case kAudioUnitAddRenderNotifySelect:
105 case kAudioUnitRemoveRenderNotifySelect:
106 case kAudioUnitScheduleParametersSelect:
107 case kAudioUnitRenderSelect:
108 result = (This->AudioUnitAPIVersion() > 1);
112 return ComponentBase::ComponentEntryDispatch(params, This);
116 case kAudioUnitInitializeSelect:
118 result = This->DoInitialize();
120 #if AU_DEBUG_DISPATCHER
121 if (This->mDebugDispatcher)
122 This->mDebugDispatcher->Initialize (nowTime, result);
127 case kAudioUnitUninitializeSelect:
132 #if AU_DEBUG_DISPATCHER
133 if (This->mDebugDispatcher)
134 This->mDebugDispatcher->Uninitialize (nowTime, result);
139 case kAudioUnitGetPropertyInfoSelect:
141 PARAM(AudioUnitPropertyID, pinID, 0, 5);
142 PARAM(AudioUnitScope, pinScope, 1, 5);
143 PARAM(AudioUnitElement, pinElement, 2, 5);
144 PARAM(UInt32 *, poutDataSize, 3, 5);
145 PARAM(Boolean *, poutWritable, 4, 5);
153 result = This->DispatchGetPropertyInfo(pinID, pinScope, pinElement, dataSize, writable);
154 if (poutDataSize != NULL)
155 *poutDataSize = dataSize;
156 if (poutWritable != NULL)
157 *poutWritable = writable;
159 #if AU_DEBUG_DISPATCHER
160 if (This->mDebugDispatcher)
161 This->mDebugDispatcher->GetPropertyInfo (nowTime, result, pinID, pinScope, pinElement,
162 poutDataSize, poutWritable);
169 case kAudioUnitGetPropertySelect:
171 PARAM(AudioUnitPropertyID, pinID, 0, 5);
172 PARAM(AudioUnitScope, pinScope, 1, 5);
173 PARAM(AudioUnitElement, pinElement, 2, 5);
174 PARAM(
void *, poutData, 3, 5);
175 PARAM(UInt32 *, pioDataSize, 4, 5);
177 UInt32 actualPropertySize, clientBufferSize;
182 if (pioDataSize == NULL) {
183 ca_debug_string(
"AudioUnitGetProperty: null size pointer");
185 goto finishGetProperty;
187 if (poutData == NULL) {
190 result = This->DispatchGetPropertyInfo(pinID, pinScope, pinElement, dataSize, writable);
191 *pioDataSize = dataSize;
192 goto finishGetProperty;
195 clientBufferSize = *pioDataSize;
196 if (clientBufferSize == 0)
198 ca_debug_string(
"AudioUnitGetProperty: *ioDataSize == 0 on entry");
201 goto finishGetProperty;
204 result = This->DispatchGetPropertyInfo(pinID, pinScope, pinElement,
205 actualPropertySize, writable);
207 goto finishGetProperty;
209 if (clientBufferSize < actualPropertySize)
211 tempBuffer =
new char[actualPropertySize];
212 destBuffer = tempBuffer;
215 destBuffer = poutData;
218 result = This->DispatchGetProperty(pinID, pinScope, pinElement, destBuffer);
220 if (result == noErr) {
221 if (clientBufferSize < actualPropertySize)
223 memcpy(poutData, tempBuffer, clientBufferSize);
227 *pioDataSize = actualPropertySize;
233 #if AU_DEBUG_DISPATCHER
234 if (This->mDebugDispatcher)
235 This->mDebugDispatcher->GetProperty (nowTime, result, pinID, pinScope, pinElement,
236 pioDataSize, poutData);
244 case kAudioUnitSetPropertySelect:
246 PARAM(AudioUnitPropertyID, pinID, 0, 5);
247 PARAM(AudioUnitScope, pinScope, 1, 5);
248 PARAM(AudioUnitElement, pinElement, 2, 5);
249 PARAM(
const void *, pinData, 3, 5);
250 PARAM(UInt32, pinDataSize, 4, 5);
252 if (pinData && pinDataSize)
253 result = This->DispatchSetProperty(pinID, pinScope, pinElement, pinData, pinDataSize);
255 if (pinData == NULL && pinDataSize == 0) {
256 result = This->DispatchRemovePropertyValue (pinID, pinScope, pinElement);
258 if (pinData == NULL) {
259 ca_debug_string(
"AudioUnitSetProperty: inData == NULL");
261 goto finishSetProperty;
264 if (pinDataSize == 0) {
265 ca_debug_string(
"AudioUnitSetProperty: inDataSize == 0");
267 goto finishSetProperty;
273 #if AU_DEBUG_DISPATCHER
274 if (This->mDebugDispatcher)
275 This->mDebugDispatcher->SetProperty (nowTime, result, pinID, pinScope, pinElement,
276 pinData, pinDataSize);
284 case kAudioUnitAddPropertyListenerSelect:
286 PARAM(AudioUnitPropertyID, pinID, 0, 3);
287 PARAM(AudioUnitPropertyListenerProc, pinProc, 1, 3);
288 PARAM(
void *, pinProcRefCon, 2, 3);
289 result = This->AddPropertyListener(pinID, pinProc, pinProcRefCon);
294 case kAudioUnitRemovePropertyListenerSelect:
296 PARAM(AudioUnitPropertyID, pinID, 0, 2);
297 PARAM(AudioUnitPropertyListenerProc, pinProc, 1, 2);
298 result = This->RemovePropertyListener(pinID, pinProc, NULL,
false);
303 case kAudioUnitRemovePropertyListenerWithUserDataSelect:
305 PARAM(AudioUnitPropertyID, pinID, 0, 3);
306 PARAM(AudioUnitPropertyListenerProc, pinProc, 1, 3);
307 PARAM(
void *, pinProcRefCon, 2, 3);
308 result = This->RemovePropertyListener(pinID, pinProc, pinProcRefCon,
true);
312 case kAudioUnitAddRenderNotifySelect:
314 PARAM(AURenderCallback, pinProc, 0, 2);
315 PARAM(
void *, pinProcRefCon, 1, 2);
316 result = This->SetRenderNotification (pinProc, pinProcRefCon);
320 case kAudioUnitRemoveRenderNotifySelect:
322 PARAM(AURenderCallback, pinProc, 0, 2);
323 PARAM(
void *, pinProcRefCon, 1, 2);
324 result = This->RemoveRenderNotification (pinProc, pinProcRefCon);
328 case kAudioUnitGetParameterSelect:
330 PARAM(AudioUnitParameterID, pinID, 0, 4);
331 PARAM(AudioUnitScope, pinScope, 1, 4);
332 PARAM(AudioUnitElement, pinElement, 2, 4);
333 PARAM(AudioUnitParameterValue *, poutValue, 3, 4);
334 result = (poutValue == NULL ? paramErr : This->GetParameter(pinID, pinScope, pinElement, *poutValue));
338 case kAudioUnitSetParameterSelect:
340 PARAM(AudioUnitParameterID, pinID, 0, 5);
341 PARAM(AudioUnitScope, pinScope, 1, 5);
342 PARAM(AudioUnitElement, pinElement, 2, 5);
343 PARAM(AudioUnitParameterValue, pinValue, 3, 5);
344 PARAM(UInt32, pinBufferOffsetInFrames, 4, 5);
345 result = This->SetParameter(pinID, pinScope, pinElement, pinValue, pinBufferOffsetInFrames);
349 case kAudioUnitScheduleParametersSelect:
351 if (This->AudioUnitAPIVersion() > 1)
353 PARAM(AudioUnitParameterEvent *, pinParameterEvent, 0, 2);
354 PARAM(UInt32, pinNumParamEvents, 1, 2);
355 result = This->ScheduleParameter (pinParameterEvent, pinNumParamEvents);
357 result = badComponentSelector;
362 case kAudioUnitRenderSelect:
365 PARAM(AudioUnitRenderActionFlags *, pinActionFlags, 0, 5);
366 PARAM(
const AudioTimeStamp *, pinTimeStamp, 1, 5);
367 PARAM(UInt32, pinOutputBusNumber, 2, 5);
368 PARAM(UInt32, pinNumberFrames, 3, 5);
369 PARAM(AudioBufferList *, pioData, 4, 5);
370 AudioUnitRenderActionFlags tempFlags;
372 if (pinTimeStamp == NULL || pioData == NULL)
375 if (pinActionFlags == NULL) {
377 pinActionFlags = &tempFlags;
379 result = This->DoRender(*pinActionFlags, *pinTimeStamp, pinOutputBusNumber, pinNumberFrames, *pioData);
382 #if AU_DEBUG_DISPATCHER
383 if (This->mDebugDispatcher)
384 This->mDebugDispatcher->Render (nowTime, result, pinActionFlags, pinTimeStamp,
385 pinOutputBusNumber, pinNumberFrames, pioData);
391 case kAudioUnitResetSelect:
393 PARAM(AudioUnitScope, pinScope, 0, 2);
394 PARAM(AudioUnitElement, pinElement, 1, 2);
395 This->mLastRenderedSampleTime = -1;
396 result = This->Reset(pinScope, pinElement);
401 result = ComponentBase::ComponentEntryDispatch(params, This);
410 OSStatus AudioUnitBaseGetParameter( AUBase * This,
411 AudioUnitParameterID inID,
412 AudioUnitScope inScope,
413 AudioUnitElement inElement,
416 OSStatus result = AUBase::noErr;
419 if (This == NULL || outValue == NULL)
return AUBase::paramErr;
420 result = This->GetParameter(inID, inScope, inElement, *outValue);
427 OSStatus AudioUnitBaseSetParameter( AUBase * This,
428 AudioUnitParameterID inID,
429 AudioUnitScope inScope,
430 AudioUnitElement inElement,
432 UInt32 inBufferOffset)
434 OSStatus result = AUBase::noErr;
437 if (This == NULL)
return AUBase::paramErr;
438 result = This->SetParameter(inID, inScope, inElement, inValue, inBufferOffset);
445 OSStatus AudioUnitBaseRender( AUBase * This,
446 AudioUnitRenderActionFlags *ioActionFlags,
447 const AudioTimeStamp * inTimeStamp,
449 UInt32 inNumberFrames,
450 AudioBufferList * ioData)
452 if (inTimeStamp == NULL || ioData == NULL)
return AUBase::paramErr;
454 #if AU_DEBUG_DISPATCHER
455 INIT_DEBUG_DISPATCHER(This)
458 OSStatus result = AUBase::noErr;
459 AudioUnitRenderActionFlags tempFlags;
462 if (ioActionFlags == NULL) {
464 ioActionFlags = &tempFlags;
466 result = This->DoRender(*ioActionFlags, *inTimeStamp, inBusNumber, inNumberFrames, *ioData);
470 #if AU_DEBUG_DISPATCHER
471 if (This->mDebugDispatcher)
472 This->mDebugDispatcher->Render (nowTime, result, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);