⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realtime-1stpass.c

📁 julius version 4.12.about sound recognition.
💻 C
📖 第 1 页 / 共 4 页
字号:
    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {            para = mfcc->para;            if (! mfcc->valid) continue;            /* check if there is data in cycle buffer of delta */      ret1 = WMP_deltabuf_flush(mfcc->db);#ifdef RDEBUG      printf("DeltaBufLast: ret=%d, status=", ret1);      for(i=0;i<mfcc->db->len;i++) {	printf("%d", mfcc->db->is_on[i]);      }      printf(", nextstore=%d\n", mfcc->db->store);#endif      if (ret1) {	/* uncomputed delta has flushed, compute it with tmpmfcc */	if (para->energy && para->absesup) {	  memcpy(mfcc->tmpmfcc, mfcc->db->vec, sizeof(VECT) * (para->baselen - 1));	  memcpy(&(mfcc->tmpmfcc[para->baselen-1]), &(mfcc->db->vec[para->baselen]), sizeof(VECT) * para->baselen);	} else {	  memcpy(mfcc->tmpmfcc, mfcc->db->vec, sizeof(VECT) * para->baselen * 2);	}	if (para->acc) {	  /* this new delta should be given to the accel cycle buffer */	  ret2 = WMP_deltabuf_proceed(mfcc->ab, mfcc->tmpmfcc);#ifdef RDEBUG	  printf("AccelBuf: ret=%d, status=", ret2);	  for(i=0;i<mfcc->ab->len;i++) {	    printf("%d", mfcc->ab->is_on[i]);	  }	  printf(", nextstore=%d\n", mfcc->ab->store);#endif	  if (ret2) {	    /* uncomputed accel was given, compute it with tmpmfcc */	    memcpy(mfcc->tmpmfcc, mfcc->ab->vec, sizeof(VECT) * (para->veclen - para->baselen));	    memcpy(&(mfcc->tmpmfcc[para->veclen - para->baselen]), &(mfcc->ab->vec[para->veclen - para->baselen]), sizeof(VECT) * para->baselen);	  } else {	    /* still no input is given: */	    /* in case of very short input: go on to the next input */	    continue;	  }	}	      } else {      	/* no data left in the delta buffer */	if (para->acc) {	  /* no new data, just flush the accel buffer */	  ret2 = WMP_deltabuf_flush(mfcc->ab);#ifdef RDEBUG	  printf("AccelBuf: ret=%d, status=", ret2);	  for(i=0;i<mfcc->ab->len;i++) {	    printf("%d", mfcc->ab->is_on[i]);	  }	  printf(", nextstore=%d\n", mfcc->ab->store);#endif	  if (ret2) {	    /* uncomputed data has flushed, compute it with tmpmfcc */	    memcpy(mfcc->tmpmfcc, mfcc->ab->vec, sizeof(VECT) * (para->veclen - para->baselen));	    memcpy(&(mfcc->tmpmfcc[para->veclen - para->baselen]), &(mfcc->ab->vec[para->veclen - para->baselen]), sizeof(VECT) * para->baselen);	  } else {	    /* actually no data exists in both delta and accel */	    mfcc->valid = FALSE; /* disactivate this instance */	    continue;		/* end this loop */	  }	} else {	  /* only delta: input fully flushed */	  mfcc->valid = FALSE; /* disactivate this instance */	  continue;		/* end this loop */	}      }      /* a new frame has been obtained from delta buffer to tmpmfcc */      if(para->cmn || para->cvn) CMN_realtime(mfcc->cmn.wrk, mfcc->tmpmfcc);      if (param_alloc(mfcc->param, mfcc->f + 1, mfcc->param->veclen) == FALSE) {	jlog("ERROR: failed to allocate memory for incoming MFCC vectors\n");	return FALSE;      }      /* store to mfcc->f */      memcpy(mfcc->param->parvec[mfcc->f], mfcc->tmpmfcc, sizeof(VECT) * mfcc->param->veclen);#ifdef ENABLE_PLUGIN      /* call postprocess plugin if any */      plugin_exec_vector_postprocess(mfcc->param->parvec[mfcc->f], mfcc->param->veclen, mfcc->f);#endif    }    /* call recognition start callback */    ok_p = FALSE;    maxf = 0;    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (!mfcc->valid) continue;      if (maxf < mfcc->f) maxf = mfcc->f;      if (mfcc->f == 0) {	ok_p = TRUE;      }    }    if (ok_p && maxf == 0) {      /* call callback when at least one of MFCC has initial frame */      if (recog->jconf->decodeopt.segment) {#ifdef BACKEND_VAD	  /* not exec pass1 begin callback here */#else	if (!recog->process_segment) {	  callback_exec(CALLBACK_EVENT_RECOGNITION_BEGIN, recog);	}	callback_exec(CALLBACK_EVENT_SEGMENT_BEGIN, recog);	callback_exec(CALLBACK_EVENT_PASS1_BEGIN, recog);	recog->triggered = TRUE;#endif      } else {	callback_exec(CALLBACK_EVENT_RECOGNITION_BEGIN, recog);	callback_exec(CALLBACK_EVENT_PASS1_BEGIN, recog);	recog->triggered = TRUE;      }    }    /* proceed for the curent frame */    ret = decode_proceed(recog);    if (ret == -1) {		/* error */      return -1;    } else if (ret == 1) {	/* segmented */      /* loop out */      break;    } /* else no event occured */#ifdef BACKEND_VAD    /* check up trigger in case of VAD segmentation */    if (recog->jconf->decodeopt.segment) {      if (recog->triggered == FALSE) {	if (spsegment_trigger_sync(recog)) {	  if (!recog->process_segment) {	    callback_exec(CALLBACK_EVENT_RECOGNITION_BEGIN, recog);	  }	  callback_exec(CALLBACK_EVENT_SEGMENT_BEGIN, recog);	  callback_exec(CALLBACK_EVENT_PASS1_BEGIN, recog);	  recog->triggered = TRUE;	}      }    }#endif    /* call frame-wise callback */    callback_exec(CALLBACK_EVENT_PASS1_FRAME, recog);    /* move to next */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (! mfcc->valid) continue;      mfcc->f++;      if (mfcc->f > r->maxframelen) mfcc->valid = FALSE;    }  }  /* finalize real-time 1st pass */  for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {    mfcc->param->header.samplenum = mfcc->f;    mfcc->param->samplenum = mfcc->f;  }  /* 呵姜フレ〖ム借妄を乖い·千急の冯蔡叫蜗と姜位借妄を乖う */  decode_end(recog);  return(TRUE);}/**  * <JA> * ケプストラム士堆の构糠.  * 肌搀の千急に洒えて·掐蜗デ〖タからCMN脱のケプストラム士堆を构糠する.  *  * @param mfcc [i/o] 纷换滦据の MFCC纷换インスタンス * @param recog [i/o] エンジンインスタンス * * </JA> * <EN> * Update cepstral mean. * * This function updates the initial cepstral mean for CMN of the next input. * * @param mfcc [i/o] MFCC Calculation instance to update its CMN * @param recog [i/o] engine instance * </EN> */voidRealTimeCMNUpdate(MFCCCalc *mfcc, Recog *recog){  boolean cmn_update_p;  Value *para;  Jconf *jconf;  RecogProcess *r;  jconf = recog->jconf;  para = mfcc->para;    /* update CMN vector for next speech */  if(para->cmn) {    if (mfcc->cmn.update) {      cmn_update_p = TRUE;      for(r=recog->process_list;r;r=r->next) {	if (!r->live) continue;	if (r->am->mfcc != mfcc) continue;	if (r->result.status < 0) { /* input rejected */	  cmn_update_p = FALSE;	  break;	}      }      if (cmn_update_p) {	/* update last CMN parameter for next spech */	CMN_realtime_update(mfcc->cmn.wrk, mfcc->param);      } else {	/* do not update, because the last input is bogus */	if (verbose_flag) {#ifdef BACKEND_VAD	  if (!recog->jconf->decodeopt.segment || recog->triggered) {	    jlog("STAT: skip CMN parameter update since last input was invalid\n");	  }#else	  jlog("STAT: skip CMN parameter update since last input was invalid\n");#endif	}      }    }    /* if needed, save the updated CMN parameter to a file */    if (mfcc->cmn.save_filename) {      if (CMN_save_to_file(mfcc->cmn.wrk, mfcc->cmn.save_filename) == FALSE) {	jlog("WARNING: failed to save CMN parameter to \"%s\"\n", mfcc->cmn.save_filename);      }    }  }}/**  * <JA> * 妈1パス士乖千急借妄を面们する.  * * @param recog [i/o] エンジンインスタンス * </JA> * <EN> * Terminate the 1st pass on-the-fly decoding. * * @param recog [i/o] engine instance * </EN> */voidRealTimeTerminate(Recog *recog){  MFCCCalc *mfcc;  for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {    mfcc->param->header.samplenum = mfcc->f;    mfcc->param->samplenum = mfcc->f;  }  /* 呵姜フレ〖ム借妄を乖い·千急の冯蔡叫蜗と姜位借妄を乖う */  decode_end(recog);}/**  * <EN> * Free the whole work area for 1st pass on-the-fly decoding * </EN> * <JA> * 妈1パス事乖借妄のためのワ〖クエリアを倡庶する * </JA> *  * @param recog [in] engine instance *  */voidrealbeam_free(Recog *recog){  RealBeam *r;  r = &(recog->real);  if (recog->real.window) {    free(recog->real.window);    recog->real.window = NULL;  }  if (recog->real.rest_Speech) {    free(recog->real.rest_Speech);    recog->real.rest_Speech = NULL;  }}/************************************************************************//************************************************************************//************************************************************************//************************************************************************//* MFCC realtime input *//**  * <EN> *  * </EN> * <JA> *  * </JA> *  * @param recog  * @param ad_check  *  * @return 2 when input termination requested by recognition process, * 1 when segmentation request returned from input module, 0 when end * of input returned from input module, -1 on error, -2 when input * termination requested by ad_check(). *  */intmfcc_go(Recog *recog, int (*ad_check)(Recog *)){  RealBeam *r;  MFCCCalc *mfcc;  int new_f;  int ret, ret3;  r = &(recog->real);  r->last_is_segmented = FALSE;    while(1/*in_data_vec*/) {    ret = mfc_module_read(recog->mfcclist, &new_f);    if (debug2_flag) {      if (recog->mfcclist->f < new_f) {	jlog("%d: %d (%d)\n", recog->mfcclist->f, new_f, ret);      }    }     /* callback poll */    if (ad_check != NULL) {      if ((ret3 = (*(ad_check))(recog)) < 0) {	if ((ret3 == -1 && mfcc->f == 0) || ret3 == -2) {	  return(-2);	}      }    }    while(recog->mfcclist->f < new_f) {      recog->mfcclist->valid = TRUE;#ifdef ENABLE_PLUGIN      /* call post-process plugin if exist */      plugin_exec_vector_postprocess(recog->mfcclist->param->parvec[recog->mfcclist->f], recog->mfcclist->param->veclen, mfcc->f);#endif      /* 借妄を1フレ〖ム渴める */      /* proceed one frame */            switch(proceed_one_frame(recog)) {      case -1:			/* error */	return -1;      case 0:			/* normal */	break;      case 1:			/* segmented by process */	return 2;      }      /* 1フレ〖ム借妄が渴んだのでポインタを渴める */      /* proceed frame pointer */      for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {	if (!mfcc->valid) continue;	mfcc->f++;      }    }        /* check if input end */    switch(ret) {    case -1: 			/* end of input */      return 0;    case -2:			/* error */      return -1;    case -3:			/* end of segment request */      return 1;    }  }  /* 涂えられた不兰セグメントに滦する千急借妄が链て姜位     钙び叫し傅に, 掐蜗を鲁けるよう帕える */  /* input segment is fully processed     tell the caller to continue input */  return(1);}/* end of file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -