Commit f8673538 authored by Simon Morlat's avatar Simon Morlat

new implementation of ms_audio_diff() that gives clever results. It is much...

new implementation of ms_audio_diff() that gives clever results. It is much less sensitives to temporal shifts at the middle of the scanned audio segment.
parent e9b2d8d4
......@@ -29,17 +29,23 @@ extern "C"{
typedef void (*MSAudioDiffProgressNotify)(void* user_data, int percentage);
typedef struct _MSAudioDiffParams{
int max_shift_percent; /*percentage of overlap between the two signals, used to restrict the cross correlation around t=0 in range [1 ; 100].*/
int chunk_size_ms; /*chunk size in milliseconds, if chunked cross correlation is to be used. Use 0 otherwise.*/
}MSAudioDiffParams;
/**
* Utility that compares two PCM 16 bits audio files and returns a similarity factor between 0 and 1.
* @param file1 a wav file path
* @param file2 a wav file path
* @param ref_file path to a wav file contaning the reference audio segment
* @param matched_file path to a wav file contaning the audio segment where the reference file is to be matched.
* @param ret the similarity factor, set in return
* @param max_shift_percent percentage of overlap between the two signals, used to restrict the cross correlation around t=0 in range [1 ; 100].
* @param func a callback called to show progress of the operation
* @param user_data a user data passed to the callback when invoked.
* @return -1 on error, 0 if succesful.
**/
MS2_PUBLIC int ms_audio_diff(const char *file1, const char *file2, double *ret, int max_shift_percent, MSAudioDiffProgressNotify func, void *user_data);
MS2_PUBLIC int ms_audio_diff(const char *ref_file, const char *matched_file, double *ret, const MSAudioDiffParams *params, MSAudioDiffProgressNotify func, void *user_data);
#ifdef __cplusplus
}
......
This diff is collapsed.
......@@ -28,16 +28,19 @@ static void completion_cb(void *user_data, int percentage){
int main(int argc, char *argv[]){
double ret=0;
double overlap=0;
MSAudioDiffParams params={0};
if (argc<3){
fprintf(stderr,"%s: file1 file2 [overlap-percentage]\nCompare two wav audio files and display a similarity factor between 0 and 1.\n",argv[0]);
fprintf(stderr,"%s: file1 file2 [overlap-percentage] [chunk size in milliseconds]\nCompare two wav audio files and display a similarity factor between 0 and 1.\n",argv[0]);
return -1;
}
if (argc>3){
overlap=atoi(argv[3]);
params.max_shift_percent=atoi(argv[3]);
}
if (argc>4){
params.chunk_size_ms = atoi(argv[4]);
}
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
if (ms_audio_diff(argv[1],argv[2],&ret,overlap,completion_cb,NULL)==0){
if (ms_audio_diff(argv[1],argv[2],&ret,&params,completion_cb,NULL)==0){
fprintf(stdout,"%s and %s are similar with a degree of %g.\n",argv[1],argv[2],ret);
return 0;
}else{
......
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