Normalizing Your Music

Listening to un-normalized music can be a painfull thing, considering one second it will be a normal volume and the next you will be deaf :o mg . Anyway, I had a bit of a look on the net for a solution and by using Mp3Gain this is actually a pretty simple solution to fix.

Basically, Mp3Gain has the ability to normalize the volumes of all music without actually editing the mp3 files. It does this by analysing the levels and applying tags to the files which lets the player know how much to increase/decrease the volumes. The good thing is that it can do this over albums, to make the files pretty generic in their levels. Another good thing is that this can be done with a one liner ;) . First install then run:


sudo apt-get install mp3gain

find . -iname '*.mp3' -execdir mp3gain -a -k "{}" + &

What that command is doing :

  • find . -iname ‘*.mp3′ searches for all mp3 files.
  • -execdir executes the command on a directory basis.
  • -a tells mp3gain to use Album gain instead of Track gain (very important!)
  • -k tells mp3gain not to increase the volume with no distortion.

For windows users this is a lot simples considering all you have to do is open the gui and tell it to run! :P .

August 4th, 2008 by David Binney | No Comments »

Using Oracle Regular Expressions

Something a little more simple this time, or so i thought ;) . Anyway, what I was trying to do was convert the first letter of every word into uppercase and the rest into lowercase. Immediatly I thought this would be a job for Oracle Regex. I started to have a look at some of the documentation and slowly noticed that this might not even be possible by directly using regular expressions, or more specifically, Oracle’s implementation of them.

Basically, the problem was that there are only 4 types that can be used and they are seperated info functions:

  • REGEXP_LIKE
  • REGEXP_INSTR
  • REGEXP_SUBSTR
  • REGEXP_REPLACE

More info on this from the earlier link!!

To cut a long story short, oracle has not implemented all of the functionality of regular expressions, that is available to os’s like linux/unix. So my thought of just using regex_replace and doing an uppercase on the first letter group could not be done. However, there is a function provided by oracle which will do that automatically with no regex :


SELECT INITCAP('don talbert jones') FROM DUAL;

This solved my initial problem of uppercasing the names, but I was thinking what if you wanted to do something more complicated like initcap the names and re-arange as well:


SELECT str,
       REGEXP_REPLACE
                 (INITCAP (str),
                  '([a-zA-Z]+)([^a-zA-Z]*)([a-zA-Z]+)([^a-zA-Z]*)([a-zA-Z]+)',
                  '\5, \1 \3'
                 )
  FROM (SELECT 'first middle last' str FROM DUAL)

This will work for strings that are names only and no special characters eg “hiphen”. A more robust approach would be :


SELECT REGEXP_REPLACE( INITCAP (str), '([^a-zA-Z]*)([a-zA-Z]{1})([a-zA-Z]*)([^a-zA-Z]*)', '\1' || '\2' || '\3' || '\4' )  RESULT
FROM (SELECT '-,riyaz ahm:ad khan' AS str FROM DUAL)

This is the breakdown of what this version will be doing:

  • Search for anything that is not a character and any number of them ([^a-zA-Z]*)
  • Followed by a single character ([a-zA-Z]{1})
  • Then any character and any number of them ([a-zA-Z]*)
  • Finally, anything other than a character and any number of them ([^a-zA-Z]*)

These groupings represent the groupings in order from 1-4, so if you wanted to thange the order of the characters or even remove the non characters then you would just manip the numbers.

Overall, I am a little dissapointed that the functions like \U “convert uppercase” was not included in the original implementation but all I can do is winge ;) .

August 4th, 2008 by David Binney | 2 Comments »