Commit 17dfcb5f authored by Simon Morlat's avatar Simon Morlat

fix bug in audio compare tool

parent 64c4f960
......@@ -384,7 +384,7 @@ void ms_fir_mem16(const ms_word16_t *x, const ms_coef_t *num, ms_word16_t *y, in
typedef void (*MSAudioDiffProgressNotify)(void* user_data, int percentage);
/*utility function to check similarity between two audio wav files*/
int ms_audio_diff(const char *file1, const char *file2, float *ret, MSAudioDiffProgressNotify func, void *user_data);
int ms_audio_diff(const char *file1, const char *file2, double *ret, MSAudioDiffProgressNotify func, void *user_data);
#ifdef __cplusplus
}
......
......@@ -120,11 +120,11 @@ static int compute_cross_correlation(int16_t *s1, int n1, int16_t *s2, int n2, d
static double energy(int16_t *s1, int n1){
int i;
double ret=0;
int64_t ret=0;
for(i=0;i<n1;++i){
ret+=(double)s1[i]*(double)s1[i];
ret+=(int)s1[i]*(int)s1[i];
}
return ret;
return (double)ret;
}
void file_info_compute_energy(FileInfo *fi){
......@@ -136,7 +136,7 @@ void file_info_compute_energy(FileInfo *fi){
/**
* Utility that compares two PCM 16 bits audio files and returns a similarity factor between 0 and 1.
**/
int ms_audio_diff(const char *file1, const char *file2, float *ret, MSAudioDiffProgressNotify func, void *user_data){
int ms_audio_diff(const char *file1, const char *file2, double *ret, MSAudioDiffProgressNotify func, void *user_data){
FileInfo *fi1,*fi2;
double *xcorr;
int xcorr_size;
......@@ -172,9 +172,9 @@ int ms_audio_diff(const char *file1, const char *file2, float *ret, MSAudioDiffP
max_index=compute_cross_correlation(fi1->buffer,fi1->nsamples,fi2->buffer,fi2->nsamples,xcorr,xcorr_size, func, user_data);
max=xcorr[max_index];
ms_free(xcorr);
file_info_destroy(fi1);
file_info_destroy(fi2);
*ret=max/(sqrt(fi1->energy)*sqrt(fi2->energy));
ms_message("Max cross-correlation obtained at position [%i], similarity factor=%f",max_index,*ret);
ms_message("Max cross-correlation obtained at position [%i], similarity factor=%g",max_index,*ret);
file_info_destroy(fi1);
file_info_destroy(fi2);
return 0;
}
......@@ -27,17 +27,17 @@ static void completion_cb(void *user_data, int percentage){
}
int main(int argc, char *argv[]){
float ret;
double ret=0;
if (argc<3){
fprintf(stderr,"%s: file1 file2\nCompare two wav audio files and display a similarity factor between 0 and 1.\n",argv[0]);
return -1;
}
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
if (ms_audio_diff(argv[1],argv[2],&ret,completion_cb,NULL)==0){
fprintf(stdout,"%s and %s are similar with a degree of %f.\n",argv[1],argv[2],ret);
fprintf(stdout,"%s and %s are similar with a degree of %g.\n",argv[1],argv[2],ret);
return 0;
}else{
fprintf(stderr,"Error encountered during processing, exiting.\n");
}
return -1;
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment