Tech used

Enabling HD Audio Output in Ubuntu 22.04 (and 20.04)

Updated 2022-09-20
Photo by Marius Masalar on Unsplash

I hope this guide to be to the point. I won't provide too much background on the underlying technologies involved and, certainly, I won't bore you with my personal story about how I came to discover this. We won't even delve into the controversy about higher bitrate giving you better audio or not.

However, there's a few things that are important to mention. This guide assumes there's an fully-functional Ubuntu installation already in the machine, as well as the machine explicitly having a motherboard that supports output of the frequencies stated here, and an external DAC (Digital-to-Analog Converter) that also supports them. Without these items this guide won't yield any improvement in output audio quality from what's already being provided.

Lastly, audio from wireless headsets will not impacted by the configurations stated here either. Most current headsets use lossy codecs to be piped through the limited bandwidth of Bluetooth. Unless the headsets explicitly state that they support Hi-Res audio you won't get any benefits.


Table of Contents

  1. Tools Needed
  2. Ubuntu Audio Setup
  3. Musings
  4. Acknowledgements

Tools Needed

I have created this guide using the following software and hardware. I'm sure it applies to other motherboards as well with similarly supported audio outputs:

The important spec of the motherboard stated above is under the audio section: "up to 24-Bit/192kHz playback". This allows us to playback music in such formats natively without having to resample. Furthermore, I know that that the RX-V481 receiver works just fine as well for this example -- though, I suspect that any recent Yamaha receiver would work. They have had stellar support for audio formats for a while.


Ubuntu Audio Setup

I must give my thanks to Mike Clements for their wonderful and truly in-depth guide for high-resolution audio setup in Ubuntu. This guide is based upon that guide -- or at least, the version last updated in June 30th, 2020.

That guide is truly detailed. Should you want to know what other options are available, why they are available, and how they work, head over and poke around.

To start, let's go over some fundamental items that need to be setup to enjoy better audio output. There's two main packages in Ubuntu doing a lot, if not all, of the work for audio processing: Alsamixer and Pulseaudio. Alsamixer, as far as I can tell, decides which audio card to use, along with some config items for that card, while Pulseaudio decides the parameters used for the audio processing. The last step is to explicitly tell Ubuntu which physical audio output to use. Let's step through each of them.

Alsamixer Setup

To get started, open a Terminal window ,type alsamixer, and hit enter. You'll be greeted with something like this:

We can hit F6 on the keyboard to bring up the list of sound cards and we should look for the one that matches the specs of the motherboard. Unfortunately, the names are not very descriptive so one does have to try each one until the relevant one is found. In the case of the B550 Plus, we're looking for "Realtek ALC S1200A" to be present in some form. Depending on how many GPUs you have attached to the motherboard, you may get more or less options here. Once you've found the right card, it should look like this:

Quick note: Be sure to disable the Auto-Mute Mode. This can cause no-sound to be output even if everything else looks right. To disable it, use the horizontal arrow keys in the keyboard to navigate the different items, and use the vertical ones to enable/disable.

Once you find the correct card, make a note of its position in the list as you'll need it coming up. In my case it is #3:


Once Auto-Mute Mode is disabled in the correct card, you can hit esc to close out of alsamixer.

Next, you'll want to specify the card to use by default. To do this, run the following command to create the relevant file: nano /etc/asound.conf (you may need to use sudo to be able to save the file in the location). The contents of the file will be as follows:

# Replace the relevant value with the correct card number
defaults.pcm.card 3
defaults.ctl.card 3
		

Pulseaudio Setup

By default, Pulseaudio is setup to resample all audio being output to two different settings: 44.1kHz or 48kHz. I suspect this has something to do with legacy, and well established, sample rates. The former is the default in CDs and the latter is the default for DVD/Blu-Ray. However, we don't want Pulseaudio to resample our music -- just to output as is as pass-through. In order to do this, we have to head over to the config file located in /etc/pulse/daemon.conf. In there the following settings need to change:

resample-method = soxr-vhq
default-sample-format = float32le
default-sample-rate = 44100
alternate-sample-rate = 48000
avoid-resampling = true
		

Find the lines and uncomment them. Be aware that the file has comments starting with # and ;.

There's a single caveat in these configurations. resample-method has lots of options and it does vary. Before committing to a simple copy/paste from this guide, run pulseaudio --dump-resample-methods and make sure it is an option in your system. The other two options that are changing, default-sample-format and avoid-resampling, are somewhat self-explanatory. The former ensures that audio doesn't get down-sampled in a lossy way, while the latter ensures that, if possible, audio does not get resampled. This guide has a little bit of background on those settings if you're curious.

Once the settings have been applied, and the config file saved, restart Pulseaudio by running pulseaudio -k.

Ubuntu Output Device

Lastly, be sure to explicitly tell Ubuntu which audio output to use. So far, we've ensured that important Ubuntu packages know which audio card to use and which parameters to apply to the audio output. This step, while simple, can save lots of frustrations when troubleshooting the lack of audio on playback.

Head over to the Ubuntu settings, top right of screen and then click Settings. Under the Audio section, select the correct Output Device:

For this guide I chose HDMI because I know it has the bandwidth available to cope with this demand.

Musings

  • There are other settings that may improve playback of Hi-Res Audio Files. Something that stood out from this guide was the size of the buffer. Given how everything is setup be default for CD or DVD audio samples, an increase of the size of the buffer may be necessary to keep things running smoothly by preventing clipping.
  • I believe it is possible to stream 192kHz audio through S/PDIF (optical) but, honestly, I'm not completely sure. If I remember correctly, the maximum output available in a Mac mini using a CalDigit TS3's optical output is 96kHz. Your mileage may vary with those experiments.
  • Speaking of Mac mini, and macOS really, is the lack of dynamic audio sample setting. While macOS allows you to define the audio sample output, it can only be set manually via the appropriately-named Audio MIDI Setup. However, if the audio source varies in sample rate, like you might find in a well-established music library, the output does not change to match the native audio sample rate. Is this such a big issue? For most folks, the existence of the Audio MIDI Setup app is irrelevant and all of this is a non-issue. But, to me, it makes a difference -- if only in principle.

    The Yamaha receivers have a nifty compressed-audio enhancer algorithm that, to my ears, does make compressed files and streams (like radio) a bit more lively. When macOS resamples the audio to comply with the set sample rate, it by-passes the algorithm as the receiver believes the source to be of higher quality than it really is.

    This is a pet-peeve of mine and I really wish they would improve that experience. It makes their whole push for lossless in Apple Music a bit silly when you can't really enjoy it at its native sample rate.

  • The HDMI plug being used doesn't really make much of a difference so long as it is correctly configured. For example, my system has at least three HDMI plugs: one built-in from the motherboard, and one on each of the GPUs attached. I can head over to the motherboard's BIOS to explicitly state which video output I want to use, which by proxy defines the audio output. Even though there's two GPUs plugged into this system, the BIOS only allows me to select either the PCIe output or the built-in one. There doesn't appear to be a distinction between GPUs like I've seen in other motherboards.

Acknowledgements

I made liberal use of the following links to gather the information in this guide: