Sunday, September 13, 2009

normalize all your movie audio on-the-fly with ALSA

I have a pretty large collection of ripped dvd movies.  Invariably, they all have different volumes, which can be very annoying.  I was just about to use mencoder to re-encode all the audio with normalized audio... and then I thought there must be a better way.  Sure enough, there is: http://alsa.opensrc.org/index.php/FAQ#Is_there_an_alsa_plugin_I_can_use_to_compress_or_normalize_my_audio_output_volume.3F

So I copied the section below into /etc/asound.conf:

pcm.ladcomp {
      type plug
      slave.pcm "ladcomp_compressor";
  }
 pcm.ladcomp_compressor {
      type ladspa
      slave.pcm "ladcomp_limiter";
      path "/usr/lib/ladspa";
      plugins [
          {
              label dysonCompress
              input {
                  #peak limit, release time, fast ratio, ratio
                  controls [0 1 0.5 0.99]
              }
          }
      ]
  }
 pcm.ladcomp_limiter {
      type ladspa
      slave.pcm "plughw:0,0";
      path "/usr/lib/ladspa";
      plugins [
          {
              label fastLookaheadLimiter
              input {
               #InputGain(Db) -20 -> +20 ; Limit (db) -20 -> 0 ; Release time (s) 0.01 -> 2
               controls [ 20 0 0.8  ]
              }
          }
     ]
  }
These plugins need to be installed though: apt-get install swh-plugins 
Now the tricky part, getting your programs to actually use this stuff. You have to tell your program to use the ladcomp alsa device. Mplayer and Xine are pretty easy, you can just type it in a box in the gui. However, Gnome's Movie Player (Totem) is a bit trickier. Google to the rescue: http://www.mail-archive.com/gnome-list@gnome.org/msg02589.html

Basically open Configuration Editor and change
system -> gstreamer -> 0.10 -> default) changing the key "musicaudiosink" from "alsasink" to "alsasink device=ladcomp"

All my movies seem to be nearly the same volume now. I setup xine to use it as well, and played a DVD and it seemed to be just a bit louder than movie files, so I'll have to look more into exactly what this filter is doing, maybe it is not reducing loud volume, but just cranking up low volume?

1 comment:

Anonymous said...

Thanks a lot, seems to work great !