Apr 24

I had the need today to read in a list of patterns from a file, expand them and then operate upon each file all from within a shell script. Apparently there is a shell built-in for csh, but I didn’t want to learn csh at that point. The eventual solution was to run an extra shell with the -c argument.

Example:

#!/bin/bash
FILES=`cat patterns.txt`
for pattern in $FILES; do
    bash -c "ls -l ${pattern}"
done
Apr 16

For my current software project I have the need to decode MP3 files for the purpose of producing an audio waveform. It doesn’t need to be overly accurate as the decoded samples will be displayed, not played. However it does need to be fast, as a typical use case for the application will be MP3 files of around 100Mb (full length CDs). The application is for Mac OS X, although the results of my testing below could be useful for other platforms.

Assisted by a code sample from Apple I wrote an initial version of the decoder that would read the source MP3 file and write the raw linear PCM data out to a file. I did this using the Core Audio framework built into Mac OS X. Once the program was working I tested it against some sample files and came to the conclusion that 4 seconds to decode a 3 min track was great but over 100 seconds for a full length CD, not so great.

I did some searching and came up with two other libraries that seemed well suited to the task of MP3 decoding, they were mpg123 (libmpg123) and MAD (libmad). mpg123 had claims of being very fast, mad claimed it was very accurate.

Methodology

I built the two additional libraries with the default configuration options, except for libmad, which I added the --enable-speed option. With the help of example code I made programs out of each that were comparable to the first version for Core Audio. I.e. MP3 file in, 16-bit Linear PCM audio samples out.

To provide a benchmark I wrote a script that would run each of the three programs against a source MP3 file. Each program reported the elapsed time (via time(3)) and the processor time (via clock(3)) when it finished decoding. The programs were run one after another on the source file 10 times. Their PCM output was written to a new file for each invocation.
Continue reading »

Apr 15

Women’s Weekly Tux Cake I snapped this with my my phone whilst I was shopping at Safeway last Sunday. It seems the Australian Women’s Weekly are Linux fans or aren’t aware that they may be infringing Larry Ewing’s copyright. Who wouldn’t want a Tux cake though.

Apr 06

Recently I wanted a to quickly lookup how to do something in sed. As headed for the man page once again I wished I had a quick reference on hand, like the Perl Pocket Reference I have. In a slight diversion I did some searching to see if there was a pocket reference for sed, there is, and as a bonus it covers awk too.

Armed with the knowledge that the sed reference exists I searched for bookshops in Melbourne to buy it from. This is where it became difficult. No one had it in stock and even if they did it would take at least a whole day to arrive if I had ordered it right then. It was here that I wished there was a delivery service for technical books that could see them delivered with the promptness and low cost of a pizza delivery.

The need for a technical book, in particular those that are mainly reference material tends to come about with a need-it-now urgency to satisfy whatever the pressing enquiry is. Typically the desired information is available via online documentation or a simple Google search however I tend to prefer references to be in dead tree form and I don’t believe I’m alone in this.

Given the relatively huge lead time in actually getting a reference book delivered, the online documentation usually wins and the books remain unordered. For a nominal fee I think if it were possible to have a book delivered within the CBD in an hour or so from ordering many more books could be sold to satify the immedaite need for the reference.

Now an hour is a long time to wait if you need to look something up now, but it would allow you to look up whatever it is you’re after online then for the rest of the day refer to your new reference that arrived a little later. So bookstores, pizza style delivery for technical books, who’s up for it?

On a side note, its extremely lame that the Australian Borders website doesn’t have the ability to search for books they stock.