1 #include "aubio_priv.h"
3 #if defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO)
5 // CFURLRef, CFURLCreateWithFileSystemPath, ...
6 #include <CoreFoundation/CoreFoundation.h>
7 // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
8 #include <AudioToolbox/AudioToolbox.h>
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);
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);
23 void freeAudioBufferList(AudioBufferList *bufferList) {
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;
35 CFURLRef createURLFromPath(const char * path) {
36 CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
37 path, kCFStringEncodingUTF8);
39 CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
40 kCFURLPOSIXPathStyle, false);
41 CFRelease(cfTotalPath);
45 char_t *getPrintableOSStatusError(char_t *str, OSStatus error)
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] = '\'';
53 // no, format it as an integer
54 sprintf(str, "%d", (int)error);
58 #endif /* defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) */