Skip to content

Commit 0839318

Browse files
committed
qext_compare: add comparison thresholds
1 parent 933a4d7 commit 0839318

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/qext_compare.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static const int BANDS[NBANDS+1]={
187187

188188

189189
void usage(const char *_argv0) {
190-
fprintf(stderr,"Usage: %s [-s] [-48k] [-s16|-s24|-f32] [-r rate2] <file1.sw> <file2.sw>\n",
190+
fprintf(stderr,"Usage: %s [-s] [-48k] [-s16|-s24|-f32] [-r rate2] [-thresholds err4 err16 rms] <file1.sw> <file2.sw>\n",
191191
_argv0);
192192
}
193193

@@ -222,6 +222,8 @@ int main(int _argc,const char **_argv){
222222
int format;
223223
double rms=-1;
224224
const char *argv0 = _argv[0];
225+
double err4_threshold=-1, err16_threshold=-1, rms_threshold=-1;
226+
int compare_thresholds=0;
225227
if(_argc<3){
226228
usage(argv0);
227229
return EXIT_FAILURE;
@@ -256,6 +258,17 @@ int main(int _argc,const char **_argv){
256258
format=FORMAT_F32_LE;
257259
_argv++;
258260
_argc--;
261+
} else if(strcmp(_argv[1],"-thresholds")==0){
262+
if (_argc < 7) {
263+
usage(argv0);
264+
return EXIT_FAILURE;
265+
}
266+
err4_threshold=atof(_argv[2]);
267+
err16_threshold=atof(_argv[3]);
268+
rms_threshold=atof(_argv[4]);
269+
compare_thresholds=1;
270+
_argv+=4;
271+
_argc-=4;
259272
} else if(strcmp(_argv[1],"-r")==0){
260273
rate=atoi(_argv[2]);
261274
if(rate!=8000&&rate!=12000&&rate!=16000&&rate!=24000&&rate!=48000&&rate!=96000){
@@ -496,5 +509,13 @@ int main(int _argc,const char **_argv){
496509
err4=pow(err4/nframes,1.0/4);
497510
err16=pow(err16/nframes,1.0/16);
498511
fprintf(stderr, "err4 = %f, err16 = %f, rms = %f\n", err4, err16, rms);
512+
if (compare_thresholds) {
513+
if (err4 <= err4_threshold && err16 <= err16_threshold && rms <= rms_threshold) {
514+
fprintf(stderr, "Comparison PASSED\n");
515+
} else {
516+
fprintf(stderr, "*** Comparison FAILED *** (thresholds were %f %f %f)\n", err4_threshold, err16_threshold, rms_threshold);
517+
return EXIT_FAILURE;
518+
}
519+
}
499520
return EXIT_SUCCESS;
500521
}

0 commit comments

Comments
 (0)