[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 | |
---|
[c833f56] | 15 | int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) { |
---|
[1223979] | 16 | bufferList->mNumberBuffers = 1; |
---|
| 17 | bufferList->mBuffers[0].mNumberChannels = channels; |
---|
[c833f56] | 18 | bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples); |
---|
| 19 | bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short); |
---|
[1223979] | 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) { |
---|
[19f222d] | 28 | AUBIO_FREE(bufferList->mBuffers[i].mData); |
---|
[1223979] | 29 | bufferList->mBuffers[i].mData = NULL; |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | bufferList = NULL; |
---|
| 33 | } |
---|
| 34 | |
---|
[2da7526] | 35 | CFURLRef createURLFromPath(const char * path) { |
---|
[1223979] | 36 | CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault, |
---|
| 37 | path, kCFStringEncodingUTF8); |
---|
| 38 | |
---|
[2da7526] | 39 | CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, |
---|
[1223979] | 40 | kCFURLPOSIXPathStyle, false); |
---|
[2da7526] | 41 | CFRelease(cfTotalPath); |
---|
| 42 | return url; |
---|
[1223979] | 43 | } |
---|
| 44 | |
---|
[98a3887] | 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 | |
---|
[9209c79] | 58 | #endif /* defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) */ |
---|