banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Recording Audio Easily On PCLinuxOS


by Alessandro Ebersol (Agent Smith)


Capturing audio and video on PClinuxOS (and any Linux for that matter) can be a frustrating task. Either the applications don't work properly with the audio/video capture software, or, the sound server is not compatible with the capture application (or vice versa, a capture application that requires a sound server that is not the default of the installation).

Java applications, for example, access the DSP directly and are not as flexible about routing audio as native PCLinuxOS applications.


ALSA is more powerful than it seems

It turns out that the Linux sound system is much more powerful than it appears at first glance. And, there is more to it than meets the eye. ALSA is very vast, complete and incredibly flexible.


The snd-aloop module, invisible magic, available in the Linux kernel

From the definition, on the Matrix ALSA website: Module-aloop - This driver provides a pair of cross-connected devices, forming a full-duplex loopback sound card. Each device can have up to 8 subgroups, which means you can have up to 8 independent loopback connections. The first application opening one device will force the second application, trying to open the other device, to use its established parameters. Therefore, no rate, format, or channel number conversion is done.

In other words, the snd-aloop module creates a virtual sound card with two audio devices, Loopback 1 and Loopback 2.

These two virtual devices, one is a speaker - a device you can write to - and the other is a microphone - a device you can read from - and both are connected, so that what you write to the speaker device can be read from the microphone device. We can call this a connected pair of microphones and speakers. ALSA provides us with 8 such pairs, with the snd-aloop kernel driver.


Why is the snd-aloop module so important?

Well, I needed a solution, to record audio from a good old IBM Thinkpad, which doesn't have many audio outputs. I was tearing my hair out: how would I capture the sound of this notebook? And, looking for solutions, I found the snd-aloop module.

It really works, as I have already tested and confirmed its features. Its advantages can be listed below:

  • Sound server independent

  • Pure ALSA and present in all Linux kernels

  • It consumes much less machine resources than any other solution for capturing audio (Jack, pulseaudio, etc).

Disadvantages? I haven't seen (or heard) any.


How to do it then ?

Basically, in simple lines, we are going to insert the snd-aloop module and create an asoundrc file, which will route a copy of the audio to the capture virtual sound card. Then, we will tell the capture program to "listen" to what comes from the capture virtual sound card.

So, let's get to work!

Step 1. As root, type modprobe snd_aloop pcm_substreams=1, as in the picture below:



Step 2. Now, with the virtual sound card driver inserted into the kernel, we test to see if we have another sound card in the system, with cat /proc /asound /cards, as in the figure below:



Step 3. Now, let's create an .asoundrc file with the following content. (The dotted lines are just to separate the contents of the .asoundrc file from the rest of the text.)

--------------------------------------------------------------------------------------



--------------------------------------------------------------------------------------

Well, we have all the operating system side ready, now, let's configure the capture software. In this case, I will capture a Java program on PCLinuxOS with Simple Screen Recorder (but the concept goes for any screen capture / audio / screen recorder software).


Setting up the capture software

Step 1. Open SSR (or your preferred capture software, except VokoScreenNG, which does not allow using ALSA server alone).

Step 2. In the Audio section, click Record Audio, ALSA Backend and Source: [hw:1,1] Loopback: Loopback PCM

Remember: The capture device will always be the second device from the snd-aloop virtual sound card.

Configure as in the picture below:



Proceed to the settings of the capture software. In the case of SSR, after everything is configured, just click start recording and record your computer/notebook screen, with audio and video, without hassles.

When you are done, remove the snd-aloop card with the command (as root) modprobe -r snd_aloop and rename the .asoundrc, to asoundrc.bak, for example, so that it doesn't interfere with the rest of the computer's audio.

I hope you enjoyed this simple but very powerful tip to get very good recordings with any sound hardware.

A big hug, and see you in the next article.

If you want to read more, these articles helped me write the tip:

https://www.alsa-project.org/main/index.php/Matrix:Module-aloop

https://noisybox.net/blog/2016/01/alsa_recording_of_device_output

https://lichtmetzger.de/en/2014/11/29/simplescreenrecorder-record-audio-with-alsa-only-no-pulseaudio-no-jack/



Previous Page              Top              Next Page