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

📄 write_binhmm.c

📁 about sound recognition.i want to downlod
💻 C
📖 第 1 页 / 共 2 页
字号:
/** * @file   write_binhmm.c * @author Akinobu LEE * @date   Wed Feb 16 06:03:36 2005 *  * <JA> * @brief  %HMM 年盗をバイナリ妨及のファイルへ今き叫す * * Julius は迫极のバイナリ妨及の %HMM 年盗ファイルをサポ〖トしていますˉ * HTKのアスキ〖妨及の %HMM 年盗ファイルからバイナリ妨及への恃垂は· * 身掳のツ〖ル mkbinhmm で乖ないますˉこのバイナリ妨及は·HTK の * バイナリ妨及とは润高垂ですので庙罢して布さいˉ * </JA> *  * <EN> * @brief  Write a binary %HMM definition to a file * * Julius supports a binary format of %HMM definition file. * The tool "mkbinhmm" can convert the ascii format HTK %HMM definition * file to this format.  Please note that this binary format is  * not compatible with the HTK binary format. * </EN> *  * $Revision: 1.5 $ *  *//* * Copyright (c) 2003-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology * All rights reserved *//* $Id: write_binhmm.c,v 1.5 2006/12/14 08:18:36 sumomo Exp $ */#include <sent/stddefs.h>#include <sent/htk_param.h>#include <sent/htk_hmm.h>#include <sent/mfcc.h>/**  * Binary write function with byte swap (assume file is BIG ENDIAN) *  * @param fp [in] file pointer * @param buf [in] data to write * @param unitbyte [in] size of a unit in bytes * @param unitnum [in] number of unit to write */static voidwrt(FILE *fp, void *buf, size_t unitbyte, int unitnum){#ifndef WORDS_BIGENDIAN  if (unitbyte != 1) {    swap_bytes((char *)buf, unitbyte, unitnum);  }#endif  if (myfwrite(buf, unitbyte, unitnum, fp) < unitnum) {    perror("write_binhmm: wrt");    j_error("write failed\n");  }#ifndef WORDS_BIGENDIAN  if (unitbyte != 1) {    swap_bytes((char *)buf, unitbyte, unitnum);  }#endif}/**  * Write a string, teminating at NULL. *  * @param fp [in] file pointer * @param str [in] string to write */static voidwrt_str(FILE *fp, char *str){  static char noname = '\0';    if (str) {    wrt(fp, str, sizeof(char), strlen(str)+1);  } else {    wrt(fp, &noname, sizeof(char), 1);  }}static char *binhmm_header_v2 = BINHMM_HEADER_V2; ///< Header string for V2/**  * Write header string as binary HMM file (ver. 2) *  * @param fp [in] file pointer */static voidwt_header(FILE *fp, boolean emp, boolean inv){  char buf[50];  char *p;  wrt_str(fp, binhmm_header_v2);  p = &(buf[0]);  if (emp) {    *p++ = '_';    *p++ = BINHMM_HEADER_V2_EMBEDPARA;  }  if (inv) {    *p++ = '_';    *p++ = BINHMM_HEADER_V2_VARINV;  }  *p = '\0';  wrt_str(fp, buf);}/**  * Write acoustic analysis configration parameters into header of binary HMM. *  * @param fp [in] file pointer * @param para [in] acoustic analysis configration parameters */static voidwt_para(FILE *fp, Value *para){  short version;  version = VALUE_VERSION;  wrt(fp, &version, sizeof(short), 1);  wrt(fp, &(para->smp_period), sizeof(long), 1);        wrt(fp, &(para->smp_freq), sizeof(long), 1);	  wrt(fp, &(para->framesize), sizeof(int), 1);          wrt(fp, &(para->frameshift), sizeof(int), 1);         wrt(fp, &(para->preEmph), sizeof(float), 1);          wrt(fp, &(para->lifter), sizeof(int), 1);             wrt(fp, &(para->fbank_num), sizeof(int), 1);          wrt(fp, &(para->delWin), sizeof(int), 1);             wrt(fp, &(para->accWin), sizeof(int), 1);             wrt(fp, &(para->silFloor), sizeof(float), 1);         wrt(fp, &(para->escale), sizeof(float), 1);           wrt(fp, &(para->hipass), sizeof(int), 1);		  wrt(fp, &(para->lopass), sizeof(int), 1);		  wrt(fp, &(para->enormal), sizeof(int), 1);            wrt(fp, &(para->raw_e), sizeof(int), 1);              wrt(fp, &(para->ss_alpha), sizeof(float), 1);	  wrt(fp, &(para->ss_floor), sizeof(float), 1);	  wrt(fp, &(para->zmeanframe), sizeof(int), 1);	}/**  * Write %HMM option specifications *  * @param fp [in] file pointer * @param opt [out] pointer to the %HMM option structure that holds the values. */static voidwt_opt(FILE *fp, HTK_HMM_Options *opt){  wrt(fp, &(opt->stream_info.num), sizeof(short), 1);  wrt(fp, opt->stream_info.vsize, sizeof(short), 50);  wrt(fp, &(opt->vec_size), sizeof(short), 1);  wrt(fp, &(opt->cov_type), sizeof(short), 1);  wrt(fp, &(opt->dur_type), sizeof(short), 1);  wrt(fp, &(opt->param_type), sizeof(short), 1);}/**  * Write %HMM type of mixture tying. *  * @param fp [in] file pointer * @param hmm [out] pointer to the writing %HMM definition data */static voidwt_type(FILE *fp, HTK_HMM_INFO *hmm){  wrt(fp, &(hmm->is_tied_mixture), sizeof(boolean), 1);  wrt(fp, &(hmm->maxmixturenum), sizeof(int), 1);}/* write transition data */static HTK_HMM_Trans **tr_index; ///< Sorted data pointers for mapping from pointer to idstatic unsigned int tr_num;	///< Length of above/**  * qsort callback function to sort transition pointers by their * address for indexing. *  * @param t1 [in] data 1 * @param t2 [in] data 2 *  * @return value required for qsort. */static intqsort_tr_index(HTK_HMM_Trans **t1, HTK_HMM_Trans **t2){  if (*t1 > *t2) return 1;  else if (*t1 < *t2) return -1;  else return 0;}/**  * @brief  Write all transition matrix data. * * The pointers of all transition matrixes are first gathered, * sorted by the address.  Then the transition matrix data are written * by the sorted order.  The index will be used later to convert any pointer * reference to a transition matrix into scholar id. *  * @param fp [in] file pointer * @param hmm [in] writing %HMM definition data  */static voidwt_trans(FILE *fp, HTK_HMM_INFO *hmm){  HTK_HMM_Trans *t;  unsigned int idx;  int i;  tr_num = 0;  for(t = hmm->trstart; t; t = t->next) tr_num++;  tr_index = (HTK_HMM_Trans **)mymalloc(sizeof(HTK_HMM_Trans *) * tr_num);  idx = 0;  for(t = hmm->trstart; t; t = t->next) tr_index[idx++] = t;  qsort(tr_index, tr_num, sizeof(HTK_HMM_Trans *), (int (*)(const void *, const void *))qsort_tr_index);    wrt(fp, &tr_num, sizeof(unsigned int), 1);  for (idx = 0; idx < tr_num; idx++) {    t = tr_index[idx];    wrt_str(fp, t->name);    wrt(fp, &(t->statenum), sizeof(short), 1);    for(i=0;i<t->statenum;i++) {      wrt(fp, t->a[i], sizeof(PROB), t->statenum);    }  }  j_printf("%d transition maxtix written\n", tr_num);}/**  * Binary search function to convert transition matrix pointer to a scholar ID. *  * @param t [in] pointer to a transition matrix *  * @return the corresponding scholar ID. */static unsigned intsearch_trid(HTK_HMM_Trans *t){  unsigned int left = 0;  unsigned int right = tr_num - 1;  unsigned int mid;  while (left < right) {    mid = (left + right) / 2;    if (tr_index[mid] < t) {      left = mid + 1;    } else {      right = mid;    }  }  return(left);}/* write variance data */static HTK_HMM_Var **vr_index;	///< Sorted data pointers for mapping from pointer to idstatic unsigned int vr_num;	///< Length of above/**  * qsort callback function to sort variance pointers by their * address for indexing. *  * @param v1 [in] data 1 * @param v2 [in] data 2 *  * @return value required for qsort. */static intqsort_vr_index(HTK_HMM_Var **v1, HTK_HMM_Var **v2){  if (*v1 > *v2) return 1;  else if (*v1 < *v2) return -1;  else return 0;}/**  * @brief  Write all variance data. * * The pointers of all variance vectors are first gathered, * sorted by the address.  Then the variance vectors are written * by the sorted order.  The index will be used later to convert any pointer * reference to a variance vector into scholar id. *  * @param fp [in] file pointer * @param hmm [in] writing %HMM definition data  */static voidwt_var(FILE *fp, HTK_HMM_INFO *hmm){  HTK_HMM_Var *v;  unsigned int idx;  vr_num = 0;  for(v = hmm->vrstart; v; v = v->next) vr_num++;  vr_index = (HTK_HMM_Var **)mymalloc(sizeof(HTK_HMM_Var *) * vr_num);  idx = 0;  for(v = hmm->vrstart; v; v = v->next) vr_index[idx++] = v;  qsort(vr_index, vr_num, sizeof(HTK_HMM_Var *), (int (*)(const void *, const void *))qsort_vr_index);    wrt(fp, &vr_num, sizeof(unsigned int), 1);  for (idx = 0; idx < vr_num; idx++) {    v = vr_index[idx];    wrt_str(fp, v->name);    wrt(fp, &(v->len), sizeof(short), 1);    wrt(fp, v->vec, sizeof(VECT), v->len);  }  j_printf("%d variance written\n", vr_num);}/**  * Binary search function to convert variance pointer to a scholar ID. *  * @param v [in] pointer to a variance data *  * @return the corresponding scholar ID. */static unsigned intsearch_vid(HTK_HMM_Var *v){  unsigned int left = 0;  unsigned int right = vr_num - 1;  unsigned int mid;  while (left < right) {    mid = (left + right) / 2;    if (vr_index[mid] < v) {      left = mid + 1;    } else {      right = mid;    }  }  return(left);}/* write density data */static HTK_HMM_Dens **dens_index; ///< Sorted data pointers for mapping from pointer to idstatic unsigned int dens_num;	///< Length of above/**  * qsort callback function to sort density pointers by their * address for indexing. *  * @param d1 [in] data 1 * @param d2 [in] data 2 *  * @return value required for qsort. */static intqsort_dens_index(HTK_HMM_Dens **d1, HTK_HMM_Dens **d2){  if (*d1 > *d2) return 1;  else if (*d1 < *d2) return -1;  else return 0;}/**  * @brief  Write all mixture density data. * * The pointers of all mixture densities are first gathered, * sorted by the address.  Then the densities are written * by the sorted order.  The pointers to the lower structure (variance etc.) * in the data are written in a corresponding scholar id. * The pointer index of this data will be used later to convert any pointer * reference to a density data into scholar id. *  * @param fp [in] file pointer * @param hmm [in] writing %HMM definition data  */static voidwt_dens(FILE *fp, HTK_HMM_INFO *hmm)

⌨️ 快捷键说明

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