dyah
dyah

Reputation: 73

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!

Upvotes: 2

Views: 1803

Answers (2)

CocoaNuts
CocoaNuts

Reputation: 189

The easiest way I found was to convert the uncompressed AVAudioPCMBuffer to CMSampleBuffer and then use AVAssetWriter to write the audio samples to file. The asset writer can handle format compression to AAC.

I haven't tried this, but you can also probably use the audio buffer list from AVAudioCompressedBuffer and construct CMSampleBuffers.

Upvotes: 0

dave234
dave234

Reputation: 4955

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

Upvotes: 3

Related Questions