From: Mark Wooding Date: Sat, 2 May 2020 18:53:28 +0000 (+0100) Subject: scripts/compare-raw, server/Makefile.am: Add script for comparing raw audio. X-Git-Tag: 5.2~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/63b86f2dd86f7c263c9e414314bf516895d61c6b scripts/compare-raw, server/Makefile.am: Add script for comparing raw audio. 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). --- diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d5d8c42..dfb4ae7 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -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 index 0000000..70c5280 --- /dev/null +++ b/scripts/compare-raw @@ -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 . +# + +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; +} diff --git a/server/Makefile.am b/server/Makefile.am index c1cd6c4..2447485 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -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