Jamoma API  0.6.0.a19
AUBaseHelper.cpp
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
2 
3  Disclaimer: IMPORTANT: This Apple software is supplied to you by
4  Apple Inc. ("Apple") in consideration of your agreement to the
5  following terms, and your use, installation, modification or
6  redistribution of this Apple software constitutes acceptance of these
7  terms. If you do not agree with these terms, please do not use,
8  install, modify or redistribute this Apple software.
9 
10  In consideration of your agreement to abide by the following terms, and
11  subject to these terms, Apple grants you a personal, non-exclusive
12  license, under Apple's copyrights in this original Apple software (the
13  "Apple Software"), to use, reproduce, modify and redistribute the Apple
14  Software, with or without modifications, in source and/or binary forms;
15  provided that if you redistribute the Apple Software in its entirety and
16  without modifications, you must retain this notice and the following
17  text and disclaimers in all such redistributions of the Apple Software.
18  Neither the name, trademarks, service marks or logos of Apple Inc.
19  may be used to endorse or promote products derived from the Apple
20  Software without specific prior written permission from Apple. Except
21  as expressly stated in this notice, no other rights or licenses, express
22  or implied, are granted by Apple herein, including but not limited to
23  any patent rights that may be infringed by your derivative works or by
24  other works in which the Apple Software may be incorporated.
25 
26  The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31 
32  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 #include "AUBaseHelper.h"
42 
43 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
44  #include <AudioUnit/AudioUnitProperties.h>
45 #else
46  #include <AudioUnitProperties.h>
47 #endif
48 
49 OSStatus GetFileRefPath (CFDictionaryRef parent, CFStringRef frKey, CFStringRef * fPath)
50 {
51  static CFStringRef kFRString = CFSTR (kAUPresetExternalFileRefs);
52 
53  const void* frVal = CFDictionaryGetValue(parent, kFRString);
54  if (!frVal) return kAudioUnitErr_InvalidPropertyValue;
55 
56  const void* frString = CFDictionaryGetValue ((CFDictionaryRef)frVal, frKey);
57  if (!frString) return kAudioUnitErr_InvalidPropertyValue;
58 
59  if (fPath)
60  *fPath = (CFStringRef)frString;
61 
62  return noErr;
63 }
64 
65 // write valid samples check, with bool for zapping
66 
67 UInt32 FindInvalidSamples(Float32 *inSource, UInt32 inFramesToProcess, bool &outHasNonZero, bool zapInvalidSamples)
68 {
69  float *sourceP = inSource;
70 
71  UInt32 badSamplesDetected = 0;
72  bool hasNonZero = false;
73  for (UInt32 i=0; i < inFramesToProcess; i++)
74  {
75  float input = *(sourceP++);
76 
77  if(input > 0)
78  hasNonZero = true;
79 
80  float absx = fabs(input);
81 
82  // a bad number!
83  if (!(absx < 1e15))
84  {
85  if (!(absx == 0))
86  {
87  //printf("\tbad sample: %f\n", input);
88  badSamplesDetected++;
89  if (zapInvalidSamples)
90  input = 0;
91  }
92  }
93  }
94 
95  return badSamplesDetected;
96 }
97 
98 
99 CFMutableDictionaryRef CreateFileRefDict (CFStringRef fKey, CFStringRef fPath, CFMutableDictionaryRef fileRefDict)
100 {
101  if (!fileRefDict)
102  fileRefDict = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
103 
104  CFDictionarySetValue (fileRefDict, fKey, fPath);
105 
106  return fileRefDict;
107 }
108 
109 #if DEBUG
110 //_____________________________________________________________________________
111 //
112 void PrintAUParamEvent (AudioUnitParameterEvent& event, FILE* f)
113 {
114  bool isRamp = event.eventType == kParameterEvent_Ramped;
115  fprintf (f, "\tParamID=%ld,Scope=%ld,Element=%ld\n", (long)event.parameter, (long)event.scope, (long)event.element);
116  fprintf (f, "\tEvent Type:%s,", (isRamp ? "ramp" : "immediate"));
117  if (isRamp)
118  fprintf (f, "start=%ld,dur=%ld,startValue=%f,endValue=%f\n",
119  (long)event.eventValues.ramp.startBufferOffset, (long)event.eventValues.ramp.durationInFrames,
120  event.eventValues.ramp.startValue, event.eventValues.ramp.endValue);
121  else
122  fprintf (f, "start=%ld,value=%f\n",
123  (long)event.eventValues.immediate.bufferOffset,
124  event.eventValues.immediate.value);
125  fprintf (f, "- - - - - - - - - - - - - - - -\n");
126 }
127 #endif
128