view tools/audio_processor_test/compare_wavs/compare_wavs.cpp @ 63:1d5cbb5343d2 pygar svn.64

[svn r64] mods to compile correctly for FPGA
author punk
date Mon, 10 May 2010 22:54:54 -0400
parents 90197e3375e2
children
line wrap: on
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
4 #include <sndfile.h>
5 #include <stdlib.h>
9 int
10 do_check (int drop, int argc, char * argv [])
11 {
12 int margin_of_error;
13 SNDFILE* goldenWavFile;
14 SNDFILE* outputWavFile;
15 SF_INFO goldenInfo ;
16 SF_INFO outputInfo ;
17 short int buffA;
18 short int buffB;
20 memset (&goldenInfo, 0, sizeof (goldenInfo)) ;
21 memset (&outputInfo, 0, sizeof (outputInfo)) ;
23 margin_of_error = atoi(argv[1]);
25 printf("Checking for Margin of Error %d\n", margin_of_error);
27 goldenWavFile = sf_open(argv[2], SFM_READ, &goldenInfo);
28 if (goldenWavFile == NULL){
29 printf ("\nERROR : failed Not able to open wav file named '%s' : %s/\n", argv[2], sf_strerror (NULL)) ;
30 exit (1) ;
31 }
33 outputWavFile = sf_open(argv[3], SFM_READ, &outputInfo);
34 if (outputWavFile == NULL){
35 printf ("\nERROR : failed Not able to open wav file named '%s' : %s/\n", argv[3], sf_strerror (NULL)) ;
36 exit (1) ;
37 }
39 int max_diff = 0;
41 // it is possible that the modified pipeline might introduce a few
42 // dummy tokens at the beginning of the stream, we'll just drop them
43 for(int i = 0; i < drop; i++){
44 sf_read_short(outputWavFile, &buffB, 1);
45 }
47 int count=0;
49 while(sf_read_short(goldenWavFile, &buffA, 1)==1){
51 if(sf_read_short(outputWavFile, &buffB, 1) != 1){
52 // the streams are of different length
53 printf("failed (length)\n");
54 exit(0);
55 }
57 int td = (buffA > buffB) ? (buffA - buffB) : (buffB - buffA);
58 max_diff = (td > max_diff) ? td : max_diff;
60 if(max_diff > margin_of_error){
61 printf("max_diff %x on drop %d (count %d)\n", max_diff, drop,count);
62 return 1;
63 }
65 count++;
66 }
68 printf("max_diff %x on drop %d\n", max_diff, drop);
70 if(max_diff > margin_of_error)
71 return 1;
72 else
73 return 0;
74 }
76 int
77 main(int argc, char* argv[])
78 {
79 for(int drop = 0; drop < 10; drop++){
80 if(do_check(drop, argc, argv)==0){
81 printf("passed on drop %d\n", drop);
82 exit(0);
83 }
84 }
85 printf("failed\n");
86 exit(1);
87 }