47 #if AU_DEBUG_DISPATCHER
49 #warning "This should * * NOT * * be seen on a Release Version"
52 #include "AUDebugDispatcher.h"
54 static char* AUErrorStr (OSStatus result);
58 AUDD_Locker (CAMutex &guard) :mGuard (guard) { didLock = mGuard.Lock(); }
59 ~AUDD_Locker () {
if (didLock) mGuard.Unlock(); }
66 AUDebugDispatcher::AUDebugDispatcher (AUBase *au, FILE* file)
69 mHaveDoneProperty (false),
70 mPrintMutex (
"AU Debug Dispatcher Printer"),
74 mHostCB_WhenToPrint (0),
75 mHostCB_WasPlaying (0)
78 AudioComponentDescription desc = mAUBase->GetComponentDescription();
79 fprintf (mFile,
"\nAUBase=0x%X, Type=%4.4s, SubType=%4.4s, Manu=%4.4s\n\n", AU(),
80 (
char*)&desc.componentType,
81 (
char*)&desc.componentSubType,
82 (
char*)&desc.componentManufacturer);
83 mFirstTime = CAHostTimeBase::GetCurrentTime();
87 AUDebugDispatcher::~AUDebugDispatcher()
89 PrintHeaderString (CAHostTimeBase::GetCurrentTime(), (
unsigned int)pthread_self(),
"Close");
90 fprintf (mFile,
"\n");
93 void AUDebugDispatcher::PrintHeaderString (UInt64 inNowTime,
unsigned int inThread,
const char* inMethod)
95 double secsSinceStart = SecsSinceStart(inNowTime);
96 fprintf (mFile,
"[AUDisp:AUBase = 0x%X, Time = %.6lf secs, Thread = 0x%X, IsInitialized = '%c'] %s()\n",
97 AU(), secsSinceStart, inThread, (mAUBase->IsInitialized() ?
'T' :
'F'), inMethod);
100 unsigned int AUDebugDispatcher::RecordDispatch (UInt64 inStartTime, OSStatus result,
const char* inMethod)
102 UInt64 nowTime = CAHostTimeBase::GetCurrentTime();
104 unsigned int theThread = (
unsigned int)pthread_self();
106 PrintHeaderString (nowTime, theThread, inMethod);
108 UInt64 nanos = CAHostTimeBase::ConvertToNanos(nowTime - inStartTime);
110 fprintf (mFile,
"\t[Time To execute = %.6lf secs", (nanos * 1.0e-9));
113 fprintf (mFile,
", * * * result = %ld, %s * * * ", result, AUErrorStr(result));
115 fprintf (mFile,
"]\n");
121 #pragma mark __AU Dispatch
124 void AUDebugDispatcher::Initialize (UInt64 nowTime, OSStatus result)
126 AUDD_Locker lock (mPrintMutex);
127 RecordDispatch (nowTime, result,
"Initialize");
130 void AUDebugDispatcher::Uninitialize (UInt64 nowTime, OSStatus result)
132 AUDD_Locker lock (mPrintMutex);
133 RecordDispatch (nowTime, result,
"Uninitialize");
136 void AUDebugDispatcher::GetPropertyInfo (UInt64 nowTime,
138 AudioUnitPropertyID inID,
139 AudioUnitScope inScope,
140 AudioUnitElement inElement,
142 Boolean *outWritable)
144 AUDD_Locker lock (mPrintMutex);
145 RecordDispatch (nowTime, result,
"GetPropertyInfo");
146 PrintProperty (inID, inScope, inElement);
149 void AUDebugDispatcher::GetProperty (UInt64 nowTime,
151 AudioUnitPropertyID inID,
152 AudioUnitScope inScope,
153 AudioUnitElement inElement,
161 AUDD_Locker lock (mPrintMutex);
162 const char *dispStr = outData != NULL ?
"GetProperty" :
"GetProperty - Info";
163 RecordDispatch (nowTime, result, dispStr);
164 PrintProperty (inID, inScope, inElement);
167 void AUDebugDispatcher::SetProperty (UInt64 nowTime,
169 AudioUnitPropertyID inID,
170 AudioUnitScope inScope,
171 AudioUnitElement inElement,
176 AUDD_Locker lock (mPrintMutex);
177 RecordDispatch (nowTime, result,
"SetProperty");
178 PrintProperty (inID, inScope, inElement);
181 void AUDebugDispatcher::Render ( UInt64 nowTime,
183 AudioUnitRenderActionFlags * inRenderFlags,
184 const AudioTimeStamp * inTimeStamp,
185 UInt32 inOutputBusNumber,
187 AudioBufferList * inIOData)
189 if (mHaveDoneProperty) {
190 AUDD_Locker lock (mPrintMutex);
191 RecordDispatch (nowTime, result,
"Render");
192 fprintf (mFile,
"\t\t[Sample Time = %.0lf, NumFrames = %ld]\n", inTimeStamp->mSampleTime, inNumFrames);
193 mHaveDoneProperty =
false;
195 RenderActions_HostCallbacks ();
198 #define kBeginLine " "
200 void AUDebugDispatcher::RenderActions_HostCallbacks ()
202 bool doPrint = !(mHostCB_WhenToPrint++ % 5000);
206 Boolean isPlaying, transStateChange, isCycling;
207 Float64 currentSample, cycleStartBeat, cycleEndBeat;
208 OSStatus result = mAUBase->CallHostTransportState (&isPlaying, &transStateChange, ¤tSample,
209 &isCycling, &cycleStartBeat, &cycleEndBeat);
210 bool newCB3Result =
false;
211 if (result != mHostCB3_Result) {
212 mHostCB3_Result = result;
216 if (transStateChange) mHostCB_WhenToPrint = 1;
219 Float64 currentBeat, currentTempo;
222 result = mAUBase->CallHostBeatAndTempo (¤tBeat, ¤tTempo);
225 if (result != mHostCB1_Result) {
226 printf (
"_HCback_ Error Calling HostBeatAndTempo:%ld\n", result);
227 mHostCB1_Result = result;
230 if (doPrint || currentBeat < 0 || transStateChange)
231 printf (
"_HCback_ Beat and Tempo: Current Beat:%f, Current Tempo:%f\n", currentBeat, currentTempo);
235 UInt32 deltaSampleOffset, timeSig_Denom;
237 Float64 currentMeasureDownBeat;
238 result = mAUBase->CallHostMusicalTimeLocation (&deltaSampleOffset, &timeSig_Num, &timeSig_Denom, ¤tMeasureDownBeat);
241 if (result != mHostCB2_Result) {
242 printf (
"%sError Calling CallHostMusicalTimeLocation:%ld\n", kBeginLine, result);
243 mHostCB2_Result = result;
246 if (doPrint || currentMeasureDownBeat < 0 || deltaSampleOffset < 0 || transStateChange) {
247 printf (
"%sMusical Time: Delta Sample Offset:%ld, Time Sig:Num:%.1f, Time Sig:Denom:%ld, DownBeat:%f\n",
248 kBeginLine, deltaSampleOffset, timeSig_Num, timeSig_Denom, currentMeasureDownBeat);
252 if (mHostCB3_Result) {
254 printf (
"%sError Calling CallHostTransportState:%ld\n", kBeginLine, mHostCB3_Result);
257 if (doPrint || (mHostCB_WasPlaying != isPlaying) || transStateChange || currentSample < 0)
259 printf (
"%sTransport State: Was Playing:%d, ", kBeginLine, mHostCB_WasPlaying);
260 mHostCB_WasPlaying = isPlaying;
261 printf (
"Is Playing:%d, Transport State Changed:%d", isPlaying, transStateChange);
263 printf (
", Current Sample:%.1f", currentSample);
265 printf (
", Is Cycling [Start Beat:%.2f, End Beat:%.2f]", cycleStartBeat, cycleEndBeat);
273 #pragma mark __Utilities
276 static char* AUScopeStr (AudioUnitScope inScope)
279 case kAudioUnitScope_Global:
return "Global";
280 case kAudioUnitScope_Output:
return "Output";
281 case kAudioUnitScope_Input:
return "Input";
282 case kAudioUnitScope_Group:
return "Group";
287 static char* AUErrorStr (OSStatus result)
290 case kAudioUnitErr_InvalidProperty:
return "Invalid Property";
291 case kAudioUnitErr_InvalidParameter:
return "Invalid Parameter";
292 case kAudioUnitErr_InvalidElement:
return "Invalid Element";
293 case kAudioUnitErr_NoConnection:
return "Invalid Connection";
294 case kAudioUnitErr_FailedInitialization:
return "Failed Initialization";
295 case kAudioUnitErr_TooManyFramesToProcess:
return "Too Many Frames";
296 case kAudioUnitErr_IllegalInstrument:
return "Illegal Instrument";
297 case kAudioUnitErr_InstrumentTypeNotFound:
return "Instrument Type Not Found";
298 case kAudioUnitErr_InvalidFile:
return "Invalid File";
299 case kAudioUnitErr_UnknownFileType:
return "Unknown File Type";
300 case kAudioUnitErr_FileNotSpecified:
return "File Not Specified";
301 case kAudioUnitErr_FormatNotSupported:
return "Format Not Supported";
302 case kAudioUnitErr_Uninitialized:
return "Un Initialized";
303 case kAudioUnitErr_InvalidScope:
return "Invalid Scope";
304 case kAudioUnitErr_PropertyNotWritable:
return "Property Not Writable";
305 case kAudioUnitErr_InvalidPropertyValue:
return "Invalid Property Value";
306 case kAudioUnitErr_PropertyNotInUse:
return "Property Not In Use";
307 case kAudioUnitErr_Initialized:
return "Initialized";
310 case badComponentSelector:
return "Bad Component Selector";
311 case paramErr:
return "Parameter Error";
312 case badComponentInstance:
return "Bad Component Instance";
314 return "Unknown Error";
317 static char* AUPropertyStr (AudioUnitPropertyID inID)
320 case kAudioUnitProperty_ClassInfo:
return "Class Info";
321 case kAudioUnitProperty_MakeConnection:
return "Connection";
322 case kAudioUnitProperty_SampleRate:
return "Sample Rate";
323 case kAudioUnitProperty_ParameterList:
return "Parameter List";
324 case kAudioUnitProperty_ParameterInfo:
return "Parameter Info";
325 case kAudioUnitProperty_FastDispatch:
return "Fast Dispatch";
326 case kAudioUnitProperty_CPULoad:
return "CPU Load";
327 case kAudioUnitProperty_StreamFormat:
return "Format";
328 case kAudioUnitProperty_ReverbRoomType:
return "Reverb Room Type";
329 case kAudioUnitProperty_ElementCount:
return "Element Count";
330 case kAudioUnitProperty_Latency:
return "Latency";
331 case kAudioUnitProperty_SupportedNumChannels:
return "Supported Num Channels";
332 case kAudioUnitProperty_MaximumFramesPerSlice:
return "Max Frames Per Slice";
333 case kAudioUnitProperty_SetExternalBuffer:
return "Set External Buffer";
334 case kAudioUnitProperty_ParameterValueStrings:
return "Parameter Value Strings";
335 case kAudioUnitProperty_GetUIComponentList:
return "Carbon UI";
336 case kAudioUnitProperty_AudioChannelLayout:
return "Audio Channel Layout";
337 case kAudioUnitProperty_TailTime:
return "Tail Time";
338 case kAudioUnitProperty_BypassEffect:
return "Bypass Effect";
339 case kAudioUnitProperty_LastRenderError:
return "Last Render Error";
340 case kAudioUnitProperty_SetRenderCallback:
return "Render Callback";
341 case kAudioUnitProperty_FactoryPresets:
return "Factory Preset";
342 case kAudioUnitProperty_ContextName:
return "Context Name";
343 case kAudioUnitProperty_RenderQuality:
return "Render Quality";
344 case kAudioUnitProperty_HostCallbacks:
return "Host Callbacks";
345 case kAudioUnitProperty_InPlaceProcessing:
return "In Place Processing";
346 case kAudioUnitProperty_ElementName:
return "Element Name";
347 case kAudioUnitProperty_CocoaUI:
return "Cocoa UI";
348 case kAudioUnitProperty_SupportedChannelLayoutTags:
return "Supported Channel Layout Tags";
349 case kAudioUnitProperty_ParameterStringFromValue:
return "Parameter Value Name";
350 case kAudioUnitProperty_UsesInternalReverb:
return "Use Internal Reverb";
351 case kAudioUnitProperty_ParameterIDName:
return "Parameter ID Name";
352 case kAudioUnitProperty_ParameterClumpName:
return "Clump Name";
353 case kAudioUnitProperty_PresentPreset:
return "Present Preset";
356 case kMusicDeviceProperty_InstrumentCount:
return "Instrument Count";
357 case kMusicDeviceProperty_InstrumentName:
return "Instrument Name";
358 case kMusicDeviceProperty_SoundBankFSRef:
return "Sound Bank - File";
359 case kMusicDeviceProperty_InstrumentNumber:
return "Instrument Number";
360 case kMusicDeviceProperty_MIDIXMLNames:
return "MIDI XML Names";
361 case kMusicDeviceProperty_BankName:
return "Bank Name";
362 case kMusicDeviceProperty_SoundBankData:
return "Sound Bank - Data";
365 case kAudioOutputUnitProperty_CurrentDevice:
return "Current AudioDevice";
366 case kAudioOutputUnitProperty_IsRunning:
return "Is Running";
367 case kAudioOutputUnitProperty_ChannelMap:
return "Channel Map";
368 case kAudioOutputUnitProperty_EnableIO:
return "Enable I/O";
369 case kAudioOutputUnitProperty_StartTime:
return "Start Time";
370 case kAudioOutputUnitProperty_SetInputCallback:
return "I/O Input Callback";
376 void AUDebugDispatcher::PrintProperty ( AudioUnitPropertyID inID,
377 AudioUnitScope inScope,
378 AudioUnitElement inElement)
380 char* scopeStr = AUScopeStr(inScope);
381 char* propStr = AUPropertyStr (inID);
383 if (scopeStr != NULL)
384 fprintf (mFile,
"\t\t[ID = %ld, %s, Scope = %s, El = %ld]\n", inID, propStr, scopeStr, inElement);
386 fprintf (mFile,
"\t\t[ID = %ld, %s, Scope = %ld, El = %ld]\n", inID, propStr, inScope , inElement);
388 bool iscback =
false;
389 bool isInput =
false;
392 case kAudioUnitProperty_SetRenderCallback:
394 case kAudioUnitProperty_MakeConnection:
396 AUInputElement *el = mAUBase->GetInput (inElement);
398 bool hasInput =
false;
400 hasInput = el->IsCallback();
402 hasInput = el->HasConnection();
403 fprintf (mFile,
"\t\tHas Input=%c, ", (hasInput ?
'T' :
'F'));
407 case kAudioUnitProperty_SampleRate:
408 case kAudioUnitProperty_StreamFormat:
410 CAStreamBasicDescription desc = mAUBase->GetStreamFormat (inScope, inElement);
412 fprintf (mFile,
"\t\t");
420 mHaveDoneProperty =
true;
423 #endif //AU_DEBUG_DISPATCHER