3 // CFURLRef, CFURLCreateWithFileSystemPath, ...
4 #include <CoreFoundation/CoreFoundation.h>
5 // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
6 #include <AudioToolbox/AudioToolbox.h>
8 int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
9 void freeAudioBufferList(AudioBufferList *bufferList);
10 CFURLRef getURLFromPath(const char * path);
12 int createAubioBufferList(AudioBufferList * bufferList, int channels, int segmentSize) {
13 bufferList->mNumberBuffers = 1;
14 bufferList->mBuffers[0].mNumberChannels = channels;
15 bufferList->mBuffers[0].mData = (short *)malloc(segmentSize * sizeof(short));
16 bufferList->mBuffers[0].mDataByteSize = segmentSize * sizeof(short);
20 void freeAudioBufferList(AudioBufferList *bufferList) {
22 if (!bufferList) return;
23 for (i = 0; i < bufferList->mNumberBuffers; i++) {
24 if (bufferList->mBuffers[i].mData) {
25 free (bufferList->mBuffers[i].mData);
26 bufferList->mBuffers[i].mData = NULL;
32 CFURLRef getURLFromPath(const char * path) {
33 CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
34 path, kCFStringEncodingUTF8);
36 return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
37 kCFURLPOSIXPathStyle, false);
40 #endif /* __APPLE__ */