C++ – Linux, C++ audio capture (microphone only) library

Linux, C++ audio capture (microphone only) library… here is a solution to the problem.

Linux, C++ audio capture (microphone only) library

I’m working on a music game that works like a singer, but you have to play recorder instead of singing oFlute, and it is still in the early stages of development.

In the game, I capture the microphone input, then run a simple FFT analysis and compare the result to the frequency of a typical recorder to get the notes played.

The audio library I used at first was RtAudio, but I can’t remember why I switched to PortAudio, which is what I’m currently using. The problem is that it sometimes randomly crashes or stops capturing, like the microphone has no sound.

My question is, what is the best option to capture microphone input on Linux? I just need to turn on, read, and close the byte stream from the microphone.

I’ve been reading this guide, and (not) surprisingly it says:

I don’t think that PortAudio is very good API for Unix-like operating systems.

So, what do you recommend to me?

Solution

Considering the other options, PortAudio is a strange choice.

I personally would abstract from everything and use GStreamer. Audio can be a mess on Linux (as a long-term victim). Letting Gstreamer handle this makes you forget about it and move on without having to think about it again.

OpenAL is probably the most popular among game developers, and it should support most systems (although you’ll be “happy” to let it play well with PulseAudio).

I’ll definitely make sure you’re working on the most popular setup (PulseAudio at the moment, I guess it’s currently PulseAudio) so that you don’t end up in a situation where the release and the bogged down person prompts that the sound isn’t working.

And don’t listen to nonsense about PulseAudio – it may be new, it may be more resource-intensive than a bare-system ALSA system, but it certainly won’t get bogged down in latency issues. Asking people to remove it is not an option for modern desktop distributions because it is so tightly integrated (and useful).

Related Problems and Solutions