Julius 4.1.5
|
00001 00018 /* 00019 * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2007 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 if (am->hmminfo) hmminfo_free(am->hmminfo); 00164 if (am->hmm_gs) hmminfo_free(am->hmm_gs); 00165 /* not free am->jconf */ 00166 /* HMMWork hmmwrk */ 00167 outprob_free(&(am->hmmwrk)); 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 wchmm */ 00304 if (process->wchmm) wchmm_free(process->wchmm); 00305 /* free backtrellis */ 00306 if (process->backtrellis) bt_free(process->backtrellis); 00307 /* free pass1 work area */ 00308 fsbeam_free(&(process->pass1)); 00309 free(process); 00310 } 00311 00328 JCONF_AM * 00329 j_jconf_am_new() 00330 { 00331 JCONF_AM *new; 00332 new = (JCONF_AM *)mymalloc(sizeof(JCONF_AM)); 00333 jconf_set_default_values_am(new); 00334 new->next = NULL; 00335 return new; 00336 } 00337 00355 void 00356 j_jconf_am_free(JCONF_AM *amconf) 00357 { 00358 free(amconf); 00359 } 00360 00381 boolean 00382 j_jconf_am_regist(Jconf *jconf, JCONF_AM *amconf, char *name) 00383 { 00384 JCONF_AM *atmp; 00385 00386 if (!name) { 00387 jlog("ERROR: j_jconf_am_regist: no name specified to register an AM conf\n"); 00388 return FALSE; 00389 } 00390 00391 for(atmp = jconf->am_root; atmp; atmp = atmp->next) { 00392 if (strmatch(atmp->name, name)) { 00393 jlog("ERROR: j_jconf_am_regist: failed to regist an AM conf: the same name \"%s\" already exist\n", atmp->name); 00394 return FALSE; 00395 } 00396 } 00397 00398 /* set name */ 00399 strncpy(amconf->name, name, JCONF_MODULENAME_MAXLEN); 00400 00401 /* append to last */ 00402 amconf->next = NULL; 00403 if (jconf->am_root == NULL) { 00404 amconf->id = 1; 00405 jconf->am_root = amconf; 00406 } else { 00407 for(atmp = jconf->am_root; atmp->next; atmp = atmp->next); 00408 amconf->id = atmp->id + 1; 00409 atmp->next = amconf; 00410 } 00411 00412 return TRUE; 00413 } 00414 00415 00432 JCONF_LM * 00433 j_jconf_lm_new() 00434 { 00435 JCONF_LM *new; 00436 new = (JCONF_LM *)mymalloc(sizeof(JCONF_LM)); 00437 jconf_set_default_values_lm(new); 00438 new->next = NULL; 00439 return new; 00440 } 00441 00457 void 00458 j_jconf_lm_free(JCONF_LM *lmconf) 00459 { 00460 free(lmconf); 00461 } 00462 00483 boolean 00484 j_jconf_lm_regist(Jconf *jconf, JCONF_LM *lmconf, char *name) 00485 { 00486 JCONF_LM *ltmp; 00487 00488 if (!name) { 00489 jlog("ERROR: j_jconf_lm_regist: no name specified to register a LM conf\n"); 00490 return FALSE; 00491 } 00492 00493 for(ltmp = jconf->lm_root; ltmp; ltmp = ltmp->next) { 00494 if (strmatch(ltmp->name, name)) { 00495 jlog("ERROR: j_jconf_lm_regist: failed to regist a LM conf: the same name \"%s\" already exist\n", ltmp->name); 00496 return FALSE; 00497 } 00498 } 00499 00500 /* set name */ 00501 strncpy(lmconf->name, name, JCONF_MODULENAME_MAXLEN); 00502 00503 /* append to last */ 00504 lmconf->next = NULL; 00505 if (jconf->lm_root == NULL) { 00506 lmconf->id = 1; 00507 jconf->lm_root = lmconf; 00508 } else { 00509 for(ltmp = jconf->lm_root; ltmp->next; ltmp = ltmp->next); 00510 lmconf->id = ltmp->id + 1; 00511 ltmp->next = lmconf; 00512 } 00513 00514 return TRUE; 00515 } 00516 00517 00534 JCONF_SEARCH * 00535 j_jconf_search_new() 00536 { 00537 JCONF_SEARCH *new; 00538 new = (JCONF_SEARCH *)mymalloc(sizeof(JCONF_SEARCH)); 00539 jconf_set_default_values_search(new); 00540 new->next = NULL; 00541 return new; 00542 } 00543 00559 void 00560 j_jconf_search_free(JCONF_SEARCH *sconf) 00561 { 00562 free(sconf); 00563 } 00564 00585 boolean 00586 j_jconf_search_regist(Jconf *jconf, JCONF_SEARCH *sconf, char *name) 00587 { 00588 JCONF_SEARCH *stmp; 00589 00590 if (!name) { 00591 jlog("ERROR: j_jconf_search_regist: no name specified to register a SR conf\n"); 00592 return FALSE; 00593 } 00594 00595 for(stmp = jconf->search_root; stmp; stmp = stmp->next) { 00596 if (strmatch(stmp->name, name)) { 00597 jlog("ERROR: j_jconf_search_regist: failed to regist an SR conf: the same name \"%s\" already exist\n", stmp->name); 00598 return FALSE; 00599 } 00600 } 00601 00602 /* set name */ 00603 strncpy(sconf->name, name, JCONF_MODULENAME_MAXLEN); 00604 00605 /* append to last */ 00606 sconf->next = NULL; 00607 if (jconf->search_root == NULL) { 00608 sconf->id = 1; 00609 jconf->search_root = sconf; 00610 } else { 00611 for(stmp = jconf->search_root; stmp->next; stmp = stmp->next); 00612 sconf->id = stmp->id + 1; 00613 stmp->next = sconf; 00614 } 00615 return TRUE; 00616 } 00617 00641 Jconf * 00642 j_jconf_new() 00643 { 00644 Jconf *jconf; 00645 00646 /* allocate memory */ 00647 jconf = (Jconf *)mymalloc(sizeof(Jconf)); 00648 /* set default values */ 00649 jconf_set_default_values(jconf); 00650 00651 /* allocate first one am / lm /search instance with their name left NULL */ 00652 jconf->am_root = j_jconf_am_new(); 00653 jconf->am_root->id = 0; 00654 strcpy(jconf->am_root->name, JCONF_MODULENAME_DEFAULT); 00655 jconf->lm_root = j_jconf_lm_new(); 00656 jconf->lm_root->id = 0; 00657 strcpy(jconf->lm_root->name, JCONF_MODULENAME_DEFAULT); 00658 jconf->search_root = j_jconf_search_new(); 00659 jconf->search_root->id = 0; 00660 strcpy(jconf->search_root->name, JCONF_MODULENAME_DEFAULT); 00661 /* assign the am /lm instance to the instance */ 00662 jconf->search_root->amconf = jconf->am_root; 00663 jconf->search_root->lmconf = jconf->lm_root; 00664 /* set current */ 00665 jconf->amnow = jconf->am_root; 00666 jconf->lmnow = jconf->lm_root; 00667 jconf->searchnow = jconf->search_root; 00668 /* set gmm am jconf */ 00669 jconf->gmm = NULL; 00670 00671 return(jconf); 00672 } 00673 00694 void 00695 j_jconf_free(Jconf *jconf) 00696 { 00697 JCONF_AM *am, *amtmp; 00698 JCONF_LM *lm, *lmtmp; 00699 JCONF_SEARCH *sc, *sctmp; 00700 00701 opt_release(jconf); 00702 00703 am = jconf->am_root; 00704 while(am) { 00705 amtmp = am->next; 00706 j_jconf_am_free(am); 00707 am = amtmp; 00708 } 00709 lm = jconf->lm_root; 00710 while(lm) { 00711 lmtmp = lm->next; 00712 j_jconf_lm_free(lm); 00713 lm = lmtmp; 00714 } 00715 sc = jconf->search_root; 00716 while(sc) { 00717 sctmp = sc->next; 00718 j_jconf_search_free(sc); 00719 sc = sctmp; 00720 } 00721 free(jconf); 00722 } 00723 00738 Recog * 00739 j_recog_new() 00740 { 00741 Recog *recog; 00742 00743 /* allocate memory */ 00744 recog = (Recog *)mymalloc(sizeof(Recog)); 00745 00746 /* clear all values to 0 (NULL) */ 00747 memset(recog, 0, sizeof(Recog)); 00748 00749 /* initialize some values */ 00750 recog->jconf = NULL; 00751 recog->amlist = NULL; 00752 recog->lmlist = NULL; 00753 recog->process_list = NULL; 00754 00755 recog->process_online = FALSE; 00756 recog->process_active = TRUE; 00757 recog->process_want_terminate = FALSE; 00758 recog->process_want_reload = FALSE; 00759 recog->gram_switch_input_method = SM_PAUSE; 00760 recog->process_segment = FALSE; 00761 00762 /* set default function for vector calculation to RealTimeMFCC() */ 00763 recog->calc_vector = RealTimeMFCC; 00764 00765 /* clear callback func. */ 00766 callback_init(recog); 00767 00768 recog->adin = (ADIn *)mymalloc(sizeof(ADIn)); 00769 memset(recog->adin, 0, sizeof(ADIn)); 00770 00771 return(recog); 00772 } 00773 00792 void 00793 j_recog_free(Recog *recog) 00794 { 00795 if (recog->gmm) hmminfo_free(recog->gmm); 00796 00797 if (recog->speech) free(recog->speech); 00798 00799 /* free adin work area */ 00800 adin_free_param(recog); 00801 /* free GMM calculation work area if any */ 00802 gmm_free(recog); 00803 00804 /* Output result -> free just after malloced and used */ 00805 /* StackDecode pass2 -> allocate and free within search */ 00806 00807 /* RealBeam real */ 00808 realbeam_free(recog); 00809 00810 /* adin */ 00811 if (recog->adin) free(recog->adin); 00812 00813 /* instances */ 00814 { 00815 RecogProcess *p, *ptmp; 00816 p = recog->process_list; 00817 while(p) { 00818 ptmp = p->next; 00819 j_recogprocess_free(p); 00820 p = ptmp; 00821 } 00822 } 00823 { 00824 PROCESS_LM *lm, *lmtmp; 00825 lm = recog->lmlist; 00826 while(lm) { 00827 lmtmp = lm->next; 00828 j_process_lm_free(lm); 00829 lm = lmtmp; 00830 } 00831 } 00832 { 00833 PROCESS_AM *am, *amtmp; 00834 am = recog->amlist; 00835 while(am) { 00836 amtmp = am->next; 00837 j_process_am_free(am); 00838 am = amtmp; 00839 } 00840 } 00841 { 00842 MFCCCalc *mfcc, *tmp; 00843 mfcc = recog->mfcclist; 00844 while(mfcc) { 00845 tmp = mfcc->next; 00846 j_mfcccalc_free(mfcc); 00847 mfcc = tmp; 00848 } 00849 } 00850 00851 /* jconf */ 00852 if (recog->jconf) { 00853 j_jconf_free(recog->jconf); 00854 } 00855 00856 free(recog); 00857 } 00858 00859 /* end of file */