Skip to content

Instantly share code, notes, and snippets.

@lightrush
Last active September 2, 2023 22:57
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save lightrush/4fc5b36e01db8fae534b0ea6c16e347f to your computer and use it in GitHub Desktop.
Save lightrush/4fc5b36e01db8fae534b0ea6c16e347f to your computer and use it in GitHub Desktop.
Normalize volume level with PulseAudio

Normalize volume level with PulseAudio and simultaneous output

This should work conceptually on any Linux OS with PulseAudio but these particular instructions are for Ubuntu. There are two major reasons for using simultaneous output. The first is self-evident - we can output to say a bluetooth headset and wired headphones at the same time to enable two people to watch a movie with headphones on a single computer. The second reason is a sort of a convenience for setup. We know the simultaneous sink name so the default.pa config would work without modification so long as simultaneous output is enabled. If we were to set this up without that, we'd have to customize the config with our specific device sink name. That's totally doable but personally I always setup simultaneous output. That's why I haven't described the alternative in this gist.

  1. Install LADSPA plugins containing the compressor and limiter we'll use:
sudo apt install swh-plugins
  1. Install PulseAudio Preferences paprefs:
sudo apt install paprefs
  1. Open PulseAudio Preferences:
paprefs
  1. Go to the Simultaneous Output tab.
  2. Check Add virtual output ... all sound cards and Close.
  3. Copy default.pa from this gist to ~/.config/pulse/.
  4. Restart PulseAudio:
pulseaudio -k

The normalized output is selected by default. If you want to change this behaviour you can comment out or delete the set-default-sink ladspa_normalized line in the ~/.config/pulse/default.pa file. You can also select any other output from the PulseAudio settings when you need unmodified output. This approach can be modified to instead normalize the volume of a particular sound device instead of normalizing the simultaneous virtual device.

Credit

https://askubuntu.com/questions/95716/automatically-adjust-the-volume-based-on-content

.nofail
.include /etc/pulse/default.pa
# Create compressed sink that outpus to the simultaneous output device
load-module module-ladspa-sink sink_name=ladspa_sink master=combined plugin=dyson_compress_1403 label=dysonCompress control=0,1,0.5,0.99
# Create normalized sink that outputs to the compressed sink
load-module module-ladspa-sink sink_name=ladspa_normalized master=ladspa_sink plugin=fast_lookahead_limiter_1913 label=fastLookaheadLimiter control=10,0,0.8
# Comment out the line below to disable setting the normalized output by default:
set-default-sink ladspa_normalized
@ryuukk
Copy link

ryuukk commented Jan 28, 2022

awesome, thanks a lot, the sound is now much better overall, no more super loud stuff randomly!

this should be the default on any linux install imo

@lightrush
Copy link
Author

Keep in mind that the compressor and the limiter both degrade the dynamic range of the sound. While that's very useful to decrease loud portions of films and increase the quiet ones, you probably want to use the direct device output when you want to listen to high quality music.

@Pednick
Copy link

Pednick commented Apr 23, 2022

There's a way to do this without having to install paprefs:

Create compressed sink that outputs to the simultaneous output device

load-module module-combine-sink sink_name=combined
load-module module-ladspa-sink sink_name=ladspa_sink master=combined plugin=dyson_compress_1403 label=dysonCompress control=0,1,0.5,0.99
load-module module-ladspa-sink sink_name=ladspa_normalized master=ladspa_sink plugin=fast_lookahead_limiter_1913 label=fastLookaheadLimiter control=20,0,0.8

@ryuukk
Copy link

ryuukk commented Apr 23, 2022

@kj-cxa
Copy link

kj-cxa commented Nov 3, 2022

For those willing to switch from Pulseaudio to Pipewire, Easyeffects has 2 community presets for audio normalization (both are designed for laptop speakers so high/low frequencies are louder): https://github.com/JackHack96/EasyEffects-Presets
The Easyeffects wiki has a list of community presets and more instructions on installing presets: https://github.com/wwmm/easyeffects/wiki/Community-Presets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment