source: src/io/utils_apple_audio.c @ 2eccf22

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 2eccf22 was 98a3887, checked in by Paul Brossier <piem@piem.org>, 11 years ago

src/io/*apple*: improve error messages

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#ifdef __APPLE__
2
3// CFURLRef, CFURLCreateWithFileSystemPath, ...
4#include <CoreFoundation/CoreFoundation.h>
5// ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
6#include <AudioToolbox/AudioToolbox.h>
7#include "aubio_priv.h"
8
9int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
10void freeAudioBufferList(AudioBufferList *bufferList);
11CFURLRef getURLFromPath(const char * path);
12char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
13
14int 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);
19  return 0;
20}
21
22void 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) {
27      AUBIO_FREE(bufferList->mBuffers[i].mData);
28      bufferList->mBuffers[i].mData = NULL;
29    }
30  }
31  bufferList = NULL;
32}
33
34CFURLRef getURLFromPath(const char * path) {
35  CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
36      path, kCFStringEncodingUTF8);
37
38  return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
39      kCFURLPOSIXPathStyle, false);
40}
41
42char_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
55#endif /* __APPLE__ */
Note: See TracBrowser for help on using the repository browser.