Playing YouTube Video with Volume Normalized in GNU/Linux
YouTube videos' loudness varies. This can be annoying. If the system volume is quiet, we won't hear some videos. If it is loud, we are worried about sudden loud sounds. That is because many videos' sounds haven't been processed. In GNU/Linux, we can do the processes on our computer in real-time system-wide.
Nowadays most GNU/Linux distributions use PulseAudio as the sound server. We will do the trick base on it.
Install the filters/plugins
We need the filters or plugins to do real-time sound analysis and compression.
On Debian/Ubuntu
# apt install swh-plugins
On Fedora/CentOS/RHEL
# dnf install ladspa-swh-plugins
swh-plugins is a suite of LADSPA (Linux Audio Developer's Simple Plugin API) plugins collected by Steve Harris.
Make sinks
pactl load-module module-ladspa-sink sink_name=compressed master=SINK_NAME_OR_INDEX plugin=sc4_1882 label=sc4 control=0,101.125,401,-15,3,3.25,0
pactl load-module module-ladspa-sink sink_name=normalized master=compressed plugin=fast_lookahead_limiter_1913 label=fastLookaheadLimiter control=10,0,0.5075
SINK_NAME_OR_INDEX is the name or index of the "sink" which plugins should be applied to.
In PulseAudio, "sinks" are what "clients" send the audio to. A client can be an audio player, a web browser or any other audio application. The default sink is most probably the audio hardware.
To view sinks:
pacmd list-sinks
"master=SINK_NAME_OR_INDEX" can be omitted so that the default sink will be selected instead.
Parameters
"control=" sets the parameters for the plugin. Each parameter is separated by a "," with no " " between them. Some of the values given in the commands are empirical and suit unprocessed audio of YouTube videos, Others are the default.
Parameter | Title | Min | Max | Default |
---|---|---|---|---|
1st | RMS/peak | 0(RMS) | 1(peak) | 0 |
2nd | Attack time (ms) | 1.5 | 400 | 101.125 |
3rd | Release time(ms) | 2 | 800 | 401 |
4th | Threshold level (dB) | -30 | 0 | 0 |
5th | Ratio (1:n) | 1 | 20 | 1 |
6th | Knee radius (dB) | 1 | 10 | 3.25 |
7th | Makeup gain (dB) | 0 | 24 | 0 |
Parameter | Title | Min | Max | Default |
---|---|---|---|---|
1st | Input gain (dB) | -20 | 20 | 0 |
2nd | Limit (dB) | -20 | 0 | 0 |
3rd | Release time (s) | 0.01 | 2 | 0.5075 |
Details for the plugins can also be checked with "analyseplugin", for example:
analyseplugin /usr/lib/ladspa/dyson_compress_1403.so
For some distributions, the plugins are under "/usr/lib64/ladspa/".
Apply Changes
To make the plugins take effect, set the default sink to "normalized" (the sink we made) with the GUI or with this command:
pactl set-default-sink normalized
Make the Changes permanent
We can either autostart these commands or make the file "~/.config/pulse/default.pa" and add the following content.
.nofail
.include /etc/pulse/default.pa
load-module module-ladspa-sink sink_name=compressed plugin=sc4_1882 label=sc4 control=0,101.125,401,-15,3,3.25,0
load-module module-ladspa-sink sink_name=normalized master=compressed plugin=fast_lookahead_limiter_1913 label=fastLookaheadLimiter control=10,0,0.5075
set-default-sink normalized
Rollback changes
With these filters, we compress the dynamic range and raise (gain) the volume while prevent clipping. This works well for unprocessed audio of YouTube videos, but for processed audios like music files or movies, you probably want to disable these filters.
To set back to the default audio sink, either via the GUI or with the following commands:
pactl set-default-sink SINK_NAME_OR_INDEX
The index of the default sink (hardware) starts from 0.
To remove the filters:
pactl unload-module MODULE_NAME_OR_INDEX
To view the modules (filters):
pacmd list-modules
Comments
Post a Comment