简体   繁体   English

Linux下C ++音频捕获API的最佳实践?

[英]Best practice for C++ audio capture API under Linux?

I need to create a C++ application with a simple audio recording from microphone functionality. 我需要创建一个具有麦克风功能的简单音频录制的C ++应用程序。

I can't say that there aren't enough audio APIs to do this! 我不能说没有足够的音频API可以做到这一点! Pulse, ALSA, /dev/dsp, OpenAL, etc. My question is what is the current "Best practice" API? Pulse,ALSA,/ dev / dsp,OpenAL等。我的问题是当前的“最佳实践” API是什么?

Pulse seems supported by most modern distros, but seems almost devoid of documentation. Pulse似乎受到大多数现代发行版的支持,但似乎几乎没有文档。 Will OpenAL be supported across different distros, or is it too obscure? OpenAL是否会在不同发行版中得到支持,还是太晦涩? Have I missed any? 我错过了吗?
Is there not a simple answer? 有没有简单的答案?


Lennart Pottering has a guide here: Lennart Pottering在这里有一个指南:

http://0pointer.de/blog/projects/guide-to-sound-apis http://0pointer.de/blog/projects/guide-to-sound-apis

basically use the 'safe' subset of alsa then all the other important ones should work too. 基本上使用alsa的“安全”子集,那么所有其他重要子集也应该起作用。

Barring that OpenAL works on Linux 除非OpenAL在Linux上有效

EDIT: Also pulseaudio has reasonably good doxygen generated documentation here and some other stuff here and some of the utilities are good examples, you can see them in gitweb here 编辑:也有相当不错的doxygen生成的文档的PulseAudio 这里和一些其他的东西在这里和一些工具,都是很好的例子,你可以看到的GitWeb他们在这里

Also I've written some code that uses pulse for audio input you can look at it here , however I'm not sure I handle everything totally correctly, and I know I'm missing code to handle certain situations... but that should get you started should you go with pulse. 另外,我已经编写了一些使用脉冲进行音频输入的代码,您可以在此处查看 ,但是我不确定我是否能完全正确地处理所有事情,而且我知道我缺少处理某些情况的代码...但是那应该让您开始工作吧。

there is no simple answer; 没有简单的答案; best practise depends on the context and specific use cases that your application will be exposed to. 最佳做法取决于您的应用程序所处的上下文和特定用例。

for the greatest ease of programming and widest audience, i would choose gstreamer as it is quick and straightforward, well integrated in gnome and ubuntu and supports a wide range of audio subsystems and configurations. 为了最大程度地简化编程并吸引最广泛的读者,我会选择gstreamer,因为它快速,简单,很好地集成在gnome和ubuntu中并支持广泛的音频子系统和配置。 it is very flexible. 这是非常灵活的。

for example, the command: 例如,命令:

gst-launch autoaudiosrc ! audioconvert ! flacenc ! filesink location="foo.flac"

will create a .flac file from microphone input, regardless of the audio system (Pulse, ALSA, ESD ...). 不管音频系统(脉冲,ALSA,ESD ...)如何,都会通过麦克风输入创建一个.flac文件。 an equivalent pipeline can be written using the c / gobject bindings as documented here . 可以使用此处记录的c / gobject绑定编写等效的管道。

ps the above command requires the gstreamer-tools package ps上面的命令需要gstreamer-tools软件包

GStreamer将在声音捕获方面为您和最终用户提供最大的灵活性,但是它的跨平台可行性并不那么好,尤其是在OS X上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM