I want to process audio online/live where I constantly read audio samples from an audio file, process these (e.g. apply some effect), and forward the processed samples to an audio output device like a soundcard. The input files have common formats such as wav, mp3, perhaps even ogg.
Is there a library available similar to libav/ffmpeg for audio files which simplifies reading various audio formats and provides me a constant stream of raw audio samples? Or is the best solution to use individual libraries for each format?
The libraries should be c/c++ and cross-plattform compatible (Mac, Win, Linux, ARM).
EDIT Thanks for all answers. I have evaluated all libraries and came to the conclusion that it is best to just stick with libav/ffmpeg because most of the libraries require ffmpeg as a backend.
Check out Juce. It is a big library that has been used to develop VST audio plug-ins for music software. There is a lot of stuff you don't need in there, but I think you can pick and choose only the audio parts to include in your build. The AudioFormatReader and its associated classes can do the file reading, and there are also classes for outputting to the sound card. There's a lot of other audio processing tools as well. It's GPL licensed, cross platform, and they claim experimental Android support. I haven't used it for a project yet, but I am waiting for the inspiration!
I can recommend RtAudio or PortAudio for cross-platform audio I/O. For audio decoding you might want to have a look at libsndfile or libaudiodecoder.
I'd check out libSDL, it has an audio subsystem that is built for doing things like that and handles ogg,mp3,flac,wav, etc..
LibVLC can do this. libvlc supports the most various audio (and video) formats. It's a C/C++ crossplatform library. It should also support Arm code generation.
You can use irrKlang library. I have used it for my games. It is very simple library to use, for example to play some file "somefile.mp3" you just need to write
engine->play2D("somefile.mp3", true);
And this library is cross-platform, too. And works with C++, C# and all .NET languages.
More features of this library (from its own site)
It has all the features known from low level audio libraries as well
as lots of useful features like a sophisticated streaming engine,
extendable audio reading, single and multithreading modes, 3d audio
emulation for low end hardware, a plugin system, multiple rolloff
models and more. All this can be accessed via an extremely simple API.
GAudio Library maybe is one you persuit.
It is simple, powerfull, cross-platform and extendable
The hello world of GAudio like this:
gaudio_init("addons");
const char* filename = "..\\media\\trek12.wav";
gsource* source = gaudio_source_create_from_file(filename,FALSE);
if(source == NULL)
{
printf("load file:%s error!\n",filename);
printf("bad source.\nerror code:%d.\n",gaudio_error_get());
gaudio_deinit();
return -1;
}
printf("play filename:%s\n",filename);
gaudio_source_play(source,FALSE);
printf("\nplaying, press any key to quit.\n");
getch();
gaudio_source_stop(source);
gaudio_source_destroy(source);
gaudio_deinit();
Related
I have an SDL app, that works under Linux, Mac and Windows. It's something like a media player, and can play audio just fine. I'd like to add audio recording feature to it, but I'd like to encode it in real time to MP3. Can anyone point me to an example how can I use LibLame, LibSoX, or possibly some other library to achieve this?
-- OR --
I'm also willing to rewrite the whole thing into something easier to manage than C++. I've looked at Kivy and Love2d which uses Lua, but audio recording it's still an issue there. If you know ANY toolkit that:
is cross platform
helps you build GUI using your own graphics
can play AND record mp3 files
ideally can operate under framebuffer (no X Window server under Linux)
Please let me know. I'm looking at Python + Pygame + Pyaudio, it can do graphics and output sound, but still can't record MP3's, only WAV's. Any way to integrate LAME into this to make it work?
FMOD can play practically anything, and handle audio input as well, although I don't know if integrating an entire audio engine is a bit overkill for your project.
It's free for non-commercial usage.
As for encoding, LAME is definitely the de-facto choice for MP3.
There's a very simple library called lame_enc.dll which wraps LAME's capabilities in a simple API. It's Windows only, but you could look at it's source for a good reference on how to use LAME.
So in Windows, you can use the PlaySound function to play an MP3 file in a C++ application. What would be some similar functions available for use in Mac OS X/Linux? I would also appreciate it if you could link to some sample Hello-World type programs demonstrating this.
You can just open("/dev/dsp") and write to it. That's as "native syscall" as you can get, I believe.
Concerning Audio: Linux != Mac, so I will answer both separately.
MacOS uses the core audio framework for low level audio. Building on that there are several higher level APIs. If you just want to play a sound file the AV Foundation Framework is most likely the way to go. Here you find an example to build a simple app for iOS, which can be ported to MacOS easily.
For Linux the whole situation is quite delicate. There exist many different frameworks and libraries and it very unclear which is low and which is high level, since some of them are emulating the others. Basically there is ALSA and OSS for low level audio. Both of them are crap. Jack is aiming to provide a framework for professional audio but it's not very portable (at least if you are interested in embedded devices). Most Linux OS currently are using PulseAudio as their audio server, which has also a simple API for just playing a single sound and a very difficult API for low level stuff. And then there is the gstreamer library, which is rather portable and has a half way descent API and is especially designed for playing audio & video files and streams, and so probably the way to go on linux.
I personally recommend to use PortAudio, which is a library that provides – as the name states – an audio framework which is portable across several operating systems and audio frameworks. PortAudio is also well designed and has a simple but flexible API.
Well, I'm not sure if current desktops have some more advanced services/libraries that play audio files, but if you really want to do some low-level OS audio output, start looking here. Maybe this is a little too low-level for your needs.
I am looking for a portable (Linux, Windows, Mac OS X) way to play either OGG or AAC (and WAV) files.
I have tried closed source options like FMOD but the license is too costly.
I have tried open source projects like Audiere but it doesnt work well in post OSS Linux distros and has not been updated, according to the site since 2006.
I have considered trying to find a solution for each platform and just abstract them in a class, but I havent found info on the best way to do this on each platform.
I do not need any special functionality, i just want to play/stop the audio files. (In C++)
Any recommendations?
How about OpenAL?
http://connect.creativelabs.com/openal/
Getting audio out to the device portably can be done using PortAudio. For a fully decoding and playback solution have a look at GStreamer.
Consider GStreamer, a cross-platform solution for dealing with multimedia stuff. There are C++ bindings through QtGstreamer.
This post discuss the setup on Windows.
I'm writing a cross-platform Qt-based program that from time to time needs to play back audio supplied externally (outside my control) as raw PCM. The exact format is 16 bit little-endian PCM at various common sample rates.
My first obvious idea was to use Qt's own Phonon for audio playback, but there are two problems with this approach:
As far as I can see, Phonon does not support headerless PCM data. I would have to hack around this and fake a WAV header every time playback starts. Not a showstopper, though.
More importantly: There doesn't seem to be any way to control how Phonon (and its backends such as xine, PulseAudio, DirectX, whatever) prebuffers. Its default behaviour seems to be something like 5 seconds of prebuffering, which is way too much for me. I'd prefer about 1 second, and I'd definitely like to be able to control this!
I'm currently looking at Gstreamer, FFMPEG and libvlc. Any thoughts? Since my audio is in a very simple format and I don't need to do fancy mixing stuff (just volume control), I'd like a simple, free (as in freedom), cross-platform and widely available library.
Qt 4.6 has the new QtMultimedia module.
https://doc.qt.io/archives/4.6/qtmultimedia.html
The QAudioOutput class would seem to do what you want - it just plays raw PCM data.
ffmpeg, libvlc and gstreamer have abilities beyond raw pcm, such as codec support.
For your purposes, SDL (example 1, example 2), OpenAL, QAudioOutput are sufficient. SDL is probably the most popular option.
Also, why do you want to control buffering? Buffering a lot means less interrupts and lower power consumption.
Have you looked at OpenAL?
I need to be able to get the length of an audio file (preferably in milliseconds, the timing is very important for the application), and play back the audio. The application is written in C++ on the windows XP platform. Any suggestions for audio formats/3rd party libraries that would do the trick?
If I have to do anything related to audio, on any platform, I just use FMOD. It's very fast, cross-platform, and supports a wide range of formats. Note that it's not free for commercial uses.
The Phonon library (part of Qt) is very powerful and comfortable.
It is LGPL.
Downside: it's not as performant as some of the game-oriented libraries such as FMod, SDL_Mixer and OpenAL. However, the latency is generally acceptable for desktop apps.
As for audio formats: use Ogg Vorbis by default. It's an open standard, royalty free and has better quality than MP3.