High Res Audio on Ubuntu: Part 3

Once we’ve got it all set up, we want to test it while playing audio. It’s the only way to know for sure it is working as expected. To do this, we’ll be using the Linux Pulseaudio command-line tool pacmd.

If you jumped directly to this page, you may want to read part 1 and part 2.

Once you’ve tested your setup, possibly made adjustments, and confirmed they are working, you may want to read about streaming audio from a browser.

Basic Audio Device Info

To start, enter this command:

pacmd list-sinks

A “sink” is an audio output device. Even if you only have 1 sound card in your system, it may support multiple sinks. And you may have multiple cards. So you may see a lot of output here.

Let’s use grep to shrink the output to only the fields most useful to us:

pacmd list-sinks | grep -e 'sample spec:' -e 'channel' -e 'buffer' -e 'latency:' -e 'name:' -e 'alsa\.card'

On my system, it returns this:

name: <alsa_output.pci-0000_04_02.0.analog-stereo>
current latency: 0.00 ms
sample spec: s32le 2ch 176400Hz
channel map: front-left,front-right
fixed latency: 185.76 ms
alsa.card = "1"
alsa.card_name = "ESI Juli@"
device.buffering.buffer_size = "262144"
device.buffering.fragment_size = "70560"

This tells you I have an ESI Juli@ sound card that is currently set to 176.4 kHz sampling and 32-bit signed. My Pulseaudio configuration uses sample rates of 176400 and 192000, so this is the default sample rate. This is 4x oversampled for normal CD quality (44.1 kHz) and 4x oversampled for normal DVD quality (48 kHz).

Now I play an audio file that happens to be sampled at 96 kHz. While it’s playing I run the above command again and it returns this:

name: <alsa_output.pci-0000_04_02.0.analog-stereo>
current latency: 170.65 ms
sample spec: s32le 2ch 192000Hz
channel map: front-left,front-right
fixed latency: 185.76 ms
alsa.card = "1"
alsa.card_name = "ESI Juli@"
device.buffering.buffer_size = "262144"
device.buffering.fragment_size = "70560"

You can see that Pulseaudio has changed the sample rate to 192 kHz. Why? I have “avoid resampling” enabled, so it should play at the audio file’s native rate of 96 kHz. But Pulseaudio will never use a sample rate lower than what you configure. Since it can’t use 96 kHz, it uses the next best thing, which is an integer multiple of the native rate. That is why it switches to 192 kHz.

Resampling

The above command showed us the current state of the audio device. We can also use pacmd to get the current state of any audio being sent to or processed by that device.

First, ensure no audio is playing on your system and then enter this command:

pacmd list-sink-inputs

You should see this response:

0 sink input(s) available.

Now, try the prior command again:

pacmd list-sinks| grep -e 'sample spec:' -e 'channel' -e 'buffer' -e 'latency:' -e 'name:' -e 'alsa\.card'

You will see something like this:

name: <alsa_output.pci-0000_04_02.0.analog-stereo>
current latency: 0.00 ms
sample spec: s32le 2ch 192000Hz
channel map: front-left,front-right
fixed latency: 185.76 ms
alsa.card = "1"
alsa.card_name = "ESI Juli@"
device.buffering.buffer_size = "262144"
device.buffering.fragment_size = "70560"

This tells you that the audio card is in a certain state, but there is no data or input being sent to that card.

Now play an audio file of any kind, and while it’s playing, repeat the above commands. In my case, I played a CD file (44.1 kHz, 16-bit) and get the following:

First, the card itself:

pacmd list-sinks| grep -e 'sample spec:' -e 'channel' -e 'buffer' -e 'latency:' -e 'name:' -e 'alsa\.card'

This returns:

name: <alsa_output.pci-0000_04_02.0.analog-stereo>
current latency: 185.75 ms
sample spec: s32le 2ch 176400Hz
channel map: front-left,front-right
fixed latency: 185.76 ms
alsa.card = "1"
alsa.card_name = "ESI Juli@"
device.buffering.buffer_size = "262144"
device.buffering.fragment_size = "70560"

You can see the card switched to 176.4 kHz sampling, because the source is 44.1 kHz and it wants to use an integer multiple for resampling.

Now let’s check the status of the audio being sent to the device:

pacmd list-sink-inputs

Now you see a bunch of output. As above, let’s use grep to filter it down to the essentials we care about:

pacmd list-sink-inputs | grep -e 'sample spec:' -e 'resample method:' -e 'application\.name'

Now we see something like this:

sample spec: float32le 2ch 44100Hz
resample method: soxr-vhq
application.name = "VLC media player (LibVLC 3.0.8)"

Here we see that the source is coming from VLC (my media player), sampled at 44.1 kHz and the system is resampling it using the soxr-vhq method.

Now let’s play an audio file that happens to exactly match one of our system’s sampling rates (in my case, 176.4 kHz or 192 kHz). And then re-run this command. We get:

sample spec: float32le 2ch 192000Hz
resample method: copy
application.name = "VLC media player (LibVLC 3.0.8)"

Look at the resample method: copy. This means Pulseaudio is not resampling the audio, but is directly copying the stream from the source to the sink without resampling it. This is an important test: it tells you when the system is resampling audio.

Conclusion

So, now we know how to test our audio settings, see how the audio card is currently configured, and also check the audio stream being played. Also, whether audio is being resampled, and if so, using what resampling method, and the source and target sample rates.

As a general guide to resampling:

  1. No resampling is always best
  2. Resampling at integer multiples is better (faster, more transparent) than fractional
  3. Up-sampling is more transparent than Down-sampling

Conclusions we can draw from this

  • Avoid resampling wherever possible
  • If you must resample, upsample by integer multiples
  • If we have 88.2 kHz, downsampling to 44.1, is better than upsampling to 96
  • If you must resample by a non-integer multiple, sample up rather than down