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