Linux、C++音频捕获(仅麦克风)库

发布于 2024-09-05 07:35:26 字数 863 浏览 4 评论 0原文

我正在开发一个音乐游戏,它就像一个歌手,但你必须演奏 录音机< /a>.它名为 oFrude,仍处于早期开发阶段。

在游戏中,我捕获麦克风输入,然后运行简单的 FFT 分析,并将结果与​​典型录音机的频率进行比较,从而获得演奏的音符。

一开始,我使用的音频库是 RtAudio,但我不知道不记得为什么我切换到 PortAudio,这是我目前正在使用的。 问题是,它有时会随机崩溃或停止捕获,就像麦克风没有发出声音一样。

我的问题是,在 Linux 上捕获麦克风输入的最佳选择是什么?我只需要打开、读取和关闭来自麦克风的字节流。

我一直在阅读本指南,并且(un)令人惊讶的是它说:

我不认为 PortAudio 对于类 Unix 操作系统来说是非常好的 API。

那么,你推荐我什么?

I'm developing a musical game, it's like a singstar but instead of singing, you have to play the recorder. It's called oFlute, and it's still in early development stage.

In the game, I capture the microphone input, then run a simple FFT analysis and compare the results to typical recorder's frequencies, thus getting the played note.

At the beginning, the audio library I was using was RtAudio, but I don't remember why I switched to PortAudio, which is what I'm currently using. The problem is that, from time to time, either it crashes randomly or stops capturing, like if there were no sound coming from the microphone.

My question is, what's the best option to capture microphone input on Linux? I just need to open, read, and close a flow of bytes from the microphone.

I've been reading this guide, and (un)surprisingly it says:

I don't think that PortAudio is very good API for Unix-like operating systems.

So, what do you recommend me?

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

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

发布评论

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

评论(1

墨小墨 2024-09-12 07:35:26

考虑到其他选项,PortAudio 是一个奇怪的选择。

我个人会从一切事物中抽象出来并使用 GStreamer。 Linux 上的音频可能会变得一团糟(作为一个长期的受害者)。让 Gstreamer 处理这个问题可以让您忘记它,继续前进,而不必再次考虑它。

不过,OpenAL 可能是最受游戏开发人员欢迎的,它应该支持大多数系统(尽管您会“享受”它与 PulseAudio 完美配合的乐趣)。

我当然会确保你正在为最流行的设置(我认为目前是 PulseAudio)进行开发,这样你就不会最终陷入这样的境地:你发布了,然后你就陷入了一群人呻吟的境地。关于声音不起作用。

不要听关于 PulseAudio 的废话 - 它可能是新的,并且可能比准系统 ALSA 系统占用更多的资源,但它肯定不会陷入延迟问题。对于现代桌面发行版来说,要求人们删除它并不是一个选项,因为它集成得如此紧密(而且也很有用)。

PortAudio is a strange choice given the other options.

I would personally abstract away from everything and use GStreamer. Audio can be a horrible mess on Linux (speaking as a long term sufferer). Letting Gstreamer deal with that lets you forget about it, move along and not have to think about it again.

OpenAL is probably the most popular for game dev though and it should support most systems (although you will have "fun" getting it playing nice with PulseAudio).

I'd certainly make sure you're developing for the most popular setup (which is PulseAudio at the moment, I reckon) so you don't end up in a situation where you release and you're plunged into a pool of people moaning about the sound not working.

And don't listen to the nonsense about PulseAudio - it might be new and it might take up a few more resources than a barebones ALSA system but it's certainly not mired with latency issues. Asking people to remove it isn't an option with modern desktop distros as it's so tightly integrated (and useful too).

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