3 // CFURLRef, CFURLCreateWithFileSystemPath, ...
4 #include <CoreFoundation/CoreFoundation.h>
5 // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
6 #include <AudioToolbox/AudioToolbox.h>
7 #include "aubio_priv.h"
9 int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
10 void freeAudioBufferList(AudioBufferList *bufferList);
11 CFURLRef getURLFromPath(const char * path);
12 char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
14 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
15 bufferList->mNumberBuffers = 1;
16 bufferList->mBuffers[0].mNumberChannels = channels;
17 bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
18 bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
22 void freeAudioBufferList(AudioBufferList *bufferList) {
24 if (!bufferList) return;
25 for (i = 0; i < bufferList->mNumberBuffers; i++) {
26 if (bufferList->mBuffers[i].mData) {
27 AUBIO_FREE(bufferList->mBuffers[i].mData);
28 bufferList->mBuffers[i].mData = NULL;
34 CFURLRef getURLFromPath(const char * path) {
35 CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
36 path, kCFStringEncodingUTF8);
38 return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
39 kCFURLPOSIXPathStyle, false);
42 char_t *getPrintableOSStatusError(char_t *str, OSStatus error)
44 // see if it appears to be a 4-char-code
45 *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
46 if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
47 str[0] = str[5] = '\'';
50 // no, format it as an integer
51 sprintf(str, "%d", (int)error);
55 #endif /* __APPLE__ */