comparison tools/audio_processor_test/compare_wavs/compare_wavs.cpp @ 23:90197e3375e2 pygar svn.24

[svn r24] added testing, but something is wrong with our c++ file.
author rlm
date Wed, 28 Apr 2010 08:19:09 -0400
parents
children
comparison
equal deleted inserted replaced
22:0cfbb1e2de22 23:90197e3375e2
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
4 #include <sndfile.h>
5 #include <stdlib.h>
6
7
8
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;
19
20 memset (&goldenInfo, 0, sizeof (goldenInfo)) ;
21 memset (&outputInfo, 0, sizeof (outputInfo)) ;
22
23 margin_of_error = atoi(argv[1]);
24
25 printf("Checking for Margin of Error %d\n", margin_of_error);
26
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 }
32
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 }
38
39 int max_diff = 0;
40
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 }
46
47 int count=0;
48
49 while(sf_read_short(goldenWavFile, &buffA, 1)==1){
50
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 }
56
57 int td = (buffA > buffB) ? (buffA - buffB) : (buffB - buffA);
58 max_diff = (td > max_diff) ? td : max_diff;
59
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 }
64
65 count++;
66 }
67
68 printf("max_diff %x on drop %d\n", max_diff, drop);
69
70 if(max_diff > margin_of_error)
71 return 1;
72 else
73 return 0;
74 }
75
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 }