Julius 4.2
|
00001 00018 /* 00019 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00022 * All rights reserved 00023 */ 00024 00025 #include <julius/juliuslib.h> 00026 00043 MFCCCalc * 00044 j_mfcccalc_new(JCONF_AM *amconf) 00045 { 00046 MFCCCalc *mfcc; 00047 00048 mfcc = (MFCCCalc *)mymalloc(sizeof(MFCCCalc)); 00049 memset(mfcc, 0, sizeof(MFCCCalc)); 00050 mfcc->param = NULL; 00051 mfcc->rest_param = NULL; 00052 mfcc->frontend.ssbuf = NULL; 00053 mfcc->cmn.loaded = FALSE; 00054 mfcc->plugin_source = -1; 00055 if (amconf) { 00056 mfcc->para = &(amconf->analysis.para); 00057 mfcc->hmm_loaded = (amconf->analysis.para_hmm.loaded == 1) ? TRUE : FALSE; 00058 mfcc->htk_loaded = (amconf->analysis.para_htk.loaded == 1) ? TRUE : FALSE; 00059 mfcc->wrk = WMP_work_new(mfcc->para); 00060 if (mfcc->wrk == NULL) { 00061 jlog("ERROR: j_mfcccalc_new: failed to initialize MFCC computation\n"); 00062 return NULL; 00063 } 00064 mfcc->cmn.load_filename = amconf->analysis.cmnload_filename; 00065 mfcc->cmn.update = amconf->analysis.cmn_update; 00066 mfcc->cmn.save_filename = amconf->analysis.cmnsave_filename; 00067 mfcc->cmn.map_weight = amconf->analysis.cmn_map_weight; 00068 mfcc->frontend.ss_alpha = amconf->frontend.ss_alpha; 00069 mfcc->frontend.ss_floor = amconf->frontend.ss_floor; 00070 mfcc->frontend.sscalc = amconf->frontend.sscalc; 00071 mfcc->frontend.sscalc_len = amconf->frontend.sscalc_len; 00072 mfcc->frontend.ssload_filename = amconf->frontend.ssload_filename; 00073 } 00074 mfcc->next = NULL; 00075 return mfcc; 00076 } 00077 00091 void 00092 j_mfcccalc_free(MFCCCalc *mfcc) 00093 { 00094 if (mfcc->rest_param) free_param(mfcc->rest_param); 00095 if (mfcc->param) free_param(mfcc->param); 00096 if (mfcc->wrk) WMP_free(mfcc->wrk); 00097 if (mfcc->tmpmfcc) free(mfcc->tmpmfcc); 00098 if (mfcc->db) WMP_deltabuf_free(mfcc->db); 00099 if (mfcc->ab) WMP_deltabuf_free(mfcc->ab); 00100 if (mfcc->cmn.wrk) CMN_realtime_free(mfcc->cmn.wrk); 00101 if (mfcc->frontend.ssbuf) free(mfcc->frontend.ssbuf); 00102 if (mfcc->frontend.mfccwrk_ss) WMP_free(mfcc->frontend.mfccwrk_ss); 00103 00104 free(mfcc); 00105 } 00106 00123 PROCESS_AM * 00124 j_process_am_new(Recog *recog, JCONF_AM *amconf) 00125 { 00126 PROCESS_AM *new, *atmp; 00127 00128 /* allocate memory */ 00129 new = (PROCESS_AM *)mymalloc(sizeof(PROCESS_AM)); 00130 memset(new, 0, sizeof(PROCESS_AM)); 00131 00132 /* assign configuration */ 00133 new->config = amconf; 00134 00135 /* append to last */ 00136 new->next = NULL; 00137 if (recog->amlist == NULL) { 00138 recog->amlist = new; 00139 } else { 00140 for(atmp = recog->amlist; atmp->next; atmp = atmp->next); 00141 atmp->next = new; 00142 } 00143 00144 return new; 00145 } 00146 00160 void 00161 j_process_am_free(PROCESS_AM *am) 00162 { 00163 /* HMMWork hmmwrk */ 00164 outprob_free(&(am->hmmwrk)); 00165 if (am->hmminfo) hmminfo_free(am->hmminfo); 00166 if (am->hmm_gs) hmminfo_free(am->hmm_gs); 00167 /* not free am->jconf */ 00168 free(am); 00169 } 00170 00187 PROCESS_LM * 00188 j_process_lm_new(Recog *recog, JCONF_LM *lmconf) 00189 { 00190 PROCESS_LM *new, *ltmp; 00191 00192 /* allocate memory */ 00193 new = (PROCESS_LM *)mymalloc(sizeof(PROCESS_LM)); 00194 memset(new, 0, sizeof(PROCESS_LM)); 00195 00196 /* assign config */ 00197 new->config = lmconf; 00198 00199 /* initialize some values */ 00200 new->lmtype = lmconf->lmtype; 00201 new->lmvar = lmconf->lmvar; 00202 new->gram_maxid = 0; 00203 new->global_modified = FALSE; 00204 00205 /* append to last */ 00206 new->next = NULL; 00207 if (recog->lmlist == NULL) { 00208 recog->lmlist = new; 00209 } else { 00210 for(ltmp = recog->lmlist; ltmp->next; ltmp = ltmp->next); 00211 ltmp->next = new; 00212 } 00213 00214 return new; 00215 } 00216 00230 void 00231 j_process_lm_free(PROCESS_LM *lm) 00232 { 00233 if (lm->winfo) word_info_free(lm->winfo); 00234 if (lm->ngram) ngram_info_free(lm->ngram); 00235 if (lm->grammars) multigram_free_all(lm->grammars); 00236 if (lm->dfa) dfa_info_free(lm->dfa); 00237 /* not free lm->jconf */ 00238 free(lm); 00239 } 00240 00257 RecogProcess * 00258 j_recogprocess_new(Recog *recog, JCONF_SEARCH *sconf) 00259 { 00260 RecogProcess *new, *ptmp; 00261 00262 /* allocate memory */ 00263 new = (RecogProcess *)mymalloc(sizeof(RecogProcess)); 00264 memset(new, 0, sizeof(RecogProcess)); 00265 new->live = FALSE; 00266 new->active = 0; 00267 new->next = NULL; 00268 00269 /* assign configuration */ 00270 new->config = sconf; 00271 00272 /* append to last */ 00273 new->next = NULL; 00274 if (recog->process_list == NULL) { 00275 recog->process_list = new; 00276 } else { 00277 for(ptmp = recog->process_list; ptmp->next; ptmp = ptmp->next); 00278 ptmp->next = new; 00279 } 00280 00281 return new; 00282 } 00283 00297 void 00298 j_recogprocess_free(RecogProcess *process) 00299 { 00300 /* not free jconf, am, lm here */ 00301 /* free part of StackDecode work area */ 00302 wchmm_fbs_free(process); 00303 /* free cache */ 00304 if (process->lmtype == LM_PROB) { 00305 max_successor_cache_free(process->wchmm); 00306 } 00307 /* free wchmm */ 00308 if (process->wchmm) wchmm_free(process->wchmm); 00309 /* free backtrellis */ 00310 if (process->backtrellis) bt_free(process->backtrellis); 00311 /* free pass1 work area */ 00312 fsbeam_free(&(process->pass1)); 00313 free(process); 00314 } 00315 00332 JCONF_AM * 00333 j_jconf_am_new() 00334 { 00335 JCONF_AM *new; 00336 new = (JCONF_AM *)mymalloc(sizeof(JCONF_AM)); 00337 jconf_set_default_values_am(new); 00338 new->next = NULL; 00339 return new; 00340 } 00341 00359 void 00360 j_jconf_am_free(JCONF_AM *amconf) 00361 { 00362 free(amconf); 00363 } 00364 00385 boolean 00386 j_jconf_am_regist(Jconf *jconf, JCONF_AM *amconf, char *name) 00387 { 00388 JCONF_AM *atmp; 00389 00390 if (!name) { 00391 jlog("ERROR: j_jconf_am_regist: no name specified to register an AM conf\n"); 00392 return FALSE; 00393 } 00394 00395 for(atmp = jconf->am_root; atmp; atmp = atmp->next) { 00396 if (strmatch(atmp->name, name)) { 00397 jlog("ERROR: j_jconf_am_regist: failed to regist an AM conf: the same name \"%s\" already exist\n", atmp->name); 00398 return FALSE; 00399 } 00400 } 00401 00402 /* set name */ 00403 strncpy(amconf->name, name, JCONF_MODULENAME_MAXLEN); 00404 00405 /* append to last */ 00406 amconf->next = NULL; 00407 if (jconf->am_root == NULL) { 00408 amconf->id = 1; 00409 jconf->am_root = amconf; 00410 } else { 00411 for(atmp = jconf->am_root; atmp->next; atmp = atmp->next); 00412 amconf->id = atmp->id + 1; 00413 atmp->next = amconf; 00414 } 00415 00416 return TRUE; 00417 } 00418 00419 00436 JCONF_LM * 00437 j_jconf_lm_new() 00438 { 00439 JCONF_LM *new; 00440 new = (JCONF_LM *)mymalloc(sizeof(JCONF_LM)); 00441 jconf_set_default_values_lm(new); 00442 new->next = NULL; 00443 return new; 00444 } 00445 00461 void 00462 j_jconf_lm_free(JCONF_LM *lmconf) 00463 { 00464 JCONF_LM_NAMELIST *nl, *nltmp; 00465 nl = lmconf->additional_dict_files; 00466 while (nl) { 00467 nltmp = nl->next; 00468 free(nl->name); 00469 free(nl); 00470 nl = nltmp; 00471 } 00472 nl = lmconf->additional_dict_entries; 00473 while (nl) { 00474 nltmp = nl->next; 00475 free(nl->name); 00476 free(nl); 00477 nl = nltmp; 00478 } 00479 free(lmconf); 00480 } 00481 00502 boolean 00503 j_jconf_lm_regist(Jconf *jconf, JCONF_LM *lmconf, char *name) 00504 { 00505 JCONF_LM *ltmp; 00506 00507 if (!name) { 00508 jlog("ERROR: j_jconf_lm_regist: no name specified to register a LM conf\n"); 00509 return FALSE; 00510 } 00511 00512 for(ltmp = jconf->lm_root; ltmp; ltmp = ltmp->next) { 00513 if (strmatch(ltmp->name, name)) { 00514 jlog("ERROR: j_jconf_lm_regist: failed to regist a LM conf: the same name \"%s\" already exist\n", ltmp->name); 00515 return FALSE; 00516 } 00517 } 00518 00519 /* set name */ 00520 strncpy(lmconf->name, name, JCONF_MODULENAME_MAXLEN); 00521 00522 /* append to last */ 00523 lmconf->next = NULL; 00524 if (jconf->lm_root == NULL) { 00525 lmconf->id = 1; 00526 jconf->lm_root = lmconf; 00527 } else { 00528 for(ltmp = jconf->lm_root; ltmp->next; ltmp = ltmp->next); 00529 lmconf->id = ltmp->id + 1; 00530 ltmp->next = lmconf; 00531 } 00532 00533 return TRUE; 00534 } 00535 00536 00553 JCONF_SEARCH * 00554 j_jconf_search_new() 00555 { 00556 JCONF_SEARCH *new; 00557 new = (JCONF_SEARCH *)mymalloc(sizeof(JCONF_SEARCH)); 00558 jconf_set_default_values_search(new); 00559 new->next = NULL; 00560 return new; 00561 } 00562 00578 void 00579 j_jconf_search_free(JCONF_SEARCH *sconf) 00580 { 00581 free(sconf); 00582 } 00583 00604 boolean 00605 j_jconf_search_regist(Jconf *jconf, JCONF_SEARCH *sconf, char *name) 00606 { 00607 JCONF_SEARCH *stmp; 00608 00609 if (!name) { 00610 jlog("ERROR: j_jconf_search_regist: no name specified to register a SR conf\n"); 00611 return FALSE; 00612 } 00613 00614 for(stmp = jconf->search_root; stmp; stmp = stmp->next) { 00615 if (strmatch(stmp->name, name)) { 00616 jlog("ERROR: j_jconf_search_regist: failed to regist an SR conf: the same name \"%s\" already exist\n", stmp->name); 00617 return FALSE; 00618 } 00619 } 00620 00621 /* set name */ 00622 strncpy(sconf->name, name, JCONF_MODULENAME_MAXLEN); 00623 00624 /* append to last */ 00625 sconf->next = NULL; 00626 if (jconf->search_root == NULL) { 00627 sconf->id = 1; 00628 jconf->search_root = sconf; 00629 } else { 00630 for(stmp = jconf->search_root; stmp->next; stmp = stmp->next); 00631 sconf->id = stmp->id + 1; 00632 stmp->next = sconf; 00633 } 00634 return TRUE; 00635 } 00636 00660 Jconf * 00661 j_jconf_new() 00662 { 00663 Jconf *jconf; 00664 00665 /* allocate memory */ 00666 jconf = (Jconf *)mymalloc(sizeof(Jconf)); 00667 /* set default values */ 00668 jconf_set_default_values(jconf); 00669 00670 /* allocate first one am / lm /search instance with their name left NULL */ 00671 jconf->am_root = j_jconf_am_new(); 00672 jconf->am_root->id = 0; 00673 strcpy(jconf->am_root->name, JCONF_MODULENAME_DEFAULT); 00674 jconf->lm_root = j_jconf_lm_new(); 00675 jconf->lm_root->id = 0; 00676 strcpy(jconf->lm_root->name, JCONF_MODULENAME_DEFAULT); 00677 jconf->search_root = j_jconf_search_new(); 00678 jconf->search_root->id = 0; 00679 strcpy(jconf->search_root->name, JCONF_MODULENAME_DEFAULT); 00680 /* assign the am /lm instance to the instance */ 00681 jconf->search_root->amconf = jconf->am_root; 00682 jconf->search_root->lmconf = jconf->lm_root; 00683 /* set current */ 00684 jconf->amnow = jconf->am_root; 00685 jconf->lmnow = jconf->lm_root; 00686 jconf->searchnow = jconf->search_root; 00687 /* set gmm am jconf */ 00688 jconf->gmm = NULL; 00689 00690 return(jconf); 00691 } 00692 00713 void 00714 j_jconf_free(Jconf *jconf) 00715 { 00716 JCONF_AM *am, *amtmp; 00717 JCONF_LM *lm, *lmtmp; 00718 JCONF_SEARCH *sc, *sctmp; 00719 00720 opt_release(jconf); 00721 00722 am = jconf->am_root; 00723 while(am) { 00724 amtmp = am->next; 00725 j_jconf_am_free(am); 00726 am = amtmp; 00727 } 00728 lm = jconf->lm_root; 00729 while(lm) { 00730 lmtmp = lm->next; 00731 j_jconf_lm_free(lm); 00732 lm = lmtmp; 00733 } 00734 sc = jconf->search_root; 00735 while(sc) { 00736 sctmp = sc->next; 00737 j_jconf_search_free(sc); 00738 sc = sctmp; 00739 } 00740 free(jconf); 00741 } 00742 00757 Recog * 00758 j_recog_new() 00759 { 00760 Recog *recog; 00761 00762 /* allocate memory */ 00763 recog = (Recog *)mymalloc(sizeof(Recog)); 00764 00765 /* clear all values to 0 (NULL) */ 00766 memset(recog, 0, sizeof(Recog)); 00767 00768 /* initialize some values */ 00769 recog->jconf = NULL; 00770 recog->amlist = NULL; 00771 recog->lmlist = NULL; 00772 recog->process_list = NULL; 00773 00774 recog->process_online = FALSE; 00775 recog->process_active = TRUE; 00776 recog->process_want_terminate = FALSE; 00777 recog->process_want_reload = FALSE; 00778 recog->gram_switch_input_method = SM_PAUSE; 00779 recog->process_segment = FALSE; 00780 00781 /* set default function for vector calculation to RealTimeMFCC() */ 00782 recog->calc_vector = RealTimeMFCC; 00783 00784 /* clear callback func. */ 00785 callback_init(recog); 00786 00787 recog->adin = (ADIn *)mymalloc(sizeof(ADIn)); 00788 memset(recog->adin, 0, sizeof(ADIn)); 00789 00790 return(recog); 00791 } 00792 00811 void 00812 j_recog_free(Recog *recog) 00813 { 00814 if (recog->gmm) hmminfo_free(recog->gmm); 00815 00816 if (recog->speech) free(recog->speech); 00817 00818 /* free adin work area */ 00819 adin_free_param(recog); 00820 /* free GMM calculation work area if any */ 00821 gmm_free(recog); 00822 00823 /* Output result -> free just after malloced and used */ 00824 /* StackDecode pass2 -> allocate and free within search */ 00825 00826 /* RealBeam real */ 00827 realbeam_free(recog); 00828 00829 /* adin */ 00830 if (recog->adin) free(recog->adin); 00831 00832 /* instances */ 00833 { 00834 RecogProcess *p, *ptmp; 00835 p = recog->process_list; 00836 while(p) { 00837 ptmp = p->next; 00838 j_recogprocess_free(p); 00839 p = ptmp; 00840 } 00841 } 00842 { 00843 PROCESS_LM *lm, *lmtmp; 00844 lm = recog->lmlist; 00845 while(lm) { 00846 lmtmp = lm->next; 00847 j_process_lm_free(lm); 00848 lm = lmtmp; 00849 } 00850 } 00851 { 00852 PROCESS_AM *am, *amtmp; 00853 am = recog->amlist; 00854 while(am) { 00855 amtmp = am->next; 00856 j_process_am_free(am); 00857 am = amtmp; 00858 } 00859 } 00860 { 00861 MFCCCalc *mfcc, *tmp; 00862 mfcc = recog->mfcclist; 00863 while(mfcc) { 00864 tmp = mfcc->next; 00865 j_mfcccalc_free(mfcc); 00866 mfcc = tmp; 00867 } 00868 } 00869 00870 /* jconf */ 00871 if (recog->jconf) { 00872 j_jconf_free(recog->jconf); 00873 } 00874 00875 free(recog); 00876 } 00877 00878 /* end of file */