开发者

How to synchronize AudioRecord and AudioTrack

Is there any way to synchronize the capturing and playback of audio data in An开发者_StackOverflow社区droid?

I need to do some signal processing (echo cancellation, etc.) that needs synchronization at sample level.

I.e. everey time the hardware captures an audio frame, I need the corresponding frame that was played through the speaker with high accuracy.

Any help or hint is really appreciated. Thanks in advance.

-flesym


I was able to get echo cancellation to work on my Arm5 (WM8650) processor. Below are the steps I took:

  1. I wrapped Speex with JNI and called echo processing routines before sending PCM frames to encoder. No echo was canceled no matter what Speex settings I tried.

  2. Because Speex is very sensitive to delay between playback and echo frames I implemented a queue and queued all packets sent to AudioTrack. The size of the queue should be roughly equal to the size of internal AudioTrack buffer. This way packet were sent to echo_playback roughly at the time when AudioTrack send packets to the sound card from its internal buffer. The delay was removed with this approach but echo was still not cancelled

  3. I wrapped WebRtc echo cancellation part with JNI and called its methods before sending packets to encoder. The echo was still present but the library obviously was trying to cancel it.

  4. I applied the buffer technique described in P2 and it finally started to work. The delay needs to be adjusted for each device though. Note also that WebRtc has mobile and full version of echo cancellation. The full version substantially slows the processor and should probably be run on ARM7 only. The mobile version works but with lower quality

I hope this will help someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜