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 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
00129 new = (PROCESS_AM *)mymalloc(sizeof(PROCESS_AM));
00130 memset(new, 0, sizeof(PROCESS_AM));
00131
00132
00133 new->config = amconf;
00134
00135
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
00166
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
00193 new = (PROCESS_LM *)mymalloc(sizeof(PROCESS_LM));
00194 memset(new, 0, sizeof(PROCESS_LM));
00195
00196
00197 new->config = lmconf;
00198
00199
00200 new->lmtype = lmconf->lmtype;
00201 new->lmvar = lmconf->lmvar;
00202 new->gram_maxid = 0;
00203 new->global_modified = FALSE;
00204
00205
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
00238 free(lm);
00239 }
00240
00257 RecogProcess *
00258 j_recogprocess_new(Recog *recog, JCONF_SEARCH *sconf)
00259 {
00260 RecogProcess *new, *ptmp;
00261
00262
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
00270 new->config = sconf;
00271
00272
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
00301
00302 #ifdef CONFIDENVE_MEASURE
00303 #ifdef CM_MULTIPLE_ALPHA
00304 free(process->pass2.cmsumlist);
00305 #endif
00306 #ifdef CM_NBEST;
00307 free(process->pass2.sentcm);
00308 free(process->pass2.wordcm);
00309 #endif
00310 #endif
00311
00312 if (process->wchmm) wchmm_free(process->wchmm);
00313
00314 if (process->backtrellis) bt_free(process->backtrellis);
00315
00316 fsbeam_free(&(process->pass1));
00317 free(process);
00318 }
00319
00336 JCONF_AM *
00337 j_jconf_am_new()
00338 {
00339 JCONF_AM *new;
00340 new = (JCONF_AM *)mymalloc(sizeof(JCONF_AM));
00341 jconf_set_default_values_am(new);
00342 new->next = NULL;
00343 return new;
00344 }
00345
00363 void
00364 j_jconf_am_free(JCONF_AM *amconf)
00365 {
00366 free(amconf);
00367 }
00368
00389 boolean
00390 j_jconf_am_regist(Jconf *jconf, JCONF_AM *amconf, char *name)
00391 {
00392 JCONF_AM *atmp;
00393
00394 if (!name) {
00395 jlog("ERROR: j_jconf_am_regist: no name specified to register an AM conf\n");
00396 return FALSE;
00397 }
00398
00399 for(atmp = jconf->am_root; atmp; atmp = atmp->next) {
00400 if (strmatch(atmp->name, name)) {
00401 jlog("ERROR: j_jconf_am_regist: failed to regist an AM conf: the same name \"%s\" already exist\n", atmp->name);
00402 return FALSE;
00403 }
00404 }
00405
00406
00407 strncpy(amconf->name, name, JCONF_MODULENAME_MAXLEN);
00408
00409
00410 amconf->next = NULL;
00411 if (jconf->am_root == NULL) {
00412 amconf->id = 1;
00413 jconf->am_root = amconf;
00414 } else {
00415 for(atmp = jconf->am_root; atmp->next; atmp = atmp->next);
00416 amconf->id = atmp->id + 1;
00417 atmp->next = amconf;
00418 }
00419
00420 return TRUE;
00421 }
00422
00423
00440 JCONF_LM *
00441 j_jconf_lm_new()
00442 {
00443 JCONF_LM *new;
00444 new = (JCONF_LM *)mymalloc(sizeof(JCONF_LM));
00445 jconf_set_default_values_lm(new);
00446 new->next = NULL;
00447 return new;
00448 }
00449
00465 void
00466 j_jconf_lm_free(JCONF_LM *lmconf)
00467 {
00468 free(lmconf);
00469 }
00470
00491 boolean
00492 j_jconf_lm_regist(Jconf *jconf, JCONF_LM *lmconf, char *name)
00493 {
00494 JCONF_LM *ltmp;
00495
00496 if (!name) {
00497 jlog("ERROR: j_jconf_lm_regist: no name specified to register a LM conf\n");
00498 return FALSE;
00499 }
00500
00501 for(ltmp = jconf->lm_root; ltmp; ltmp = ltmp->next) {
00502 if (strmatch(ltmp->name, name)) {
00503 jlog("ERROR: j_jconf_lm_regist: failed to regist a LM conf: the same name \"%s\" already exist\n", ltmp->name);
00504 return FALSE;
00505 }
00506 }
00507
00508
00509 strncpy(lmconf->name, name, JCONF_MODULENAME_MAXLEN);
00510
00511
00512 lmconf->next = NULL;
00513 if (jconf->lm_root == NULL) {
00514 lmconf->id = 1;
00515 jconf->lm_root = lmconf;
00516 } else {
00517 for(ltmp = jconf->lm_root; ltmp->next; ltmp = ltmp->next);
00518 lmconf->id = ltmp->id + 1;
00519 ltmp->next = lmconf;
00520 }
00521
00522 return TRUE;
00523 }
00524
00525
00542 JCONF_SEARCH *
00543 j_jconf_search_new()
00544 {
00545 JCONF_SEARCH *new;
00546 new = (JCONF_SEARCH *)mymalloc(sizeof(JCONF_SEARCH));
00547 jconf_set_default_values_search(new);
00548 new->next = NULL;
00549 return new;
00550 }
00551
00567 void
00568 j_jconf_search_free(JCONF_SEARCH *sconf)
00569 {
00570 free(sconf);
00571 }
00572
00593 boolean
00594 j_jconf_search_regist(Jconf *jconf, JCONF_SEARCH *sconf, char *name)
00595 {
00596 JCONF_SEARCH *stmp;
00597
00598 if (!name) {
00599 jlog("ERROR: j_jconf_search_regist: no name specified to register a SR conf\n");
00600 return FALSE;
00601 }
00602
00603 for(stmp = jconf->search_root; stmp; stmp = stmp->next) {
00604 if (strmatch(stmp->name, name)) {
00605 jlog("ERROR: j_jconf_search_regist: failed to regist an SR conf: the same name \"%s\" already exist\n", stmp->name);
00606 return FALSE;
00607 }
00608 }
00609
00610
00611 strncpy(sconf->name, name, JCONF_MODULENAME_MAXLEN);
00612
00613
00614 sconf->next = NULL;
00615 if (jconf->search_root == NULL) {
00616 sconf->id = 1;
00617 jconf->search_root = sconf;
00618 } else {
00619 for(stmp = jconf->search_root; stmp->next; stmp = stmp->next);
00620 sconf->id = stmp->id + 1;
00621 stmp->next = sconf;
00622 }
00623 return TRUE;
00624 }
00625
00649 Jconf *
00650 j_jconf_new()
00651 {
00652 Jconf *jconf;
00653
00654
00655 jconf = (Jconf *)mymalloc(sizeof(Jconf));
00656
00657 jconf_set_default_values(jconf);
00658
00659
00660 jconf->am_root = j_jconf_am_new();
00661 jconf->am_root->id = 0;
00662 strcpy(jconf->am_root->name, JCONF_MODULENAME_DEFAULT);
00663 jconf->lm_root = j_jconf_lm_new();
00664 jconf->lm_root->id = 0;
00665 strcpy(jconf->lm_root->name, JCONF_MODULENAME_DEFAULT);
00666 jconf->search_root = j_jconf_search_new();
00667 jconf->search_root->id = 0;
00668 strcpy(jconf->search_root->name, JCONF_MODULENAME_DEFAULT);
00669
00670 jconf->search_root->amconf = jconf->am_root;
00671 jconf->search_root->lmconf = jconf->lm_root;
00672
00673 jconf->amnow = jconf->am_root;
00674 jconf->lmnow = jconf->lm_root;
00675 jconf->searchnow = jconf->search_root;
00676
00677 jconf->gmm = NULL;
00678
00679 return(jconf);
00680 }
00681
00702 void
00703 j_jconf_free(Jconf *jconf)
00704 {
00705 JCONF_AM *am, *amtmp;
00706 JCONF_LM *lm, *lmtmp;
00707 JCONF_SEARCH *sc, *sctmp;
00708
00709 opt_release(jconf);
00710
00711 am = jconf->am_root;
00712 while(am) {
00713 amtmp = am->next;
00714 j_jconf_am_free(am);
00715 am = amtmp;
00716 }
00717 lm = jconf->lm_root;
00718 while(lm) {
00719 lmtmp = lm->next;
00720 j_jconf_lm_free(lm);
00721 lm = lmtmp;
00722 }
00723 sc = jconf->search_root;
00724 while(sc) {
00725 sctmp = sc->next;
00726 j_jconf_search_free(sc);
00727 sc = sctmp;
00728 }
00729 free(jconf);
00730 }
00731
00746 Recog *
00747 j_recog_new()
00748 {
00749 Recog *recog;
00750
00751
00752 recog = (Recog *)mymalloc(sizeof(Recog));
00753
00754
00755 memset(recog, 0, sizeof(Recog));
00756
00757
00758 recog->jconf = NULL;
00759 recog->amlist = NULL;
00760 recog->lmlist = NULL;
00761 recog->process_list = NULL;
00762
00763 recog->process_online = FALSE;
00764 recog->process_active = TRUE;
00765 recog->process_want_terminate = FALSE;
00766 recog->process_want_reload = FALSE;
00767 recog->gram_switch_input_method = SM_PAUSE;
00768 recog->process_segment = FALSE;
00769
00770
00771 recog->calc_vector = RealTimeMFCC;
00772
00773
00774 callback_init(recog);
00775
00776 recog->adin = (ADIn *)mymalloc(sizeof(ADIn));
00777 memset(recog->adin, 0, sizeof(ADIn));
00778
00779 return(recog);
00780 }
00781
00800 void
00801 j_recog_free(Recog *recog)
00802 {
00803 if (recog->gmm) hmminfo_free(recog->gmm);
00804
00805 if (recog->speech) free(recog->speech);
00806
00807
00808 adin_free_param(recog);
00809
00810 gmm_free(recog);
00811
00812
00813
00814
00815
00816 realbeam_free(recog);
00817
00818
00819 if (recog->adin) free(recog->adin);
00820
00821
00822 {
00823 RecogProcess *p, *ptmp;
00824 p = recog->process_list;
00825 while(p) {
00826 ptmp = p->next;
00827 j_recogprocess_free(p);
00828 p = ptmp;
00829 }
00830 }
00831 {
00832 PROCESS_LM *lm, *lmtmp;
00833 lm = recog->lmlist;
00834 while(lm) {
00835 lmtmp = lm->next;
00836 j_process_lm_free(lm);
00837 lm = lmtmp;
00838 }
00839 }
00840 {
00841 PROCESS_AM *am, *amtmp;
00842 am = recog->amlist;
00843 while(am) {
00844 amtmp = am->next;
00845 j_process_am_free(am);
00846 am = amtmp;
00847 }
00848 }
00849 {
00850 MFCCCalc *mfcc, *tmp;
00851 mfcc = recog->mfcclist;
00852 while(mfcc) {
00853 tmp = mfcc->next;
00854 j_mfcccalc_free(mfcc);
00855 mfcc = tmp;
00856 }
00857 }
00858
00859
00860 if (recog->jconf) {
00861 j_jconf_free(recog->jconf);
00862 }
00863
00864 free(recog);
00865 }
00866
00867