summaryrefslogtreecommitdiff
path: root/datasets/dataset.pl
blob: 8b77af9d7b29a4c295146315e8d02f35b0d96ddb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

use strict;
use Getopt::Std;

our $opt_c;
getopts('c');

my $fmt = <<FMT;
Input File     : '01_snapping_clean.wav'
Channels       : 1
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:03:09.35 = 8350438 samples = 14201.4 CDDA sectors
File Size      : 16.7M
Bit Rate       : 706k
Sample Encoding: 16-bit Signed Integer PCM
FMT

sub process($) {
  my $filename = shift or die "Usage: $0 [...filenames]\n";
  my ($name, $ext) = split(/\./, $filename, 2);
  if ($ext !~ /(wav|mp3|aiff?|flac)/) {
    print "not a valid file extension: $ext\n";
    return;
  }

  my $soxi = `soxi $filename`;
  my @lines = split("\n", $soxi);

  print $soxi;

  my $seconds;
  for my $line (@lines) {
    if ($line =~ /Duration       : (\d\d):(\d\d):(\d\d)\./) {
      my $h = $1;
      my $m = $2;
      my $s = $3;
      $seconds = (((($h * 60) + $m) * 60) + $s) + 0;
    }
  }

  my $scale = sprintf("%.09f", 5e-7 * $seconds);

  print "Seconds: $seconds\n";
  print "Scale factor: $scale\n";
  print "\n";

  my $a_tmp = "a_" . $filename;
  my $b_tmp = "b_" . $filename;
  if ($opt_c) {
    print "Normalizing...";
    system("sox", "-v", 0.945, $filename, $a_tmp);
  } else {
    $a_tmp = $filename;
  }
  system("./spread.sh", $a_tmp, $b_tmp, 0.999, $scale, 1.001);
  system("./split44k.sh", $b_tmp, 8, $name);
  if ($opt_c) {
    system("/bin/rm", $a_tmp);
  }
  system("/bin/rm", $b_tmp);
}

foreach my $file (@ARGV) {;
  if ( -e $file ) {
    process($file);
  }
}