Linux 简单的 C++ 声音 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9981087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple C++ Sound API
提问by Rocky
My commercial embedded C++ Linux project requires playing wav files and tones at individual volume levels concurrently. A few examples of the sounds:
我的商业嵌入式 C++ Linux 项目需要同时播放单个音量级别的 wav 文件和音调。一些声音的例子:
? “Click” sounds each time user presses screen played at a user-specified volume
? Warning sounds played at max-volume
? Warning tones requested by other applications at app-specified volume level (0-100%)
? Future support for MP3 player and/or video playback (with sound) at user-specified volume. All other sounds should continue while song/video is playing.
? 每次用户按下以用户指定音量播放的屏幕时都会发出“咔嗒”声
? 警告声音以最大音量播放
?其他应用程序在应用程序指定的音量级别 (0-100%) 请求的警告音
? 未来支持用户指定音量的 MP3 播放器和/或视频播放(带声音)。播放歌曲/视频时,所有其他声音都应继续。
We're using Qt as our UI framework which has QtMultimedia and Phonon support. However, I heard the former has spotty sound support on Linux and the latter is an older version and may be deprecated in an upcoming Qt release.
我们使用 Qt 作为我们的 UI 框架,它支持 QtMultimedia 和 Phonon。但是,我听说前者在 Linux 上的声音支持参差不齐,而后者是旧版本,可能会在即将发布的 Qt 版本中弃用。
I've done some research and here are a few APIs I've come across:
KDE Phonon
SFML
PortAudio
SDL_Mixer
OpenAL Soft
FMOD(though I'd prefer to avoid license fees)
ALSA(perhaps a bit too low-level...)
我做了一些研究,这里有一些我遇到的 API:
KDE Phonon
SFML
PortAudio
SDL_Mixer
OpenAL Soft
FMOD(虽然我更愿意避免许可费用)
ALSA(可能有点太低级了......)
Other considerations: Cross-platform isn't required but preferred. We'd like to limit dependencies as much as possible. There is no need for advanced features like 3D audio or special effects in the foreseeable future. My team doesn't have much audio experience so ease-of-use is important.
其他注意事项:跨平台不是必需的,但首选。我们希望尽可能地限制依赖。在可预见的未来,不需要 3D 音频或特效等高级功能。我的团队没有太多的音频经验,所以易用性很重要。
Are any of these overkill for my application? Which seems like the best fit?
这些对我的应用程序来说是否有些矫枉过正?哪个看起来最合适?
Update:It turns out we were already dependent on SDL for other reasons so we decided on SDL_Mixer. For other Embedded applications, however, I'd take a long at the PortAudio/libsndfile combo as well due to their minimal dependencies.
更新:事实证明,由于其他原因,我们已经依赖 SDL,因此我们决定使用 SDL_Mixer。但是,对于其他嵌入式应用程序,由于它们的依赖性最小,我也会在 PortAudio/libsndfile 组合上花很长时间。
采纳答案by iKlsR
i have used SDL_Mixer time and time again, lovely library, it should serve well for your needs, the license is flexible and its heavily documented. i have also experimented with SFML, while more modern and fairly documented, i find it a bit bulky and cumbersome to work with even tho both libraries are very similar. imo SDL_Mixer is the best.
我一次又一次地使用 SDL_Mixer,可爱的库,它应该可以很好地满足您的需求,许可证很灵活,并且有大量文档记录。我也尝试过 SFML,虽然更现代且文档齐全,但我发现使用它有点笨重和麻烦,即使两个库非常相似。imo SDL_Mixer 是最好的。
however you might also want to check out this one i found a few weeks ago http://www.mpg123.de/, i haven't delved too much into it, but it is very lightweight and again the license is flexible.
但是,您可能还想看看我几周前发现的这个http://www.mpg123.de/,我没有深入研究它,但它非常轻巧,而且许可证也很灵活。
回答by Mario
There is a sound library called STK that would meet most of your requirements:
有一个名为 STK 的声音库可以满足您的大部分要求:
回答by karlphillip
Don't forget about:
不要忘记:
FFmpeg: is a complete, cross-platform solution to record, convert and stream audio and video.
GStreamer: is a library for constructing graphs of media-handling components. The applications it supports range from simple Ogg/Vorbis playback, audio/video streaming to complex audio (mixing) and video (non-linear editing) processing.
回答by gnud
libaois simple, cross-platform, Xiphy goodness. There's documentationtoo!
Usage is outlined here- simple usage goes like this:
- Initialize (
ao_initialize()
) - Call
ao_open_live()
orao_open_file()
- Play sound using
ao_play()
- Close device/file using
ao_close()
and thenao_shutdown()
to clean up.
- 初始化 (
ao_initialize()
) - 打电话
ao_open_live()
或ao_open_file()
- 播放声音使用
ao_play()
- 使用 关闭设备/文件
ao_close()
,然后ao_shutdown()
进行清理。
回答by André Bergner
Go for PortAudio. For just plain audio without unneeded overhead such as complex streaming pipelines, or 3D, it is the best lib out there. In addition you have really nice cross-platform support. It is used by several professional audio programs and has really high quality.
去 PortAudio。对于没有不必要开销的纯音频,例如复杂的流媒体管道或 3D,它是最好的库。此外,您还有非常好的跨平台支持。它被多个专业音频程序使用并且具有非常高的质量。