1 /*
2 Copyright (C) 2016 Apple Inc. All Rights Reserved.
3 See LICENSE.txt for this sample’s licensing information
4
5 Abstract:
6 Part of Core Audio AUBase Classes
7 */
8
9 #include "AUBaseHelper.h"
10
11 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
12 #include <AudioUnit/AudioUnitProperties.h>
13 #else
14 #include <AudioUnitProperties.h>
15 #endif
16
GetFileRefPath(CFDictionaryRef parent,CFStringRef frKey,CFStringRef * fPath)17 OSStatus GetFileRefPath (CFDictionaryRef parent, CFStringRef frKey, CFStringRef * fPath)
18 {
19 static CFStringRef kFRString = CFSTR (kAUPresetExternalFileRefs);
20
21 const void* frVal = CFDictionaryGetValue(parent, kFRString);
22 if (!frVal) return kAudioUnitErr_InvalidPropertyValue;
23
24 const void* frString = CFDictionaryGetValue ((CFDictionaryRef)frVal, frKey);
25 if (!frString) return kAudioUnitErr_InvalidPropertyValue;
26
27 if (fPath)
28 *fPath = (CFStringRef)frString;
29
30 return noErr;
31 }
32
CreateFileRefDict(CFStringRef fKey,CFStringRef fPath,CFMutableDictionaryRef fileRefDict)33 CFMutableDictionaryRef CreateFileRefDict (CFStringRef fKey, CFStringRef fPath, CFMutableDictionaryRef fileRefDict)
34 {
35 if (!fileRefDict)
36 fileRefDict = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
37
38 CFDictionarySetValue (fileRefDict, fKey, fPath);
39
40 return fileRefDict;
41 }
42
43 #if TARGET_OS_MAC
44 // check if the URL can be accessed for reading/writing. Returns 0 if yes, or the error value.
AccessURLAsset(const CFURLRef inURL,int mode)45 int AccessURLAsset(const CFURLRef inURL, int mode)
46 {
47 char path[PATH_MAX];
48 if (CFURLGetFileSystemRepresentation(inURL, TRUE, (UInt8 *)path, PATH_MAX) == FALSE)
49 return kAudio_FileNotFoundError;
50 // check whether we have access
51 int ret = access(path, mode);
52 // syslog(LOG_CRIT, "access() error is %d for \"%s\".\n", ret, path);
53 if (ret == 0) return 0;
54 switch (errno) {
55 case EACCES:
56 case EPERM:
57 return -54; /*permission denied error*/
58 case ENOENT:
59 case ENOTDIR:
60 case ELOOP:
61 return kAudio_FileNotFoundError;
62 default:
63 return errno;
64 }
65 }
66 #endif
67
68 #if DEBUG
69 //_____________________________________________________________________________
70 //
PrintAUParamEvent(AudioUnitParameterEvent & event,FILE * f)71 void PrintAUParamEvent (AudioUnitParameterEvent& event, FILE* f)
72 {
73 bool isRamp = event.eventType == kParameterEvent_Ramped;
74 fprintf (f, "\tParamID=%ld,Scope=%ld,Element=%ld\n", (long)event.parameter, (long)event.scope, (long)event.element);
75 fprintf (f, "\tEvent Type:%s,", (isRamp ? "ramp" : "immediate"));
76 if (isRamp)
77 fprintf (f, "start=%ld,dur=%ld,startValue=%f,endValue=%f\n",
78 (long)event.eventValues.ramp.startBufferOffset, (long)event.eventValues.ramp.durationInFrames,
79 event.eventValues.ramp.startValue, event.eventValues.ramp.endValue);
80 else
81 fprintf (f, "start=%ld,value=%f\n",
82 (long)event.eventValues.immediate.bufferOffset,
83 event.eventValues.immediate.value);
84 fprintf (f, "- - - - - - - - - - - - - - - -\n");
85 }
86 #endif
87
88