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