Ubuntu 20.04 LTS - How to improve the sound quality

If you notice the sound quality when playing a youtube video sounds off and not as good as Windows, I recommend you modify some PulseAudio settings by editing a configuration file with a text editor of your choice, sudo powers required.

The file in question is is /etc/pulse/daemon.conf

Look for the setting below,

;resample-method = speex-float-1

Uncomment the line by deleting the ; and change the default value from speex-float-1 to sox-vhq.

resample-method = soxr-vhq

I would also recommend the following,

default-sample-rate = 48000
alternate-sample-rate = 48000

Explaining it in more detail

No doubt you have seen this recommendation all over the internet.

By default Ubuntu 20.04 LTS will set your sound device to run with a sample rate of 48KHz. This is where the setting 'default-sample-rate = 48000' comes in. When you watch a video on youtube through your browser, the audio sample rate from youtube is 44.1KHz (because that is what youtube encodes audio at). Ideally the 'alternate-sample-rate' setting at 44.1KHz will then kick in, changing your sound device sample rate to 44.1KHz and there would be no issue as PulseAudio has switched the sound device sample rate to match.

However, let us take a look at the PulseAudio documentation in relation to the alternate sample rate setting,

"Sinks and sources will use either the default-sample-rate or this alternate value, typically 44.1 or 48 KHz. Switching between default and alternate values is enabled only when the sinks/sources are suspended......If set to the same value as the default rate, this feature is disabled".

What is a sink and source?

Sink is an output device, which is all sound output devices connected to your PC such as any USB headsets, sound cards, GPU HDMI sound outputs. Source is an input device, for example a microphone input.

So in theory, if nothing was using your output device and it was in a suspended state, running that youtube video in Firefox should wake up the sound device and switch it to the alternate sample rate. This does indeed happen but there may be times when it can't.

In Ubuntu you can view the current state of all your sinks by typing in a terminal

pacmd list-sinks



As you may notice in the screenshot, my Sony headset is in a suspended state, currently at 48000 Hz.

Following on from above, there may be times when playing that youtube video does not cause PulseAudio to switch to the alternate 44.1KHz sample rate. It is in these instances that you will get a degrade in audio quality.

Some of these instances may be caused because you previously had another application that sent a 48KHz audio stream to your sound device, and your sound device has not yet gone into a suspended state, therefore it is locked to 48KHz. As a result the only way to play that youtube video is for PulseAudio to resample the 44.1KHz audio stream into 48KHz.

Now, because the default resample method in Ubuntu is set to a very low quality setting (speex-float-1) the end result is a noticeable loss in audio quality that many people can hear.

Equally things could be the other way around, your sound device is locked to 44.1KHz and you decided to play 48KHz music file or video, the resample method will come into play and affect the quality.

Understanding how and when PulseAudio can alternate the sample rate in Ubuntu should give you a better understanding into the comments made around sound quality in Linux compared to Windows.

However, the internet being the internet, there are also claims that there are no sound quality issues in Ubuntu. Everyone has different auditory perception and the quality of your sound device / equipment will have an impact on what you hear. But this being said, I would ask anyone making such a claim to conduct a proper test by invoking conditions to lock their sink device at 48 KHz and then play a 44.1KHz audio stream (or vice versa), I am sure you are likely to notice the difference with the default Ubuntu settings.

Explanation to the further recommendations

I would recommend setting Ubuntu to disable switching between sample rates and lock it to 48KHz, as noted in the PulseAudio documentation by setting both 'default-sample-rate' and 'alternate-sample-rate' to the same value. Alternating between sample rates can cause some sound distortion issues, in my experience this tends to be when these devices are running at 44.1KHz.

Hope the above helps.

Comments

Popular posts from this blog

My top tweaks for gaming in Windows 10

Ubuntu 23.10 - How to build a kernel package from kernel.org

How to fix OBS Intel Quick Sync MFX_ERR_NOT_FOUND error in Ubuntu