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

📄 read_binhmm.c

📁 about sound recognition.i want to downlod
💻 C
📖 第 1 页 / 共 2 页
字号:
  hmm->vr_root = NULL;  for (idx = 0; idx < vr_num; idx++) {    v = (HTK_HMM_Var *)mybmalloc2(sizeof(HTK_HMM_Var), &(hmm->mroot));    v->name = rdn_str(fp, hmm);    rdn(fp, &(v->len), sizeof(short), 1);    v->vec = (VECT *)mybmalloc2(sizeof(VECT) * v->len, &(hmm->mroot));    rdn(fp, v->vec, sizeof(VECT), v->len);    vr_index[idx] = v;    var_add(hmm, v);  }#ifdef DMES  j_printf("%d variance read\n", vr_num);#endif}/* read density data */static HTK_HMM_Dens **dens_index; ///< Map density id to its pointerstatic unsigned int dens_num;	///< Length of above/**  * @brief  Read a sequence of mixture densities for @a dens_num. * * The mixture densities are stored into @a hmm, and their references * to lower structure (variance etc.) are recovered from the id-to-pointer * index.  Their pointers are also stored in @a dens_index for * later data mapping operation from upper structure (state etc.). *  * @param fp [in] file pointer * @param hmm [out] %HMM definition structure to hold the read densities. */static voidrd_dens(FILE *fp, HTK_HMM_INFO *hmm){  HTK_HMM_Dens *d;  unsigned int idx;  unsigned int vid;  rdn(fp, &dens_num, sizeof(unsigned int), 1);  hmm->totalmixnum = dens_num;  dens_index = (HTK_HMM_Dens **)mymalloc(sizeof(HTK_HMM_Dens *) * dens_num);  hmm->dnstart = NULL;  hmm->dn_root = NULL;  for (idx = 0; idx < dens_num; idx++) {    d = (HTK_HMM_Dens *)mybmalloc2(sizeof(HTK_HMM_Dens), &(hmm->mroot));    d->name = rdn_str(fp, hmm);    rdn(fp, &(d->meanlen), sizeof(short), 1);    d->mean = (VECT *)mybmalloc2(sizeof(VECT) * d->meanlen, &(hmm->mroot));    rdn(fp, d->mean, sizeof(VECT), d->meanlen);    rdn(fp, &vid, sizeof(unsigned int), 1);    d->var = vr_index[vid];    rdn(fp, &(d->gconst), sizeof(LOGPROB), 1);    dens_index[idx] = d;    dens_add(hmm, d);  }#ifdef DMES  j_printf("%d gaussian densities read\n", dens_num);#endif}/* read tmix data */static GCODEBOOK **tm_index;	///< Map codebook id to its pointerstatic unsigned int tm_num;	///< Length of above/**  * @brief  Read a sequence of mixture codebook for @a tm_num. * * The mixture codebook data are stored into @a hmm, and their references * to lower structure (mixtures etc.) are recovered from the id-to-pointer * index.  Their pointers are also stored in @a tm_index for * later data mapping operation from upper structure (state etc.). *  * @param fp [in] file pointer * @param hmm [out] %HMM definition structure to hold the read codebooks. */static voidrd_tmix(FILE *fp, HTK_HMM_INFO *hmm){  GCODEBOOK *tm;  unsigned int idx;  unsigned int did;  int i;  rdn(fp, &tm_num, sizeof(unsigned int), 1);  hmm->codebooknum = tm_num;  tm_index = (GCODEBOOK **)mymalloc(sizeof(GCODEBOOK *) * tm_num);  hmm->maxcodebooksize = 0;  hmm->codebook_root = NULL;  for (idx = 0; idx < tm_num; idx++) {    tm = (GCODEBOOK *)mybmalloc2(sizeof(GCODEBOOK), &(hmm->mroot));    tm->name = rdn_str(fp, hmm);    rdn(fp, &(tm->num), sizeof(int), 1);    if (hmm->maxcodebooksize < tm->num) hmm->maxcodebooksize = tm->num;    tm->d = (HTK_HMM_Dens **)mybmalloc2(sizeof(HTK_HMM_Dens *) * tm->num, &(hmm->mroot));    for(i=0;i<tm->num;i++) {      rdn(fp, &did, sizeof(unsigned int), 1);      if (did >= dens_num) {	tm->d[i] = NULL;      } else {	tm->d[i] = dens_index[did];      }    }    tm->id = idx;    tm_index[idx] = tm;    codebook_add(hmm, tm);  }#ifdef DMES  j_printf("%d tied-mixture codebooks read\n", tm_num);#endif  }/* read state data */static HTK_HMM_State **st_index; ///< Map state id to its pointerstatic unsigned int st_num;	///< Length of above/**  * @brief  Read a sequence of state data for @a st_num. * * The state data are stored into @a hmm, and their references * to lower structure (mixture, codebook, etc.) are recovered * from the id-to-pointer index.  Their pointers are also stored * in @a st_index for later data mapping operation from * upper structure (models etc.). *  * @param fp [in] file pointer * @param hmm [out] %HMM definition structure to hold the read states. */static voidrd_state(FILE *fp, HTK_HMM_INFO *hmm){  HTK_HMM_State *s;  unsigned int idx;  unsigned int did;  int i;  rdn(fp, &st_num, sizeof(unsigned int), 1);  hmm->totalstatenum = st_num;  st_index = (HTK_HMM_State **)mymalloc(sizeof(HTK_HMM_State *) * st_num);  hmm->ststart = NULL;  hmm->st_root = NULL;  for (idx = 0; idx < st_num; idx++) {    s = (HTK_HMM_State *)mybmalloc2(sizeof(HTK_HMM_State), &(hmm->mroot));    s->name = rdn_str(fp, hmm);    rdn(fp, &(s->mix_num), sizeof(short), 1);    if (s->mix_num == -1) {      /* tmix */      rdn(fp, &did, sizeof(unsigned int), 1);      s->b = (HTK_HMM_Dens **)tm_index[did];      s->mix_num = (tm_index[did])->num;    } else {      /* mixture */      s->b = (HTK_HMM_Dens **)mybmalloc2(sizeof(HTK_HMM_Dens *) * s->mix_num, &(hmm->mroot));      for (i=0;i<s->mix_num;i++) {	rdn(fp, &did, sizeof(unsigned int), 1);	if (did >= dens_num) {	  s->b[i] = NULL;	} else {	  s->b[i] = dens_index[did];	}      }    }    s->bweight = (PROB *)mybmalloc2(sizeof(PROB) * s->mix_num, &(hmm->mroot));    rdn(fp, s->bweight, sizeof(PROB), s->mix_num);    s->id = idx;    st_index[idx] = s;    state_add(hmm, s);  }#ifdef DMES  j_printf("%d states read\n", st_num);#endif}/**  * @brief  Read a sequence of %HMM models. * * The models are stored into @a hmm.  Their references * to lower structures (state, transition, etc.) are stored in schalar * ID, and are recovered from the previously built id-to-pointer index. * when reading the sub structures. *  * @param fp [in] file pointer * @param hmm [out] %HMM definition structure to hold the read models. */static voidrd_data(FILE *fp, HTK_HMM_INFO *hmm){  HTK_HMM_Data *d;  unsigned int md_num;  unsigned int sid, tid;  unsigned int idx;  int i;  rdn(fp, &(md_num), sizeof(unsigned int), 1);  hmm->totalhmmnum = md_num;  hmm->start = NULL;  hmm->physical_root = NULL;  for (idx = 0; idx < md_num; idx++) {    d = (HTK_HMM_Data *)mybmalloc2(sizeof(HTK_HMM_Data), &(hmm->mroot));    d->name = rdn_str(fp, hmm);    rdn(fp, &(d->state_num), sizeof(short), 1);    d->s = (HTK_HMM_State **)mybmalloc2(sizeof(HTK_HMM_State *) * d->state_num, &(hmm->mroot));    for (i=0;i<d->state_num;i++) {      rdn(fp, &sid, sizeof(unsigned int), 1);      if (sid > hmm->totalstatenum) {	d->s[i] = NULL;      } else {	d->s[i] = st_index[sid];      }    }    rdn(fp, &tid, sizeof(unsigned int), 1);    d->tr = tr_index[tid];    htk_hmmdata_add(hmm, d);  }#ifdef DMES  j_printf("%d HMM model definition read\n", md_num);#endif}/**  * Top function to read a binary %HMM file from @a fp. *  * @param fp [in] file pointer * @param hmm [out] %HMM definition structure to hold the read models. * @param gzfile_p [in] TRUE if the file pointer points to a gzip file * @param para [out] store acoustic parameters if embedded in binhmm (V2) *  * @return TRUE on success, FALSE on failure. */booleanread_binhmm(FILE *fp, HTK_HMM_INFO *hmm, boolean gzfile_p, Value *para){  gzfile = gzfile_p;  /* read header */  if (rd_header(fp, hmm, para) == FALSE) {    return FALSE;  }  j_printerr("(binary)...");    /* read option data */  rd_opt(fp, &(hmm->opt));  /* read type data */  rd_type(fp, hmm);  /* read transition data */  rd_trans(fp, hmm);  /* read variance data */  rd_var(fp, hmm);  /* read density data */  rd_dens(fp, hmm);  /* read tmix data */  if (hmm->is_tied_mixture) {    rd_tmix(fp, hmm);  }  /* read state data */  rd_state(fp, hmm);  /* read model data */  rd_data(fp, hmm);  /* free pointer->index work area */  free(tr_index);  free(vr_index);  free(dens_index);  if (hmm->is_tied_mixture) free(tm_index);  free(st_index);  /* count maximum state num (it is not stored in binhmm... */  {    HTK_HMM_Data *dtmp;    int maxlen = 0;    for (dtmp = hmm->start; dtmp; dtmp = dtmp->next) {      if (maxlen < dtmp->state_num) maxlen = dtmp->state_num;    }    hmm->maxstatenum = maxlen;  }  if (! hmm->variance_inversed) {    /* inverse all variance values for faster computation */    htk_hmm_inverse_variances(hmm);    hmm->variance_inversed = TRUE;  }  j_printerr("finished\n");  return (TRUE);}

⌨️ 快捷键说明

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