6

Sometimes people scream in an otherwise quiet video.

How do I set a loudness limit? Sounds louder than the limit would be scaled down to the limit. Sounds quieter than the limit would pass unchanged. Best would be to set a specific dB limit. Is this even possible?

wos
  • 181

2 Answers2

2

The audio concept involved here is compression. So we need to install a compression plugin to the audio output. The following is working in Ubuntu 20.04. I needed to install pulse audio first:


Verbatim from Is there a way of leveling/compressing the sound system-wide?

I had success with the example shown in this answer.

  1. Install Steve Harris's LADSPA plugins Install swh-plugins

     sudo apt install swh-plugins
    
  2. Run pacmd and then this commands:

     load-module module-ladspa-sink sink_name=compressor plugin=sc4m_1916 label=sc4m control=1,1.5,401,-30,20,5,12
     set-default-sink compressor
    

This answer explains how to load the plugin permanently.


The parameters (the control=1,1.5,401,-30,20,5,12 part above) for this compressor are described in Steve Harris' LADSPA Plugin Docs:

  1. RMS/peak: The balance between the RMS and peak envelope followers.RMS is generally better for subtle, musical compression and peak is better for heavier, fast compression and percussion.
  2. Attack time (ms): The attack time in milliseconds.
  3. Release time (ms): The release time in milliseconds.
  4. Threshold level (dB): The point at which the compressor will start to kick in.
  5. Ratio (1:n): The gain reduction ratio used when the signal level exceeds the threshold.
  6. Knee radius (dB): The distance from the threshold where the knee curve starts.
  7. Makeup gain (dB): Controls the gain of the makeup input signal in dB's.
  8. Amplitude (dB): The level of the input signal, in decibels.
  9. Gain reduction (dB): The degree of gain reduction applied to the input signal, in decibels.

Due to a limitation of PulseAudio, it is not possible to adjust them in real time.

To experiment with different parameters, I also loaded the compressor as a real-time adjustable ALSA plugin via Alsaequal Install libasound2-plugin-equal by creating the following ~/.asoundrc:

ctl.compressor {
  type equal;
  library "/usr/lib/ladspa/sc4m_1916.so";
  module "sc4m";
}

pcm.plugcompressor { type equal; slave.pcm "plug:pulse"; library "/usr/lib/ladspa/sc4m_1916.so"; module "sc4m"; }

pcm.compressor { type plug; slave.pcm plugcompressor; }

A sample MP3 file can be played through the compressor using mpg321 Install mpg321,

mpg321 -a hw:compressor "04 - Love Song for Yoshimi.mp3"

while alsamixer -D compressor can be used to adjust parameters in real-time.


End verbatim


I recorded a simple voice ver loud and then very quiet. Playing it with the params shown in the command above, the difference was outstandig compared with no plugin.

Also, in the PulseAudio interface I could select what application should use the plugin's output:

enter image description here

Glorfindel
  • 815
  • 2
  • 10
  • 19
1

I found an easier solution. There is program to do this it is called EasyEffects (used to be called PulseEffects). The AutoGain function does exactly what I needed.

EasyEffects github page

Installed on Ubuntu with the command

sudo apt install pulseeffects

[Disclaimer: EasyEffects cannot hard limit decibels. This is not an answer, but rather an idea for alternatives.]

wos
  • 181
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Oct 05 '21 at 08:37