Beginners Guide for better Audio Quality in Linux

Edit: Latest developments happen in the Linux world quickly. So there is a new audio server called “Pipewire” which has the potential to replace Pulseaudio and Jack audio servers. Pipe wire is great. I don’t have all the details but to anyone interested, check the below links.

PipeWire

PipeWire — ArchWiki (archlinux.org)

Introduction:

Audio quality in any Linux distribution, when compared to Windows or Mac OS is bad…but why…? read the below paragraph to know.

The problem was audio drivers. The audio chip manufactures(for ex: Realtek) develops drivers for windows operating system. Whereas Apple creates its own hardware and software, so there is no question of driver problem here. But in case of Linux, the open-source community develops drivers. The problem here is, developers don’t know correct specifications of the audio hardware (The audio chip manufacturer won't provide these details to open source community). The challenge for the developers here is, the audio driver should work for most hardware. By most hardware i mean, the same audio chip can be used by different manufacturers in different products. For ex: Let’s just say Realtek has some audio chip, the same audio chip can be used in different laptops and desktops with different features. For the same chip, features like multi-channel HD audio with more codec support for high end desktops and power efficient HD audio with noise cancelling feature for internal microphone in laptops. So the developers build a driver(generic driver) that just works. That is why audio quality in Linux is bad.

Below is a very good article giving a clear explanation on how Linux and Windows handles audio differently.

Why there is difference in audio quality between Windows and Linux…? What additional audio features Windows OS has…?

After wondering and not knowing why audio quality in Windows is much better than Linux. I found out that the default audio driver in Windows OS has a built-in real-time equalizer and many other audio features such as bass boost, loudness equalization.., etc. Check the below official Microsoft document on the available audio effects in Windows 10. The audio driver developers have the choice of utilizing these OS provided audio effects or implement their own custom audio effects.

Audio Signal Processing Modes — Windows drivers | Microsoft Docs

On top of this, audio hardware vendors such as RealTek provide proper drivers for the hardware. So that is why audio on Windows is better.

In Linux, there is no magical equalizer and other audio enhancements installed by default. There is a PulseAudio equalizer, but it needs some tuning and tweaking by oneself for their own hardware. The second downside is, hardware vendors, don’t provide audio drivers for Linux. Hence, the difference in audio quality compared to windows or mac OS.

Keeping this in mind, I thought of an easy guide for beginners to get the best output from their audio hardware.

The Guide:

This guide provides a simple and easy way to get better audio quality in any Linux distro that is using pulseaudio as its audio server. Follow the below 2 steps.

Should change the default settings in the pulse-audio config file. This file is generally found in /etc/pulse/daemon.conf. Before changing any settings, keep a backup of the daemon.conf file in any other location.

Note: In the daemon.conf file, all the default settings are commented using “#(Hash) or ;(semi-colon)”. To change a setting, just copy-paste the default setting to the next line, un-comment the setting, and change it.

1. Change the resample-method: By default, in most distro’s resample-method is speex-float-1. Here, the range is from 1(Low) to 10(Best). Higher the value, better the audio quality and demands high CPU usage. This also depends on the CPU. To know the available resample methods supported by a CPU, run the following command in a terminal.

pulseaudio — dump-resample-methods

For desktop users, use the speex-float-10 or the soxr resample method. For the latest processors (less than 2–3 years old), use soxr resample methods. The soxr resample methods offer better audio quality than speex based methods. But they are more CPU intensive than speex methods.

For laptops, speex-float resample methods are best. I recommend using speex-float-5, speex-float-6 or speex-float-7. Check the CPU usage of the PulseAudio process using htop or any system-monitor. Choose the best resample method that fits perfectly between battery life and audio quality.

2. Change default-sample-format: Firstly, the Endianness of the CPU should be checked before changing default-sample-format. This can be easily found by using the following command.

lscpu | grep ‘Byte Order'

The CPU can be either little-endian or big-endian. Remember the CPU endianness, we need this later.

First, let’s understand the audio bit depth. We have 8-bit, 16-bit, 24-bit, and 32-bit depth sample formats. Currently, 8-bit audio is rarely used(It is old). 16-bit audio is used in music streaming services and in general, many audio files use 16-bit depth. 24-bit is known as High-Res audio. FLAC and Apple’s ALAC lossless audio codecs use 24-bit audio. Some premium audio streaming services use 24-bit audio. So, if you have 24-bit FLAC, ALAC files, or any other high-quality audio files, go for 24-bit. Now, 32-bit depth is for even higher quality audio. Some advanced codecs like HEVC (or) h265 codec and others support 32-bit depth files. The easy way to find bit depth for any audio or video file is by using vlc media player. Play the file and select Tools →Codec Information. Below is an example.

Most distros use s16le or s16be as the default-sample format. Let's understand this. Here in s16le, ‘s’ means signed integer, and ‘le’ means little Endian CPU, or in the case of s16be, ‘be’ means big Endian CPU. The number 16 denotes the bit depth.

Let’s see the available audio quality options in windows.

Change the default-sample format according to your preference (like bit depth) and CPU Endianness. Here are some examples for default-sample-format.

s16le, s24le, s32le (or) s16be, s24be, s32be, float32le, float32be. {float formats should be better than signed integer formats mathematically. If you know this.}

Below is an official link for all the supported audio formats by pulseaudio. Check the link below to get some idea on audio formats.

Using the above steps as a reference, change the resample-method and default-sample-format to your liking in the pulseaudio daemon.conf file. In the daemon.config file, there is default-sample-rate and alternate-sample-rate which are 44100 Hz and 48000 Hz respectively.

In Windows, 48000 Hz is the default-sample-rate and no alternate one. But in PulseAudio, we have both. If you need 48KHz as default, set the default-sample-rate to 48000 Hz or leave it as is, the choice is yours . If you do change it, then what should be the alternate-sampling rate..? Leave it to 48000 Hz or change it to 44100 Hz. If you are tech savvy and know that your audio hardware supports higher sampling rates such as 96KHz, 192KHz..etc. Change the alternate-sampling-rate to your hardware supported high sampling rate.

Check out the arch wiki page on what all these settings do, using the link below.

After these changes, save the daemon.conf file and reboot the system. Play any audio file and check the quality. These changes will improve the overall audio quality in Linux. But when compared to Windows or Mac OS, we are missing a few things.

The first thing is an equalizer, we have pulseaudio equalizer (it is hard to learn and tune correctly) and pulseeffects (has built-in presets for equalizer) which now changed their name to easyeffects (to support for pipewire). The pulseeffects is not just an equalizer, it is a fully-featured audio effects suite. Check out the pulseeffects /easyeffects GitHub page using the link below to learn more about it.

The pulseeffects has a built-in equalizer with presets like perfect equalizer, bass-boosted, bass-heavy, and so on. This application solves the equalizer part. The only other thing missing is loudness equalization.

Loudness-equalization can be achieved. I think there is a GitHub repo regarding that. Alternatively, by learning how to play with pulseeffects, loudness equalization can be achieved.

I hope this guide helps to solve the audio problem in Linux. If you find it useful or have some suggestions or any other improvements please share your thoughts and comments below.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Veda Swaroop

Veda Swaroop

I am Post Grad. Electrical Engineering graduate. I love Science, Technology, Linux and Computers in general. Machine Learning, Deep Learning Enthusiast.