I have 1 second of PCM data that I write to the AAC file successfully.
However, I cannot control the bitrate of the output file.
Here is the configuration of my AAC codec:
AudioStreamBasicDescription clientFormat = {0}; clientFormat.mSampleRate = 44100; clientFormat.mFormatID = kAudioFormatMPEG4AAC; clientFormat.mFormatFlags = kMPEG4Object_AAC_Main; clientFormat.mChannelsPerFrame = 2; clientFormat.mBytesPerPacket = 0; clientFormat.mBytesPerFrame = 0; clientFormat.mFramesPerPacket = 1024; clientFormat.mBitsPerChannel = 0; clientFormat.mReserved = 0;
As far as I explored other examples, this is the correct way to set the bitrate:
AudioConverterRef acRef; UInt32 acsize = sizeof(acRef); UInt32 bitRateIn = 96000; ExtAudioFileGetProperty(audiofileRef, kExtAudioFileProperty_AudioConverter, &acsize, &acRef); AudioConverterSetProperty(acRef, kAudioConverterEncodeBitRate, sizeof(UInt32), &bitRateIn);
After that I write my data to a file.
Since the file is 1 second and the bit is 96 kbps, the output file should be around 96/8 = 12 kilobytes. But the output file is about 62 kilobytes.
After getting this strange behavior, I opened the file using MediaInfo and had 3 different bitrates:
The nominal bitrate is 96kb / s (this is what I set)
Bitrate - 48kb / s
Total bitrate - 476kb / s

Here, the file size corresponds to the total bitrate, since 476/8 = 59 kilobytes (the rest are metadata and headers).
How to set the bitrate?