source: src/io/utils_apple_audio.c @ 88d3d31

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 88d3d31 was 33d0242, checked in by Paul Brossier <piem@piem.org>, 8 years ago

src/aubio_priv.h: move include config.h here

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