1 | #include "aubio_priv.h" |
---|
2 | |
---|
3 | #if defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) |
---|
4 | |
---|
5 | // CFURLRef, CFURLCreateWithFileSystemPath, ... |
---|
6 | #include <CoreFoundation/CoreFoundation.h> |
---|
7 | // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ... |
---|
8 | #include <AudioToolbox/AudioToolbox.h> |
---|
9 | |
---|
10 | int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); |
---|
11 | void freeAudioBufferList(AudioBufferList *bufferList); |
---|
12 | CFURLRef getURLFromPath(const char * path); |
---|
13 | char_t *getPrintableOSStatusError(char_t *str, OSStatus error); |
---|
14 | |
---|
15 | int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) { |
---|
16 | bufferList->mNumberBuffers = 1; |
---|
17 | bufferList->mBuffers[0].mNumberChannels = channels; |
---|
18 | bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples); |
---|
19 | bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short); |
---|
20 | return 0; |
---|
21 | } |
---|
22 | |
---|
23 | void freeAudioBufferList(AudioBufferList *bufferList) { |
---|
24 | UInt32 i = 0; |
---|
25 | if (!bufferList) return; |
---|
26 | for (i = 0; i < bufferList->mNumberBuffers; i++) { |
---|
27 | if (bufferList->mBuffers[i].mData) { |
---|
28 | AUBIO_FREE(bufferList->mBuffers[i].mData); |
---|
29 | bufferList->mBuffers[i].mData = NULL; |
---|
30 | } |
---|
31 | } |
---|
32 | bufferList = NULL; |
---|
33 | } |
---|
34 | |
---|
35 | CFURLRef createURLFromPath(const char * path) { |
---|
36 | CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault, |
---|
37 | path, kCFStringEncodingUTF8); |
---|
38 | |
---|
39 | CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, |
---|
40 | kCFURLPOSIXPathStyle, false); |
---|
41 | CFRelease(cfTotalPath); |
---|
42 | return url; |
---|
43 | } |
---|
44 | |
---|
45 | char_t *getPrintableOSStatusError(char_t *str, OSStatus error) |
---|
46 | { |
---|
47 | // see if it appears to be a 4-char-code |
---|
48 | *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error); |
---|
49 | if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) { |
---|
50 | str[0] = str[5] = '\''; |
---|
51 | str[6] = '\0'; |
---|
52 | } else |
---|
53 | // no, format it as an integer |
---|
54 | sprintf(str, "%d", (int)error); |
---|
55 | return str; |
---|
56 | } |
---|
57 | |
---|
58 | #endif /* defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) */ |
---|