diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/audio_processor_test/compare_wavs/compare_wavs.cpp	Wed Apr 28 08:19:09 2010 -0400
     1.3 @@ -0,0 +1,87 @@
     1.4 +#include <stdio.h>
     1.5 +#include <assert.h>
     1.6 +#include <string.h>
     1.7 +#include <sndfile.h>
     1.8 +#include <stdlib.h>
     1.9 +
    1.10 +
    1.11 +
    1.12 +int
    1.13 +do_check (int drop, int argc, char * argv [])
    1.14 +{
    1.15 +  int margin_of_error;
    1.16 +  SNDFILE* goldenWavFile;
    1.17 +  SNDFILE* outputWavFile;
    1.18 +  SF_INFO goldenInfo ;
    1.19 +  SF_INFO outputInfo ;
    1.20 +  short int buffA;
    1.21 +  short int buffB;
    1.22 +
    1.23 +  memset (&goldenInfo, 0, sizeof (goldenInfo)) ;
    1.24 +  memset (&outputInfo, 0, sizeof (outputInfo)) ;
    1.25 +
    1.26 +  margin_of_error = atoi(argv[1]);
    1.27 +
    1.28 +  printf("Checking for Margin of Error %d\n", margin_of_error);
    1.29 +
    1.30 +  goldenWavFile = sf_open(argv[2], SFM_READ, &goldenInfo);
    1.31 +  if (goldenWavFile == NULL){      
    1.32 +    printf ("\nERROR : failed Not able to open wav file named '%s' : %s/\n", argv[2], sf_strerror (NULL)) ;
    1.33 +    exit (1) ;
    1.34 +  }
    1.35 +
    1.36 +  outputWavFile = sf_open(argv[3], SFM_READ, &outputInfo);
    1.37 +  if (outputWavFile == NULL){      
    1.38 +    printf ("\nERROR : failed Not able to open wav file named '%s' : %s/\n", argv[3], sf_strerror (NULL)) ;
    1.39 +    exit (1) ;
    1.40 +  }
    1.41 + 
    1.42 +  int max_diff = 0;
    1.43 +
    1.44 +  // it is possible that the modified pipeline might introduce a few
    1.45 +  // dummy tokens at the beginning of the stream, we'll just drop them
    1.46 +  for(int i = 0; i < drop; i++){
    1.47 +    sf_read_short(outputWavFile, &buffB, 1);
    1.48 +  }
    1.49 +
    1.50 +  int count=0;
    1.51 +
    1.52 +  while(sf_read_short(goldenWavFile, &buffA, 1)==1){
    1.53 +
    1.54 +    if(sf_read_short(outputWavFile, &buffB, 1) != 1){
    1.55 +      // the streams are of different length
    1.56 +      printf("failed (length)\n");
    1.57 +      exit(0);
    1.58 +    }
    1.59 +    
    1.60 +    int td =  (buffA > buffB) ? (buffA - buffB) : (buffB - buffA);
    1.61 +    max_diff = (td > max_diff) ? td : max_diff;
    1.62 +    
    1.63 +    if(max_diff > margin_of_error){
    1.64 +      printf("max_diff %x on drop %d (count %d)\n", max_diff, drop,count);
    1.65 +      return 1;
    1.66 +    }
    1.67 +
    1.68 +    count++;
    1.69 +  }
    1.70 +
    1.71 +  printf("max_diff %x on drop %d\n", max_diff, drop);
    1.72 +
    1.73 +  if(max_diff > margin_of_error)
    1.74 +    return 1;
    1.75 +  else
    1.76 +    return 0;
    1.77 +}
    1.78 +
    1.79 +int
    1.80 +main(int argc, char* argv[])
    1.81 +{
    1.82 +  for(int drop = 0; drop < 10; drop++){
    1.83 +    if(do_check(drop, argc, argv)==0){
    1.84 +      printf("passed on drop %d\n", drop);
    1.85 +      exit(0);
    1.86 +    }
    1.87 +  }
    1.88 +  printf("failed\n");
    1.89 +  exit(1);
    1.90 +}