⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mlpg.c

📁 Speech Signal Processing Toolkit 3.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ----------------------------------------------------------------	Speech Signal Processing Toolkit (SPTK): version 3.0			 SPTK Working Group		   Department of Computer Science		   Nagoya Institute of Technology				and    Interdisciplinary Graduate School of Science and Engineering		   Tokyo Institute of Technology		      Copyright (c) 1984-2000			All Rights Reserved.  Permission is hereby granted, free of charge, to use and  distribute this software and its documentation without  restriction, including without limitation the rights to use,  copy, modify, merge, publish, distribute, sublicense, and/or  sell copies of this work, and to permit persons to whom this  work is furnished to do so, subject to the following conditions:    1. The code must retain the above copyright notice, this list       of conditions and the following disclaimer.    2. Any modifications must be clearly marked as such.  NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF TECHNOLOGY,  SPTK WORKING GROUP, AND THE CONTRIBUTORS TO THIS WORK DISCLAIM  ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT  SHALL NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF  TECHNOLOGY, SPTK WORKING GROUP, NOR THE CONTRIBUTORS BE LIABLE  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS  ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  PERFORMANCE OF THIS SOFTWARE. ----------------------------------------------------------------*//*************************************************************************************************												**    ML-based Parameter Generation from PDFs	 						**												**									2000.4  T.Masuko	**												**	usage:											**		mlpg [ options ] [infile] > stdout						**	options:										**		-m m              : order of vector                              [25]		**		-l l              : length of vector                             [m-1]		**		-d fn             : filename of delta coefficients               [N/A]		**		-d coef [coef...] : delta coefficients                           [N/A]		**		-r n w1 [w2]      : number and width of regression coefficients  [N/A]		**		-i i              : type of input PDFs                           [0]		**		-s s              : range of influenced frames                   [30]		**		-h                : print this message						**	infile:											**		PDF sequence									**		ex.)	, m(0), m(1), ..., m((m+1)*d-1),					**			  U(0), U(1), ..., U((m+1)*d-1),					**	stdout:											**		parameter sequence								**			, c(0), c(1), ..., c_1(m),						**												*************************************************************************************************/static char *rcs_id = "$Id: mlpg.c,v 1.5 2002/12/25 05:31:50 sako Exp $";/* Standard C Libraries */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <SPTK.h>/* default values */#define		ORDER		25#define		ITYPE		0#define		RANGE		30/*  Command Name  */char		*cmnd;/*  Other Definitions  */#ifdef DOULBE	typedef double real;#else	typedef float real;#endif#define	LENGTH		256#define	INFTY		((double) 1.0e+38)#define	INFTY2		((double) 1.0e+19)#define	INVINF		((double) 1.0e-38)#define	INVINF2		((double) 1.0e-19)#define	WLEFT		0#define	WRIGHT		1#define	abs(x)		((x) > 0.0 ? (x) : -(x))#define	sign(x)		((x) >= 0.0 ? 1 : -1)#define	finv(x)		(abs(x) <= INVINF2 ? sign(x)*INFTY : (abs(x) >= INFTY2 ? 0 : 1.0/(x)))#define	min(x, y)	((x) < (y) ? (x) : (y))typedef struct _DWin {	int		num;		/* number of static + deltas */	int		calccoef;	/* calculate regression coefficients */	char		**fn;		/* delta window coefficient file */	int		**width;	/* width [0..num-1][0(left) 1(right)] */	double		**coef;		/* coefficient [0..num-1][length[0]..length[1]] */	int		maxw[2];	/* max width [0(left) 1(right)] */} DWin;typedef struct _SMatrix {	double		**mseq;		/* sequence of mean vector */	double		**ivseq;	/* sequence of invarsed variance vector */	double		***P;		/* matrix P[th][tv][m] */	double		**c;		/* parameter c */	double		**pi;	double		**k;	int		t;		/* time index */	int		length;		/* matrix length (must be power of 2) */	unsigned int	mask;		/* length - 1 */} SMatrix;typedef struct _PStream {	int		vSize;		/* data vector size */	int		order;		/* order of cepstrum */	int		range;	DWin		dw;	double		*mean;		/* input mean vector */	double		*ivar;		/* input inversed variance vector */	double		*par;		/* output parameter vector */	int		iType;		/* type of input PDFs */					/*   0: ( m       , U      ) */					/*   1: ( m       , U^{-1} ) */					/*   2: ( mU^{-1} , U^{-1} ) */	SMatrix		sm;} PStream;void usage(int status){    fprintf(stderr, "\n");    fprintf(stderr, " %s - obtain parameter sequence from PDF sequence\n", cmnd);    fprintf(stderr, "\n");    fprintf(stderr, "  usage:\n");    fprintf(stderr, "       %s [ options ] [infile] > stdout\n", cmnd);    fprintf(stderr, "  options:\n");    fprintf(stderr, "       -m m              : order of vector                              [%d]\n", ORDER);    fprintf(stderr, "       -l l              : length of vector                             [m+1]\n");    fprintf(stderr, "       -d fn             : filename of delta coefficients               [N/A]\n");    fprintf(stderr, "       -d coef [coef...] : delta coefficients                           [N/A]\n");    fprintf(stderr, "       -r n t1 [t2]      : number and width of regression coefficients  [N/A]\n");    fprintf(stderr, "       -i i              : type of input PDFs                           [%d]\n", ITYPE);    fprintf(stderr, "                             0: ( m       , U      )\n");    fprintf(stderr, "                             1: ( m       , U^{-1} )\n");    fprintf(stderr, "                             2: ( mU^{-1} , U^{-1} )\n");    fprintf(stderr, "       -s s              : range of influenced frames                   [%d]\n", RANGE);    fprintf(stderr, "       -h                : print this message\n");    fprintf(stderr, "\n");    fprintf(stderr, "  infile:\n");    fprintf(stderr, "       PDF sequence                                                     [stdin]\n");    fprintf(stderr, "  stdout:\n");    fprintf(stderr, "       parameter sequence\n");    fprintf(stderr, "  note:\n");    fprintf(stderr, "       1) Option '-d' may be repeated to use multiple delta parameters.\n");    fprintf(stderr, "       2) Options '-d' and '-r' shuold not be defined simultaneously.\n");    fprintf(stderr, "\n");    exit(status);}int main(int argc, char **argv){	char		*s;	FILE		*pdffp = stdin, *parfp = stdout;	int		nframe, delay;	char		*coef;	int		coeflen;	PStream		pst;	register int	i, j;	int		isfloat(char *);	void		InitPStream(PStream *);	double		*mlpg(PStream *);	pst.order = ORDER;	pst.range = RANGE;	pst.iType = ITYPE;	pst.dw.fn = (char **)calloc(sizeof(char *), argc);	pst.dw.num = 1;	pst.dw.calccoef = -1;	if ((cmnd = strrchr(argv[0], '/')) == NULL)		cmnd = argv[0];	else		cmnd++;	while (--argc) {		if (**++argv == '-') {			switch (*(*argv+1)) {				case 'd':					if (pst.dw.calccoef == 1) {						fprintf(stderr, "Options '-r' and '-d' should not be defined simultaneously.\n");						exit(1);					}					pst.dw.calccoef = 0;					if (isfloat(*++argv)) {						coeflen = 0;						for (i = 0; (i < argc - 1) && isfloat(argv[i]); i++) {							coeflen += strlen(argv[i]) + 1;						}						coeflen += 1;						coef = pst.dw.fn[pst.dw.num] = (char *)calloc(coeflen, sizeof(char));						for (j = 0; j < i; j++) {							sprintf(coef, " %s", *argv);							coef += strlen(*argv) + 1;							if (j < i-1) {								argv++;								argc--;							}						}					}					else {						pst.dw.fn[pst.dw.num] = *argv;					}					pst.dw.num++;					--argc;					break;				case 'r':					if (pst.dw.calccoef == 0) {						fprintf(stderr, "Options '-r' and '-d' should not be defined simultaneously.\n");						exit(1);					}					pst.dw.calccoef = 1;					coeflen = atoi(*++argv);					--argc;					if ((coeflen != 1) && (coeflen != 2)) {						fprintf(stderr, "Number of delta parameter should be 1 or 2\n");						exit(1);					}					if (argc <= 1) {						fprintf(stderr, "Window size for delta parameter required.\n");						exit(1);					}					pst.dw.fn[pst.dw.num] = *++argv;					pst.dw.num++;					--argc;					if (coeflen == 2) {						if (argc <= 1) {							fprintf(stderr, "Window size for delta-delta parameter required.\n");							exit(1);						}						pst.dw.fn[pst.dw.num] = *++argv;						pst.dw.num++;						--argc;					}					break;				case 'm':					pst.order = atoi(*++argv);					--argc;					break;				case 'l':					pst.order = atoi(*++argv) - 1;					--argc;					break;				case 'i':					pst.iType = atoi(*++argv);					--argc;					break;				case 's':					pst.range = atoi(*++argv);					--argc;					break;				case 'h':					usage(0);				default:					fprintf(stderr, "%s : Invalid option '%c' !\n", cmnd, *(*argv+1));					usage(1);				}		}		else			if ((pdffp = fopen(*argv, "r")) == NULL){				fprintf(stderr, "%s: Can't open '%s'!\n", cmnd, *argv);				exit(2);			}	}	InitPStream(&pst);	delay = pst.range + pst.dw.maxw[WRIGHT];	nframe = 0;	while (freadf(pst.mean, sizeof(*(pst.mean)), pst.vSize * 2, pdffp) == pst.vSize * 2) {		if (pst.dw.num == 1)			fwritef(pst.mean, sizeof(*pst.mean), pst.order + 1, parfp);		else {			if (pst.iType == 0)				for (i = 0; i < pst.vSize; i++)					pst.ivar[i] = finv(pst.ivar[i]);			mlpg(&pst);			if (nframe >= delay)				fwritef(pst.par, sizeof(*(pst.par)), pst.order + 1, parfp);		}		nframe++;	}	if (pst.dw.num > 1) {		for (i = 0; i < pst.vSize; i++) {			pst.mean[i] = 0.0;			pst.ivar[i] = 0.0;		}		for (i = 0; i < min(nframe, delay); i++) {			mlpg(&pst);			fwritef(pst.par, sizeof(*(pst.par)), pst.order + 1, parfp);		}	}	exit(0);}int isfloat(char *c){	int		isnum = 0, wfe = 1;	register int	i = 0;	if (strlen(c) == 0)		return(0);	if ((c[i] == '+') || (c[i] == '-'))		i++;	while ((c[i] >= '0') && (c[i] <= '9')) {		isnum = 1;		i++;	}	if (c[i] == '.') {		i++;		while ((c[i] >= '0') && (c[i] <= '9')) {			isnum = 1;			i++;		}	}	if ((c[i] == 'e') || (c[i] == 'E')) {		wfe = 0;		i++;		if ((c[i] == '+') || (c[i] == '-'))			i++;		while ((c[i] >= '0') && (c[i] <= '9')) {			wfe = 1;			i++;		}	}	if ((c[i] == 'f') || (c[i] == 'F') || (c[i] == 'l') || (c[i] == 'L'))		i++;

⌨️ 快捷键说明

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