Audacity recovery script
Jump to navigation
Jump to search
I wrote this script because the Audacity Recovery Utility I installed didn't work at all. It operates on mostly the same principles. It prints an sh script on stdout so you can edit it before running it.
This version only handles two-channel recording, but could easily be modified.
Usage
cd to the data directory of the project and do
ls | recov > out.sh sh out.sh
Source
#! /usr/bin/perl use warnings; use strict; use Carp; my @rescue = (); while(<>) { chomp; if(/b(\d+)\.au$/o) { push(@rescue,$_); } } print STDERR "Got " . scalar(@rescue) . " file(s).\n"; my @chains = (); my $previndex = undef; my $chain = undef; foreach(sort @rescue) { /b(\d+)\.au$/o or die "Unrecognized filename $_\n"; my $index = $1; unless( defined($chain) and +($index == $previndex + 1) ) { $chain = []; push(@chains,$chain); } push(@$chain, $_); $previndex = $index; } print STDERR "Separated into " . scalar(@chains) . " contiguous chain(s).\n"; print "#! /bin/sh\n"; my $chainno = 0; my $tmp = 0; foreach my $chain (@chains) { my @lists = ([],[]); my $chan = 0; foreach(sort @$chain) { push( @{$lists[$chan]}, $_ ); $chan = +($chan + 1) % 2; } foreach my $chan (0, 1) { print "echo Recovering chain $chainno channel $chan\n"; my @oproc = ( @{$lists[$chan]} ); $_ = qq("$_") foreach @oproc; my $dst = ''; my $ind = 0; while( @oproc > 1 ) { my @proc = @oproc; last if @proc == 1; @oproc = (); while( @proc ) { print "echo Pass $ind\n"; $dst = "tmp.output-$tmp.au"; my @round = splice @proc, 0, 30; print "sox @round $dst\n"; push(@oproc, $dst); ++$ind; ++$tmp; } } print "mv $oproc[0] output-$chainno-$chan.au\n"; print "echo Done.\n"; } ++$chainno; }