📄 time_align.c
字号:
word_bp_table[i].end_frame = cur_frame; word_bp_table[i].score = prior_score; word_bp_table[i].prev = prior_bp; ++word_bp_table_next_free; return i;}intnew_phone_bp(int model_index, int prior_bp, int prior_score){ int i = phone_bp_table_next_free; phone_bp_table = ck_alloc(phone_bp_table, i + 1, &max_phone_bp_table_size, PHONE_BP_TABLE_SIZE_INCREMENT); phone_bp_table[i].id = model_index; phone_bp_table[i].end_frame = cur_frame; phone_bp_table[i].score = prior_score; phone_bp_table[i].prev = prior_bp; ++phone_bp_table_next_free; return i;}intnew_state_bp(int model_index, int exit_state, int prior_bp, int prior_score){ int i = state_bp_table_next_free; state_bp_table = ck_alloc(state_bp_table, i + 1, &max_state_bp_table_size, STATE_BP_TABLE_SIZE_INCREMENT); state_bp_table[i].id = model_index * NODE_CNT + exit_state; state_bp_table[i].end_frame = cur_frame; state_bp_table[i].score = prior_score; state_bp_table[i].prev = prior_bp; ++state_bp_table_next_free; return i;}static voidevaluate_active_models_boundary(int *active_models, /* the models being actively searched */ int *n_active, /* a pointer to the number of active models in the active_models list. The number may be increased as new start nodes are inserted */ int *bnd_models, /* the set of models with phone boundary paths to be explored */ int bnd_cnt, /* the number of such models */ int32 * phone_id_map, int32 * word_id_map, char *boundary, int *in_out_best_score){ int i, j, k; int exit_score; int next_score; int *next_scores; int *next_bp; int *next; int next_cnt; int *scores; int *wbp; int *pbp; int *sbp; int end_active; DYNMODEL_T *bnd_model; DYNMODEL_T *next_model; int next_model_index; int new_wbp_index; int new_pbp_index; int local_best_score = *in_out_best_score; end_active = *n_active; for (i = 0; i < bnd_cnt; i++) { k = bnd_models[i]; bnd_model = &all_models[k]; scores = bnd_model->score; wbp = bnd_model->wbp; pbp = bnd_model->pbp; sbp = bnd_model->sbp; next = bnd_model->next; next_cnt = bnd_model->next_cnt; exit_score = scores[NODE_CNT - 1]; new_pbp_index = new_phone_bp(k, pbp[NODE_CNT - 1], exit_score); if (boundary[k]) { new_wbp_index = new_word_bp(word_id_map[k], wbp[NODE_CNT - 1], exit_score); } else { new_wbp_index = wbp[NODE_CNT - 1]; /* just copy the boundary node bp across */ } for (j = 0; j < next_cnt; j++) { next_model_index = next[j]; next_model = &all_models[next_model_index]; next_scores = next_model->score; next_score = next_scores[0]; if (exit_score > next_score) { if (next_score == WORST_SCORE) { /* not already in the active model list */ active_models[end_active] = next_model_index; ++end_active; } next_scores[0] = exit_score; if (exit_score > next_model->model_best_score) next_model->model_best_score = exit_score; if (exit_score > local_best_score) local_best_score = exit_score; /* just copy the state backpointer as no data is consumed between phone boundaries */ next_bp = next_model->sbp; next_bp[0] = sbp[NODE_CNT - 1]; next_bp = next_model->pbp; next_bp[0] = new_pbp_index; next_bp = next_model->wbp; next_bp[0] = new_wbp_index; } } } *n_active = end_active; *in_out_best_score = local_best_score;}#define T44 t00#define T45 t01#define T33 t10#define T34 t11#define T35 t12#define T22 t20#define T23 t21#define T24 t22#define T11 t00#define T12 t01#define T13 t02#define T00 t10#define T01 t11#define T02 t12static voidevaluate_active_models_internal(int *phone_bnd_models, int *bnd_cnt, int *active_model_index, int n_models, int *in_out_best_score){ /* iteration variables */ int i, j; int model_best_score; int local_best_score; /* local storage for a frequently used score */ int score; /* this keeps track of which state to compute output scores for */ int state; /* local pointer to the best scoring path to the states in a model */ int *scores; /* local pointers to the word, phone and state back pointers for a model respectively */ int *wbp; int *pbp; int *sbp; int nsbp[NODE_CNT - 1]; /* A brief description of the t?? variables below: t?0 is the self transition from some state t?1 is the transition to the next state from some state t?2 is the skip-next transition out of some state There are three sets of these variables since for the fixed topology models currently used, you need to select scores from at most three sets of outgoing node transitions to compute the next score for the node. */ int t00, t01, t02; int t10, t11, t12; int t20, t21, t22; local_best_score = *in_out_best_score; for (i = 0, j = 0; i < n_models; i++) { /* local copy of model transition probably table */ int32 **tp; /* local copy of the senone indexes for each state of the model */ s3senid_t *dist; /* local copy of the senone sequence id of the model currently being evaluated */ int sseq_id; /* local copy of the transition matrix id of the model currently being evaluated */ int tmat_id; /* index of the model currently being evaluated */ int active_model; model_best_score = WORST_SCORE; active_model = active_model_index[i]; sseq_id = all_models[active_model].sseq_id; tmat_id = all_models[active_model].tmat_id; scores = all_models[active_model].score; wbp = all_models[active_model].wbp; pbp = all_models[active_model].pbp; sbp = all_models[active_model].sbp; tp = tmat->tp[tmat_id]; dist = mdef->sseq[sseq_id];#if SHOW&SHOW_MODEL_EVAL printf("%s: %d [%d, %d, %d, %d, %d]\n", model_name[active_model], sseq_id, dist[0], dist[1], dist[2], dist[3], dist[4]);#endif /* compute scores of arcs out of state 4 (4->4, 4->5) */ state = NODE_CNT - 2;#if SHOW&SHOW_MODEL_EVAL printf("%d(", state);#endif score = scores[state]; if (score > WORST_SCORE) { nsbp[state] = new_state_bp(active_model, state, sbp[state], score); T44 = T45 = score + senone_scores[dist[4]]; T44 += tp[4][4];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t12= %d ", senone_scores[dist[4]], T44);#endif T45 += tp[4][5];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t13= %d ", senone_scores[dist[4]], T45);#endif } else { T44 = T45 = WORST_SCORE; }#if SHOW&SHOW_MODEL_EVAL printf(")\n", state);#endif /* compute scores of arcs out of state 3 (3->3, 3->4, 3->5) */ --state;#if SHOW&SHOW_MODEL_EVAL printf("%d(", state);#endif score = scores[state]; if (score > WORST_SCORE) { nsbp[state] = new_state_bp(active_model, state, sbp[state], score); T33 = T34 = T35 = score + senone_scores[dist[3]]; T33 += tp[3][3];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t9= %d ", senone_scores[dist[3]], T33);#endif T34 += tp[3][4];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t10= %d ", senone_scores[dist[3]], T34);#endif T35 += tp[3][5];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t11= %d ", senone_scores[dist[3]], T35);#endif } else { T33 = T34 = T35 = WORST_SCORE; }#if SHOW&SHOW_MODEL_EVAL printf(")\n", state);#endif /* compute scores of arcs out of state 2 (2->2, 2->3, 2->4) */ --state;#if SHOW&SHOW_MODEL_EVAL printf("%d(", state);#endif score = scores[state]; if (score > WORST_SCORE) { nsbp[state] = new_state_bp(active_model, state, sbp[state], score); T22 = T23 = T24 = score + senone_scores[dist[2]]; T22 += tp[2][2];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t6= %d ", senone_scores[dist[2]], T22);#endif T23 += tp[2][3];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t7= %d ", senone_scores[dist[2]], T23);#endif T24 += tp[2][4];#if SHOW&SHOW_MODEL_EVAL printf("sc=%d t8= %d ", senone_scores[dist[2]], T24);#endif } else { T22 = T23 = T24 = WORST_SCORE; }#if SHOW&SHOW_MODEL_EVAL printf(")\n", state);#endif /* determine best arc incident on state 5 */ /* conceptually, state 5 is connected to state 0 via a null arc. The score associated w/ this state will be compared to the score associated with state 0 of the next model and the back pointers for state 0 of the next model will be updated to reflect which score was better */ /* update backpointers based on best scoring transition */ if (T45 > T35) { /* (4->5) > (3->5) */ scores[5] = T45; if (T45 > model_best_score) model_best_score = T45; phone_bnd_models[j++] = active_model; wbp[5] = wbp[4]; /* forward word back pointer */ pbp[5] = pbp[4]; /* forward phone back pointer */ sbp[5] = nsbp[4]; } else if (T35 > WORST_SCORE) { /* 3->5 best */ scores[5] = T35; if (T35 > model_best_score) model_best_score = T35; phone_bnd_models[j++] = active_model; wbp[5] = wbp[3]; /* forward word back pointer */ pbp[5] = pbp[3]; /* forward phone back pointer */ sbp[5] = nsbp[3]; } else { scores[5] = WORST_SCORE; } score = T44; /* (4->4) is best so far */ if (score < T34) score = T34; /* (3->4) is best so far */ if (score < T24) score = T24; /* (2->4) is best */ if (score > WORST_SCORE) { if (score == T34) { /* (3->4) is best */ wbp[4] = wbp[3]; /* forward word back pointer along */ pbp[4] = pbp[3]; /* forward phone back pointer along */ sbp[4] = nsbp[3]; } else if (score == T24) { /* 2->4 transition best */ wbp[4] = wbp[2]; /* forward word back pointer along */ pbp[4] = pbp[2]; /* forward phone back pointer along */ sbp[4] = nsbp[2]; } else { /* 4->4 transition best */ sbp[4] = nsbp[4]; } scores[4] = score; if (score > model_best_score) model_best_score = score; } else { scores[4] = WORST_SCORE; } /* compute scores of arcs out of state 1 (1->1, 1->2, 1->3) */ --state;#if SHOW&SHOW_MODEL_EVAL printf("%d(", state);#endif score = scores[state]; if (score > WORST_SCORE) { nsbp[state] = new_state_bp(active_model, state, sbp[state], score); T11 = T12 = T13 = score + senone_scores[dist[1]]; T11 += tp[1][1];#if SHOW&SHOW_MODEL_EV
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -