Monday, 23 December 2013

Ubuntu Audio CD Burning Fun

Burning an audio CD in Ubuntu takes way more effort than I would have imagined.

Say someone gives you a USB stick with a bunch of .m4a files and a .m3u playlist, and a stack of blank CDs to be turned into lovely thoughtful gift CDs for Christmastime for relatives to play in their cars as they drive to work.  In some operating systems, you'd just open the playlist and then burn it to the blank CD and everything would be fairy dust and unicorns.  In Ubuntu, you do the following steps, amid Googling lots of things.

1. Convert the .m4a files to .wav as described here:

http://smartcoding.wordpress.com/2012/08/18/unix-convert-m4a-to-mp3/

#!/bin/bash
# 
# m4a2wav
# 
for i in *.m4a; do
    mplayer -ao pcm "$i" -ao pcm:file="${i%.m4a}.wav"
done
Ubuntu doesn't really handle .m4a files out of the box, and ultimately you'll need .wav files anyways for a standard audio CD that plays in a normal CD player, so might as well go straight there instead of to .mp3 as an intermediate step.

2. Install K3B KDE Burning tool for burning audio CDs

$ sudo apt-get install k3b 
(or, open Ubuntu Software Center, search for K3B and install)

3. Install normalize-audio for normalizing the audio in your files for uniform playback

$ sudo apt-get install normalize-audio
(or, open Ubuntu Software Center, search for normalize-audio and install)

Otherwise, when you go to burn the CD in K3B and select the "Normalize volume levels" checkbox, it will tell you to go install it.

4. Apply hack to fix this bug, open since 2006, still outstanding:

https://bugs.launchpad.net/ubuntu/+source/k3b/+bug/45026

Workaround helpfully provided by kimus and Vanessa Ezekowitz:

Workaround for Maverick:
In Bug #44524, comment #11, a user posted a script he used to fix this issue in Feisty. With some tweaks, this script works in Maverick also. K3B doesn't like normalize-audio including a version number on the first line. The sheer audacity - how dare it do what it was asked. :-)
The fix is to move the version string to somewhere else in the output:
sudo mv /usr/bin/normalize-audio /usr/bin/normalize
sudo nano /usr/bin/normalize-audio
###
#/bin/bash
case "$1" in
        --version)
                normalize --version | sed -e 's/normalize 0.7.7/normalize-audio/g'
                echo "normalize-audio 0.7.7"
                ;;
        *)
                normalize $*
                ;;
esac
###
sudo chmod 755 /usr/bin/normalize-audio
Restart K3B - it should work fine now.

Otherwise, even after installing normalize-audio, you'll still get the same message in K3B about not having it installed.  Now you can open K3B and prepare to burn your CD.

5. Open K3B.



6. Create a New Audio CD Project.


7. Add your .wav files to your project, manually order them.

Put them in the order originally intended by your playlist file that can't be opened in K3B but can be opened in something like Clementine audio player or your audio player of choice.

8. Manually input artist and title info for all tracks.

The artist and title info will be lost in your .wav files.  Put them back in manually in K3B so if you play your CD in a fancy CD player the track info will display properly. I guess if we'd converted to .mp3 instead of .wav initially then this info would still be encoded, and then K3B would do the conversion from .mp3 to .wav.



Now you have your set of audio files ready to go.

9. Click on burn to open the CD burning dialog.


10. On the CD-text tab, put a name for your CD.

For fancy CD players or whatever.

11. Normalize volume levels

On the Advanced tab, now you should be able to check the "Normalize volume levels" checkbox.  It will warn you that you can't burn on-the-fly if you want to use normalize-audio.  That's ok, click 'Disable on-the-fly burning' and let it check the checkboxes about creating and removing a temp image before it burns on the Writing tab.




12. Insert your blank recordable CD and select it from the Burn Medium dropdown selector.


13. Now, you may burn your audio CD! Burn it!

That, to me, feels like too many steps (even ignoring the self-evident ones like opening the application and adding your files). I miss iTunes terribly sometimes -- still no support for Linux. Maybe there's a better way to do some of these steps, but this is the path that worked for me as I Googled around for solutions to all the bits I needed.



p.s. sorry for neglecting this blog for 3 months.  Maybe I'll post stuff here sometimes.

Monday, 30 September 2013

AI for Robotics/Python/Paging Woes

Just started the Artificial Intelligence for Robotics (a.k.a. Programming a Self-Driving Car) course online at Udacity: https://www.udacity.com/course/cs373.  TIL 1: writing Python on a mobile browser is hard; I got about halfway through the first section before I had to give up on working on my phone in bed with inconsistent whitespace and weird backspace behaviour and switch to a real laptop and keyboard, which was much nicer.  Python does not deal gracefully with ugly whitespace.  It's partly what makes Python so beautiful but definitely what makes Python sometimes frustrating.  But being able to get started into the course on my phone was definitely helpful for actually doing it vs maybe coming back later.  TIL 2: the functional features in Python are super handy - doing something to a bunch of things in a list is way easier with a lambda function and a map call than trying to awkwardly do the same in Java (http://docs.python.org/2/library/functions.html#maphttp://www.secnetix.de/olli/Python/lambda_functions.hawk)  TIL 3: self-driving cars are cool!  So far the course is really interesting, I like how the sections are really short so you can stop at any time, or go as far as you want.  We'll see if it's able to hold my interest for the entirety of the course or if I get bored and wander off partway through.

In other TIL today, be suspicious any time you add an if without an else.  At some point we'd added a check for an index out of bounds case in our paging code so we weren't taking a sublist bigger than the original list, but neglected to deal with the opposite, resulting in bad behaviour if our sublist was smaller than the second page.  I've now refactored out that bit of awkward logic into its own method and peppered it with unit tests covering all sizes of things (empty list, list less than one page of data, list exactly one page, exactly two pages, more than one page but less than two pages) and it's all working happily now.




Saturday, 21 September 2013

First Post! Learn to Code Day.

Disclaimer: I've never blogged before (aside from Twitter and the like). This space is going to be about life as a programmer in healthcare, inspired by this post: how to blog about code and give zero fucks, so no promises that anything interesting will ever happen here, and feel free to not read along.

I'm currently mentoring at a Ladies Learning Code National Learn to Code Day event in Toronto; they've organized a huge event this year across 13 cities, with hundreds of people getting together to learn a bit of HTML+CSS, it's pretty cool. I myself have had a real easy time of things, I've always felt really supported in my quest to make computers do things, ever since my Dad introduced me to a 'Learning DOS' program when I was about 7; I used to love going into Windows 3.1 and Norton Commander and poking about in there. When I was 13, a friend of mine and I made a website about our favourite band with an interactive choose-your-own-adventure story and it was pretty popular (as I choose to remember it). We continually worked to improve the site by learning how to do fancier things in HTML like adding frames (ooh!) and CSS. When I first got involved with Ladies Learning Code, I was surprised at how many stories I heard from people who had earlier had an interest in computers, but were encouraged not to follow that for one reason or another, so they'd abandoned it and gone into some kind of artsy thing instead. Participating in Ladies Learning Code is my opportunity to pass on to others the support and encouragement that I've received.