iosswiftavaudioengineavaudiofileavaudiopcmbuffer

How do I write AVAudioCompressedBuffer to an AAC file in iOS?


I've successfully converted the AVAudioPCMBuffers from AVAudioEngine into AVAudioCompressedBuffers with an AAC format. Now I'm trying to write those buffers to a file but don't know how to do it. AVAudioFile only accepts AVAudioPCMBuffers.

Any help would be greatly appreciated!


Solution

  • The easiest methods are to write to AVAudioFile before converting to compressed, or to convert back to PCM buffer and write to AVAudioFile.

    If the easy methods are not an option, I believe you are stuck using Audio File Services. You would use the AVAudioCompressedBuffer's AudioBufferList property's data pointer as a the inBuffer argument to AudioFileWriteBytes. Interacting with the C API can get ugly fast, but it's the only way to write straight data to an audio file, short of doing it manually.

    let data  = myAVAudioBufferlist.audioBufferList[0].mBuffers.mData