I have been trying to record from a RemoteIO unit directly to AAC in a renderCallback in iOS 5 on an iPad 2. I have seen conflicting info saying it is not possible & tha
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)
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.