I have extracted relevant code from an app as follows:
OutputAudioQueue _audioQueue = new OutputAudioQueue(new AudioStreamBasicDescription()
{
Format = AudioFormatType.MPEG4AAC_HE,
BytesPerFrame = 0, //Set this field to 0 for compressed formats.
SampleRate = 16000,
ChannelsPerFrame = 1,
FramesPerPacket = 1024 //for AAC. According to Appple's document
});
for (int i = 0; i < 10; i++)
{
IntPtr ipBuffer;
_audioQueue.AllocateBuffer(BufferSize, out ipBuffer);
_qFreeAudioOutputBuffers.Enqueue(ipBuffer);
}
...
if (_qFreeAudioOutputBuffers.TryDequeue(out ipBuffer))
{
Marshal.Copy(abData, 0, ipBuffer, abData.Length);
AudioStreamPacketDescription aspDescription = new AudioStreamPacketDescription()
{
DataByteSize = abData.Length,
StartOffset = 0,
VariableFramesInPacket = 0 //The codec should be able to know the number of frames based on supplied AudioStreamBasicDescription
};
AudioQueueStatus aqStatus = _audioQueue.EnqueueBuffer(ipBuffer, new AudioStreamPacketDescription[] { aspDescription });
Console.WriteLine("Queued audio sample with status: " + aqStatus);
}
audioQueue.EnqueueBuffer() keeps generating aqStatus: GeneralParamError.
Could anyone shed some light on this? What are the possible causes?