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 --

    InitiateAecm()

    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).
         

    Playback()

        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
            then,
                fetch the data from delay buffer and add it to the latency buffer
                and remove it from delay buffer.
        else
            nothing to do.


    Capture()
       
        if latency buffer not full with real playe frame data
            then,
                nothing to do.

        else
            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
                then,
                    fetch the frame data from delay buffer and add it to the
                    latency buffer.

            else
                store a demo frame in the latency buffer. 



       

How to enable hotspot in TPG iPhone

 By default, the hotspot does not work on the phone. It will ask you to contact the provider. This video will help you bypass the network ...