gendistort.c

来自「speech signal process tools」· C语言 代码 · 共 333 行

C
333
字号
/* gen_distort - compute distortion measures between two ESPS "generic" files * * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing by * Entropic Speech, Inc. must bear the notice * *    "Copyright (c) 1987 Entropic Speech, Inc.; All rights reserved" * * Module Name:  gen_distort *  * Written By:  Ajaipal S. Virdy * * * Purpose:  compute distortion measure for speech processes * * */#ifdef SCCS	static char *sccs_id = "@(#)gendistort.c	3.3	10/20/93	ESI";#endif#include <stdio.h>#include <esps/esps.h>/* declare external variables for modules in distort */#include  "distort.h"/* Global variables for gen_distort only */double	*data1;      /* used to store generic data elements */double	*data2;      /* used to store generic data elements */double	**diff;      /* used to store the difference between two files */long	tag;/* * U N I X *  R O U T I N E S *   R E F E R E N C E D *//* * E S P S *  R O U T I N E S *   R E F E R E N C E D */short	get_rec_len();int	get_gen_recd();/* * L O C A L *  R O U T I N E S *   R E F E R E N C E D */void	allo_gen_memory();void gen_distort(){   int		rec_num;	/* current record number */   int		i_rec;		/* record index */   int		i_ele;  	/* current element number */   int		j;		/* temporary element index */   int	data1_len;	/* length of generic data buffer read */   int	data2_len;	/* length of generic data buffer read */   int	size1;	/* used to store the maximum memory we need to allocate */   int	size2;	/* used to store the maximum memory we need to allocate */   int	rows;		/* size of row to allocate */   int	columns;	/* size of column to allocate *//* *  BEGIN *    gen_distort *      module */   if ( debug_level > 3)      (void) fprintf (stderr,      "\n");/* * Check the generic files to make sure they are compatible * */   if ( get_rec_len (f1h) != get_rec_len (f2h) ) {      (void) fprintf (stderr,      "gen_distort: warning, elements per record not equal in both files.\n");    } else 	if (debug_level > 4)	   (void) fprintf (stderr,	   "gen_distort: same number of elements in these generic files.\n");/* * The following variables are used to compute the size of  * our multi-dimensional arrays*/   size1 = get_rec_len (f1h);   size2 = get_rec_len (f2h);/* * Now allocate: * *   number of records [rows] * 	    by  *   MAX ( f1h->common.ndouble + nfloat + nlong + nshort + nchar, *         f2h->common.ndouble + nfloat + nlong + nshort + nchar ) [columns] * * memory space to store all * differences between elements in each record for computing the Element * Average, Record Average, and File Average. * */   rows = (e_rec - s_rec + 1);	/* number of rows to allocate */   columns = MAX (size1, size2);   if (debug_level > 2)      (void) fprintf (stderr,      "gen_distort: rows to allocate = %d, columns to allocate = %d\n",      rows, columns);   (void) allo_gen_memory (rows, columns);/* * Skip appropiate number of records (as specified by the -f option) * *//* already skipped appropriate number of records *//* * This is the way I originally skipped records: * * *   for ( rec_num = 1; rec_num < s_rec; rec_num++ ) { * *     \* Skip records *\ * *     if (get_gen_recd (data1, &tag, f1h, f1p) == EOF) { *	(void) fprintf (stderr, *	"gen_distort: only %d records read.\n", rec_num); *	exit (1); *     } *     if (get_gen_recd (data2, &tag, f2h, f2p) == EOF) { *	(void) fprintf (stderr, *	"gen_distort: only %d records read.\n", rec_num); *	exit (1); *     } * *   } \* Skipping records . . . *\ * *//* * Here is the big loop for ESPS generic files. * Note: we have to check for consistency *       each time through the loop.   */   if (debug_level > 4)      (void) fprintf (stderr,      "gen_distort: for (rec_num = %d; rec_num <= %d; rec_num++) {\n",      s_rec, e_rec);/* * *  M A I N    L O O P: * */   for ( rec_num = s_rec, i_rec = 0; rec_num <= e_rec; rec_num++, i_rec++ ) {     if (debug_level > 4)	(void) fprintf (stderr,	"\n  gen_distort: getting record no. %d.\n", rec_num);     if ((data1_len = get_gen_recd (data1, &tag, f1h, f1p)) == EOF) {	(void) fprintf (stderr,	"gen_distort: only %d records read.\n", i_rec);	exit (1);     }     if ((data2_len = get_gen_recd (data2, &tag, f2h, f2p)) == EOF) {	(void) fprintf (stderr,	"gen_distort: only %d records read.\n", i_rec);	exit (1);     }     if (debug_level > 3)	(void) fprintf (stderr,	"gen_distort: data1_len = %d, data2_len = %d\n",	data1_len, data2_len);/* * check for consistency in file1 and file2 * */     if (debug_level > 4)	(void) fprintf (stderr,	"  gen_distort: checking for consistency in this record.\n");/*     if (data1_len != data2_len) {	(void) fprintf (stderr,	"gen_distort: number of elements in this record not equal in both files.\n");	exit (1);     } else	if (debug_level > 2)	   (void) fprintf (stderr,	   "  gen_distort: record no. %d is consistent.\n", rec_num);*/     if ( e_ele > data1_len ) {	(void) fprintf (stderr,       "gen_distort: element range incorrect, only %d elements in %s.\n",	data1_len, f1str);	exit (1);     }     if ( e_ele > data2_len ) {	(void) fprintf (stderr,       "gen_distort: element range incorrect, only %d elements in %s.\n",	data1_len, f2str);	exit (1);     }/* * Now begin to compute: *   Difference, Difference Magnitude, and Difference Magnitude Squared. */		if (debug_level > 4) {	   (void) fprintf (stderr,	   "  gen_distort: for (i_ele = %d, j = 0;\n", s_ele - 1);	   (void) fprintf (stderr,	   "                      i_ele < %d; i_ele++,j++) {\n",	   e_ele);	}/* * 	E L E M E N T   L O O P: *  * Loop through each element and store the difference between all elements * (possibly restricted by -e option) for all specified records. * */	for (i_ele = s_ele - 1, j = 0; i_ele < e_ele; i_ele++, j++) {	   if (debug_level > 4)	      (void) fprintf (stderr,	      "    gen_distort: i_ele = %d, j = %d\n", i_ele, j);	   diff[i_rec][j] = data1[i_ele] - data2[i_ele];	   if (debug_level > 4)	      (void) fprintf (stderr,	      "    gen_distort: diff[%d][%d] = %f\n",	      i_rec, j, diff[i_rec][j]);	} /*  end  E L E M E N T    L O O P   */   }  /* end big for loop */   if (Eflag)      pr_gen_ele (diff);   if (rflag && !Eflag) {	/* print only Record and File Averages */      pr_gen_rec_avg (diff);	  	/* print Record Average */      pr_gen_file_avg (diff);  		/* print File Average */      return;   }   pr_gen_ele_avg (diff);	/* print Element Average */   if (rflag)      pr_gen_rec_avg (diff);  	/* print Record Average */   pr_gen_file_avg (diff);  	/* print File Average */} /* end gen_distort() */static voidallo_gen_memory (rows, columns)int	rows;int	columns;{   double	**d_mat_alloc();#ifndef DEC_ALPHA   char		*calloc();#endif   if ( (diff = (double **) d_mat_alloc (rows, columns)) == NULL ) {	(void) fprintf (stderr,	"gen_distort: d_mat_alloc: diff: could not allocate memory.\n");	exit (1);   }   if ( (data1 = (double *) calloc ((unsigned int) columns, sizeof (double))) == NULL ) {	(void) fprintf (stderr,	"gen_distort: calloc: data1: could not allocate memory.\n");	exit (1);   }   if ( (data2 = (double *) calloc ((unsigned int) columns, sizeof (double))) == NULL ) {	(void) fprintf (stderr,	"gen_distort: calloc: data2: could not allocate memory.\n");	exit (1);   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?