Audio Hacking - monday 2004-04-05 0707 last modified 2004-04-05 0707
Categories: Nerdy
TrackBacks Sent: None

I use the open source project Audacity for converting tapes into sermons via the headphone out jack on a stereo and the line in jack on my laptop. Unfortunately, it's not very stable on Mac OS X, the odd case where something on Windows was more stable than other platforms.

Fortunately, Audacity leaves behind raw Sun audio format (.au) files it keeps around as a set of temporary six-second clips for later integration into a recording project. Except it provides no way to restore these. In fact, it asks you on a crash restart if you want to delete or keep the temporary files, explaining rather uselessly that "you can restore them manually, but Audacity can't." I don't know why not.

After reading up on the .au format, I wrote a Perl script to strip the audio files of their headers. After that, it was just a matter of using find and cat. I would assume if it's this easy to restore their temporary files, they must have designed things with restoration in mind. So what gives?

Call this strip-headers:

#!/usr/bin/perl -w
use strict;
die "usage: $0 in" unless @ARGV == 1;
my ($infile) = @ARGV;
my $buf;
my $outfile = "a" . substr($infile, 2);
open(IN, "<$infile") || die "problem opening 'in'
";
while() {
    $buf .= $_;
}
$buf = substr($buf, 12380);
close(IN) || die "problem closing 'in'
";
open(OUT, ">$outfile") || die "problem opening 'out' $outfile
";
print OUT $buf;
close(OUT) || die "problem closing 'out'
";
exit 0;

And this header:

#!/usr/bin/perl
use strict;
die "usage: $0 in" unless @ARGV == 1;
my ($infile) = @ARGV;
my ($buf, $head);
my $outhead = "head";
open(IN, "<$infile") || die "problem opening 'in'
";
while() {
    $buf .= $_;
}
$head = substr($buf, 0, 12380);
close(IN) || die "problem closing 'in'
";
open(OUT, ">$outhead") || die "problem opening 'out' $outhead
";
print OUT $head;
close(OUT) || die "problem closing 'out'
";

Then do:

[~ ]$ ./header
[~ ]$ find . -name "b*.au" -exec ./strip-headers \{} \;
[~ ]$ cat head a*.au > raw.au

Audacity should be able to import raw.au with no problems. Yes, this is just a one time hack. It could and should probably be cleaned up considering I'll very likely have to deal with this same problem again.

You must login to leave a comment

TrackBacks

No TrackBacks for this entry.