You are not logged in.

#1 2017-11-09 23:12:56

cloverskull
Member
Registered: 2015-10-01
Posts: 348

Let's improve pulse audio output

Hey guys,

On OSX I use an application called "Boom2" to transparently apply equalizer settings via postprocessing an audio signal before it hits the speakers/headphones. For a long time I wanted to do this with linux, via pulse, but have come up short. I think today I finally cracked the code on a bit of this.

I'll continue to update this initial post as we refine this process over time.

Ok, basic assumptions here are that you've already got Bunsenlabs installed and pulse working. Unfortunately pulseaudio-equalizer is not currently available in jessie, but it is available in stretch, and I think we're all waiting with bated breath for helium to drop. smile

Ok, first step is to install some dependencies as well as pulseaudio-equalizer

sudo apt-get install python-dbus python-qt4 python-qt4-dbus pulseaudio-utils pulseaudio-equalizer

Once that installs, from a command line, type

qpaeq

Notice that it spits out an error: There was an error connecting to pulseaudio, please make sure you have the pulseaudio dbus module loaded, exiting...

We need to load a few modules. Again, from a command line

pactl load module-equalizer-sink
pactl load module-dbus-protocol

Test running 'qpaeq' again and notice that it does actually pop up a gui this time. Excellent! You probably also realize that moving the sliders does nothing. We'll address this shortly. For now, let's make these module loads permanent. Go ahead and quit out of the equalizer. Open a terminal and

sudo nano /etc/pulse/default.pa

At the very end of this file, append the following two lines, save, and exit

load-module module-equalizer-sink
load-module module-dbus-protocol

After saving and exiting, let's sanity check our spelling and syntax. From the command line run

pulseaudio --kill
pulseaudio --start

Presumably pulse starts up and there are no errors or anything strange happening here. If we see an error, check your spelling or syntax in /etc/pulse/default.pa.

Now, let's figure out why we can't slide these equalizer settings and actually have any impact on audio files. Strange, right? Well, turns out 'module-equalizer-sink' has created a bit of an abstraction on top of the regular audio stream, we just have to select it as our device...more or less. This is a gross oversimplification, but it explains things well enough for our purposes.

Let's see what "sinks" we have available, i.e. what devices we have available to bind to pulse as our output streams

pactl list short sinks

For me, the output listed two sinks. First was my analog-stereo sink, which is the alsa output device connected to the kernel where it references my actual hardware audio output. I had another sink, though, which was essentially the same thing, but it's also got the phrase "equalizer". This is the equalizer itself, acting as an abstraction layer between the software and the hardware, allowing us to do some postprocessing of audio signals before we touch hardware.

For me, the option without the equalizer was option #0. The option with the equalizer was option #1. So we just need to switch to sink option #1.

pactl set-default-sink 1

After running this command, go ahead and play an audio stream. Run 'qpaeq' and slide the "preamp" knob up and down and notice the drastic change.

Ok, if that works, let's persist this setting.

sudo nano /etc/pulse/default.pa

At the very end, after everything else in the file, let's manually set it to use the default sink we've identified just above. For example, if I persist this to use sink 1, my setting should read

set-default-sink 1

Cool, let's inspect our sample rates. Go ahead and play an .mp3 quick and just try to absorb the sound quality. Store it away in your head for a bit. We're going to tweak a few settings.

Note: If you optimize on cpu performance, don't touch these settings! This is where we separate the men from the non-audiophiles wink

Ok, let's dig into the sample rates.

pacmd list-sinks | grep sample

My results were that I had two sinks sampling at 16 bits. I want to up that sample rate to 32 bits. There's no mathematical way to do this, but we can at least tweak our settings to be a bit higher quality / less performance, and prove it by looking at these rates later.

Edit your pulse daemon

sudo nano /etc/pulse/daemon.conf

Find the 'resample-method' line. It's commented. Leave it that way! Easier to revert to later. However, right underneath it, create a line that is not commented, and make it say

resample-method = src-sinc-medium-quality

You can also mess with 'src-sinc-best-quality' at your discretion. In my experimentation, the cpu cycles weren't worth the change in audio, especially considering my laptop tin-can speakers. YMMV.

Let's also add two more lines (these have default values elsewhere in this file which are commented; let's not muck with that, it's safer just to create new values and be able to completely remove it later). Add the next two lines as well.

default-sample-format = s24le
default-sample-rate=96000

Save this file, and then bounce pulseaudio

pulseaudio --kill
pulseaudio --start

And listen to that same mp3. Any difference?

Also, run

pacmd list-sinks | grep sample

Notice that we're running at a different bitrate?

---

I'm saving this space to discuss other ways to optimize the sound quality via pulse configuration settings, as well as (hopefully) linking to some default equalizer configuration settings.

Last edited by cloverskull (2017-11-09 23:52:07)

Offline

Board footer

Powered by FluxBB