msaudiocmp.c 1.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2014  Belledonne Communications SARL
Author: Simon Morlat <simon.morlat@linphone.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "mediastreamer2/mscommon.h"
22
#include "mediastreamer2/msutils.h"
23 24 25 26 27 28 29

static void completion_cb(void *user_data, int percentage){
	fprintf(stdout,"%i %% completed\r",percentage);
	fflush(stdout);
}

int main(int argc, char *argv[]){
30
	double ret=0;
31
	MSAudioDiffParams params={0};
32
	if (argc<3){
33
		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]);
34 35
		return -1;
	}
36
	if (argc>3){
37 38 39 40
		params.max_shift_percent=atoi(argv[3]);
	}
	if (argc>4){
		params.chunk_size_ms = atoi(argv[4]);
41
	}
42
	ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
43
	if (ms_audio_diff(argv[1],argv[2],&ret,&params,completion_cb,NULL)==0){
44
		fprintf(stdout,"%s and %s are similar with a degree of %g.\n",argv[1],argv[2],ret);
45 46 47 48 49
		return 0;
	}else{
		fprintf(stderr,"Error encountered during processing, exiting.\n");
	}
	return -1;
50
}