00001
00018
00019
00020
00021
00022
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 if (amconf) {
00055 mfcc->para = &(amconf->analysis.para);
00056 mfcc->hmm_loaded = (amconf->analysis.para_hmm.loaded == 1) ? TRUE : FALSE;
00057 mfcc->htk_loaded = (amconf->analysis.para_htk.loaded == 1) ? TRUE : FALSE;
00058 mfcc->wrk = WMP_work_new(mfcc->para);
00059 if (mfcc->wrk == NULL) {
00060 jlog("ERROR: j_mfcccalc_new: failed to initialize MFCC computation\n");
00061 return NULL;
00062 }
00063 mfcc->cmn.load_filename = amconf->analysis.cmnload_filename;
00064 mfcc->cmn.update = amconf->analysis.cmn_update;
00065 mfcc->cmn.save_filename = amconf->analysis.cmnsave_filename;
00066 mfcc->cmn.map_weight = amconf->analysis.cmn_map_weight;
00067 mfcc->frontend.ss_alpha = amconf->frontend.ss_alpha;
00068 mfcc->frontend.ss_floor = amconf->frontend.ss_floor;
00069 mfcc->frontend.sscalc = amconf->frontend.sscalc;
00070 mfcc->frontend.sscalc_len = amconf->frontend.sscalc_len;
00071 mfcc->frontend.ssload_filename = amconf->frontend.ssload_filename;
00072 }
00073 mfcc->next = NULL;
00074 return mfcc;
00075 }
00076
00090 void
00091 j_mfcccalc_free(MFCCCalc *mfcc)
00092 {
00093 if (mfcc->rest_param) free_param(mfcc->rest_param);
00094 if (mfcc->param) free_param(mfcc->param);
00095 if (mfcc->wrk) WMP_free(mfcc->wrk);
00096 if (mfcc->tmpmfcc) free(mfcc->tmpmfcc);
00097 if (mfcc->db) WMP_deltabuf_free(mfcc->db);
00098 if (mfcc->ab) WMP_deltabuf_free(mfcc->ab);
00099 if (mfcc->cmn.wrk) CMN_realtime_free(mfcc->cmn.wrk);
00100 if (mfcc->frontend.ssbuf) free(mfcc->frontend.ssbuf);
00101 if (mfcc->frontend.mfccwrk_ss) WMP_free(mfcc->frontend.mfccwrk_ss);
00102
00103 free(mfcc);
00104 }
00105
00122 PROCESS_AM *
00123 j_process_am_new(Recog *recog, JCONF_AM *amconf)
00124 {
00125 PROCESS_AM *new, *atmp;
00126
00127
00128 new = (PROCESS_AM *)mymalloc(sizeof(PROCESS_AM));
00129 memset(new, 0, sizeof(PROCESS_AM));
00130
00131
00132 new->config = amconf;
00133
00134
00135 new->next = NULL;
00136 if (recog->amlist == NULL) {
00137 recog->amlist = new;
00138 } else {
00139 for(atmp = recog->amlist; atmp->next; atmp = atmp->next);
00140 atmp->next = new;
00141 }
00142
00143 return new;
00144 }
00145
00159 void
00160 j_process_am_free(PROCESS_AM *am)
00161 {
00162 if (am->hmminfo) hmminfo_free(am->hmminfo);
00163 if (am->hmm_gs) hmminfo_free(am->hmm_gs);
00164
00165
00166 outprob_free(&(am->hmmwrk));
00167 free(am);
00168 }
00169
00186 PROCESS_LM *
00187 j_process_lm_new(Recog *recog, JCONF_LM *lmconf)
00188 {
00189 PROCESS_LM *new, *ltmp;
00190
00191
00192 new = (PROCESS_LM *)mymalloc(sizeof(PROCESS_LM));
00193 memset(new, 0, sizeof(PROCESS_LM));
00194
00195
00196 new->config = lmconf;
00197
00198
00199 new->lmtype = lmconf->lmtype;
00200 new->lmvar = lmconf->lmvar;
00201 new->gram_maxid = 0;
00202 new->global_modified = FALSE;
00203
00204
00205 new->next = NULL;
00206 if (recog->lmlist == NULL) {
00207 recog->lmlist = new;
00208 } else {
00209 for(ltmp = recog->lmlist; ltmp->next; ltmp = ltmp->next);
00210 ltmp->next = new;
00211 }
00212
00213 return new;
00214 }
00215
00229 void
00230 j_process_lm_free(PROCESS_LM *lm)
00231 {
00232 if (lm->winfo) word_info_free(lm->winfo);
00233 if (lm->ngram) ngram_info_free(lm->ngram);
00234 if (lm->grammars) multigram_free_all(lm->grammars);
00235 if (lm->dfa) dfa_info_free(lm->dfa);
00236
00237 free(lm);
00238 }
00239
00256 RecogProcess *
00257 j_recogprocess_new(Recog *recog, JCONF_SEARCH *sconf)
00258 {
00259 RecogProcess *new, *ptmp;
00260
00261
00262 new = (RecogProcess *)mymalloc(sizeof(RecogProcess));
00263 memset(new, 0, sizeof(RecogProcess));
00264 new->live = FALSE;
00265 new->active = 0;
00266 new->next = NULL;
00267
00268
00269 new->config = sconf;
00270
00271
00272 new->next = NULL;
00273 if (recog->process_list == NULL) {
00274 recog->process_list = new;
00275 } else {
00276 for(ptmp = recog->process_list; ptmp->next; ptmp = ptmp->next);
00277 ptmp->next = new;
00278 }
00279
00280 return new;
00281 }
00282
00296 void
00297 j_recogprocess_free(RecogProcess *process)
00298 {
00299
00300
00301 #ifdef CONFIDENVE_MEASURE
00302 #ifdef CM_MULTIPLE_ALPHA
00303 free(process->pass2.cmsumlist);
00304 #endif
00305 #ifdef CM_NBEST;
00306 free(process->pass2.sentcm);
00307 free(process->pass2.wordcm);
00308 #endif
00309 #endif
00310
00311 if (process->wchmm) wchmm_free(process->wchmm);
00312
00313 if (process->backtrellis) bt_free(process->backtrellis);
00314
00315 fsbeam_free(&(process->pass1));
00316 free(process);
00317 }
00318
00335 JCONF_AM *
00336 j_jconf_am_new()
00337 {
00338 JCONF_AM *new;
00339 new = (JCONF_AM *)mymalloc(sizeof(JCONF_AM));
00340 jconf_set_default_values_am(new);
00341 new->next = NULL;
00342 return new;
00343 }
00344
00362 void
00363 j_jconf_am_free(JCONF_AM *amconf)
00364 {
00365 free(amconf);
00366 }
00367
00388 boolean
00389 j_jconf_am_regist(Jconf *jconf, JCONF_AM *amconf, char *name)
00390 {
00391 JCONF_AM *atmp;
00392
00393 if (!name) {
00394 jlog("ERROR: j_jconf_am_regist: no name specified to register an AM conf\n");
00395 return FALSE;
00396 }
00397
00398 for(atmp = jconf->am_root; atmp; atmp = atmp->next) {
00399 if (strmatch(atmp->name, name)) {
00400 jlog("ERROR: j_jconf_am_regist: failed to regist an AM conf: the same name \"%s\" already exist\n", atmp->name);
00401 return FALSE;
00402 }
00403 }
00404
00405
00406 strncpy(amconf->name, name, JCONF_MODULENAME_MAXLEN);
00407
00408
00409 amconf->next = NULL;
00410 if (jconf->am_root == NULL) {
00411 amconf->id = 1;
00412 jconf->am_root = amconf;
00413 } else {
00414 for(atmp = jconf->am_root; atmp->next; atmp = atmp->next);
00415 amconf->id = atmp->id + 1;
00416 atmp->next = amconf;
00417 }
00418
00419 return TRUE;
00420 }
00421
00422
00439 JCONF_LM *
00440 j_jconf_lm_new()
00441 {
00442 JCONF_LM *new;
00443 new = (JCONF_LM *)mymalloc(sizeof(JCONF_LM));
00444 jconf_set_default_values_lm(new);
00445 new->next = NULL;
00446 return new;
00447 }
00448
00464 void
00465 j_jconf_lm_free(JCONF_LM *lmconf)
00466 {
00467 free(lmconf);
00468 }
00469
00490 boolean
00491 j_jconf_lm_regist(Jconf *jconf, JCONF_LM *lmconf, char *name)
00492 {
00493 JCONF_LM *ltmp;
00494
00495 if (!name) {
00496 jlog("ERROR: j_jconf_lm_regist: no name specified to register a LM conf\n");
00497 return FALSE;
00498 }
00499
00500 for(ltmp = jconf->lm_root; ltmp; ltmp = ltmp->next) {
00501 if (strmatch(ltmp->name, name)) {
00502 jlog("ERROR: j_jconf_lm_regist: failed to regist a LM conf: the same name \"%s\" already exist\n", ltmp->name);
00503 return FALSE;
00504 }
00505 }
00506
00507
00508 strncpy(lmconf->name, name, JCONF_MODULENAME_MAXLEN);
00509
00510
00511 lmconf->next = NULL;
00512 if (jconf->lm_root == NULL) {
00513 lmconf->id = 1;
00514 jconf->lm_root = lmconf;
00515 } else {
00516 for(ltmp = jconf->lm_root; ltmp->next; ltmp = ltmp->next);
00517 lmconf->id = ltmp->id + 1;
00518 ltmp->next = lmconf;
00519 }
00520
00521 return TRUE;
00522 }
00523
00524
00541 JCONF_SEARCH *
00542 j_jconf_search_new()
00543 {
00544 JCONF_SEARCH *new;
00545 new = (JCONF_SEARCH *)mymalloc(sizeof(JCONF_SEARCH));
00546 jconf_set_default_values_search(new);
00547 new->next = NULL;
00548 return new;
00549 }
00550
00566 void
00567 j_jconf_search_free(JCONF_SEARCH *sconf)
00568 {
00569 free(sconf);
00570 }
00571
00592 boolean
00593 j_jconf_search_regist(Jconf *jconf, JCONF_SEARCH *sconf, char *name)
00594 {
00595 JCONF_SEARCH *stmp;
00596
00597 if (!name) {
00598 jlog("ERROR: j_jconf_search_regist: no name specified to register a SR conf\n");
00599 return FALSE;
00600 }
00601
00602 for(stmp = jconf->search_root; stmp; stmp = stmp->next) {
00603 if (strmatch(stmp->name, name)) {
00604 jlog("ERROR: j_jconf_search_regist: failed to regist an SR conf: the same name \"%s\" already exist\n", stmp->name);
00605 return FALSE;
00606 }
00607 }
00608
00609
00610 strncpy(sconf->name, name, JCONF_MODULENAME_MAXLEN);
00611
00612
00613 sconf->next = NULL;
00614 if (jconf->search_root == NULL) {
00615 sconf->id = 1;
00616 jconf->search_root = sconf;
00617 } else {
00618 for(stmp = jconf->search_root; stmp->next; stmp = stmp->next);
00619 sconf->id = stmp->id + 1;
00620 stmp->next = sconf;
00621 }
00622 return TRUE;
00623 }
00624
00648 Jconf *
00649 j_jconf_new()
00650 {
00651 Jconf *jconf;
00652
00653
00654 jconf = (Jconf *)mymalloc(sizeof(Jconf));
00655
00656 jconf_set_default_values(jconf);
00657
00658
00659 jconf->am_root = j_jconf_am_new();
00660 jconf->am_root->id = 0;
00661 strcpy(jconf->am_root->name, JCONF_MODULENAME_DEFAULT);
00662 jconf->lm_root = j_jconf_lm_new();
00663 jconf->lm_root->id = 0;
00664 strcpy(jconf->lm_root->name, JCONF_MODULENAME_DEFAULT);
00665 jconf->search_root = j_jconf_search_new();
00666 jconf->search_root->id = 0;
00667 strcpy(jconf->search_root->name, JCONF_MODULENAME_DEFAULT);
00668
00669 jconf->search_root->amconf = jconf->am_root;
00670 jconf->search_root->lmconf = jconf->lm_root;
00671
00672 jconf->amnow = jconf->am_root;
00673 jconf->lmnow = jconf->lm_root;
00674 jconf->searchnow = jconf->search_root;
00675
00676 jconf->gmm = j_jconf_am_new();
00677
00678 return(jconf);
00679 }
00680
00701 void
00702 j_jconf_free(Jconf *jconf)
00703 {
00704 JCONF_AM *am, *amtmp;
00705 JCONF_LM *lm, *lmtmp;
00706 JCONF_SEARCH *sc, *sctmp;
00707
00708 opt_release(jconf);
00709
00710 am = jconf->am_root;
00711 while(am) {
00712 amtmp = am->next;
00713 j_jconf_am_free(am);
00714 am = amtmp;
00715 }
00716 lm = jconf->lm_root;
00717 while(lm) {
00718 lmtmp = lm->next;
00719 j_jconf_lm_free(lm);
00720 lm = lmtmp;
00721 }
00722 sc = jconf->search_root;
00723 while(sc) {
00724 sctmp = sc->next;
00725 j_jconf_search_free(sc);
00726 sc = sctmp;
00727 }
00728 free(jconf);
00729 }
00730
00745 Recog *
00746 j_recog_new()
00747 {
00748 Recog *recog;
00749
00750
00751 recog = (Recog *)mymalloc(sizeof(Recog));
00752
00753
00754 memset(recog, 0, sizeof(Recog));
00755
00756
00757 recog->jconf = NULL;
00758 recog->amlist = NULL;
00759 recog->lmlist = NULL;
00760 recog->process_list = NULL;
00761
00762 recog->process_online = FALSE;
00763 recog->process_active = TRUE;
00764 recog->process_want_terminate = FALSE;
00765 recog->process_want_reload = FALSE;
00766 recog->gram_switch_input_method = SM_PAUSE;
00767 recog->process_segment = FALSE;
00768
00769
00770 recog->calc_vector = RealTimeMFCC;
00771
00772
00773 callback_init(recog);
00774
00775 recog->adin = (ADIn *)mymalloc(sizeof(ADIn));
00776 memset(recog->adin, 0, sizeof(ADIn));
00777
00778 return(recog);
00779 }
00780
00799 void
00800 j_recog_free(Recog *recog)
00801 {
00802 if (recog->gmm) hmminfo_free(recog->gmm);
00803
00804 if (recog->speech) free(recog->speech);
00805
00806
00807 adin_free_param(recog);
00808
00809 gmm_free(recog);
00810
00811
00812
00813
00814
00815 realbeam_free(recog);
00816
00817
00818 if (recog->adin) free(recog->adin);
00819
00820
00821 {
00822 RecogProcess *p, *ptmp;
00823 p = recog->process_list;
00824 while(p) {
00825 ptmp = p->next;
00826 j_recogprocess_free(p);
00827 p = ptmp;
00828 }
00829 }
00830 {
00831 PROCESS_LM *lm, *lmtmp;
00832 lm = recog->lmlist;
00833 while(lm) {
00834 lmtmp = lm->next;
00835 j_process_lm_free(lm);
00836 lm = lmtmp;
00837 }
00838 }
00839 {
00840 PROCESS_AM *am, *amtmp;
00841 am = recog->amlist;
00842 while(am) {
00843 amtmp = am->next;
00844 j_process_am_free(am);
00845 am = amtmp;
00846 }
00847 }
00848 {
00849 MFCCCalc *mfcc, *tmp;
00850 mfcc = recog->mfcclist;
00851 while(mfcc) {
00852 tmp = mfcc->next;
00853 j_mfcccalc_free(mfcc);
00854 mfcc = tmp;
00855 }
00856 }
00857
00858
00859 if (recog->jconf) {
00860 j_jconf_free(recog->jconf);
00861 }
00862
00863 free(recog);
00864 }
00865
00866