Android 中的实时音频处理

发布于 2024-12-26 03:19:49 字数 1003 浏览 1 评论 0原文

我正在使用 AudioRecord.read 将 PCM 数据捕获为字节。 但是,我发现它限制了初始化具有至少 3904 个缓冲区的 AudioRecord 对象。其中采样率为44100。 由于我需要对数据执行 FFT,因此我将样本增加到 4096。 因此,回调每 40-60 毫秒运行一次,将 setPositionNotificationPeriod 设置为 500。由于进一步减少持续时间,因此不会进行任何更改。 我想知道以下配置是否是最快的回调时间?

采样率:44100

通道:单声道

编码:PCM 16 BIT

缓冲区大小:4096

(我不确定它是 4096 还是 2048,因为我每次读取 4096 字节,它只能填充 2048 2 字节缓冲区)

即使 40-60ms 也是可以接受的,然后我执行 FFT,最终阻止每个回调大约 200-300 毫秒。而且仍然存在很多影响精度的噪声。 我正在使用这些源代码: FFT in Java 和 < a href="http://introcs.cs.princeton.edu/java/97data/Complex.java.html" rel="nofollow">复杂类

是否还有其他执行快速、可靠且消耗的选择较少的内存处理FFT? 我发现上面的类新了太多对象并弹出大量垃圾收集消息。

总之,我有 3 个问题:

  1. 初始 bufferSize 是否等于我可以从 .read 方法读取的缓冲区?
  2. 40-60ms 是捕获 44100 采样率音频数据的限制吗?
  3. 您能否推荐一些 FFT 库,以便我在处理 FFT 时可以有更好的性能? (我认为使用C代码库是否更好?)

抱歉我的英语不好,也感谢您花时间回答我的问题。

PS我在iOS上尝试过,它只能以44100采样率采集512个样本。所以每次回调只需要大约10ms。

I am using AudioRecord.read to capture PCM data to bytes.
However, I found that it restricted to initialize the AudioRecord object with at least 3904 buffers. Where the sampling rate is 44100.
Since I need to perform FFT of the data so I increased the samples to 4096.
As a result, the callback runs every 40-60ms by setPositionNotificationPeriod to 500. Since a further decrease the duration doesn't make any changes.
I'm wondoring if it is the fastest callback time with below configuration?

Sampling Rate: 44100

Channel: Mono

Encoding: PCM 16 BIT

BufferSize: 4096

(Im not sure if it is 4096 or 2048 since I read 4096 bytes every time and it can only fill 2048 2bytes buffer)

even 40-60ms is acceptable, I then perform FFT which eventually block each callback around 200-300ms. And there is still many noise affecting the accuracy.
I'm using these source code: FFT in Java and Complex class

Is there any other choice that perform fast, reliable and consume less memory processing FFT?
I found that the above classes new too much objects and pop up loads of gragarbage collection's messages.

In conclude, I have 3 questions:

  1. Is the initial bufferSize equal to the buffers that I can read from the .read method?
  2. Is 40-60ms the limitation to capture audio data with 44100 sampling rate?
  3. Could you suggest some FFT library so that I can have a better performance in processing FFT? (I think if it is better to use C code library?)

Sorry for my bad english, also thank you for spending your time on my question.

P.S I tried it on iOS and it can just take 512 samples with 44100 sampling rate. So every callback takes around 10ms only.

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

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

发布评论

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

评论(1

始终不够 2025-01-02 03:19:49

关于问题#3:也许不如本机库那么快,但我已经开始使用这些类,并且它们似乎适合实时工作(尽管我是从文件而不是麦克风中读取):FFPack

最常见的本机库是 KissFFT,您可以找到它作为 libGDX 的一部分针对 Android 编译的库。

Regarding question #3: Maybe not as fast as a native library, but I've started using these classes, and they seem to be fine for real-time work (although I am reading from files, not the microphone): FFTPack.

The most common native library is KissFFT, which you can find compiled for Android as part of libGDX.

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