1 | #ifdef __APPLE__ |
---|
2 | |
---|
3 | // CFURLRef, CFURLCreateWithFileSystemPath, ... |
---|
4 | #include <CoreFoundation/CoreFoundation.h> |
---|
5 | // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ... |
---|
6 | #include <AudioToolbox/AudioToolbox.h> |
---|
7 | |
---|
8 | int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); |
---|
9 | void freeAudioBufferList(AudioBufferList *bufferList); |
---|
10 | CFURLRef getURLFromPath(const char * path); |
---|
11 | |
---|
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); |
---|
17 | return 0; |
---|
18 | } |
---|
19 | |
---|
20 | void freeAudioBufferList(AudioBufferList *bufferList) { |
---|
21 | UInt32 i = 0; |
---|
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; |
---|
27 | } |
---|
28 | } |
---|
29 | bufferList = NULL; |
---|
30 | } |
---|
31 | |
---|
32 | CFURLRef getURLFromPath(const char * path) { |
---|
33 | CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault, |
---|
34 | path, kCFStringEncodingUTF8); |
---|
35 | |
---|
36 | return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, |
---|
37 | kCFURLPOSIXPathStyle, false); |
---|
38 | } |
---|
39 | |
---|
40 | #endif /* __APPLE__ */ |
---|