Simple C++ Sound API - c++

My commercial embedded C++ Linux project requires playing wav files and tones at individual volume levels concurrently. A few examples of the sounds:
• “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.
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.
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...)
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.
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.

libao is simple, cross-platform, Xiphy goodness.
There's documentation too!
Usage is outlined here - simple usage goes like this:
Initialize (ao_initialize())
Call ao_open_live() or ao_open_file()
Play sound using ao_play()
Close device/file using ao_close() and then ao_shutdown() to clean up.

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.

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.
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.

There is a sound library called STK that would meet most of your requirements:
https://ccrma.stanford.edu/software/stk/faq.html

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.

Related

Cross-platform C/C++ libraries with examples for raw audio record and playback

I'm developing a note-taking utility and want to add a feature for voice-recording and playback in full duplex asynchronous mode.
What cross-platform c/c++ libraries/API's can I evaluate for my purpose? Google isn't much help in this case and the existing QA's on SO doesn't quite cover this.
PortAudio can accomplish what you want. It has lots of backends for different technologies like ALSA, ASIO, DirectSound etc.
Take a look at JUCE. Has lots of audio helpers and numerous other utilities that make for fast development.

Any cross-platform video playback library for c++?

I mainly code using the Qt library, which is cross-platform enough for my need. However, I found out that if I'd like to play a video file there are no good options for cross-platform video playback. The Phonon module doesn't seem to work on my machine and I am not sure if it is supported on the major platforms (Windows, OSX, Linux).
Are their any light-weight alternatives for simple video playback? I would be okay to change my video to any format as long as its playable cross-platform.
I am considering libVLC as one option. Someone have already made a wrapper but it only supports Windows and Linux.
I found the Theora playback library to be very useful and only depends on the original theora library. Here is a simple Qt project I made that encapsulate everything needed to play (only video) theora media. You just type 'qmake' and you are good to go.
According to the documentation is appears Phonon needs third party libraries to work correctly. Have you installed the appropriate backend to the platform you're on?
From the documentation:
Backends
The multimedia functionality is not implemented by Phonon itself, but
by a back end - often also referred to as an engine. This includes
connecting to, managing, and driving the underlying hardware or
intermediate technology. For the programmer, this implies that the
media nodes, e.g., media objects, processors, and sinks, are produced
by the back end. Also, it is responsible for building the graph, i.e.,
connecting the nodes. The backends of Qt use the media systems
DirectShow (which requires DirectX) on Windows, QuickTime on Mac, and
GStreamer on Linux. The functionality provided on the different
platforms are dependent on these underlying systems and may vary
somewhat, e.g., in the media formats supported.
Backends expose
information about the underlying system. It can tell which media
formats are supported, e.g., AVI, mp3, or OGG.
A user can often add
support for new formats and filters to the underlying system, by, for
instance, installing the DivX codex. We can therefore not give an
exact overview of which formats are available with the Qt backends.
QtWebKit 2.2 has support for HTML5 media. It should (at least eventually) be pretty cross-platform, but probably has the same backend issues as Phonon. But a Q(Graphics)WebView with a <video> element could do the trick for a truly play-and-forget solution.

Playing Sound in C++

I need to play sound in C++.
It should be compatible across all platforms.
Thanks,
goerdy
Try OpenAL, FMOD or SDL_mixer. The choice is wide.
std::cout << "\a\a\a\a\a\a\a\a";
)))
My suggestion is to go with OpenAl (3D cross platform Audio API)
It's fairly easy to learn and meant to have a similar flow of programming as OpenGl. It's free and has different extensions to take advantage of sound cards. OpenAl has a library akin to OpenGl's Utility Toolkit (GLUT) that's called freealut. It makes things even simpler.
This might be a good place to get started:
http://www.devmaster.net/articles/openal/
Some of the functions in that code are deprecated but reading the documentation, you'll be able to update it.
The devmaster tutorial also teaches you how to load ogg vorbis (royalty free) files into memory and play them. You'll need to download and build libvorbis and libogg to do that but there's good documentation and, in case you're using Visual Studio, already made solutions.
The fact that Creative Labs (largest sound card manufacturer) is a major contributor to the project is a great point in it's favor. Hardware will not be ignored.
Last thing, remember to download the OpenAl SDK and link to the proper libraries and include directories. There's always a lot of people asking for specific files stored inside it.
"Compatible to all platforms" is a bit of a tall order. After all, "all platforms" includes the controller in your car, the regulator in a nuclear plant, and the router in your network.
If you mean "all desktop platforms", you may have a bit more luck. While it is impossible to produce sound in 100% standards C++, there are libraries that are available. However, I don't think that even these will get you "all platforms". Are you willing to settle for "most common platforms"?

Powerful audio lib

Can you recommend a powerful audio lib?
I need it to timestrech & pitchshift independently, as well as give me full access to the raw audio data and let me stream bytes into its pipeline.
Other effects like eq, filtering, distortion are a plus.
Needs to be accessible from C++ / Linux.
Maybe gstreamer, xine or mplayer would work? Or what would you suggest.
I think FMod is widely recognized as one of the most powerful audio engine available for free until you do something commercial with it, and cross-platform, like in console-mac-pc cross-platform.
Now, OpenAL is worth giving a try.
OpenAL, PulseAudio, JACK, and Phonon, I believe, each have these features in some form.
If you willing to pay for it Miles is very nice. I can't recommend FMOD for much outside of hobby projects. It's had some truly nasty bugs, and I've seen new versions introduce as many as they fix.
I've used soundtouch in the past. Focused on changing speed/pitch/etc.
ALSA looks like the big one.
JACK for Linux also looks promising.

Playing sounds with C++?

How would i make it so in my program there is a button when that button is clicked i want it to play a .wma file without opening and media player?
The C++ standard does not include this functionality. That means it depends on what your system offers.
For Windows, you can try something like PlaySound.
However, you best bet is to use a pre-existing library, like:
OpenAL
BASS
FMOD
SDL's: Sound.
Searching for C++ Sound Library brings up a lot of information.
Also, check out these three other SO topics:
What Is The Best C++ Sound API For Windows?
How to play MP3 files in C?
Learning to work with audio in C++
Although the above answer mentions it (and everything else, it doesn't give any recommendations so...), FMOD is the king of C++ sound (the most used) and works great so I'd recommend FMOD in particular.
Gstreamer is a free, cross-platform multimedia framework written in C (using GObject) that allows encoding/decoding for many types of media, including wma. Very easy to use and well documented.
KDE's Phonon is a cross-platform(!) C++ multimedia library. It supports native sound systems as backends. Worth a look if you haven't seen it before, and a simple video player can be written in a mere 83 lines of code.
For Windows, in all honesty your best bet is DirectShow. The RenderFile API allows you to play most audio file types with just a few lines of code.
The best part about DirectShow is that it's a part of the Windows platform so you don't need to bundle an external component.