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
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.
Mar 27
Strangely enough I had the need to determine if it was possible to create a valid but empty tar file. Turns out it is. The method varies slightly depending on your flavour of tar program, here’s how to do it on three of the big ones:
BSD
tar cvf empty.tar --from-file /dev/null
GNU (Linux)
tar cvf empty.tar --files-from /dev/null
Solaris
tar cvf empty.tar -I /dev/null
Now if you wondering why I would want this, here’s the explanation. I work on a batch processing system that processes files delivered from other systems. In some cases its necessary to wait for a file to arrive but give up after some time. In order to give up we copy and empty file (automatically) so that the processing proceeds normally. Ordinarily this is an empty plain file but for the system I’m working on I’m expecting a tar file, hence the need for an empty one.
Mar 05
An interesting email passed through the webkit-dev mailing list today. In what appears to be a small glimpse into what goes on in preparation for a Stevenote, Geoffrey Garen (Apple) noted in a reply to an email from Akos Kiss (Department of Software Engineering, University of Szeged, Hungary) that one of the reasons WebKit likes to do its own thing and not depend on code it doesn’t own is to be able to fix problems with very short notice. Citing the example of, “12 hours before a keynote address”.
Akos Kiss (Department of Software Engineering, University of Szeged, Hungary):
b) JIT compilation to Java bytecode or ActionScript bytecode.
Comment: Huge work. Currently available compiler implementations do not fit to the architecture of the JS engine.
Geoffrey Garen (Apple):
Right. We’re also reluctant to rely on code that we don’t own. We’ve seen very large performance wins from tightly integrating and customizing all the components of the web stack. We also need the freedom to fix crashes and compatibility problems on very short notice (for example, 12 hours before a keynote address).
Mar 05
I encountered a (Microsoft) site the other day that required Silverlight to be installed. Given I was using my work laptop (running Windows XP) I thought I’d give it a try. The first attempt at running the setup file I downloaded resulted in the following error message (which was opened in a browser window, not displayed by the installer):
The Microsoft Silverlight download was automatically extracted to a virtual drive. You should manually extract the download to a physical drive, and then run it from there. Please follow these steps to complete your installation:
1. Create a new folder on drive C called SilverlightTemp.
2. Save the Silverlight download to this folder.
3. Click Start, click Run, type cmd.exe, and then click OK.
4. In the cmd.exe window, type cd C:\SilverlightTemp\, and then press Enter.
5. This step depends on which version of Silverlight you are installing.
* For Silverlight 1.0 Beta:
In the cmd.exe window, type Silverlight.1.0beta.exe /X, and then press Enter.
* For Silverlight 1.1 Alpha:
6. In the cmd.exe window, type Silverlight.1.1alpha.exe /X, and then press Enter.
7. If you receive a User Account Control (UAC) prompt, click Continue.
8. In the Choose Directory For Extracted Files box, type C:\SilverlightTemp, and then click OK.
9. In the Extraction Complete box, click OK.
10. In the cmd.exe window, type install.exe, and then press Enter.
11. If you receive a UAC prompt, click Continue.
12. In the cmd.exe window, type cd.. and then press Enter.
13. In the cmd.exe window, type rmdir SilverlightTemp /S /Q, and then press Enter.
14. In the cmd.exe window, type exit, and then press Enter.
After recovering from the initial shock of the installation instructions for a very consumer oriented technology requiring use of the command line, I followed the instructions only to be shown another web based error message:
This installation is forbidden by system policy. Contact your system administrator for assistance.
Yes, that’s right I don’t have administrator privileges on my work laptop. Surely the installer could have worked this out at the start of the process.