📄 trakpit.c
字号:
/* This material contains proprietary software of Entropic Processing, Inc. Any reproduction, distribution, or publication without the the prior written permission of Entropic Processing, Inc. is strictly prohibited. Any public distribution of copies of this work authorized in writing by Entropic Processing, Inc. must bear the notice Copyright 1986, Entropic Proccessing, Inc (C) 1985, Entropic Processing, Inc.*/#ifdef SCCSstatic char *sccsid = "@(#)trakpit.c 1.5 10/14/86 EPI";#endif#include <stdio.h>extern FILE * hptr, *anaptr; /* header variables */extern int debug_level, freq_knt[];extern int order, u_pflt_order, v_pflt_order, ptrack_state;extern int frmlen, pt_wsize, pitch_range_min, pitch_range_max;extern float uv_thresh;extern int smpnum, pulse_locn;extern int initflag;extern int prev_frame_size[4], prev_frame_locn[4], prev_frame_type[4];extern int min_pitch, max_pitch;extern float peakcor, RELENT_min;extern int best_pitch, prev_best_pitch;#define MAX(a, b) (a > b) ? a : b/* returns larger of a, b */#define MIN(a, b) (a < b) ? a : b/* returns smaller of a, b */#define one_msec 8#define voiced 1#define unvoiced 0#define uuu 0#define uuu1 1#define uuu2 2#define uuuv 3#define uuvv 4#define uvvv 5#define uvvu 6#define vvv 7#define vvvu 8#define vvuu 9#define vvuu1 10#define vvuv 11#define vuuv 12#define vvv1 13int next_state[2][14] ={ uuu, uuu2, uuu, uuu, uvvu, vvvu, uuu, vvv1, vvuu, uuu, uuu, uuu, uuu, vvvu, uuu1, uuu2, uuuv, uuvv, uvvv, vvv, vvuv, vvv, vvuv, vvuu1, vuuv, uvvv, uvvv, vvv};int prev_state;char *v_chr[] ={ "uuu", "uuu1", "uuu2", "uuuv", "uuvv", "uvvv", "uvvu", "vvv", "vvvu", "vvuu", "vvuu1", "vvuv", "vuuv", "vvv1"};#define lookback 1#define nolookback 0int disp;track_pitch (databuf, frame_locn, frame_size, frame_type, max_coh_dst)int frame_locn[], frame_size[], frame_type[];float databuf[], max_coh_dst[];{ int scan_beg, scan_end, scan_size; int i, j, tmp_locn, fbeg; extern int stepsz; /* stepsize = frame size for unvoiced period */ if (debug_level) fprintf (stderr, "track_pitch: %d ", smpnum + pulse_locn); prev_frame_locn[3] = smpnum + pulse_locn; prev_frame_size[3] = best_pitch; min_pitch = pitch_range_min; max_pitch = pitch_range_max; prev_state = ptrack_state; if (RELENT_min > uv_thresh) { prev_frame_type[3] = unvoiced; if (debug_level) fprintf (stderr, "(unvoiced,%s)\n", v_chr[ptrack_state]); ptrack_state = next_state[unvoiced][prev_state]; switch (prev_state) { case uvvu: prev_frame_type[0] = unvoiced; case vuuv: prev_frame_type[1] = unvoiced; prev_frame_type[2] = unvoiced; case vvuv: case vvuu: case vvuu1: case uuu: pulse_locn += stepsz / 2; disp = get_pulsepos (databuf, stepsz); pulse_locn += disp; break; case uuu1: /* No pulse found by moving back. So undo what was done earlier and proceed */ pulse_locn += prev_frame_locn[3] - prev_frame_locn[2] - 1; if (hptr) fprintf (hptr, "Probable u/v change in frame %d\n", smpnum + pulse_locn); pulse_locn -= one_msec; disp = get_pulsepos (databuf, prev_best_pitch); pulse_locn += disp; break; case uuuv: prev_frame_type[2] = unvoiced; case uuu2: /* This following is done to avoid possible infinite loop */ if (pulse_locn < 0) pulse_locn = 0; pulse_locn += stepsz / 2; disp = get_pulsepos (databuf, stepsz); pulse_locn += disp; break; case vvvu: scan_beg = MAX (best_pitch - one_msec, pitch_range_min); scan_end = MIN (best_pitch + one_msec, pitch_range_max); scan_size = scan_end - scan_beg + 1; pulse_locn += scan_beg; pulse_locn += get_pulsepos (databuf, scan_size); break; case vvv: min_pitch = MAX (prev_best_pitch / 2 + one_msec, pitch_range_min); max_pitch = MIN (2 * prev_best_pitch - one_msec, pitch_range_max); best_pitch = prev_best_pitch; break; case vvv1: tracking_mode_range (prev_best_pitch); case uvvv: if (hptr) { fprintf (hptr, "Probable v/u transition at %d\n", pulse_locn + smpnum); } case uuvv: scan_beg = MAX (prev_best_pitch - one_msec, pitch_range_min); scan_end = MIN (prev_best_pitch + one_msec, pitch_range_max); scan_size = scan_end - scan_beg + 1; pulse_locn += scan_beg; pulse_locn += get_pulsepos (databuf, scan_size); prev_frame_type[3] = voiced; break; } } else { prev_frame_type[3] = voiced; if (debug_level) fprintf (stderr, "(voiced %d,%s)\n", best_pitch, v_chr[ptrack_state]); ptrack_state = next_state[voiced][prev_state]; switch (prev_state) { case uuu: pulse_locn -= (prev_frame_locn[3] - prev_frame_locn[2]) / 2; break; case uuu1: /* Sometimes the first pitch estimate is 2 or 3 times the real pitch. we may miss the first pulse. The following statement reduces this probability */ j = prev_best_pitch + prev_frame_locn[3] - prev_frame_locn[2]; if (best_pitch > j) best_pitch = j; if (hptr) fprintf (hptr, "Probable u/v change in frame %d\n", prev_frame_locn[3]); pulse_locn -= one_msec; pulse_locn += get_pulsepos (databuf, best_pitch); break; case uuu2: if (hptr) { fprintf (hptr, "Corresponding pulse locn %d\n" ,prev_frame_locn[3]); } if (debug_level >= 2) fprintf (stderr, "\t%d\t%d\t1\t%s\t%f\n", prev_frame_locn[3], best_pitch, v_chr[prev_state], RELENT_min);/* Was there a pulse before the present one ? */ prev_best_pitch = best_pitch; ptrack_state = prev_state; get_raw_pitch (v_pflt_order, lookback); ptrack_state = next_state[voiced][prev_state]; scan_beg = MAX (best_pitch - one_msec, pitch_range_min); scan_end = MIN (best_pitch + one_msec, pitch_range_max); scan_size = scan_end - scan_beg + 1; best_pitch = scan_end - get_pulsepos (databuf - scan_end, scan_size); tmp_locn = prev_frame_locn[3] - best_pitch; if (RELENT_min < uv_thresh && tmp_locn > prev_frame_locn[0] + pitch_range_min) {/* Yes. The following is done to adjust previous pitch locations and sizes, whenever it is possible to do so.*/ j = 2; while (tmp_locn <= prev_frame_locn[j]) prev_frame_locn[j--] = tmp_locn; prev_frame_locn[3] = tmp_locn; prev_frame_size[3] = best_pitch; max_pitch = min_pitch = prev_best_pitch; prev_best_pitch = best_pitch; } else { best_pitch = prev_best_pitch; scan_beg = MAX (best_pitch / 2 - one_msec, pitch_range_min); scan_end = MIN (best_pitch * 3 / 2 - one_msec, pitch_range_max); scan_size = scan_end - scan_beg + 1; pulse_locn += scan_beg; pulse_locn += get_pulsepos (databuf, scan_size); } break; case vvuu1: prev_frame_type[2] = voiced; if (hptr) { fprintf (hptr, "Corresponding pulse locn %d\n" ,prev_frame_locn[3]); } if (debug_level >= 2) fprintf (stderr, "\t%d\t%d\t1\t%s\t%f\n", prev_frame_locn[3], best_pitch, v_chr[prev_state], RELENT_min); /* Adjust previous pulse location if possible */ prev_best_pitch = best_pitch; ptrack_state = prev_state; get_raw_pitch (v_pflt_order, lookback); ptrack_state = next_state[voiced][prev_state]; if (RELENT_min < uv_thresh) { scan_beg = MAX (best_pitch - one_msec, pitch_range_min); scan_end = MIN (best_pitch + one_msec, pitch_range_max); scan_size = scan_end - scan_beg + 1; best_pitch = scan_end - get_pulsepos (databuf - scan_end, scan_size); tmp_locn = prev_frame_locn[3] - best_pitch; if (tmp_locn > prev_frame_locn[1]) { /* Adjust previous frame location */ if (tmp_locn - prev_frame_locn[1] > pitch_range_min) prev_frame_locn[2] = tmp_locn; else /* possible pulse duration stretching */ if (prev_frame_locn[3] - prev_frame_locn[1] < pitch_range_max) prev_frame_locn[2] = prev_frame_locn[1]; } } best_pitch = prev_best_pitch; scan_beg = MAX (best_pitch / 2 - one_msec, pitch_range_min);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -