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

📄 hmodel.c

📁 该压缩包为最新版htk的源代码,htk是现在比较流行的语音处理软件,请有兴趣的朋友下载使用
💻 C
📖 第 1 页 / 共 5 页
字号:
    HMError(src,"<MMFIDMASK> symbol expected in GetBaseClass");    return(NULL);  }  bclass->nUse++;  return bclass;}/* Find a node in the regression tree given the index and return the node */static RegNode *FindNode(RegNode *n, RegNode *r, int id){  int i;  if (n != NULL) {    if (n->nodeIndex == id)      return n;    for (i=1;i<=n->numChild;i++)       r = FindNode(n->child[i], r, id);  }  return r;}static RegNode *CreateRegNode(MemHeap *m, int nodeId){   RegNode *n;     n  = (RegNode *) New(m, sizeof(RegNode));   n->nodeIndex = nodeId;   n->nodeOcc = 0.0;   n->numChild = 0;   n->child = NULL;   n->baseClasses = NULL;   n->info = NULL;   n->vsize = 0;   return n;}/* GetRegTree: parse src and return the regression tree structure */static RegTree *GetRegTree(HMMSet *hset, Source *src, Token *tok){   RegTree *rtree = NULL;   RegNode *rnode, *root;   int index,nbases,base,nchild,i,sw;   char buf[MAXSTRLEN];   /* allocate space for the regression tree root node */   if (trace&T_PAR) printf("HModel: GetRegTree\n");   if (tok->sym == BASECLASS){     rtree = (RegTree *) New(hset->hmem, sizeof(RegTree));     rtree->fname = CopyString(hset->hmem,src->name);     if(GetToken(src,tok)<SUCCESS){       HMError(src,"GetToken failed");       return(NULL);     }     if (tok->sym==MACRO && tok->macroType=='b') {       if (!ReadString(src,buf))	 HError(7013,"GetRegTree: cannot read base class macro name");      rtree->bclass = LoadBaseClass(hset,buf,NULL);	      if(GetToken(src,tok)<SUCCESS){	HMError(src,"GetToken failed");	return(NULL);      }     } else /* or just load the macro explicitly */       rtree->bclass = GetBaseClass(hset,src,tok);     /* Check the BaseClass stream info to see if root can be adapted */     if (rtree->bclass->swidth == NULL)       rtree->valid = TRUE;     else {       rtree->valid = TRUE;       sw = rtree->bclass->swidth[1];       for (i=2;i<=rtree->bclass->swidth[0];i++)	 if (rtree->bclass->swidth[i] != sw)	   rtree->valid = FALSE;     }     rtree->root = root = CreateRegNode(hset->hmem,1);     while ((tok->sym != EOFSYM) && 	    ((tok->sym==NODE) || (tok->sym==TNODE))) {       switch(tok->sym) {       case NODE:	 if (!ReadInt(src,&index,1,tok->binForm)){	   HMError(src,"Node index for regression tree expected");	   return(NULL);	 }	 if ((rnode = FindNode(root, NULL, index)) == NULL)	   HError(999,"Nodes are expected in numerical order");	 rtree->numNodes ++;	 if (!ReadInt(src,&nchild,1,tok->binForm)){	   HMError(src,"Number of children for regression tree expected");	   return(NULL);	 }	 rnode->numChild = nchild;	 rnode->child = (RegNode **)New(hset->hmem,(nchild+1)*sizeof(RegNode));	 for (i=1;i<=nchild;i++) {	   if (!ReadInt(src,&index,1,tok->binForm)){	     HMError(src,"Node index of child in regression tree expected");	     return(NULL);	   }	   rnode->child[i] = CreateRegNode(hset->hmem,index);	 }	 break;       case TNODE:	 if (!ReadInt(src,&index,1,tok->binForm)){	   HMError(src,"Node index for regression tree expected");	   return(NULL);	 }	 if ((rnode = FindNode(root, NULL, index)) == NULL)	   HError(999,"Nodes are expected in numerical order");	 rtree->numTNodes ++;	 if (!ReadInt(src,&nbases,1,tok->binForm)){	   HMError(src,"Number of baseclasses for regression base class expected");	   return(NULL);	 }	 rnode->baseClasses = CreateIntVec(hset->hmem,nbases);	 for (i=1;i<=nbases;i++) {	   if (!ReadInt(src,&base,1,tok->binForm)){	     HMError(src,"Baseclasse number for regression base class expected");	     return(NULL);	   }	   rnode->baseClasses[i] = base;	 }	 break;       default:	 HRError(7085,"GetRegTree:Unexpected token symbol");	 return(NULL);       }       if(GetToken(src,tok)<SUCCESS){	 HMError(src,"GetToken failed");	 return(NULL);       }     }   } else      HMError(src,"Regression Tree definition expected");        return rtree; }/* GetMean: parse src and return Mean structure */static SVector GetMean(HMMSet *hset, Source *src, Token *tok){   SVector m = NULL;   short size;      if (trace&T_PAR) printf("HModel: GetMean\n");   if (tok->sym==MEAN) {            if (!ReadShort(src,&size,1,tok->binForm)){         HMError(src,"Size of Mean Vector expected");         return(NULL);      }      m = CreateSVector(hset->hmem,size);      if (!ReadVector(src,m,tok->binForm)){         HMError(src,"Mean Vector expected");         return(NULL);      }   }      else if (tok->sym==MACRO && tok->macroType=='u'){      if((m=(SVector)GetStructure(hset,src,'u'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(m);   } else{      HMError(src,"<Mean> symbol expected in GetMean");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return m;}/* GetVariance: parse src and return Variance structure */static SVector GetVariance(HMMSet *hset, Source *src, Token *tok){   SVector v = NULL;   short size;       if (trace&T_PAR) printf("HModel: GetVariance\n");   if (tok->sym==VARIANCE) {      if (!ReadShort(src,&size,1,tok->binForm)){         HMError(src,"Size of Variance Vector expected");         return(NULL);      }      v = CreateSVector(hset->hmem,size);      if (!ReadVector(src,v,tok->binForm)){         HMError(src,"Variance Vector expected");         return(NULL);      }   }      else if (tok->sym==MACRO && tok->macroType=='v'){      if((v=(SVector)GetStructure(hset,src,'v'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(v);   } else{      HMError(src,"<Variance> symbol expected in GetVariance");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return v;}/* GetCovar: parse src and return Covariance structure */static STriMat GetCovar(HMMSet *hset, Source *src, Token *tok){   STriMat m = NULL;   short swidth;      if (trace&T_PAR) printf("HModel: GetCovar\n");   if (tok->sym==INVCOVAR || tok->sym==LLTCOVAR) {      if (!ReadShort(src,&swidth,1,tok->binForm)){         HMError(src,"Size of Inv Covariance expected");         return(NULL);      }      m = CreateSTriMat(hset->hmem,swidth);      if (!ReadTriMat(src,m,tok->binForm)){         HMError(src,"Inverse/LLT Covariance Matrix expected");         return(NULL);      }   } else if (tok->sym==MACRO &&               (tok->macroType=='i' || tok->macroType=='c') ){      if((m=(STriMat)GetStructure(hset,src,tok->macroType))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(m);   } else{      HMError(src,"<InvCovar>/<LLTCovar> symbol expected in GetCovar");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return m;}/* GetTransform: parse src and return Transform structure */static SMatrix GetTransform(HMMSet *hset, Source *src, Token *tok){   SMatrix m = NULL;   MemHeap *hmem;   short xformRows,xformCols;      if (trace&T_PAR) printf("HModel: GetTransform\n");   if (tok->sym==XFORM) {      if (hset==NULL) hmem = &xformStack;      else hmem = hset->hmem;      if (!ReadShort(src,&xformRows,1,tok->binForm)){         HMError(src,"Num Rows in Xform matrix expected");         return(NULL);      }      if (!ReadShort(src,&xformCols,1,tok->binForm)){         HMError(src,"Num Cols in Xform matrix expected");         return(NULL);      }      m = CreateSMatrix(hmem,xformRows,xformCols);      if (!ReadMatrix(src,m,tok->binForm)){         HMError(src,"Transform Matrix expected");         return(NULL);      }   }  else  if ((tok->sym==MACRO && tok->macroType=='x') && (hset != NULL)) {      if((m=(SMatrix)GetStructure(hset,src,'x'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(m);   } else{      HMError(src,"<Xform> symbol expected in GetTransform");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return m;}/* GetDuration: parse src and return Duration structure */static SVector GetDuration(HMMSet *hset, Source *src, Token *tok){   SVector v = NULL;   short size;      if (trace&T_PAR) printf("HModel: GetDuration\n");   if (tok->sym==DURATION) {      if (!ReadShort(src,&size,1,tok->binForm)){         HMError(src,"Size of Duration Vector expected");         return(NULL);      }      v = CreateSVector(hset->hmem,size);      if (!ReadVector(src,v,tok->binForm)){         HMError(src,"Duration Vector expected");         return(NULL);      }   } else  if (tok->sym==MACRO && tok->macroType=='d'){      if((v=(SVector)GetStructure(hset,src,'d'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(v);   } else{      HMError(src,"<Duration> symbol expected in GetDuration");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return v;}/* GetSWeights: parse src and return vector of stream weights */static SVector GetSWeights(HMMSet *hset, Source *src, Token *tok){   SVector v = NULL;   short size;      if (trace&T_PAR) printf("HModel: GetSWeights\n");   if (tok->sym==SWEIGHTS) {      if (!ReadShort(src,&size,1,tok->binForm)){         HMError(src,"Num stream weights expected");         return(NULL);      }      v = CreateSVector(hset->hmem,size);      if (!ReadVector(src,v,tok->binForm)){         HMError(src,"Stream Weights expected");         return(NULL);      }   } else  if (tok->sym==MACRO && tok->macroType=='w'){      if((v=(SVector)GetStructure(hset,src,'w'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      IncUse(v);   } else{      HMError(src,"<SWeights> symbol expected in GetSWeights");      return(NULL);   }   if(GetToken(src,tok)<SUCCESS){      HMError(src,"GetToken failed");      return(NULL);   }   return v;}/* GetMixPDF: parse src and return MixPDF structure */static MixPDF *GetMixPDF(HMMSet *hset, Source *src, Token *tok){   MixPDF *mp;     if (trace&T_PAR) printf("HModel: GetMixPDF\n");   if (tok->sym==MACRO && tok->macroType=='m') {      if ((mp = (MixPDF *)GetStructure(hset,src,'m'))==NULL){         HMError(src,"GetStructure Failed");         return(NULL);      }      ++mp->nUse;      if(GetToken(src,tok)<SUCCESS){         HMError(src,"GetToken failed");         return(NULL);      }   } else {      mp = (MixPDF *)New(hset->hmem,sizeof(MixPDF));      mp->nUse = 0; mp->hook = NULL; mp->gConst = LZERO;      mp->mIdx = 0;      if((mp->mean = GetMean(hset,src,tok))==NULL){               HMError(src,"GetMean Failed");         return(NULL);      }      if (tok->sym==VARIANCE || (tok->sym==MACRO && tok->macroType=='v')) {         if((mp->cov.var = GetVariance(hset,src,tok))==NULL){            HMError(src,"GetVariance Failed");            return(NULL);         }         if (hset->ckind == DIAGC || hset->ckind == NULLC)            mp->ckind = DIAGC;         else{            HRError(7032,"GetMixPDF: trying to change global cov type to DiagC");            return(NULL);         }      } else if (tok->sym==INVCOVAR || (tok->sym==MACRO && tok->macroType=='i')){         if((mp->cov.inv = GetCovar(hset,src,tok))==NULL){            HMError(src,"GetCovar Failed");            return(NULL);         }         if (hset->ckind == FULLC || hset->ckind == NULLC)            mp->ckind = FULLC;         else{            HRError(7032,"GetMixPDF: trying to change global cov type to FullC");            return(NULL);         }      } else if (tok->sym==LLTCOVAR || (tok->sym==MACRO && tok->macroType=='c')){         if((mp->cov.inv = GetCovar(hset,src,tok))==NULL){            HMError(src,"GetCovar Failed");            return(NULL);         }         if (hset->ckind == LLTC || hset->ckind == NULLC)            mp->ckind = LLTC;         else{            HRError(7032,"GetMixPDF: trying to change global cov type to LLTC");            return(NULL);         }      } else if (tok->sym==XFORM || (tok->sym==MACRO && tok->macroType=='x')){         if((mp->cov.xform = GetTransform(hset,src,tok))==NULL){            HMError(src,"GetTransform Failed");            return(NULL);         }         if (hset->ckind == XFORMC || hset->ckind == NULLC)            mp->ckind = XFORMC;         else{            HRError(7032,"GetMixPDF: trying to change global cov type to XFormC");            return(NULL);         }

⌨️ 快捷键说明

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