chiark / gitweb /
scripts/compare-raw, server/Makefile.am: Add script for comparing raw audio.
[disorder] / scripts / compare-raw
CommitLineData
63b86f2d
MW
1#! /usr/bin/perl -w
2#
3# This file is part of DisOrder
4# Copyright (C) 2020 Mark Wooding
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19
20use autodie;
21use strict;
22
23(our $PROG = $0) =~ s:^.*/::;
24sub usage (\*) { print {$_[0]} "usage: $PROG DELTA FIRST SECOND\n"; }
25sub fail ($;$) { print STDERR "$PROG: $_[0]\n"; exit($_[1] // 2); }
26
27if (@ARGV != 3) { usage *STDERR; exit 2; }
28my $delta = $ARGV[0];
29open my $f, "<", $ARGV[1]; binmode $f;
30open my $g, "<", $ARGV[2]; binmode $g;
31my $off = 0;
32SAMPLE: for (;;) {
33 my $n = read $f, my $a, 2;
34 my $m = read $g, my $b, 2;
35 if (!$n) {
36 if ($m) { fail "$PROG: second file is longer (offset = $off)", 1; }
37 last SAMPLE;
38 } elsif (!$m) { fail "$PROG: first file is longer (offset = $off)", 1; }
39
40 my ($x) = unpack "s>", $a;
41 my ($y) = unpack "s>", $b;
42 if (abs($x - $y) > $delta)
43 { fail "$PROG: content differs (offset = $off: $x != $y)", 1; }
44 $off += 2;
45}