source: src/io/utils_apple_audio.c @ b74513d

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

wscript, src/io/*.c: use custom defines instead of APPLE

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[9209c79]1#include "config.h"
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>
[19f222d]9#include "aubio_priv.h"
[1223979]10
11int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
12void freeAudioBufferList(AudioBufferList *bufferList);
13CFURLRef getURLFromPath(const char * path);
[98a3887]14char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
[1223979]15
[c833f56]16int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
[1223979]17  bufferList->mNumberBuffers = 1;
18  bufferList->mBuffers[0].mNumberChannels = channels;
[c833f56]19  bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
20  bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
[1223979]21  return 0;
22}
23
24void 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
36CFURLRef getURLFromPath(const char * path) {
37  CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
38      path, kCFStringEncodingUTF8);
39
40  return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
41      kCFURLPOSIXPathStyle, false);
42}
43
[98a3887]44char_t *getPrintableOSStatusError(char_t *str, OSStatus error)
45{
46    // see if it appears to be a 4-char-code
47    *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
48    if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
49        str[0] = str[5] = '\'';
50        str[6] = '\0';
51    } else
52        // no, format it as an integer
53        sprintf(str, "%d", (int)error);
54    return str;
55}
56
[9209c79]57#endif /* defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) */
Note: See TracBrowser for help on using the repository browser.