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

📄 hhed.c

📁 该压缩包为最新版htk的源代码,htk是现在比较流行的语音处理软件,请有兴趣的朋友下载使用
💻 C
📖 第 1 页 / 共 5 页
字号:
      p=ParseAlpha(p,buf);      while(isspace((int) *p)) p++;      if (*p!=',')         HError(2660,"LoadQuestion: missing , in itemlist");       p++;      ip=(IPat*) New(&questHeap,sizeof(IPat));      ip->pat = NewString(&questHeap,strlen(buf));      strcpy(ip->pat,buf);      ip->next = q->patList; q->patList = ip;   } while (p<r);}/* QMatch: return true if given name matches question */Boolean QMatch(char *name, QLink q){   IPat *ip;      for (ip=q->patList;ip!=NULL;ip=ip->next)      if (DoMatch(name,ip->pat)) return TRUE;   return FALSE;}/* ----------------------- HMM Management ---------------------- */typedef enum { baseNorm=0, baseLeft, baseRight, baseMono } baseType;/* FindBaseModel: return the idx in hList of base model corresponding    to id, type determines type of base model wanted and is    baseMono (monophone); baseRight (right biphone); baseLeft (left biphone) */HLink FindBaseModel(HMMSet *hset,LabId id,baseType type){   char baseName[255],buf[255],*p;   LabId baseId;   MLink ml;      strcpy(baseName,id->name);   if (type==baseMono || type==baseRight) { /* strip Left context */      strcpy(buf,baseName);      if ((p = strchr(buf,'-')) != NULL)         strcpy(baseName,p+1);   }   if (type==baseMono || type==baseLeft) { /* strip Right context */      strcpy(buf,baseName);      if ((p = strrchr(buf,'+')) != NULL) {         *p = '\0';         strcpy(baseName,buf);      }   }   if ((baseId = GetLabId(baseName,FALSE))==NULL)      HError(2635,"FindBaseModel: No Base Model %s for %s",baseName,id->name);   ml = FindMacroName(hset,'l',baseId);   if (ml==NULL)      HError(2635,"FindBaseModel: Cannot Find HMM %s in Current List",baseName);   return ((HLink) ml->structure);}/* OutMacro: output the name of macro associated with structure */void OutMacro(char type,Ptr structure){   MLink ml;      if ((ml = FindMacroStruct(hset,type,structure))==NULL)      HError(2635,"OutMacro: Cannot find macro to print");   printf(" ~%c:%s",type,ml->id->name);}/* ShowWhere: print state, stream, mix if necessary */void ShowWhere(int state, int stream, int mix){   static int j = -1;   static int s = -1;   static int m = -1;      if (state != j) {      printf("\n  State %d: ",state);      s = -1; m = -1; j = state;   }   if (stream != s && stream != -1) {      printf("\n    Stream %d: ",stream);      m = -1; s = stream;   }   if (mix != m && mix != -1) {      printf("\n      Mix %d: ",mix);      m = mix;   }}/* ShowMacros: list macros used by given HMM */void ShowMacros(HMMDef *hmm){   StateElem *se;   StateInfo *si;   MixtureElem *me;   StreamElem *ste;   MixPDF *mp;   Ptr strct;   int i,j,s;   char type;      if (GetUse(hmm->transP) > 0) {      printf("\n   TransP: ");      OutMacro('t',hmm->transP);   }   se = hmm->svec+2;   for (i=2;i<hmm->numStates;i++,se++) {      si = se->info;      if (si->nUse > 0) {         ShowWhere(i,-1,-1);         OutMacro('s',si);      }           if (si->dur != NULL && GetUse(si->dur) > 0) {         ShowWhere(i,-1,-1);         OutMacro('d',si->dur);      }      if (si->weights != NULL && GetUse(si->weights) > 0) {         ShowWhere(i,-1,-1);         OutMacro('w',si->weights);      }      ste = si->pdf +1;      if (hset->hsKind==PLAINHS || hset->hsKind==SHAREDHS)         for (s=1; s<=hset->swidth[0]; s++,ste++) {            me = ste->spdf.cpdf + 1;            for (j=1; j<=ste->nMix;j++,me++) {               if (me->weight > MINMIX) {                  mp = me->mpdf;                  if (mp->nUse>0) {                     ShowWhere(i,s,j); OutMacro('m',mp);                  }                  if (GetUse(mp->mean) > 0) {                     ShowWhere(i,s,j); OutMacro('u',mp->mean);                  }                  switch(mp->ckind) {                  case FULLC:                     strct=mp->cov.inv; type='i'; break;                  case LLTC:                     strct=mp->cov.inv; type='c'; break;                  case XFORMC:                     strct=mp->cov.xform; type='x'; break;                  case DIAGC:                  case INVDIAGC:                     strct=mp->cov.var; type='v'; break;                  default:                     strct=NULL; type=0; break;                  }                  if (type && GetUse(strct) > 0) {                     ShowWhere(i,s,j);                     OutMacro(type,strct);                  }               }            }         }   }}/* ShowHMMSet: print a summary of currently loaded HMM Set */void ShowHMMSet(void){   HMMScanState hss;   LabId id;   int h=0;      printf("Summary of Current HMM Set\n");   NewHMMScan(hset,&hss);   do {      id = hss.mac->id;      h++;      printf("\n%d.Name: %s",h,id->name);      ShowMacros(hss.hmm);   }   while(GoNextHMM(&hss));   printf("\n------------\n"); fflush(stdout);}/* ZapAliases: reduce hList to just distinct physical HMM's */void ZapAliases(void){   int h;   MLink q;   HLink hmm;      for (h=0; h<MACHASHSIZE; h++)      for (q=hset->mtab[h]; q!=NULL; q=q->next)         if (q->type=='l')            DeleteMacro(hset,q);   for (h=0; h<MACHASHSIZE; h++)      for (q=hset->mtab[h]; q!=NULL; q=q->next)         if (q->type=='h') {            hmm=(HLink) q->structure;            NewMacro(hset,fidx,'l',q->id,hmm);            hmm->nUse=1;         }}/* EquivMix: return TRUE if both states are identical */Boolean EquivMix(MixPDF *a, MixPDF *b){   if (a->mean != b->mean ||       a->cov.var != b->cov.var ) return FALSE;   return TRUE;}/* EquivStream: return TRUE if both streams are identical */Boolean EquivStream(StreamElem *a, StreamElem *b){   int m,M;   MixtureElem *mea,*meb;   MixPDF *ma,*mb;      mea = a->spdf.cpdf+1; meb = b->spdf.cpdf+1;   M = a->nMix;   for (m=1; m<=M; m++,mea++,meb++) {         /* This really should search b for matching mixture */      if (M>1 && mea->weight != meb->weight)         return FALSE;      ma = mea->mpdf; mb = meb->mpdf;      if (ma != mb && !EquivMix(ma,mb))         return FALSE;   }   return TRUE;}/* EquivState: return TRUE if both states are identical (only CONT) */Boolean EquivState(StateInfo *a, StateInfo *b, int S){   int s;   StreamElem *stea,*steb;         stea = a->pdf+1; steb = b->pdf+1;   for (s=1; s<=S; s++,stea++,steb++) {      if ((stea->nMix!=steb->nMix) || !EquivStream(stea,steb))         return FALSE;   }   return TRUE;}/* EquivHMM: return TRUE if both given hmms are identical */Boolean EquivHMM(HMMDef *a, HMMDef *b){   int i;   StateInfo *ai,*bi;      if (a->numStates!=b->numStates ||       a->transP!=b->transP) return FALSE;   for (i=2;i<a->numStates;i++) {      ai=a->svec[i].info; bi=b->svec[i].info;      if (ai!=bi && (!equivState ||                     hset->hsKind==TIEDHS || hset->hsKind==DISCRETEHS ||                     !EquivState(ai, bi, hset->swidth[0])))         return FALSE;   }   return TRUE;}/* PurgeMacros: purge all unused macros */void PurgeMacros(HMMSet *hset){   int h,n;   MLink q;      /* First mark all macros with usage > 0 */   ResetHooks(hset,NULL);   SetVFloor(hset,NULL,0.0);   for (h=0; h<MACHASHSIZE; h++)      for (q=hset->mtab[h]; q!=NULL; q=q->next) {         if (q->type=='*') continue;         n=GetMacroUse(q);         if (n>0 && !IsSeen(n)) {            Touch(&n);            SetMacroUse(q,n);         }      }   /* Delete unused macros in next pass */   for (h=0; h<MACHASHSIZE; h++)      for (q=hset->mtab[h]; q!=NULL; q=q->next) {         if (q->type=='*') continue;         n=GetMacroUse(q);         if (!IsSeen(n)) {            SetMacroUse(q,0);            DeleteMacro(hset,q);         }      }   /* Finally unmark all macros */   for (h=0; h<MACHASHSIZE; h++)      for (q=hset->mtab[h]; q!=NULL; q=q->next) {         if (q->type=='*') continue;         n=GetMacroUse(q);         if (IsSeen(n)) {            Untouch(&n);            SetMacroUse(q,n);         }      }}/* -------------------- Vector/Matrix Resizing Operations -------------------- *//* SwapMacro: swap macro from old to new, and delete old */void SwapMacro(HMMSet *hset,char type,Ptr o, Ptr n){   MLink ml;      ml = FindMacroStruct(hset,type,o);   if (trace & (T_MAC | T_DET)) {      printf("   Swapping Macro %s to resized vector",ml->id->name);      fflush(stdout);   }   DeleteMacro(hset,ml);   NewMacro(hset, fidx, type, ml->id, n);}void SetVSize(SVector v,int n){   *((int*) v)=n;}void SetMSize(STriMat m,int n){   *((int*) m)=n;}/* ResizeSVector: resize the given vector to n components, if   extension is needed, new elements have pad value */SVector ResizeSVector(HMMSet *hset,SVector v, int n, char type, float pad){   int i,u,z;   SVector w;   u = GetUse(v);   if (u==0 || !IsSeen(u)) {      if (u!=0)         TouchV(v);      z = VectorSize(v);      if (z >= n) {         w = v;         SetVSize(v,n);      }      else {         w = CreateSVector(&hmmHeap,n);         for (i=1;i<=z;i++) w[i] = v[i];         for (i=z+1;i<=n;i++) w[i] = pad;         if (u!=0)            SwapMacro(hset,type,v,w);      }   }   else {      w=(SVector) GetHook(v);      IncUse(w);   }   return(w);}/* ResizeSTriMat: resize the given matrix to be n x n, if   extension is needed, new diag elements have pad value   and the rest are zero */STriMat ResizeSTriMat(HMMSet *hset,STriMat m, int n, char type, float pad){   int i,j,u,z;   STriMat w;   u = GetUse(m);   if (u==0 || !IsSeen(u)) {      if (u!=0)         TouchV(m);      z = NumRows(m);      if (z >= n) {         w = m;         SetMSize(m,n);      }      else {         w = CreateSTriMat(&hmmHeap,n);         CovInvert(m,m);         ZeroTriMat(w);         for (i=1; i<=z; i++)            for (j=1;j<=i; j++)               w[i][j] = m[i][j];         for (i=z+1; i<=n; i++)             w[i][i] = pad;         CovInvert(w,w);         if (u!=0)            SwapMacro(hset,type,m,w);      }   }   else {      w=(STriMat) GetHook(m);      IncUse(w);   }   return(w);}/* ----------------- Stream Splitting Operations ------------------- *//* SliceVector: return vec[i..j] as a vector */Vector SliceVector(Vector vec, int i, int j){   Vector w;   int k,l;      w = CreateSVector(&hmmHeap,j-i+1);   for (l=1,k=i; k<=j; k++,l++)      w[l] = vec[k];   return w;}/* SliceTriMat: return submatrix mat[i..j,i..j] */Matrix SliceTriMat(Matrix mat, int i, int j){   TriMat w;   int k,l,m,n;      w = CreateSTriMat(&hmmHeap,j-i+1);   for (l=1,k=i; k<=j; k++,l++)      for (n=1,m=i; m<=k; m++,n++)         w[l][n] = mat[k][m];   return w;}/* ChopVector: return i,j,k elements of vec as a vector,   element k is optional */Vector ChopVector(Vector vec, int i, int j, int k){   Vector w;   int size;      size =  (k>0) ? 3 : 2;   w = CreateSVector(&hmmHeap,size);   w[1] = vec[i]; w[2] = vec[j];   if (k>0) w[3] = vec[k];   return w;}/* ChopTriMat: return submatrix formed by extracting the intersections   of i, j, and k from trimat mat, k'th is optional */TriMat ChopTriMat(TriMat mat, int i, int j, int k)

⌨️ 快捷键说明

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