如何同步AudioRecord和AudioTrack

发布于 2024-09-02 10:28:05 字数 154 浏览 7 评论 0原文

Android中有没有办法同步音频数据的采集和播放?

我需要进行一些需要在样本级别同步的信号处理(回声消除等)。

即每次硬件捕获音频帧时,我都需要通过扬声器高精度播放的相应帧。

非常感谢任何帮助或提示。提前致谢。

-flesym

Is there any way to synchronize the capturing and playback of audio data in Android?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南烟雨〆相思醉 2024-09-09 10:28:05

我能够在我的 Arm5 (WM8650) 处理器上使用回声消除功能。以下是我采取的步骤:

  1. 我用 JNI 封装了 Speex,并在将 PCM 帧发送到编码器之前调用回声处理例程。无论我尝试什么 Speex 设置,都没有取消回声。

  2. 因为 Speex 对播放和回显帧之间的延迟非常敏感,所以我实现了一个队列并对发送到 AudioTrack 的所有数据包进行排队。队列的大小应大致等于内部 AudioTrack 缓冲区的大小。这样,当 AudioTrack 将数据包从其内部缓冲区发送到声卡时,数据包大致会发送到 echo_playback。通过这种方法消除了延迟,但回声仍然没有取消

  3. 我用 JNI 封装了 WebRtc 回声消除部分,并在将数据包发送到编码器之前调用其方法。回声仍然存在,但库显然正在尝试取消它。

  4. 我应用了 P2 中描述的缓冲技术,它终于开始工作了。不过,需要针对每个设备调整延迟。另请注意,WebRtc 有移动版和完整版的回声消除功能。完整版本会大大降低处理器速度,并且可能只能在 ARM7 上运行。移动版本可以工作,但质量较低

我希望这会对某人有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文