来自麦克风的 OpenAL 实时音频处理
我想编写一个跨平台应用程序,可以实时处理和回放麦克风数据。想象一下作为概念验证的聊天室,人们可以在其中互相交谈并对他们的声音应用过滤器。 OpenAL 适合这个吗?如果没有,有人可以提供替代方案吗?此外,如果有人可以向我提供或链接到一个简单的“hello world”程序,该程序从麦克风读取数据并将输出吐出,那就太棒了。
谢谢!
I would like to write a cross-platform application that can process and play back microphone data in real time. Imagine as a proof of concept a chat room where people can talk to each other and apply filters to their voices. Is OpenAL appropriate for this? If not, can someone provide an alternative? Additionally, if anyone can provide or link me to a simple "hello world" program that reads from the microphone and spits the output back out, that would be awesome.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenAL 可能不太适合这个目的。我建议使用 SDL(也许使用 SDL_Mixer)或 PortAudio。两者都是跨平台的,并且都相当易于使用。
要使用 OpenAL 实现此目的,您必须轮询以查看隐藏的循环缓冲区中累积了多少样本。当你决定准备好时,你就可以把它们拿出来。然后应用过滤器。然后将过滤后的数据附加到缓冲区。然后将缓冲区排队到源上并告诉源播放(除非它已经在播放)。在我看来,OpenAL 的优势在于应用 3D 效果。它在实时过滤方面并不那么出色,尽管我希望如果您愿意接受输出上的一点延迟,您可以使其发挥作用。我更喜欢回调模型而不是缓冲区对象模型来进行过滤。
编辑:我发布了一些代码,可以在以下位置执行此操作: OpenAL:如何创建简单的“麦克风回声”程序? 注释指出了将处理放在哪里。
OpenAL might not be great for this purpose. I would recommend using SDL (perhaps with SDL_Mixer) or PortAudio. Both are cross-platform and both are fairly easy to use.
To use OpenAL for this purpose you have to poll to see how many samples have accumulated in a hidden circular buffer. Then you grab them out when you decide you're ready. Then you apply your filter. Then you attach the filtered data to a buffer. Then you queue the buffer onto a source and tell the source to play (unless it's already playing). The strength of OpenAL, in my opinion, is for applying 3D effects. It's not as great at real-time filtering, although I expect you can make it work if you're willing to accept a little more lag on the output. I prefer the callback model over the buffer-object model for filtering.
Edit: I posted some code that would do exactly this over at: OpenAL: How to create simple "Microphone Echo" programm? A comment points out where one would put the processing.
根据 API,OpenAL 在技术上能够实现此功能,但 Apple 的 iOS 实现不包括音频捕获功能。
在 iOS 上,您需要使用音频队列或音频单元进行录制。对于应用实时效果,音频单元是最佳选择,尽管比音频队列复杂得多。
OpenAL is technically capable of it according to the API, but Apple's implementation for iOS doesn't include the audio capture features.
On iOS, you'll need to either use Audio Queues or Audio Units to record. For applying realtime effects, Audio Units is the way to go, though much more complicated than Audio Queues.
苹果有两个(或更多)样本可以做到这一点。查看 aurioTouch 和 SpeakHere。 aurioTouch 可以接受麦克风输入并回放,SpeakHere 可以接受输入并录制它,您可以很容易地修改它来回放。
Apple has two samples (or more) that do that. Check out aurioTouch and SpeakHere. aurioTouch can take mic input and play it back and SpeakHere can take in input and record it, and you can pretty easily modify it to play that back.