compare.c 2.21 KB
Newer Older
Gildas Bazin's avatar
Gildas Bazin committed
1 2 3 4 5
/*
 * compare.c
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
6 7
 * This file is part of libdca, a free DTS Coherent Acoustics stream decoder.
 * See http://www.videolan.org/developers/libdca.html for updates.
Gildas Bazin's avatar
Gildas Bazin committed
8
 *
9
 * libdca is free software; you can redistribute it and/or modify
Gildas Bazin's avatar
Gildas Bazin committed
10 11 12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
14
 * libdca is distributed in the hope that it will be useful,
Gildas Bazin's avatar
Gildas Bazin committed
15 16 17 18 19
 * 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
20 21 22
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Gildas Bazin's avatar
Gildas Bazin committed
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 72 73 74 75 76 77 78 79 80
 */

#include <stdio.h>
#include <math.h>

int main (int argc, char ** argv)
{
    FILE * f1;
    FILE * f2;
    float buf1[512];
    float buf2[512];
    int i, j;
    int total = 0;
    double max = 0, err = 0, square = 0;

    if (argc != 3)
	return 1;
    f1 = fopen (argv[1], "rb");
    f2 = fopen (argv[2], "rb");
    if ((f1 == NULL) || (f2 == NULL)) {
	printf ("cannot open file %s\n", (f1 == NULL) ? argv[1] : argv[2]);
	return 1;
    }
    while (1) {
	i = fread (buf1, sizeof (float), 512, f1);
	j = fread (buf2, sizeof (float), 512, f2);
	if ((i < 512) || (j < 512))
	    break;
	for (i = 0; i < 512; i++) {
	    double delta;

	    delta = buf2[i] - buf1[i];
	    err += delta;
	    square += delta * delta;
	    if (delta > max)
		max = delta;
	    if (-delta > max)
		max = -delta;
	}
	total += 512;
    }
    if (i == j) {
	err /= total;
	square = (square / total) - (err * err);
	if (square > 0)
	    square = 32768 * sqrt (square);
	err *= 32768;
	max *= 32768;
	printf ("max error %f mean error %f standard deviation %f\n",
		max, err, square);
	return ((max > 0.01) || (err > 0.001) || (square > 0.001));
    }
    if (i < j)
	printf ("%s is too short\n", argv[1]);
    else
	printf ("%s is too short\n", argv[2]);
    return 1;
}