Recording to AAC from RemoteIO: data is getting written but file unplayable

☆樱花仙子☆ 提交于 2019-11-27 03:54:24

So I finally sorted this out! Ugh, what an information scavenger hunt.

Anyway, here is the bit in the docs for ExtAudioFile that I missed (see bolded text). I wasn't setting this property. Data was being written to my .m4a file but it was unreadable at playback. So to sum up: I have a bunch of AUSamplers -> AUMixer -> RemoteIO. A render callback on the RemoteIO instance writes the data out to disk in a compressed m4a format. So it is possible to generate compressed audio on the fly (iOS 5/iPad 2)

Seems pretty robust - I had some printf statements in the rendercallback and the write worked fine.

Yay!

ExtAudioFileProperty_CodecManufacturer The manufacturer of the codec to be used by the extended audio file object. Value is a read/write UInt32. You must specify this property before setting the kExtAudioFileProperty_ClientDataFormat (page 20) property, which in turn triggers the creation of the codec. Use this property in iOS to choose between a hardware or software encoder, by specifying kAppleHardwareAudioCodecManufacturer or kAppleSoftwareAudioCodecManufacturer. Available in Mac OS X v10.7 and later. Declared in ExtendedAudioFile.h.

// specify codec
UInt32 codec = kAppleHardwareAudioCodecManufacturer;
size = sizeof(codec);
result = ExtAudioFileSetProperty(extAudioFileRef, 
                                 kExtAudioFileProperty_CodecManufacturer, 
                                 size, 
                                 &codec);

if(result) printf("ExtAudioFileSetProperty %ld \n", result);

Did you write the magic cookie required at the start of an mpg 4 audio file?

You also need to do at least the first file write outside of the audio unit render callback.

Added:

Did you flush and close the audio file properly at the end? (outside of the AU callback)

rmigneco

It appears there's a little bit more to this than just specifying the Codec for the output audio file ID.

According to this thread: ExtAudioFileWrite to m4a/aac failing on dual-core devices (ipad 2, iphone 4s) certain iPhone models (4S) for example, don't play nice with the hardware decoder.

From my experience with a 4S, trying to encode an AAC file with the hardware codec either a) works sometimes, b) fails with an error -66567 (kExtAudioFileError_MaxPacketSizeUnknown) or c) writes a few samples out and then just hangs with no traceable error.

The software codec works fine on an iPhone 4S at the expense of slower performance.

Edit: Some are claiming that the hardware codec doesn't like 44.1kHz sample rate. I have yet to confirm this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!