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

📄 cepanal.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (debug_level >= 1)	fprintf(stderr,		"%s: output file for phase = \"%s\".\n", PROG, phname);    phhd = new_header(FT_FEA);    add_source_file(phhd, sdname, sdhd);    (void) strcpy(phhd->common.prog, PROG);    (void) strcpy(phhd->common.vers, VERSION);    (void) strcpy(phhd->common.progdate, DATE);    add_comment(phhd, get_cmd_line(argc, argv));    update_waves_gen(sdhd, phhd,		     (float) (startrec + framelen/2), (float) step);    /* framelen/2 is integer division     * (for compatibility with fft & fftcep) */    *add_genhd_l("start", NULL, 1, phhd) = startrec;    *add_genhd_l("nan", NULL, 1, phhd) = nan;    *add_genhd_d("sf", NULL, 1, phhd) = sf;    *add_genhd_l("fft_length", NULL, 1, phhd) = translen;    *add_genhd_l("frmlen", NULL, 1, phhd) = framelen;    *add_genhd_l("step", NULL, 1, phhd) = step;    *add_genhd_e("window_type", NULL, 1, window_types, phhd) = win;    phlen = translen/2 + 1;    (void) add_fea_fld("phase", phlen, 1, NULL, FLOAT, NULL, phhd);    if (debug_level >= 1)	fprintf(stderr, "%s: size of phase field is %ld.\n", PROG, phlen);    if (debug_level >= 1)	fprintf(stderr, "%s: writing phase file header.\n", PROG);    write_header(phhd, phfile);        /* CEPSTRUM FILE */    cepname = eopen(PROG, cepname, "w", NONE, NONE, NULL, &cepfile);    if (debug_level >= 1)	fprintf(stderr,		"%s: output file for cepstrum = \"%s\".\n", PROG, cepname);    cephd = new_header(FT_FEA);    add_source_file(cephd, sdname, sdhd);    (void) strcpy(cephd->common.prog, PROG);    (void) strcpy(cephd->common.vers, VERSION);    (void) strcpy(cephd->common.progdate, DATE);    add_comment(cephd, get_cmd_line(argc, argv));    update_waves_gen(sdhd, cephd,		     (float) (startrec + framelen/2), (float) step);    /* framelen/2 is integer division     * (for compatibility with fft & fftcep) */    *add_genhd_l("start", NULL, 1, cephd) = startrec;    *add_genhd_l("nan", NULL, 1, cephd) = nan;    *add_genhd_d("sf", NULL, 1, cephd) = sf;    *add_genhd_l("fft_length", NULL, 1, cephd) = translen;    *add_genhd_l("frmlen", NULL, 1, cephd) = framelen;    *add_genhd_l("step", NULL, 1, cephd) = step;    *add_genhd_e("window_type", NULL, 1, window_types, cephd) = win;    ceplen = translen/2 + 1;    (void) add_fea_fld("cepstrum", ceplen, 1, NULL, FLOAT, NULL, cephd);    if (debug_level >= 1)	fprintf(stderr, "%s: size of cepstrum field is %ld.\n", PROG, ceplen);    if (debug_level >= 1)	fprintf(stderr, "%s: writing cepstrum file header.\n", PROG);    write_header(cephd, cepfile);    /*     * ALLOCATE RECORD STRUCTURES AND STORAGE     */    if (debug_level >= 1)	fprintf(stderr, "%s: allocating storage.\n", PROG);    sdrec = allo_feasd_recs(sdhd, FLOAT, framelen, NULL, NO);    sddata = (float *) sdrec->data;    maxlen = MAX(framelen, translen);    x = (float *) arr_alloc(1, &maxlen, FLOAT, 0);    y = (float *) arr_alloc(1, &maxlen, FLOAT, 0);    z = NULL;			/* first call of arr_op will allocate */    logz = NULL;		/* first call of arr_func will allocate */    phrec = allo_fea_rec(phhd);    phdata = (float *) get_fea_ptr(phrec, "phase", phhd);    ceprec = allo_fea_rec(cephd);    cepdata = (float *) get_fea_ptr(ceprec, "cepstrum", cephd);    /*     * MAIN LOOP     */    /* Set up for eof test.  In the case of overlapping frames     * (framelen > step), the function get_feasd_orecs will return     * framelen - step when it fails to read any new samples, since     * it obtains that many valid samples by shifting samples already     * in the buffer.     */    minvalid = (framelen <= step) ? 0 : framelen - step;    eof = NO;    /* Get first frame. */    fea_skiprec(sdfile, startrec - 1, sdhd);    nvalid = get_feasd_recs(sdrec, 0, framelen, sdhd, sdfile);    REQUIRE(nvalid > 0,	    "No samples read from input");    ifrm = 1;    if (debug_level >= 1)	fprintf(stderr, "%s: beginning of main loop.\n", PROG);    /* Loop, processing a frame, writing the results, and reading a new     * frame, until we reach either the end of the specified range or the     * end of the file.     */    do    {	if (debug_level >= 2)	    fprintf(stderr, "\n%s: FRAME %ld\n", PROG, ifrm);	if (nvalid < framelen)	{	    eof = YES;	    fprintf(stderr,		    "%s: EOF in frame %ld; only %ld points read.\n",		    PROG, ifrm, nvalid);	}	if (debug_level >= 2)	    pr_farray("input sampled data",		      (debug_level == 2) ? MIN(framelen, 10) : framelen,		      sddata);	/* WINDOW INPUT DATA */	window(framelen, sddata, x, win, NULL); /* when win is WT_RECT,						 * this just copies */	for (i = 0; i < framelen; i++)	{	    y[i] = 0.0;		/* supply imag part */	}	for (i = framelen; i < translen; i++)	{	    x[i] = 0.0;	    y[i] = 0.0;	}	/* GET FFT OF WINDOWED DATA */	if (debug_level >= 2)	    pr_farray("windowed sampled data",		      (debug_level == 2) ? MIN(framelen, 10) : framelen,		      sddata);	get_rfft(x, y, order);	if (debug_level >= 2)	{	    pr_farray("FFT of input (real part)",		      (debug_level == 2) ? MIN(translen, 10) : translen,		      x);	    pr_farray("FFT of input (imag part)",		      (debug_level == 2) ? MIN(translen, 10) : translen,		      y);	}	/* TAKE COMPLEX LOG OF FFT */	z = (float_cplx *) arr_op(OP_CPLX, translen,				  (char *) x, FLOAT, (char *) y, FLOAT,				  (char *) z, FLOAT_CPLX);	logz = (float_cplx *) arr_func(FN_LOG, translen,				       (char *) z, FLOAT_CPLX,				       (char *) logz, FLOAT_CPLX);	if (debug_level >= 2)	    pr_fcarray("complex log of FFT",		       (debug_level == 2) ? MIN(framelen, 10) : framelen,		       logz);	/* GET PHASE AND WRITE IT OUT */	(void) arr_func(FN_IM, phlen,			(char *) logz, FLOAT_CPLX, (char *) phdata, FLOAT);	put_fea_rec(phrec, phhd, phfile);	if (debug_level >= 2)	    pr_farray("phase",		      (debug_level == 2) ? MIN(phlen, 10) : phlen,		      phdata);	/* GET CEPSTRUM AND WRITE IT OUT */	(void) arr_func(FN_RE, translen,			(char *) logz, FLOAT_CPLX, (char *) x, FLOAT);	for (i = 0; i < translen; i++)	    y[i] = 0.0;	if (debug_level >= 2)	    pr_farray("log of magnitude of FFT",		      (debug_level == 2) ? MIN(translen, 10) : translen,		      x);	get_fft_inv(x, y, order);	for (i = 0; i < ceplen; i++)	    cepdata[i] = x[i];	put_fea_rec(ceprec, cephd, cepfile);	if (debug_level >= 2)	{	    pr_farray("cepstrum (Re)",		      (debug_level == 2) ? MIN(ceplen, 10) : ceplen,		      x);	    pr_farray("cepstrum (Im)",		      (debug_level == 2) ? MIN(ceplen, 10) : ceplen,		      y);	}	/* We go back to process a new frame as long as	 * (1) we haven't yet processed the number of frames required for	 *     the specified range,	 * (2) we didn't hit the end of file while reading the current	 *     frame, and	 * (3) we get at least one new sample when we try to read the new	 *     frame (i.e. nvalid > minvalid; see comment above on	 *     initialization of minvalid).	 */    } while (++ifrm <= nfrm	     && !eof	     && ((nvalid = get_feasd_orecs(sdrec, 0,					   framelen, step, sdhd, sdfile))		 > minvalid));    if (debug_level >= 2)	fprintf(stderr, "\n");    if (debug_level >= 1)	fprintf(stderr, "%s: end of main loop; ifrm = %ld.\n",		PROG, ifrm);    if (nfrm != LONG_MAX && ifrm <= nfrm)	fprintf(stderr, "%s: Premature EOF; only %ld frames read.\n",		PROG, ifrm - 1);    /*     * WRITE COMMON AND EXIT     */    if (phfile != stdout && cepfile != stdout)    {	REQUIRE(startrec <= INT_MAX		&& putsym_i("start", (int) startrec) != -1,		"Can't write \"start\" to Common.");	REQUIRE(nan <= INT_MAX		&& putsym_i("nan", (int) nan) != -1,		"Can't write \"nan\" to Common.");	REQUIRE(putsym_s("prog", PROG) != -1,		"Can't write \"prog\" to Common.");	REQUIRE(putsym_s("filename", sdname) != -1,		"Can't write \"filename\" to Common.");    }    exit(0);    return 0;}/* LOCAL FUNCTION DEFINITIONS *//* * For debug printout of float arrays */static voidpr_farray(char    *text,	  long    n,	  float   *arr){    long    i;    fprintf(stderr, "%s: %s -- %d points:\n", PROG, text, n);    for (i = 0; i < n; i++)    {	fprintf(stderr, "%g ", arr[i]);	if (i%5 == 4 || i == n - 1)	    fprintf(stderr, "\n");    }}/* * For debug printout of float_cplx arrays */static voidpr_fcarray(char		*text,	   long		n,	   float_cplx	*arr){    long    i;    fprintf(stderr, "%s: %s -- %d points:\n", PROG, text, n);    for (i = 0; i < n; i++)    {	fprintf(stderr, "[%g %g] ", arr[i].real, arr[i].imag);	if (i%2 == 1 || i == n - 1)	    fprintf(stderr, "\n");    }}

⌨️ 快捷键说明

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