I am trying to convert the RAW PCM buffers to G711u Codec in IOS using Audio Toolbox. I see many code examples working for the AAC codec using the same code and APIs.But when I try to do it for PCMU then it is not working. AudioConverter is setup with no errors but when I try to query the output packet size in AudioConverterGetProperty then it returns value of 2 which seems wrong to me because when I use same code for AAC codec then it returns output packet size of 600. Below here I paste my code and thanks in advance to help me out in this .
=====Source Code ===========
OSStatus result = 0;
AudioStreamBasicDescription in = {0}, out = {0};
in.mSampleRate = frequencyInHz;
in.mChannelsPerFrame = channelCount;
in.mBitsPerChannel = 16;
in.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
in.mFormatID = kAudioFormatLinearPCM;
in.mFramesPerPacket = 1;
in.mBytesPerFrame = in.mBitsPerChannel * in.mChannelsPerFrame / 8;
in.mBytesPerPacket = in.mFramesPerPacket*in.mBytesPerFrame;
m_in = in;
out.mFormatID = kAudioFormatULaw;
out.mFormatFlags = 0;
out.mFramesPerPacket = kSamplesPerFrame;
out.mSampleRate = frequencyInHz;
out.mChannelsPerFrame = channelCount;
m_out = out;
UInt32 outputBitrate = bitrate;
UInt32 propSize = sizeof(outputBitrate);
UInt32 outputPacketSize = 1024;
const OSType subtype = kAudioFormatULaw;
AudioClassDescription requestedCodecs[2] = {
{
kAudioEncoderComponentType,
subtype,
kAppleSoftwareAudioCodecManufacturer
},
{
kAudioEncoderComponentType,
subtype,
kAppleHardwareAudioCodecManufacturer
}
};
result = AudioConverterNewSpecific(&in, &out, 2, requestedCodecs, &m_audioConverter);
if(result !=0) {
DLog("Error AudioConverterNewSpecific %x \n", (int)result);
}
result = AudioConverterSetProperty(m_audioConverter, kAudioConverterEncodeBitRate, propSize, &outputBitrate);
if(result !=0) {
DLog("Error AudioConverterSetProperty %x \n", (int)result);
}
result = AudioConverterGetProperty(m_audioConverter, kAudioConverterPropertyMaximumOutputPacketSize, &propSize, &outputPacketSize);
if(result !=0) {
DLog("Error AudioConverterGetProperty %x \n", (int)result);
}
DLog("The output packet size is %x \n", (int)outputPacketSize);
======Output============
Error AudioConverterSetProperty 70726f70
The output packet size is 2
The problem is that the output packet size is returned to 2 and when I try to use the encoder then it gives me the output in 2 bytes for each call. I think we are not receiving the correct output packet size . How to correct it?