lpcsynt.c
来自「speech signal process tools」· C语言 代码 · 共 709 行 · 第 1/2 页
C
709 行
exit (1); } if (debug_level) Fprintf (stderr, "Locn = %ld\tlag = %d\n", locn, blksze); i++; start = locn; } while (start_r >= i || blksze == 0); } if(start == 0){ /* fudge start time from record freq*/ start = record_freq*(start_r-1)/get_genhd_val( "record_freq", fea_ih, (double) 1.); } if (debug_level) Fprintf (stderr, "start: locn = %ld\n", locn);/* * update start_time generic*/ start_time = get_genhd_val("start_time", fea_ih, (double)0); new_start_time = start_time + (start-1)/record_freq; (void)add_genhd_d("start_time", &new_start_time, (int)1, sd_oh); /* * ALL set, now write output header*/ write_header (sd_oh, sd_strm);/* Insert leading zeros if start < locn. If the difference is greater than one frame, complain and exit */ if (i == 1 && locn - start > frame_size) { Fprintf (stderr, "lpcsynt: no analysis data near point %d; first locn = %ld\n", start, locn); exit (1); } zeros ((locn - start), sd_oh, sd_strm); prev_seg_type = VOICED;/* Do the desired speech */ if(pflag){ while (locn < (start + nan)) { if (debug_level) Fprintf (stderr, "locn = %ld\tsize = %d\n", locn, blksze); if (prev_seg_type == UNVOICED && seg_type == VOICED) for (i = 0; i <= synt_filt_order; synstate[i++] = 0.0); if (seg_type == VOICED) { rmsval = sqrt ((double) res_power * blksze); input = rmsval; outbfr[0] = lattice_filt (int_rc, synt_filt_order, synstate, input); input = 0.0; for (i = 1; i < blksze; i++) outbfr[i] = lattice_filt (int_rc, synt_filt_order, synstate, input); } else { /* Unvoiced segment */ rmsval = sqrt ((double) res_power); for (i = 0; i < blksze; i++) { input = rmsval * gauss (); outbfr[i] = lattice_filt (int_rc, synt_filt_order, synstate, input); } } /* Post-filtering */ iir_filter (outbfr, blksze, pfilt_num, pfilt_den, pfilt_state, pfilt_order); /* convert output data to shorts*/ for (i = 0; i < blksze; i++){ bfr[i] = (short)outbfr[i]; } /*put out data*/ put_sd_recs (bfr, blksze, sd_oh, sd_strm); prev_seg_type = seg_type; oblksze = blksze; if (!get_ana (&locn, &seg_type, &blksze, &res_power, synt_filt_order, fea_ih, fea_strm)) {/* Don't beef if we're within one frame of the end */ if (start + nan - locn - oblksze > frame_size) { Fprintf (stderr, "lpcsynt: EOF encountered in input file\n"); Fprintf(stderr, "lpcsynt: Input FEA file represents only %ld points\n", (long)(locn+oblksze)); exit (2); } else { zeros ((start + nan - locn), sd_oh, sd_strm); exit (0); } } if (debug_level) Fprintf (stderr, "Locn = %ld\tlag = %d\n", locn, blksze); } } else{/*the -r option was used*/ int used = 1; while (used <= nan_r){ if (debug_level) Fprintf (stderr, "locn = %ld\tsize = %d\n", locn, blksze); if (prev_seg_type == UNVOICED && seg_type == VOICED) for (i = 0; i <= synt_filt_order; synstate[i++] = 0.0); if (seg_type == VOICED) { rmsval = sqrt ((double) res_power * blksze); input = rmsval; outbfr[0] = lattice_filt (int_rc, synt_filt_order, synstate, input); input = 0.0; for (i = 1; i < blksze; i++) outbfr[i] = lattice_filt (int_rc, synt_filt_order, synstate, input); } else { /* Unvoiced segment */ rmsval = sqrt ((double) res_power); for (i = 0; i < blksze; i++) { input = rmsval * gauss (); outbfr[i] = lattice_filt (int_rc, synt_filt_order, synstate, input); } } /* Post-filtering */ iir_filter (outbfr, blksze, pfilt_num, pfilt_den, pfilt_state, pfilt_order); /* convert output data to shorts*/ for (i = 0; i < blksze; i++){ bfr[i] = (short)outbfr[i]; } /*put out data*/ put_sd_recs (bfr, blksze, sd_oh, sd_strm); prev_seg_type = seg_type; oblksze = blksze; if (!get_ana (&locn, &seg_type, &blksze, &res_power, synt_filt_order, fea_ih, fea_strm)) exit (0); /*update "used" counter*/ used++; if (debug_level) Fprintf (stderr, "Locn = %ld\tlag = %d\n", locn, blksze); } } exit (0); return(0); /*lint pleasing*/}zeros (n, h, fd)long n;struct header *h;FILE * fd;/*add a zero to output file*/{ static short zero[1] = { 0 }; while (n-- > 0) put_sd_recs (zero, 1, h, fd);}fcopy (dst, src, n)float *dst, *src;/*copy float pointer*/{ while (n-- > 0) *dst++ = *src++;}get_ana (plocn, ptype, psize, pres_power, synt_filt_order, hd, stream)long *plocn;int *ptype, *psize, synt_filt_order;float *pres_power;struct header *hd;FILE * stream;/* This routine reads parameters from the fea_ana file and returns interpolated spectral parameters */{ int i, rcs_not_ok; static long locn[3]; static int type[3], size[3], EOF_flag = 0; static float res_power[3]; if (debug_level) Fprintf (stderr, "get_ana: "); if (EOF_flag) { return 0; } if (!read_ana (&locn[2], &size[2], &type[2], &res_power[2], rc2, synt_filt_order, hd, stream)) { /* EOF encountered. Flush buffer */ *plocn = locn[1]; *ptype = type[1]; *psize = size[1]; *pres_power = res_power[1]; EOF_flag = 1; return 1; } /* Check if rc's are valid. Otherwise, complain and quit */ rcs_not_ok = 0; for (i = 0; i < synt_filt_order; i++) if (rc2[i] * rc2[i] > 1) { rc2[i] = .99 * ((rc2[i] > 0) ? 1 : -1); rcs_not_ok = 1; } if (rcs_not_ok) { Fprintf(stderr, "Invalid RC's in record starting at locn %ld\n", locn[2]); Fprintf(stderr, " replaced with + or - .99\n"); } if (type[0] == VOICED && type[1] == VOICED && type[2] == VOICED) for (i = 0; i < synt_filt_order; i++) int_rc[i] = (rc0[i] + rc1[i] + rc2[i]) / 3.0; else for (i = 0; i < synt_filt_order; i++) int_rc[i] = rc1[i]; *ptype = type[1]; *plocn = locn[1]; *pres_power = res_power[1]; *psize = size[1]; *ptype = type[1]; for (i = 0; i < 2; i++) { type[i] = type[i + 1]; res_power[i] = res_power[i + 1]; size[i] = size[i + 1]; locn[i] = locn[i + 1]; } for (i = 0; i < synt_filt_order; i++) rc0[i] = rc1[i]; for (i = 0; i < synt_filt_order; i++) rc1[i] = rc2[i]; return 1;}read_ana (plocn, psize, ptype, pres_power, rc, synt_filt_order, hd, stream)long *plocn;int *psize, *ptype;float *pres_power;float rc[];int synt_filt_order;struct header *hd;FILE * stream;/* get data from a FEA_ANA frame*/{ if (get_anafea_rec (anafea_rec, hd, stream) == EOF)/* eof */ { if (debug_level) Fprintf (stderr, "no more anafea_records.\n"); return 0; } *plocn = *anafea_rec -> tag; *psize = *anafea_rec -> frame_len; *ptype = *anafea_rec -> frame_type; *pres_power = anafea_rec -> lpc_power[0]; fcopy (rc, anafea_rec -> spec_param, synt_filt_order); if (debug_level) Fprintf (stderr, "locn: %ld, size: %d, power: %f, order: %d.\n", *plocn, *psize, *pres_power, synt_filt_order); return 1;}iir_filter (outbfr, blksze, num, den, state, order)float outbfr[], num[], den[], state[];int blksze, order;/*post-empahsis filtering*/{ int i, j; float inp, out; for (i = 0; i < blksze; i++) { inp = outbfr[i]; for (j = 1; j <= order; j++) inp -= state[j] * den[j]; out = inp * num[0]; for (j = 1; j <= order; j++) out += state[j] * num[j]; for (j = order; j > 1; j--) state[j] = state[j - 1]; state[1] = inp; outbfr[i] = out; }}/* Synthesis filter in ladder form */float lattice_filt (rc, order, lsstate, input)float rc[], lsstate[], input;int order;{ int i; float output, ki; output = input; for (i = order; i > 0; i--) { ki = rc[i - 1]; output += ki * lsstate[i]; lsstate[i + 1] = lsstate[i] - ki * output; } lsstate[1] = output; return (output);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?