本文介绍了跨平台音频API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找到发展,这将需要音频直播的应用程序。我想preFER使用一些跨平台(Windows / Linux的/ BSD)开源库用C或C ++,即使使用各自的操作系统声音API写它仍是一个选项。

I'm looking into developing an application that will require live streaming of audio. I would prefer to use some cross-platform (windows/linux/BSD) open source library written in C or C++ even though writing it using the respective OSs' Sound APIs is still an option.

我读了一些关于各种声音库,包括SFML,SDL和PortAudio。诚然,我还没有足够的研究声音左右了FreeBSD和Linux(多么相似是这2间?)

I have read a bit about various sound libraries, including SFML, SDL and PortAudio. Admittedly, I have not yet researched enough about Sound in FreeBSD and Linux (how similar is it between these 2?)

主要要求将


  1. 从选定的麦克风来获取音频/麦克风通过网络发送,

  2. 将数据发送到一个选择的输出设备,

  3. 过程中的声音(过滤,清理噪音,复流等),但可以做到这一点,一旦我有音频数据,库本身并不需要能够做任何这一点。

  4. 有合理的低时延

我主要关心的是,这些提到的API似乎主要是针对游戏(如声音通常是从磁盘加载并没有太多,如果有的话,录音参与,而不是与记录之间同等重要流通过网络回放。

My main concern is that these mentioned APIs seem to be mainly targeted for Games (where sound is usually loaded from disk and there is not much, if any, sound recording involved rather than streamed over the network with equal importance between recording and playback.

有没有人有关于这些或其他声音的API或任何指针/警告/建议有关的各个OS的API去了漫长的道路,实施这一优势/劣势?

Does anyone have any pointers/warnings/suggestions regarding these or other sound APIs or about the advantages/disadvantages of going the long way and implementing this in the respective OSs' APIs?

请注意:
而这样的:问题要求我们建议还是找一本书,工具,软件库,教程或其他异地的资源是题外话堆栈溢出确实让题外话的问题,当一个人还认为因为他们往往吸引自以为是的答案和垃圾邮件那么我不认为这个问题应该关闭。有人找描述将pssed找到任何和这个问题的答案几乎总结了所有可用的选项硬$ P $这样的库。因此,这是在一般涵盖...程序员常用的软件工具;接受答案的范畴。

NOTE:while this: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow " DOES make the question off-topic, when one also considers "as they tend to attract opinionated answers and spam" then I do not think this question should be closed. Someone looking for such a library as described will be hard-pressed to find anything and the answers to this question practically summarize all available options. This is thus in the "generally covers...software tools commonly used by programmers;" category of accepted answers.

推荐答案

PortAudio是你所描述的应用程序的最佳选择 - 它运行在所有这些平台,用C语言编写,提供低延迟,并有两个回调和阻塞I / O选项。它绝对符合您的要求,并且是的没有特别针对的在比赛。事实上,我会说有其他的API,是游戏更好,而PortAudio是通用音频更好的I / O,如像你这样的VoIP的应用程序一样,音频播放器,专业音频应用,音频录制,软件无线电,等等。

PortAudio is an excellent choice for the application you are describing -- it runs on all those platforms, is written in C, provides low-latency, and has both callback and blocking I/O options. It definitely meets your requirements, and is not particularly aimed at games. In fact, I would say there are other apis that are better for games, whereas PortAudio is better for general purpose audio I/O such as voip-like applications like yours, audio players, pro-audio applications, audio recording, software radios, etc.

您可以考虑另一种选择是RTAudio,这我不熟悉。我的理解是这是一个有点简单(没有阻塞I / O据我所知),并有更多的平台,包括移动操作系统的支持,虽然PortAudio人们正在就这一工作。

Another option you might consider is RTAudio, which I am not as familiar with. My understanding is it's a bit simpler (no blocking I/O AFAIK), and has support for more platforms, including mobile OSes, though PortAudio folks are working on that.

您关于FreeBSD与Linux的问题:Linux使用ALSA,而其他的Unix使用OSS。无论OSS和ALSA提供兼容层,因此有ALSA OSS兼容,反之亦然,但在我的经验有两个兼容层错误。也许事情已经得到了,因为我最后一次使用它,但更好的。

Your question about FreeBSD vs. Linux: Linux uses ALSA, while other unixes use OSS. Both OSS and ALSA offer compatibility layers, so ALSA has OSS compatibility and vice versa, but in my experience there are bugs in both compatibility layers. Maybe things have gotten better since I last used it, though.

一些Linux桌面上的ALSA之上运行的PulseAudio。我不知道这是否是FreeBSD的也是如此。出于某种原因,ALSA是独占模式默认配置在大多数系统上。虽然这是很容易在理论上解决,该配置文件是奇怪,大多数用户还没有做它,永远不会,这意味着一旦pulseaudio的接管,你不能访问ALSA设备直接了,所以你可能需要有一个司机的PulseAudio,除非你想使你的用户更改其配置(您可能,如果你的应用需要非常低的延迟)。

Some linux desktops run PulseAudio on top of ALSA. I am not sure if this is true of FreeBSD. For some reason, ALSA is configured in exclusive mode by default on most systems. While this is easy to fix in theory, the config files are weird and most users haven't done it and never will, meaning that once PulseAudio takes over, you can't access the ALSA devices directly anymore, so you may want to have a PulseAudio driver as well, unless you want to make your users change their configuration (which you might if your application requires really low latency).

我是pretty确保PortAudio支持的PulseAudio,尽管它可能会或可能不会在网站上说。我会请在邮件列表和更新在这里。

I am pretty sure PortAudio supports PulseAudio, despite what it may or may not say on the website. I will ask on the mailing list and update here.

更新:有人在邮件列表上认为你可以使用ALSA驱动程序访问的PulseAudio。这是(太棒了!)消息给我,但它是。

UPDATE: someone on the mailing list thought that you can use Alsa drivers to access PulseAudio. That's (great!) news to me, but there it is.

这篇关于跨平台音频API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:27