1 | #!/usr/bin/perl
|
---|
2 | use warnings;
|
---|
3 | use strict;
|
---|
4 |
|
---|
5 | my $num = 3624;
|
---|
6 |
|
---|
7 | my $infile = 'simon.voc';
|
---|
8 |
|
---|
9 | my $tmpvocfile = 'tmp.voc';
|
---|
10 | my $offsetfile = 'offsets';
|
---|
11 | my $tmpwavfile_all = 'tmpall.wav';
|
---|
12 |
|
---|
13 | system("rm $tmpwavfile_all") if stat($tmpwavfile_all);
|
---|
14 |
|
---|
15 | my $outfile = $infile;
|
---|
16 | $outfile =~ s/\.voc$/.wav/;
|
---|
17 |
|
---|
18 | my $tmpwavfile = $tmpvocfile;
|
---|
19 | $tmpwavfile =~ s/\.voc$/.wav/;
|
---|
20 |
|
---|
21 | if (stat($outfile)) {
|
---|
22 | die "$outfile: File exists. Exiting\n";
|
---|
23 | }
|
---|
24 |
|
---|
25 | open(IN, "<$infile") || die "Could not open file: $infile\n";
|
---|
26 | binmode(IN);
|
---|
27 |
|
---|
28 | my @offsets;
|
---|
29 | my @new_offsets;
|
---|
30 |
|
---|
31 | my $buf;
|
---|
32 | my $i;
|
---|
33 |
|
---|
34 | for ($i = 0; $i < $num; $i++) {
|
---|
35 | seek(IN, $i * 4, 0);
|
---|
36 | read(IN, $buf, 4);
|
---|
37 |
|
---|
38 | $offsets[$i] = unpack('I', $buf);
|
---|
39 | }
|
---|
40 | $offsets[$i] = (stat(IN))[7];
|
---|
41 |
|
---|
42 | $new_offsets[0] = 0;
|
---|
43 | $new_offsets[1] = $num * 4;
|
---|
44 |
|
---|
45 | for ($i = 1; $i < $num; $i++) {
|
---|
46 | if ($offsets[$i] == $offsets[$i + 1]) {
|
---|
47 | $new_offsets[$i + 1] = $new_offsets[$i];
|
---|
48 | next;
|
---|
49 | }
|
---|
50 |
|
---|
51 | seek(IN, $offsets[$i], 0);
|
---|
52 | read(IN, $buf, 8);
|
---|
53 |
|
---|
54 | if ($buf eq 'Creative') {
|
---|
55 | printf("Audio found at offset: %x\n", $offsets[$i]);
|
---|
56 | } else {
|
---|
57 | printf("ERROR: No audio found at offset: %x\n", $offsets[$i]);
|
---|
58 | die "Exiting.\n";
|
---|
59 | }
|
---|
60 |
|
---|
61 | seek(IN, $offsets[$i], 0);
|
---|
62 | read(IN, $buf, $offsets[$i + 1] - $offsets[$i]);
|
---|
63 |
|
---|
64 | open(TMP, ">$tmpvocfile");
|
---|
65 | binmode(TMP);
|
---|
66 | print TMP $buf;
|
---|
67 | close(TMP);
|
---|
68 | undef $buf;
|
---|
69 |
|
---|
70 | system("sox $tmpvocfile $tmpwavfile; cat $tmpwavfile >> $tmpwavfile_all");
|
---|
71 |
|
---|
72 | $new_offsets[$i + 1] = $new_offsets[$i] + (stat($tmpwavfile))[7];
|
---|
73 | }
|
---|
74 | pop(@new_offsets);
|
---|
75 |
|
---|
76 | close(IN);
|
---|
77 |
|
---|
78 | open(OUT, ">$outfile");
|
---|
79 | binmode(OUT);
|
---|
80 | foreach (@new_offsets) {
|
---|
81 | print OUT pack('I', $_);
|
---|
82 | }
|
---|
83 | close(OUT);
|
---|
84 |
|
---|
85 | system("cat $tmpwavfile_all >> $outfile");
|
---|
86 |
|
---|
87 | exit(0);
|
---|
88 |
|
---|