Wednesday, November 26, 2014

Google's webRTC AECM for Android Mobile devices in C++

Now a days many of mobile devices comes with built-in hardware echo canceler.  But the low end devices that cost little doesn't have this feature integrated. And moreover the previous older android devices doesn't have the echo canceler. In my journey of echo cancellation I have came across a valuable library that will do everything for you , if you provide it the necessary gasoline .

I have tested this echo canceler tool with my HTC desire 610. Which is pretty cheap and doesn't have any built-in hardware echo canceler.  I have designed an algorithm for capture and playback, which uses ring-buffer, calculate the delay and use the webRTC aecm modules API.

Here we go --


    Set the clock cycle rate.
    Set the echo tail length.
    Set the channel count.
    Set the byte per sample. // it's 2 byte per sample


    Calculate sample per frame.
           sampleperframe = byte per sample * (clock cycle rate) / 100

    Set the output latency. // device play-out latecny

    Calculate the frame play delay.
            frameplaydelay = output latency * 3 / 4

    Initiate the webRTC echo module with clock cycle rate.

        Calculate Audio Play time.
            ptime = sampleperframe * 1000 / clock cycle rate

    Calculate latency buffer size.   
            lateframecount = frameplaydelay / ptime

    Add these late frame in latency buffer with filling demo audio data (with zero).


        Store the played frame in the delay buffer (it will be a FIFO ringbuffer
        with your estimated size).

        Now need to remove the demo frame from latency buffer and add real frame
        to the latency buffer.       
        if the latency buffer not filled with real data
                fetch the data from delay buffer and add it to the latency buffer
                and remove it from delay buffer.
            nothing to do.

        if latency buffer not full with real playe frame data
                nothing to do.

            fetch the data from latency buffer and do the echo cancellation by
            setting this frame as far-end and current capture data as the input.
            remove the used frame data from latency buffer.
            if the delay buffer is not empty
                    fetch the frame data from delay buffer and add it to the
                    latency buffer.

                store a demo frame in the latency buffer. 


No comments:

Post a Comment