libjulius/src/jfunc.c

Go to the documentation of this file.
00001 
00025 /*
00026  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00027  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00028  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00029  * All rights reserved
00030  */
00031 
00032 #include <julius/juliuslib.h>
00033 
00051 void
00052 j_request_pause(Recog *recog)
00053 {
00054   /* pause recognition: will stop when the current input ends */
00055   if (recog->process_active) {
00056     recog->process_want_terminate = FALSE;
00057     recog->process_want_reload = TRUE;
00058     recog->process_active = FALSE;
00059   }
00060   if (recog->jconf->input.speech_input == SP_ADINNET) {
00061     /* when taking speech from adinnet client,
00062        always tell the client to stop recording */
00063     adin_tcpip_send_pause();
00064   }
00065 }
00066 
00084 void
00085 j_request_terminate(Recog *recog)
00086 {
00087   /* terminate recognition: input will terminate immidiately */
00088   /* set flags to stop adin to terminate immediately, and
00089      stop process */
00090   if (recog->process_active) {
00091     recog->process_want_terminate = TRUE;
00092     recog->process_want_reload = TRUE;
00093     recog->process_active = FALSE;
00094   }
00095   if (recog->jconf->input.speech_input == SP_ADINNET) {
00096     /* when taking speech input from adinnet client,
00097        always tell the client to stop recording immediately */
00098     adin_tcpip_send_terminate();
00099   }
00100 }
00101 
00116 void 
00117 j_request_resume(Recog *recog)
00118 {
00119   if (recog->process_active == FALSE) {
00120     recog->process_want_terminate = FALSE;
00121     recog->process_active = TRUE;
00122   }
00123   if (recog->jconf->input.speech_input == SP_ADINNET) {
00124     /* when taking speech from adinnet client,
00125        tell the client to restart recording */
00126     adin_tcpip_send_resume();
00127   }
00128 }
00129 
00151 void
00152 schedule_grammar_update(Recog *recog)
00153 {
00154   if (recog->process_active) {
00155     /* if recognition is currently running, tell engine how/when to
00156        re-construct global lexicon. */
00157     switch(recog->gram_switch_input_method) {
00158     case SM_TERMINATE:  /* discard input now and change (immediate) */
00159       recog->process_want_terminate = TRUE;
00160       recog->process_want_reload = TRUE;
00161       break;
00162     case SM_PAUSE:              /* segment input now, recognize it, and then change */
00163       recog->process_want_terminate = FALSE;
00164       recog->process_want_reload = TRUE;
00165       break;
00166     case SM_WAIT:               /* wait until the current input end and recognition completed */
00167       recog->process_want_terminate = FALSE;
00168       recog->process_want_reload = FALSE;
00169       break;
00170     }
00171     /* After the update, recognition will restart without sleeping. */
00172   } else {
00173     /* If recognition is currently not running, the received
00174        grammars are merely stored in memory here.  The re-construction of
00175        global lexicon will be delayed: it will be re-built just before
00176        the recognition process starts next time. */
00177   }
00178 }
00179 
00196 void
00197 j_reset_reload(Recog *recog)
00198 {
00199   recog->process_want_reload = FALSE;
00200 }
00201 
00213 void
00214 j_enable_debug_message()
00215 {
00216   debug2_flag = TRUE;
00217 }
00218 
00231 void
00232 j_disable_debug_message()
00233 {
00234   debug2_flag = FALSE;
00235 }
00236 
00249 void
00250 j_enable_verbose_message()
00251 {
00252   verbose_flag = TRUE;
00253 }
00254 
00267 void
00268 j_disable_verbose_message()
00269 {
00270   verbose_flag = FALSE;
00271 }
00272               
00273 
00282 void
00283 j_internal_error(char *fmt, ...)
00284 {
00285   va_list ap;
00286   int ret;
00287 
00288   va_start(ap,fmt);
00289   ret = vfprintf(stderr, fmt, ap);
00290   va_end(ap);
00291 
00292   /* clean up socket if already opened */
00293   cleanup_socket();
00294 
00295   exit(1);
00296 }
00297 
00318 int
00319 j_config_load_args(Jconf *jconf, int argc, char *argv[])
00320 {
00321   JCONF_AM *am;
00322   JCONF_LM *lm;
00323   JCONF_SEARCH *s;
00324 
00325   /* parse options and set variables */
00326   if (opt_parse(argc, argv, NULL, jconf) == FALSE) {
00327     return -1;
00328   }
00329   /* if multiple instances defined from init, remove initial one (id=0) */
00330   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00331     am = jconf->am_root->next;
00332     free(jconf->am_root);
00333     jconf->am_root = am;
00334   }
00335   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00336     lm = jconf->lm_root->next;
00337     free(jconf->lm_root);
00338     jconf->lm_root = lm;
00339   }
00340   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00341     s = jconf->search_root->next;
00342     free(jconf->search_root);
00343     jconf->search_root = s;
00344   }
00345   return 0;
00346 }
00347 
00367 int
00368 j_config_load_file(Jconf *jconf, char *filename)
00369 {
00370   JCONF_AM *am;
00371   JCONF_LM *lm;
00372   JCONF_SEARCH *s;
00373 
00374   /* parse options and set variables */
00375   if (config_file_parse(filename, jconf) == FALSE) {
00376     return -1;
00377   }
00378   /* if multiple instances defined from init, remove initial one (id=0) */
00379   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00380     am = jconf->am_root->next;
00381     free(jconf->am_root);
00382     jconf->am_root = am;
00383   }
00384   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00385     lm = jconf->lm_root->next;
00386     free(jconf->lm_root);
00387     jconf->lm_root = lm;
00388   }
00389   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00390     s = jconf->search_root->next;
00391     free(jconf->search_root);
00392     jconf->search_root = s;
00393   }
00394   return 0;
00395 }
00396 
00416 Jconf *
00417 j_config_load_args_new(int argc, char *argv[])
00418 {
00419   Jconf *jconf;
00420   JCONF_AM *am;
00421   JCONF_LM *lm;
00422   JCONF_SEARCH *s;
00423 
00424   jconf = j_jconf_new();
00425   /* parse options and set variables */
00426   if (opt_parse(argc, argv, NULL, jconf) == FALSE) {
00427     j_jconf_free(jconf);
00428     return NULL;
00429   }
00430   /* if multiple instances defined from init, remove initial one (id=0) */
00431   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00432     am = jconf->am_root->next;
00433     free(jconf->am_root);
00434     jconf->am_root = am;
00435   }
00436   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00437     lm = jconf->lm_root->next;
00438     free(jconf->lm_root);
00439     jconf->lm_root = lm;
00440   }
00441   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00442     s = jconf->search_root->next;
00443     free(jconf->search_root);
00444     jconf->search_root = s;
00445   }
00446   return jconf;
00447 }
00448 
00467 Jconf *
00468 j_config_load_file_new(char *filename)
00469 {
00470   Jconf *jconf;
00471   JCONF_AM *am;
00472   JCONF_LM *lm;
00473   JCONF_SEARCH *s;
00474 
00475   jconf = j_jconf_new();
00476   /* parse options and set variables */
00477   if (config_file_parse(filename, jconf) == FALSE) {
00478     j_jconf_free(jconf);
00479     return NULL;
00480   }
00481   /* if multiple instances defined from init, remove initial one (id=0) */
00482   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00483     am = jconf->am_root->next;
00484     free(jconf->am_root);
00485     jconf->am_root = am;
00486   }
00487   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00488     lm = jconf->lm_root->next;
00489     free(jconf->lm_root);
00490     jconf->lm_root = lm;
00491   }
00492   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00493     s = jconf->search_root->next;
00494     free(jconf->search_root);
00495     jconf->search_root = s;
00496   }
00497   return jconf;
00498 }
00499 
00520 boolean
00521 j_adin_init(Recog *recog)
00522 {
00523   boolean ret;
00524 
00525   ret = adin_initialize(recog);
00526 
00527     /* initialize A/D-in device */
00528     /* create A/D-in thread here */
00529 #ifdef HAVE_PTHREAD
00530   if (ret) {
00531     if (recog->adin->enable_thread) {
00532       if (adin_thread_create(recog) == FALSE) {
00533         return FALSE;
00534       }
00535     }
00536   }
00537 #endif
00538 
00539   return(ret);
00540 }
00541 
00564 boolean
00565 j_adin_init_user(Recog *recog, void *arg)
00566 {
00567   boolean ret;
00568 
00569   ret = adin_initialize_user(recog, arg);
00570 
00571     /* initialize A/D-in device */
00572     /* create A/D-in thread here */
00573 #ifdef HAVE_PTHREAD
00574   if (ret) {
00575     if (recog->adin->enable_thread) {
00576       if (adin_thread_create(recog) == FALSE) {
00577         return FALSE;
00578       }
00579     }
00580   }
00581 #endif
00582   return(ret);
00583 }
00584 
00601 char *
00602 j_get_current_filename()
00603 {
00604 #ifdef HAVE_LIBSNDFILE
00605   return(adin_sndfile_get_current_filename());
00606 #else
00607   return(adin_file_get_current_filename());
00608 #endif
00609 }
00610 
00611 
00626 void
00627 j_recog_info(Recog *recog)
00628 {
00629   /* print out system information */
00630   print_engine_info(recog);
00631 }
00632 
00661 Recog *
00662 j_create_instance_from_jconf(Jconf *jconf)
00663 {
00664   Recog *recog;
00665 
00666   /* check option values and set parameters needed for model loading */
00667   if (j_jconf_finalize(jconf) == FALSE) {
00668     return NULL;
00669   }
00670 
00671   /* create a recognition instance */
00672   recog = j_recog_new();
00673 
00674   /* assign configuration to the instance */
00675   recog->jconf = jconf;
00676 
00677   /* load all files according to the configurations */
00678   if (j_load_all(recog, jconf) == FALSE) {
00679     jlog("ERROR: j_create_instance_from_jconf: error in loading model\n");
00680     /* j_model_free(model); */
00681     return NULL;
00682   }
00683 
00684   /* checkout for recognition: build lexicon tree, allocate cache */
00685   if (j_final_fusion(recog) == FALSE) {
00686     jlog("ERROR: j_create_instance_from_jconf: error while setup for recognition\n");
00687     j_recog_free(recog);
00688     return NULL;
00689   }
00690 
00691   return recog;
00692 }
00693 
00719 boolean
00720 j_regist_user_lm_func(PROCESS_LM *lm, 
00721           LOGPROB (*unifunc)(WORD_INFO *winfo, WORD_ID w, LOGPROB ngram_prob), 
00722           LOGPROB (*bifunc)(WORD_INFO *winfo, WORD_ID context, WORD_ID w, LOGPROB ngram_prob),
00723           LOGPROB (*probfunc)(WORD_INFO *winfo, WORD_ID *contexts, int context_len, WORD_ID w, LOGPROB ngram_prob))
00724 {
00725   lm->lmfunc.uniprob = unifunc;
00726   lm->lmfunc.biprob = bifunc;
00727   lm->lmfunc.lmprob = probfunc;
00728   return TRUE;
00729 }
00730 
00748 boolean
00749 j_regist_user_param_func(Recog *recog, boolean (*user_calc_vector)(MFCCCalc *, SP16 *, int))
00750 {
00751   recog->calc_vector = user_calc_vector;
00752   return TRUE;
00753 }
00754 
00755 
00773 JCONF_AM *
00774 j_get_amconf_by_name(Jconf *jconf, char *name)
00775 {
00776   JCONF_AM *amconf;
00777 
00778   for(amconf=jconf->am_root;amconf;amconf=amconf->next) {
00779     if (strmatch(amconf->name, name)) {
00780       break;
00781     }
00782   }
00783   if (!amconf) {                /* error */
00784     jlog("ERROR: j_get_amconf_by_name: [AM \"%s\"] not found\n", name);
00785     return NULL;
00786   }
00787   return amconf;
00788 }
00789 
00807 JCONF_AM *
00808 j_get_amconf_by_id(Jconf *jconf, int id)
00809 {
00810   JCONF_AM *amconf;
00811 
00812   for(amconf=jconf->am_root;amconf;amconf=amconf->next) {
00813     if (amconf->id == id) {
00814       break;
00815     }
00816   }
00817   if (!amconf) {                /* error */
00818     jlog("ERROR: j_get_amconf_by_id: [AM%02d] not found\n", id);
00819     return NULL;
00820   }
00821   return amconf;
00822 }
00823 
00844 JCONF_AM *
00845 j_get_amconf_default(Jconf *jconf)
00846 {
00847   JCONF_AM *amconf;
00848 
00849   if (jconf->am_root == NULL) return NULL;
00850   for(amconf=jconf->am_root;amconf->next;amconf=amconf->next);
00851   return(amconf);
00852 }
00853 
00871 JCONF_LM *
00872 j_get_lmconf_by_name(Jconf *jconf, char *name)
00873 {
00874   JCONF_LM *lmconf;
00875 
00876   for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) {
00877     if (strmatch(lmconf->name, name)) {
00878       break;
00879     }
00880   }
00881   if (!lmconf) {                /* error */
00882     jlog("ERROR: j_get_lmconf_by_name: [LM \"%s\"] not found\n", name);
00883     return NULL;
00884   }
00885   return lmconf;
00886 }
00887 
00905 JCONF_LM *
00906 j_get_lmconf_by_id(Jconf *jconf, int id)
00907 {
00908   JCONF_LM *lmconf;
00909 
00910   for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) {
00911     if (lmconf->id == id) {
00912       break;
00913     }
00914   }
00915   if (!lmconf) {                /* error */
00916     jlog("ERROR: j_get_lmconf_by_id: [LM%02d] not found\n", id);
00917     return NULL;
00918   }
00919   return lmconf;
00920 }
00921 
00939 JCONF_SEARCH *
00940 j_get_searchconf_by_name(Jconf *jconf, char *name)
00941 {
00942   JCONF_SEARCH *sconf;
00943 
00944   for(sconf=jconf->search_root;sconf;sconf=sconf->next) {
00945     if (strmatch(sconf->name, name)) {
00946       break;
00947     }
00948   }
00949   if (!sconf) {         /* error */
00950     jlog("ERROR: j_get_searchconf_by_name: [SR \"%s\"] not found\n", name);
00951     return NULL;
00952   }
00953   return sconf;
00954 }
00955 
00973 JCONF_SEARCH *
00974 j_get_searchconf_by_id(Jconf *jconf, int id)
00975 {
00976   JCONF_SEARCH *sconf;
00977 
00978   for(sconf=jconf->search_root;sconf;sconf=sconf->next) {
00979     if (sconf->id == id) {
00980       break;
00981     }
00982   }
00983   if (!sconf) {         /* error */
00984     jlog("ERROR: j_get_searchconf_by_id: [SR%02d] not found\n", id);
00985     return NULL;
00986   }
00987   return sconf;
00988 }
00989 
01010 boolean
01011 j_process_deactivate(Recog *recog, char *name)
01012 {
01013   RecogProcess *r;
01014 
01015   for(r=recog->process_list;r;r=r->next) {
01016     if (strmatch(r->config->name, name)) {
01017       /* book to be inactive at next interval */
01018       r->active = -1;
01019       break;
01020     }
01021   }
01022   if (!r) {                     /* not found */
01023     jlog("ERROR: j_process_deactivate: no SR instance named \"%s\", cannot deactivate\n", name);
01024     return FALSE;
01025   }
01026 
01027   /* tell engine to update */
01028   recog->process_want_reload = TRUE;
01029 
01030   return TRUE;
01031 }
01032 
01054 boolean
01055 j_process_deactivate_by_id(Recog *recog, int id)
01056 {
01057   RecogProcess *r;
01058 
01059   for(r=recog->process_list;r;r=r->next) {
01060     if (r->config->id == id) {
01061       /* book to be inactive at next interval */
01062       r->active = -1;
01063       break;
01064     }
01065   }
01066   if (!r) {                     /* not found */
01067     jlog("ERROR: j_process_deactivate_by_id: no SR instance whose id is \"%02d\", cannot deactivate\n", id);
01068     return FALSE;
01069   }
01070 
01071   /* tell engine to update */
01072   recog->process_want_reload = TRUE;
01073 
01074   return TRUE;
01075 }
01076 
01098 boolean
01099 j_process_activate(Recog *recog, char *name)
01100 {
01101   RecogProcess *r;
01102 
01103   for(r=recog->process_list;r;r=r->next) {
01104     if (strmatch(r->config->name, name)) {
01105       /* book to be active at next interval */
01106       r->active = 1;
01107       break;
01108     }
01109   }
01110   if (!r) {                     /* not found */
01111     jlog("ERROR: j_process_activate: no SR instance named \"%s\", cannot activate\n", name);
01112     return FALSE;
01113   }
01114 
01115   /* tell engine to update */
01116   recog->process_want_reload = TRUE;
01117 
01118   return TRUE;
01119 }
01120 
01142 boolean
01143 j_process_activate_by_id(Recog *recog, int id)
01144 {
01145   RecogProcess *r;
01146 
01147   for(r=recog->process_list;r;r=r->next) {
01148     if (r->config->id == id) {
01149       /* book to be active at next interval */
01150       r->active = 1;
01151       break;
01152     }
01153   }
01154   if (!r) {                     /* not found */
01155     jlog("ERROR: j_process_activate_by_id: no SR instance whose id is \"%02d\", cannot activate\n", id);
01156     return FALSE;
01157   }
01158 
01159   /* tell engine to update */
01160   recog->process_want_reload = TRUE;
01161 
01162   return TRUE;
01163 }
01164 
01195 boolean
01196 j_process_add_lm(Recog *recog, JCONF_LM *lmconf, JCONF_SEARCH *sconf, char *name)
01197 {
01198   /* add lmconf to global config */
01199   if (j_jconf_lm_regist(recog->jconf, lmconf, name) == FALSE) {
01200     jlog("ERROR: j_process_add_lm: failed to regist new LM conf as \"%s\"\n", name);
01201     return FALSE;
01202   }
01203   /* assign lmconf and default amconf to the sconf */
01204   sconf->amconf = j_get_amconf_default(recog->jconf);
01205   sconf->lmconf = lmconf;
01206   /* add the sconf to global config */
01207   if (j_jconf_search_regist(recog->jconf, sconf, name) == FALSE) {
01208     jlog("ERROR: j_process_add_lm: failed to regist new SR conf as \"%s\"\n", name);
01209     j_jconf_search_free(sconf);
01210     return FALSE;
01211   }
01212   /* finalize the whole parameters */
01213   if (j_jconf_finalize(recog->jconf) == FALSE) {
01214     jlog("ERROR: j_process_add_lm: failed to finalize the updated whole jconf\n");
01215     return FALSE;
01216   }
01217   /* create LM process intance for the lmconf, and load LM */
01218   if (j_load_lm(recog, lmconf) == FALSE) {
01219     jlog("ERROR: j_process_add_lm: failed to load LM \"%s\"\n", lmconf->name);
01220     return FALSE;
01221   }
01222   /* create recognition process instance for the sconf, and setup for recognition */
01223   if (j_launch_recognition_instance(recog, sconf) == FALSE) {
01224     jlog("ERROR: j_process_add_lm: failed to start a new recognizer instance \"%s\"\n", sconf->name);
01225     return FALSE;
01226   }
01227   /* the created process will be live=FALSE, active = 1, so
01228      the new recognition instance is dead now but
01229      will be made live at next session */
01230 
01231   /* tell engine to update */
01232   recog->process_want_reload = TRUE;
01233 
01234   return TRUE;
01235 }
01236 
01258 boolean
01259 j_process_remove(Recog *recog, JCONF_SEARCH *sconf)
01260 {
01261   RecogProcess *r, *r_prev;
01262   JCONF_SEARCH *sc, *sc_prev;
01263 
01264   if (sconf == NULL) {
01265     jlog("ERROR: j_process_remove: sconf == NULL\n");
01266     return FALSE;
01267   }
01268 
01269   /* find corresponding process in engine and remove it from list */
01270   r_prev = NULL;
01271   for(r=recog->process_list;r;r=r->next) {
01272     if (r->config == sconf) {
01273       if (r_prev == NULL) {
01274         recog->process_list = r->next;
01275       } else {
01276         r_prev->next = r->next;
01277       }
01278       break;
01279     }
01280     r_prev = r;
01281   }
01282   if (!r) {
01283     jlog("ERROR: j_process_remove: specified sconf %02d %s not found in recogprocess, removal failed\n", sconf->id, sconf->name);
01284     return FALSE;
01285   }
01286 
01287   /* remove config from list in engine */
01288   sc_prev = NULL;
01289   for(sc=recog->jconf->search_root;sc;sc=sc->next) {
01290     if (sc == sconf) {
01291       if (sc_prev == NULL) {
01292         recog->jconf->search_root = sc->next;
01293       } else {
01294         sc_prev->next = sc->next;
01295       }
01296       break;
01297     }
01298     sc_prev = sc;
01299   }
01300   if (!sc) {
01301     jlog("ERROR: j_process_remove: sconf %02d %s not found\n", sconf->id, sconf->name);
01302   }
01303 
01304   /* free them */
01305   j_recogprocess_free(r);
01306   if (verbose_flag) jlog("STAT: recogprocess %02d %s removed\n", sconf->id, sconf->name);
01307   j_jconf_search_free(sconf);
01308 
01309   /* tell engine to update */
01310   recog->process_want_reload = TRUE;
01311 
01312   return TRUE;
01313 }
01314 
01336 boolean
01337 j_process_lm_remove(Recog *recog, JCONF_LM *lmconf)
01338 {
01339   RecogProcess *r;
01340   PROCESS_LM *lm, *lm_prev;
01341   JCONF_LM *l, *l_prev;
01342 
01343   if (lmconf == NULL) {
01344     jlog("ERROR: j_process_lm_remove: lmconf == NULL\n");
01345     return FALSE;
01346   }
01347 
01348   /* check if still used by a process */
01349   for(r=recog->process_list;r;r=r->next) {
01350     if (r->config->lmconf == lmconf) {
01351       jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s still used in a recogprocess %02d %s\n", lmconf->id, lmconf->name, r->config->id, r->config->name);
01352       return FALSE;
01353     }
01354   }
01355 
01356   /* find corresponding LM process in engine and remove it from list */
01357   lm_prev = NULL;
01358   for(lm=recog->lmlist;lm;lm=lm->next) {
01359     if (lm->config == lmconf) {
01360       if (lm_prev == NULL) {
01361         recog->lmlist = lm->next;
01362       } else {
01363         lm_prev->next = lm->next;
01364       }
01365       break;
01366     }
01367     lm_prev = lm;
01368   }
01369   if (!lm) {
01370     jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s not found in LM process, removal failed\n", lmconf->id, lmconf->name);
01371     return FALSE;
01372   }
01373 
01374   /* remove config from list in engine */
01375   l_prev = NULL;
01376   for(l=recog->jconf->lm_root;l;l=l->next) {
01377     if (l == lmconf) {
01378       if (l_prev == NULL) {
01379         recog->jconf->lm_root = l->next;
01380       } else {
01381         l_prev->next = l->next;
01382       }
01383       break;
01384     }
01385     l_prev = l;
01386   }
01387   if (!l) {
01388     jlog("ERROR: j_process_lm_remove: lmconf %02d %s not found\n", lmconf->id, lmconf->name);
01389     return FALSE;
01390   }
01391 
01392   /* free them */
01393   j_process_lm_free(lm);
01394   if (verbose_flag) jlog("STAT: LM process %02d %s removed\n", lmconf->id, lmconf->name);
01395   j_jconf_lm_free(lmconf);
01396 
01397   /* tell engine to update */
01398   recog->process_want_reload = TRUE;
01399 
01400   return TRUE;
01401 }
01402 
01424 boolean
01425 j_process_am_remove(Recog *recog, JCONF_AM *amconf)
01426 {
01427   RecogProcess *r;
01428   PROCESS_LM *lm;
01429   PROCESS_AM *am, *am_prev;
01430   JCONF_AM *a, *a_prev;
01431 
01432   if (amconf == NULL) {
01433     jlog("ERROR: j_process_am_remove: amconf == NULL\n");
01434     return FALSE;
01435   }
01436 
01437   /* check if still used by a process */
01438   for(r=recog->process_list;r;r=r->next) {
01439     if (r->config->amconf == amconf) {
01440       jlog("ERROR: j_process_am_remove: specified amconf %02d %s still used in a recogprocess %02d %s\n", amconf->id, amconf->name, r->config->id, r->config->name);
01441       return FALSE;
01442     }
01443   }
01444 
01445   /* check if still used by a LM process */
01446   for(lm=recog->lmlist;lm;lm=lm->next) {
01447     if (lm->am->config == amconf) {
01448       jlog("ERROR: j_process_am_remove: specified amconf %02d %s still used in a LM %02d %s\n", amconf->id, amconf->name, lm->config->id, lm->config->name);
01449       return FALSE;
01450     }
01451   }
01452 
01453   /* find corresponding AM process in engine and remove it from list */
01454   am_prev = NULL;
01455   for(am=recog->amlist;am;am=am->next) {
01456     if (am->config == amconf) {
01457       if (am_prev == NULL) {
01458         recog->amlist = am->next;
01459       } else {
01460         am_prev->next = am->next;
01461       }
01462       break;
01463     }
01464     am_prev = am;
01465   }
01466   if (!am) {
01467     jlog("ERROR: j_process_am_remove: specified amconf %02d %s not found in AM process, removal failed\n", amconf->id, amconf->name);
01468     return FALSE;
01469   }
01470 
01471   /* remove config from list in engine */
01472   a_prev = NULL;
01473   for(a=recog->jconf->am_root;a;a=a->next) {
01474     if (a == amconf) {
01475       if (a_prev == NULL) {
01476         recog->jconf->am_root = a->next;
01477       } else {
01478         a_prev->next = a->next;
01479       }
01480       break;
01481     }
01482     a_prev = a;
01483   }
01484   if (!a) {
01485     jlog("ERROR: j_process_am_remove: amconf %02d %s not found\n", amconf->id, amconf->name);
01486     return FALSE;
01487   }
01488 
01489   /* free them */
01490   j_process_am_free(am);
01491   if (verbose_flag) jlog("STAT: AM process %02d %s removed\n", amconf->id, amconf->name);
01492   j_jconf_am_free(amconf);
01493 
01494   /* tell engine to update */
01495   recog->process_want_reload = TRUE;
01496 
01497   return TRUE;
01498 }
01499 
01500 /* end of file */

Generated on Tue Dec 18 15:59:52 2007 for Julius by  doxygen 1.5.4