Is the Audio Output Quality on Linux Not Good? Try This Method.

 

The audio output quality on Linux sounds ordinary or even bad, even when using good speakers or headphones. Sometimes it feels muffled, distorted, or unclear, even with high-quality speakers or headphones.

Additionally, how to change the Hz rate, channels, sample rate, and similar settings is rarely known to maximize audio output quality on Linux. Well, maybe this article can help improve the audio quality. It can also be applied to various Linux distributions that support ALSA.

DWYOR : Do With Your Own Risk
Errors in saving configurations or commands in the terminal might cause no sound.

Tweak file daemon audio 

Step 1: Copy file /etc/pulse/daemon.conf

Directly modify the /etc/pulse/daemon.conf file. Or, to be safer, first copy the file without changing the original file by doing the following:
sudo cp /etc/pulse/daemon.conf ~/.config/pulse/daemon.conf
Then modify the ~/.config/pulse/daemon.conf file by typing:
sudo nano ~/.config/pulse/daemon.conf
There will be a built-in configuration as below:
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see .

## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; local-server-type = user
; enable-shm = yes
; enable-memfd = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

; realtime-scheduling = yes
; realtime-priority = 5

; exit-idle-time = 20
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

; resample-method = speex-float-1
; avoid-resampling = false
; enable-remixing = yes
; remixing-use-all-sink-channels = yes
; remixing-produce-lfe = no
; remixing-consume-lfe = no
; lfe-crossover-freq = 0

; flat-volumes = no

; rescue-streams = yes

; rlimit-fsize = -1
; rlimit-data = -1
; rlimit-stack = -1
; rlimit-core = -1
; rlimit-as = -1
; rlimit-rss = -1
; rlimit-nproc = -1
; rlimit-nofile = 256
; rlimit-memlock = -1
; rlimit-locks = -1
; rlimit-sigpending = -1
; rlimit-msgqueue = -1
; rlimit-nice = 31
; rlimit-rtprio = 9
; rlimit-rttime = 200000

; default-sample-format = s16le
; default-sample-rate = 44100
; alternate-sample-rate = 48000
; default-sample-channels = 2
; default-channel-map = front-left,front-right

; default-fragments = 4
; default-fragment-size-msec = 25

; enable-deferred-volume = yes
deferred-volume-safety-margin-usec = 1
; deferred-volume-extra-delay-usec = 0

Step 2: Edit the file ~/.config/pulse/daemon.conf

Change to:
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see .

## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; local-server-type = user
; enable-shm = yes
; enable-memfd = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

realtime-scheduling = yes
realtime-priority = 9

; exit-idle-time = 20
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

resample-method = soxr-vhq
; avoid-resampling = false
enable-remixing = no
; remixing-use-all-sink-channels = yes
; remixing-produce-lfe = no
; remixing-consume-lfe = no
; lfe-crossover-freq = 0

; flat-volumes = no

; rescue-streams = yes

; rlimit-fsize = -1
; rlimit-data = -1
; rlimit-stack = -1
; rlimit-core = -1
; rlimit-as = -1
; rlimit-rss = -1
; rlimit-nproc = -1
; rlimit-nofile = 256
; rlimit-memlock = -1
; rlimit-locks = -1
; rlimit-sigpending = -1
; rlimit-msgqueue = -1
; rlimit-nice = 31
rlimit-rtprio = 9
; rlimit-rttime = 200000

default-sample-format = float32le
default-sample-rate = 48000
alternate-sample-rate = 44100
; default-sample-channels = 2
; default-channel-map = front-left,front-right

default-fragments = 2
default-fragment-size-msec = 125

; enable-deferred-volume = yes
deferred-volume-safety-margin-usec = 1
; deferred-volume-extra-delay-usec = 0
Look at the part that does not have a comment sign “;”, which means the line is functional or enabled.

Then press <Ctrl+o> then <enter> to save the file and <Ctrl+x> to exit the nano editor.

Explanation of configuration lines

Below, I explain the meaning of the configuration above and what I only know.

default-sample-format:
The quality will vary with each sample format. To maximize it, adjust it to your CPU’s byte order or endianness. For this configuration, I use float32le because the CPU supports float32le. To find out the CPU’s endianness, you can type:
lscpu | grep 'Byte Order'
When display
Byte Order: Little Endian
so, support with float32le.

Sampling format options:
u8, s16le, s16be, s24le, s24be, s24-32le, s24-32be, s32le, s32be float32le, float32be, ulaw, alaw.

Look at the suffix of the sampling format above:
_le which means Little Endian
_be which means Big Endian

Try switching between the sampling formats above and find the one that suits you best and gives the best results.

default-sample-rate and alternate-sample-rate:
This refers to the use of the sample rate or alternative sample rate in ADC (Analog to Digital Conversion) or DAC (Digital to Analog Conversion). In the configuration example, 48000Hz is used, while the alternative is 44100Hz.

Why choose 48000Hz? Because the audio quality is already good at a sample rate of 48000Hz. Then, if the system cannot use the 48000Hz sample rate, it will automatically use the alternative sample rate, which is 44100Hz.

default-sample-channels:
If you only use a headset or speakers just left and right and enter the number 2.

I have never tried a 2.1 or 5.1 surround system. So, I am unsure about the sound settings for a 5.1 surround system or others. There is only an example in the Debian wiki, if you are using a 2.1 surround system, enter 3. If you are using a 5.1 surround system, enter 6.

resample-method:
From the Ubuntu manpages, the best option is soxr-vhq. However, sometimes it can delay around 20ms or more (rarely happens).

The vhq variant has more precision than hq and is more suitable for larger samples. The Soxr resamplers generally offer better quality at less CPU compared to other resamplers, such as speex. The downside is that they can add a significant delay to the output (usually up to around 20 ms, in rare cases more).

http://manpages.ubuntu.com/manpages/bionic/man5/pulse-daemon.conf.5.html

So the options are:
src-sinc-best-quality, src-sinc-medium-quality, src-sinc-fastest, src-zero-order-hold, src-linear, trivial, speex-float-N, speex-fixed-N, ffmpeg, soxr-mq, soxr-hq, soxr-vhq.

Alsa Output Configuration

Step 1: Copy the file /usr/share/alsa/pulse-alsa.conf

For older versions of Linux, the ALSA configuration is usually /etc/asound.conf, while for newer versions, the ALSA configuration is /usr/share/alsa/pulse-alsa.conf. Please check where the configuration system is on your PC. Then copy it by doing the following:
sudo cp /usr/share/alsa/pulse-alsa.conf ~/.local/share/alsa/pulse-alsa.conf
Then open that file:
sudo nano ~/.local/share/alsa/pulse-alsa.conf
The default configuration will appear as follows:
pcm.!default {
    type pulse
    hint {
        show on
        description "Playback/recording through the PulseAudio sound server"
    }
}

ctl.!default {
    type pulse
}

Step 2: Edit the file ~/.local/share/alsa/pulse-alsa.conf Change to:

# Use PulseAudio plugin hw
pcm.!default {
    type plug
    slave.pcm hw
}
Then press <Ctrl+o> then <enter> to save the file and <Ctrl+x> to exit the nano editor. 

Conclusion

A little configuration can result in better sound quality, even very good. However, please note that some configurations can make the CPU work harder. It is highly recommended for new-generation PCs or laptops. For older PCs, you might want to try it yourself, and it is best to avoid enabling real-time scheduling, as it can cause the PC to freeze or hang.

Source: 
https://medium.com/@gamunu/enable-high-quality-audio-on-linux-6f16f3fe7e1f https://linux.die.net/man/5/pulse-daemon.conf https://askubuntu.com/questions/14535/whats-the-local-folder-for-in-my-home-directory https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SupportedAudioFormats/ http://manpages.ubuntu.com/manpages/bionic/man5/pulse-daemon.conf.5.html
Next Post Previous Post
No Comment
Add Comment
comment url