source: src/io/utils_apple_audio.c @ b63c7d3

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since b63c7d3 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
RevLine 
[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
10int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
11void freeAudioBufferList(AudioBufferList *bufferList);
12CFURLRef getURLFromPath(const char * path);
[98a3887]13char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
[1223979]14
[c833f56]15int 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
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) {
[19f222d]28      AUBIO_FREE(bufferList->mBuffers[i].mData);
[1223979]29      bufferList->mBuffers[i].mData = NULL;
30    }
31  }
32  bufferList = NULL;
33}
34
[2da7526]35CFURLRef 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]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
[9209c79]58#endif /* defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) */
Note: See TracBrowser for help on using the repository browser.