我想要的只是读取一个caf文件并将其写入另一个文件,希望我可以操作它,例如将多个文件合并为一个或修剪。所以我找到了苹果公司自己的 iPhoneExtAudioFileConvertTest 示例,这看起来非常具有挑战性,但我想,一旦我将这些部分放入我自己的项目中,那么我可以玩它,这被证明是相当麻烦的。
现在,经过几个不眠之夜的挖掘信息和大量的试验和错误运行; 我相信我已经设法在我自己的项目中使用 iPhoneExtAudioFileConvertTest 示例。我以为我会发布这个来节省一个同伴睡眠。
步骤:
DoConvertFile(sourceURL, destinationURL, outputFormat, sampleRate);
方法的 myViewController.m (UIViewController)类中,我添加了一行以使DoConvertFile方法可见
extern OSStatus DoConvertFile(CFURLRef sourceURL, CFURLRef destinationURL, OSType outputFormat, Float64 outputSampleRate);
static void interruptionListener(void *inClientData, UInt32 inInterruption)
static void propertyListener(void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData)
#import
语句后添加了以下4行
extern void ThreadStateInitalize();
extern void ThreadStateBeginInterruption();
extern void ThreadStateEndInterruption();
applicationDidFinishLaunching
中的代码添加到我的didFinishLaunchingWithOptions
现在,当我编译时,我没有得到任何错误,只有当我在ExtAudioFileConvert.mm中注释掉断言时,运行时才有效
// in this sample we should never be on the main thread here
assert(![NSThread isMainThread]);
同样在启动时,我收到一个错误,这不会导致任何问题,但我更愿意删除它。任何人?
Error: couldn't set audio category (-50)
似乎来自我的appDelegate中的此调用
// our default category -- we change this for conversion and playback appropriately
UInt32 audioCategory = kAudioSessionCategory_SoloAmbientSound;
XThrowIfError(AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory), "couldn't set audio category");
除了这些警告/错误,我可以写/转换一个caf文件:)。 我将不胜感激任何反馈。