I am currently working on cross platform Voip app development based on Xamarin.iOS platform. I did search about the AEC implementation on iOS but most topics are related to Objective-C. What I have already achieved now is: I could use Audiotoolbox (audio queue) to obtain the input raw sound data from mic and send it out with socket. But during testing with other device, I am experiencing very clear echo on the phone. Here is code:
private void SetupInputQueue()
{
inputQueue = new InputAudioQueue(audioStreamBasicDescription);
//sendbuffer initialization
heading = Encoding.ASCII.GetBytes("msg ");
sendBuffer = new byte[CountAudioBuffers][];
for (int i = 0; i < CountAudioBuffers; i++)
{
sendBuffer[i] = new byte[516];
for (int j = 0; j < heading.Length; j++)
{
sendBuffer[i][j] = heading[j];
}
}
for (int count = 0; count < CountAudioBuffers; count++)
{
IntPtr bufferpointer;
inputQueue.AllocateBuffer(AudioBufferLength, out bufferpointer);
inputQueue.EnqueueBuffer(bufferpointer, AudioBufferLength, null);
}
inputQueue.InputCompleted += HandleInputCompleted;
}
private void HandleInputCompleted(object sender, InputCompletedEventArgs e)
{
unsafe
{
byte* shortPtr = (byte*)e.UnsafeBuffer->AudioData;
for (int count = heading.Length; count < sendBuffer[sendOutIndex].Length; count++)
{
sendBuffer[sendOutIndex][count] = *shortPtr;
shortPtr++;
}
}
socket.SendTo(sendBuffer[sendOutIndex], master);
this.inputQueue.EnqueueBuffer(e.IntPtrBuffer, AudioBufferLength, null);
sendOutIndex = (sendOutIndex + 1) % CountAudioBuffers;
}
According to AEC on OSX using AudioQueue, I learnt the hint that I should pass the raw sound data to I/O unit (audio unit?). But due to the lack of examples in Xamarin.iOS(c#), I can't figure out how to implement this process in detail. Could any one familiar with Voip app development on Xamarin platform give me some example to study? Very appreciate any help or hint on this.
(Nov, 21, 2018)Some related posts I found:Record audio with audio unit Audio unit Callbacks An audio unit example