/** * Recursive function to traverse index tree and execute * the callback for all the existing data. * * @param node [in] current node * @param callback [in] callback function */ void aptree_traverse_and_do(APATNODE *node, void (*callback)(void *)) { if (node->left0 == NULL && node->right1 == NULL) { (*callback)(node->value.data); } else { if (node->left0 != NULL) { aptree_traverse_and_do(node->left0, callback); } if (node->right1 != NULL) { aptree_traverse_and_do(node->right1, callback); } } }
/** * Output all error phones appeared while readin a word dictionary. * * @param winfo [in] word dictionary data */ static void list_error(WORD_INFO *winfo) { jlog("Error: voca_load_htkdict: begin missing phones\n"); aptree_traverse_and_do(winfo->errph_root, callback_list_error); jlog("Error: voca_load_htkdict: end missing phones\n"); }
/** * Remove all the registered category-indexed pseudo state sets. * This function will be called when a grammar is changed to re-build the * state sets. * * @param root [i/o] pointer to hold the root index pointer */ void free_cdset(APATNODE **root, BMALLOC_BASE **mroot) { if (*root != NULL) { aptree_traverse_and_do(*root, callback_free_lcdset_content); mybfree2(mroot); *root = NULL; } }
/** * @brief Write all codebook data. * * The pointers of all codebook densities are first gathered, * sorted by the address. Then the densities are written * by the sorted order. The pointers to the lower structure (mixture etc.) * in the data are written by the corresponding scholar id. * The pointer index of this data will be used later to convert any pointer * reference to a codebook into scholar id. * * @param fp [in] file pointer * @param hmm [in] writing %HMM definition data */ static boolean wt_tmix(FILE *fp, HTK_HMM_INFO *hmm) { GCODEBOOK *tm; unsigned int idx; unsigned int did; int i; tm_num = hmm->codebooknum; tm_index = (GCODEBOOK **)mymalloc(sizeof(GCODEBOOK *) * tm_num); tm_idx = 0; aptree_traverse_and_do(hmm->codebook_root, tmix_list_callback); qsort(tm_index, tm_num, sizeof(GCODEBOOK *), (int (*)(const void *, const void *))qsort_tm_index); wrt(fp, &tm_num, sizeof(unsigned int), 1); for (idx = 0; idx < tm_num; idx++) { tm = tm_index[idx]; wrt_str(fp, tm->name); wrt(fp, &(tm->num), sizeof(int), 1); for(i=0;i<tm->num;i++) { if (tm->d[i] == NULL) { did = dens_num; } else { did = search_did(tm->d[i]); /* for debug */ if (tm->d[i] != dens_index[did]) { jlog("Error: write_binhmm: index not match!!!\n"); return FALSE; } } wrt(fp, &did, sizeof(unsigned int), 1); } } jlog("Stat: write_binhmm: %d tied-mixture codebooks written\n", tm_num); return TRUE; }
/** * Output all pseudo phone set information to stdout * * @param hmminfo [in] %HMM definition data that holds pseudo phone data. */ void put_all_cdinfo(HTK_HMM_INFO *hmminfo) { aptree_traverse_and_do(hmminfo->cdset_info.cdtree, put_cdset); }