chiark / gitweb /
scripts/compare-raw, server/Makefile.am: Add script for comparing raw audio.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 2 May 2020 18:53:28 +0000 (19:53 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 2 May 2020 18:59:52 +0000 (19:59 +0100)
It does a very stupid comparison of corresponding samples to ensure that
they're not too far apart.  This is still an improvement over using
cmp(1).

scripts/Makefile.am
scripts/compare-raw [new file with mode: 0755]
server/Makefile.am

index d5d8c42..dfb4ae7 100644 (file)
@@ -25,6 +25,6 @@ include ${top_srcdir}/scripts/sedfiles.make
 
 EXTRA_DIST=htmlman sedfiles.make text2c oggrename make-unidata fix-names \
        format-gcov-report make-version-string setup.in teardown.in macro-docs \
-       setversion protocol
+       setversion protocol compare-raw
 
 CLEANFILES=$(SEDFILES)
diff --git a/scripts/compare-raw b/scripts/compare-raw
new file mode 100755 (executable)
index 0000000..70c5280
--- /dev/null
@@ -0,0 +1,45 @@
+#! /usr/bin/perl -w
+#
+# This file is part of DisOrder
+# Copyright (C) 2020 Mark Wooding
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+use autodie;
+use strict;
+
+(our $PROG = $0) =~ s:^.*/::;
+sub usage (\*) { print {$_[0]} "usage: $PROG DELTA FIRST SECOND\n"; }
+sub fail ($;$) { print STDERR "$PROG: $_[0]\n"; exit($_[1] // 2); }
+
+if (@ARGV != 3) { usage *STDERR; exit 2; }
+my $delta = $ARGV[0];
+open my $f, "<", $ARGV[1]; binmode $f;
+open my $g, "<", $ARGV[2]; binmode $g;
+my $off = 0;
+SAMPLE: for (;;) {
+  my $n = read $f, my $a, 2;
+  my $m = read $g, my $b, 2;
+  if (!$n) {
+    if ($m) { fail "$PROG: second file is longer (offset = $off)", 1; }
+    last SAMPLE;
+  } elsif (!$m) { fail "$PROG: first file is longer (offset = $off)", 1; }
+
+  my ($x) = unpack "s>", $a;
+  my ($y) = unpack "s>", $b;
+  if (abs($x - $y) > $delta)
+    { fail "$PROG: content differs (offset = $off: $x != $y)", 1; }
+  $off += 2;
+}
index c1cd6c4..2447485 100644 (file)
@@ -141,7 +141,8 @@ check-decode: check-wav check-flac check-mp3
 check-mp3: disorder-decode disorder-normalize
        ./disorder-decode ${top_srcdir}/sounds/scratch.mp3 | \
          ./disorder-normalize --config ${srcdir}/test-config > mp3ed.raw
-       cmp mp3ed.raw ${top_srcdir}/sounds/scratch-mp3.raw
+       $(top_srcdir)/scripts/compare-raw 0 \
+               mp3ed.raw ${top_srcdir}/sounds/scratch-mp3.raw
        rm -f mp3ed.raw
 
 # TODO ogg decoding comes out OK but different depending on platform, version
@@ -149,19 +150,22 @@ check-mp3: disorder-decode disorder-normalize
 check-ogg: disorder-decode disorder-normalize
        ./disorder-decode ${top_srcdir}/sounds/scratch.ogg | \
          ./disorder-normalize --config ${srcdir}/test-config > ogged.raw
-       cmp ogged.raw ${top_srcdir}/sounds/scratch.raw
+       $(top_srcdir)/scripts/compare-raw 0 \
+               ogged.raw ${top_srcdir}/sounds/scratch.raw
        rm -f ogged.raw
 
 check-wav: disorder-decode disorder-normalize
        ./disorder-decode ${top_srcdir}/sounds/scratch.wav | \
          ./disorder-normalize --config ${srcdir}/test-config > waved.raw
-       cmp waved.raw ${top_srcdir}/sounds/scratch.raw
+       $(top_srcdir)/scripts/compare-raw 0 \
+               waved.raw ${top_srcdir}/sounds/scratch.raw
        rm -rf waved.raw
 
 check-flac: disorder-decode disorder-normalize
        ./disorder-decode ${top_srcdir}/sounds/scratch.flac | \
          ./disorder-normalize --config ${srcdir}/test-config > flacced.raw
-       cmp flacced.raw ${top_srcdir}/sounds/scratch.raw
+       $(top_srcdir)/scripts/compare-raw 0 \
+               flacced.raw ${top_srcdir}/sounds/scratch.raw
        rm -f flacced.raw
 
 EXTRA_DIST=README.dbversions test-config