summaryrefslogtreecommitdiff
path: root/datasets/dataset.pl
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-05-14 19:15:58 +0200
committerJules Laplace <julescarbon@gmail.com>2018-05-14 19:15:58 +0200
commit60fb2b7c87b7e6aa179c6a973a8d6e39cbe7c594 (patch)
tree8a738a43e8583f38f151cdc643a38b5a9437cda2 /datasets/dataset.pl
parent9766ef0f3a539be7ee68bb93918f25a3298afe39 (diff)
parente2d8a6f26c5e44d970d7c069f171105376835495 (diff)
Merge branch 'master' of asdf.us:samplernn
Diffstat (limited to 'datasets/dataset.pl')
-rwxr-xr-xdatasets/dataset.pl75
1 files changed, 75 insertions, 0 deletions
diff --git a/datasets/dataset.pl b/datasets/dataset.pl
new file mode 100755
index 0000000..75aa2b1
--- /dev/null
+++ b/datasets/dataset.pl
@@ -0,0 +1,75 @@
+#!/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;
+ }
+
+ if ($ext eq 'mp3') {
+ system('ffmpeg', '-i', $filename, $name . '.wav');
+ $filename = $name . '.wav';
+ }
+ 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);
+ }
+}
+
+