Friday, April 15, 2011

Fixing Normalize Audio Feature in K3b

I usually burn and copy optical media with K3b. I don't do this often, but when I do, it usually just works. Except when it doesn't.

My wife asked me to create an audio CD for her, from an assortment of audio tracks she collected from various sources. It was easy enough to accomplish this with K3b. But the resulting audio CD was annoying to listen to, because I had to change the volume setting for each track.

It's a classic noob's mistake: I should've enabled audio normalization.

So I tried it again, but found that I couldn't enable audio normalization in K3b. Turns out that K3b uses an external application (called - surprise! - normalize-audio) to perform this task, and K3b just couldn't find it - a fact that was clearly (?) stated in the programs section of the K3b settings dialog.

I tried launching normalize-audio at the command line, and it seemed to be installed alright. A quick Net search brought me to Debian bug #597155 and Ubuntu bug #45026. The root cause of the problem is that normalize-audio reports its version number as
normalize 0.7.7
while K3b expects
normalize-audio 0.7.7

This can be fixed either in K3b or in normalize-audio, and patches for both sides have already been posted. But neither has been incorporated yet. In the meantime, I've implemented a workaround, based on suggestions in those bug reports:
  1. create (as root) an executable script named normalize-audio under /usr/local/bin/ with the following contents:
    #!/bin/bash
    case "$1" in    
        --version)
            /usr/bin/normalize-audio --version | sed -e 's/normalize/normalize-audio/g'
            ;;
        *)
            /usr/bin/normalize-audio "$@"
            ;;
    esac
  2. make this script executable:
    chmod a+x /usr/local/bin/normalize-audio
  3. this script is supposed to be used as a wrapper for normalize-audio, so make sure that /usr/local/bin/ appears in the PATH environment variable, and that it comes before /usr/bin
  4. launch K3b from a new command shell - it should now detect normalize-audio and allow you to use it

Time to Burn!
[05 Nov 2011] UPDATE: fixed script to work with file names/paths that contain spaces (Thanks anonymous commenter!)

16 comments:

  1. Many thanks for the script. Nice :)

    ReplyDelete
  2. Thank you. It's amazing that the maintainer of k3b hasn't fixed the simple error in the code that causes this issue.

    ReplyDelete
  3. Hi I m sorry can you post step by step I,d really aprecciate it
    I know enough to move around using gui on ubuntu but really Im triying to learn day after day Thanks

    ReplyDelete
  4. It's already there, but I guess you need a few more details spelled out. I'm too short on time to do that, but I can provide a few hints:

    1) start by opening a terminal (gnome-terminal, xterm, etc),

    2) "create as root" means something like typing "sudo nano /usr/local/bin/normalize-audio" where sudo makes you root (well, not quite - you'd better look it up) and nano is a text editor

    3) "make sure that ..." means "nano ~/.bashrc" and fix the PATH if needed.

    In general, I suggest you hit the ubuntu forums for more help.

    I hope this is enough to get you going ...

    ReplyDelete
  5. Many thanks, worked like a charm!

    ReplyDelete
  6. /usr/bin/normalize-audio $*
    should be
    /usr/bin/normalize-audio "$@"

    If it isn't, it will blow up when the files contain spaces (it happened to me).

    ReplyDelete
  7. I've seen this issue for multiple versions but just lived with it (wasn't a deal breaker for using K3B). Today it is officially FIXED! Thanks so much!

    ReplyDelete
  8. Thanks a lot, that certainly helped me with my current audio mix CD for the car ;-)

    ReplyDelete
  9. Cheers, helped a lot!

    ReplyDelete
  10. Thank you for sharing your expertise. I'm no power user; I just like the Linux philosophy. So, when I run into problems, it's wonderful to have people like yourself decoding the magic inside the machine for us regular folk.

    Many thanks.

    ReplyDelete
  11. Awesome! Thank you for posting the script. I've been stumped over this for year or so.

    ReplyDelete
  12. Wow, thanks, really :))

    ReplyDelete
  13. /me finally sighs in relief. Thanks, mucho!

    ReplyDelete