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