The CovertFile sample code will fail for input with variable bitrates (VBR), such as MP3 and AAC files. I have updated the sample file /Developer/Examples/CoreAudio/SimpleSDK/ConvertFile with the goal to handle such input.
In order to do this, I have replaced
UInt32 maxPackets = afio->srcBufferSize / afio->srcFormat.mBytesPerPacket;
in the EncoderDataProc (file UseAC-AF.c, line 81) with this:
----> int sizePerPacket = afio->srcFormat.mBytesPerPacket; // this will be non-zero of the format is CBR
if (sizePerPacket == 0) { // we have a VBR format, what's the max packet size? OSStatus err; UInt32 size = sizeof(sizePerPacket); err = AudioConverterGetProperty(inAudioConverter, kAudioConverterPropertyMaximumOutputPacketSize, &size, &sizePerPacket);
}
UInt32 maxPackets = afio->srcBufferSize / sizePerPacket; <----
It is the same code that can be found a little further down in the same file, and with it the sample seems to convert mp3 files to linear PCM flawlessly. However, I am still chewing on AAC (.m4a) files, for which AudioConverterFillComplexBuffer fails with an kAudioFileInvalidPacketOffsetError (the EncoderDataProc is called once, with no apparent error)
If someone has a hint for me there, it would be greatly appreciated.
Thanks
Alex |