开发者

ios - How to use ExtAudioFileConvert sample in a new project

All I wanted was to read a caf file and write it to another file, in the hopes that perhaps I can manipulate it such as combine multiple files into one, or trimming. So I found Apples's own iPhoneExtAudioFileConvertTest Sample, which looks very challenging but I figured once I take the pieces into my own project, then I can play with it, this proved to be rather cumbersome.

Now, after a few sleepless nights of digging for information and lots trial and 开发者_如何学Pythonerrors runs; I believed I have managed to use the the iPhoneExtAudioFileConvertTest Sample in my own project. I thought I would post this to save a fellow coder some sleep.

Steps:

  • Added the iPublicUtility folder and the ExtAudioFileConvert.cpp file from the iPhoneExtAudioFileConvertTest sample to my project.
  • Renamed the extension of the 3 new .cpp files to .mm (the .h files stay the same). This allows xcode to view the cpp files as objective c++ files.
    • ExtAudioFileConvert.mm
    • iPublicUtility/CAStreamBasicDescription.mm
    • iPublicUtility/CAXException.mm
  • In my myViewController.m (UIViewController) class that plans to call the

    DoConvertFile(sourceURL, destinationURL, outputFormat, sampleRate); method, I added one line to make the DoConvertFile method visible

    extern OSStatus DoConvertFile(CFURLRef sourceURL, CFURLRef destinationURL, OSType outputFormat, Float64 outputSampleRate);

  • Also renamed myViewController.m to myViewController.mm because it's using a .cpp file to make the convertFile method call
  • In my project setting under Targets / Build Settings, I searched for the key "Header Search Paths" and added the following for it's value /Developer/Extras/CoreAudio/PublicUtility/ $(inherited) without this line the compiler would give me over 30 errors, such as 'DebugPrintfFile' was not declared in this scope*
  • I noticed that the sample also has code in the app delegate
    • so I copied the code of the 2 methods directly from the sample's appDelegate into my own appDelegate, namly
      • static void interruptionListener(void *inClientData, UInt32 inInterruption)
      • static void propertyListener(void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData)
    • and added the the following 4 lines right after the original #import statement
      • #import "CAXException.h"
      • extern void ThreadStateInitalize();
      • extern void ThreadStateBeginInterruption();
      • extern void ThreadStateEndInterruption();
    • of course also added the code from the samples applicationDidFinishLaunching into my didFinishLaunchingWithOptions
    • and once again renamed my appDelegate.m to appDelegate.mm

Now when I compile I get no errors and runtime only works if I comment out the assert in ExtAudioFileConvert.mm

    // in this sample we should never be on the main thread here
    assert(![NSThread isMainThread]);

Also at startup I receive an error which is not causing any issues, but I'd prefer to remove it. Anyone ?

    Error: couldn't set audio category (-50)

which seems to be coming from this call in my 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");

Other than these warnings/errors, I can write/convert a caf file :). I would appreciate any feedback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜