我需要将 obj-C 源文件从 .m 更改为 .mm 才能访问一些 c++ 类。只要我这样做,AudioFileGetProperty() 和 AudioFileReadPackets() 就会报告“无匹配函数调用”错误。
如果我将它从方法中移出并移到实现之外的 C 样式块中,或者重命名为 .m,它就可以工作。
为什么我不能在 .mm 文件的方法中使用 AudioFileGetProperty()?
- (SInt16*)loadSingleWAVBuffer:(NSString*)inName ofLength:(UInt32*)outLength
{
AudioFileID audioFileID;
SInt64 dataSize, packetsRead, numBytesRead, storageSize, packetCount;
NSString *filePath = [NSString stringWithFormat:@"%@/%@%@%@", [[NSBundle mainBundle] bundlePath], self.lessonName, @"/Phrase Data/", inName];
CFURLRef myFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filePath, kCFURLPOSIXPathStyle, false);
OSStatus err = AudioFileOpenURL(myFileURL, kAudioFileReadPermission, 0, &audioFileID);
AudioStreamBasicDescription asbd;
UInt32 propSize = sizeof(asbd);
AudioFileGetProperty(audioFileID, kAudioFilePropertyDataFormat,&propSize, &asbd);
dataSize = sizeof packetCount;
OSStatus result = AudioFileGetProperty(audioFileID, kAudioFilePropertyAudioDataPacketCount, &dataSize, &packetCount);
packetsRead = packetCount;
printf("File Opened, packet Count: %lld", packetCount);
storageSize = 2 * packetCount;
SInt16* outBuffer = (SInt16*)malloc( storageSize);
result = AudioFileReadPackets (audioFileID, false, &numBytesRead, NULL, 0, &packetsRead, outBuffer);
*outLength = packetsRead;
return outBuffer;
}
我正在使用 AudioToolbox 框架并包含标题。
#import <AudioToolbox/AudioToolbox.h>
我正在使用 iOS 6.1 SDK 构建,针对 iOS 6.0