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.