ALSA graphic

Tech Talk

Tech Talk



ALSA: Friend of Foe?


By Alexjan Carrturo | Senior Software Engineerr

Alexjan Carrturo

If, when you hear the word Linux the only thing that comes to mind is some strange medicine for high blood pressure, you’ve probably never heard of ALSA, either. At first you may feel sorry for your shortcoming, but you have to know that this regret would be totally misplaced, because without knowing it, you may have dodged a potentially fatal bullet.

Let’s start by saying what Linux is: Linux, or as purists prefer to say – GNU/Linux – is a free operating system based on free and open-source software. One of the peculiarities of this operating system is that it is not released by a single company, as happens with Microsoft Windows or Apple MacOS, but is available in many variants, each with different characteristics. These variants are called Linus distributions. The name Linux comes from its main component, the Linux Kernel (named after its creator, Linus Torvalds). Although these systems have existed for over 30 years, don’t be surprised if you have never heard of them: despite the numerous merits of these operating systems, Linux has never become relevant in the Desktop/Workstation world, remaining in a small circle of enthusiasts (sometimes true fanatics, like me). At this point you might ask yourself: if it wasn’t successful, why are we here talking about it? For the simple fact that the lack of success on the desktop system was balanced by enormous success in two opposite areas of the tech world: server and embedded systems.

If in a server environment we can easily speak of a clear Linux majority for everything relating to the web, the cloud and online services, in embed environments (to be clear, embed systems that use high-performance System on Chip), we can speak calmly of absolute dominion. This means that Linux, in its various forms, is present in many communication devices, mobile systems, home automation, and domestic and automotive infotainment systems. Suffice to say that one of the most used mobile systems in the world, Android, is heavily based on Linux. We could say that if you have a mobile device or surfed the Internet or used a social network, without knowing it, you have interacted with a Linux system.

ALSA
Although the name might suggest a spicy Mexican sauce or some type of South American dance, ALSA is simply the acronym for “Advanced Linux Sound Architecture.” In other words, it is the Linux component that manages audio and sounds within the system. Said in more formal terms, it is a software element, both kernel space and user space, which offers a level of abstraction for the management of audio devices (sound cards, codecs, DACs, ADCs, microphones, acquisition devices, etc.) at the application level of the system.

ALSA Mixer


Anyone with a minimum knowledge about digital audio devices is well aware that if these were to be driven directly without any type of intermediation, their use would become a very complicated operation. For this reason, within each system with multimedia functionality, there are one or more software layers that mediate the complexity of using and managing a low-level audio device with a standardized interface. In the case of Linus, ALSA.

You’ve probably noticed that I refer to ALSA, for simplicity’s sake, as a single monolithic component, but it is contextually incorrect: ALSA must be considered as a set of modules. There are the drivers (low-level interface for the hardware, present in the kernel), the libraries (they offer medium-level API to interface with audio devices from user space), the utilities and the tools (a series of user-level applications to manage sound cards, volumes and settings) as well as a series of plug-ins.

The drivers provide a system-level abstractions with PCM capability, usually present in the system at the path /dev/snd/pcm/XXXXX (where the X values may vary in name and numbers) usable for both audio inputs and outputs. The libraries, more specifically from alsa-lib, provides a series of functions and date structures through which it is possible to manipulate audio streams within high-level programming (for example, C/C++).

Recording 100ms From Microphone


As a good Linux fan, I would like to tell you that ALSA is a perfect software, better than anything I have ever seen, but unfortunately this is not the case. For may years ALSA has been considered one of the Achilles’ heels of Linux systems. Keep in mind that in the early years of Linux audio systems there was another system, called OSS, which in turn did not shine in terms of functionality. The transition to ALSA, in addition to the inevitable early problems, was complicated by the presence of drivers that were not always complete or were created by third parties without the necessary documentation.

Over time, the architectural limitations of Linux in the multimedia sector were also highlighted, particularly in systems that required low latency and predictability. It must be said, however, that in recent years the situation has improved a lot in terms of reliability. About the drivers it must be said that in the last few years, many audio hardware manufacturers have actively collaborated in the release of high-quality drivers for Linux, based on the ALSA framework.

Linux enthusiasts might point out that ALSA is outdated and that modern Linux systems use software like GStreamer, PulseAudio, Jack and the very recent Pipewire. These softwares actually offer more advanced architectures, cutting-edge APIs, management tools with a graphical interface, and high levels of abstraction. So, once again you may ask, why talk about ALSA if all this new software exists? The reason is actually very simple: all these software work by exploiting the ALSa infrastructure already present in the Linux system underneath them. In other words, none of these modern systems would work without ALSA.

If after reading this article you have more questions, don’t worry – all will be addressed in Part Two!

ALSA Audacity