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

📄 hparm.c

📁 该压缩包为最新版htk的源代码,htk是现在比较流行的语音处理软件,请有兴趣的朋友下载使用
💻 C
📖 第 1 页 / 共 5 页
字号:
   switch (cf->style){   case LPCbased:      order = cf->lpcOrder;      if (order<2 || order>1000)         HError(6371,"ValidCodeParms: unlikely lpc order %d",cf->lpcOrder);      if (cf->tgtPK&HASZEROC)         HError(6321,"ValidCodeParms: cannot have C0 with lpc");      break;   case FFTbased:      order = cf->numChans;      if (order<2 || order>1000)         HError(6371,"ValidCodeParms: unlikely num channels %d",cf->numChans);      if (cf->loFBankFreq > cf->hiFBankFreq ||           cf->hiFBankFreq > 0.5E7/cf->srcSampRate)         HError(6371,"ValidCodeParms: bad band-pass filter freqs %.1f .. %.1f",                cf->loFBankFreq,cf->hiFBankFreq);      if (btgt == PLP) {         order = cf->lpcOrder;         if (order < 2 || order > 1000)            HError(6371,"ValidCodeParms: unlikely lpc order %d",cf->lpcOrder);         if (!cf->usePower)            HError(-6371,"ValidCodeParms: Using linear spectrum with PLP");         if (cf->compressFact >= 1.0 || cf->compressFact <= 0.0)            HError(6371,"ValidCodeParms: Compression factor (%f) should have a value between 0 and 1\n",cf->compressFact);      }      break;   default: break;   }   if (btgt == LPCEPSTRA || btgt == MFCC || btgt == PLP){      if (cf->numCepCoef < 2 || cf->numCepCoef > order)         HError(6371,"ValidCodeParms: unlikely num cep coef %d",cf->numCepCoef);      if (cf->cepLifter < 0 || cf->cepLifter > 1000)         HError(6371,"ValidCodeParms: unlikely cep lifter %d",cf->cepLifter);   }   if (cf->warpFreq < 0.5 || cf->warpFreq > 2.0)      HError (6371, "ValidCodeParms: unlikely warping factor %s\n", cf->warpFreq);   if (cf->warpFreq != 1.0) {      if (cf->warpLowerCutOff == 0.0 || cf->warpUpperCutOff == 0.0 ||          cf->warpLowerCutOff > cf->warpUpperCutOff)         HError (6371, "ValidCodeParms: invalid warping cut-off frequencies %f %f \n",                 cf->warpLowerCutOff , cf->warpUpperCutOff);      if (cf->warpUpperCutOff == 0.0 && cf->warpLowerCutOff != 0.0) {         cf->warpUpperCutOff = cf->warpLowerCutOff;         HError (-6371, "ValidCodeParms: setting warp cut-off frequencies to %f %f\n",                 cf->warpLowerCutOff, cf->warpUpperCutOff);      }      if (cf->warpLowerCutOff == 0.0 && cf->warpUpperCutOff != 0.0) {         cf->warpUpperCutOff = cf->warpLowerCutOff ;         HError (-6371, "ValidCodeParms: setting warp cut-off frequencies to %f %f\n",                 cf->warpLowerCutOff, cf->warpUpperCutOff);      }   }}/* EXPORT->ValidConversion: checks that src -> tgt conversion is possible */Boolean ValidConversion (ParmKind src, ParmKind tgt){   static short xmap[13][13] = {      { 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0},    /* src = WAVEFORM */      { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = LPC */      { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = LPREFC */      { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = LPCEPSTRA */      { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = LPDELCEP */      { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = IREFC */      { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},    /* src = MFCC */      { 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},    /* src = FBANK */      { 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},    /* src = MELSPEC */      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},    /* src = USER */      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},    /* src = DISCRETE */      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},    /* src = PLP */      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},    /* src = ANON */   };   if (src == tgt) return TRUE;   if (xmap[src&BASEMASK][tgt&BASEMASK] == 0 ) return FALSE;   if ((tgt&BASEMASK) == DISCRETE){      if ((tgt&~(BASEMASK|HASCRCC)) != 0) return FALSE;   } else {      if ((tgt&HASENERGY) && !(src&HASENERGY) )          return FALSE;      if ((tgt&HASZEROC)  && !(src&HASZEROC) )          return FALSE;      if ((tgt&HASENERGY) && (tgt&HASZEROC) && (tgt&HASDELTA))          return FALSE;      if ((tgt&HASENERGY) && (tgt&HASZEROC) && (tgt&HASNULLE))          return FALSE;      if (!(tgt&HASDELTA) && (tgt&HASACCS)) return FALSE;      if ((tgt&HASNULLE) && !((tgt&HASENERGY) || (tgt&HASZEROC)) )          return FALSE;      if ((tgt&HASNULLE) && !(tgt&HASDELTA) ) return FALSE;   }   return TRUE;}/* FindSpans: Finds the positions of the subcomponents of a parameter    vector with size components as follows (span values are -ve if    subcomponent does not exist):   span: [0] .. [1]  [2]    [3]  [4] .. [5]  [6] .. [7] [8] .. [9]           statics   cep0 energy   deltas       accs      third   */static void FindSpans(short span[12], ParmKind k, int size){   int i,stat,en=0,del=0,acc=0,c0=0,third=0,fourth=0;      for (i=0; i<10; i++) span[i] = -1;   /*       if having higher order differentials and the precondition       is there is third oder differentials    */   if (k&HASTHIRD && highDiff == TRUE)      fourth = third = acc = del = size/5;   else if (k&HASTHIRD)      third = acc = del = size/4;   else if (k&HASACCS)      acc = del = size/3;    else if (k&HASDELTA)       del = size/2;   if (k&HASENERGY) ++en;  if (k&HASZEROC) ++c0;   stat = size - c0 - en - del - acc - third - fourth;   if (stat>0) { span[0] = 0;              span[1] = stat-1;}   if (c0>0)     span[2] = stat; if (en>0) span[3] = stat+c0;   if (del>0)  { span[4] = stat+c0+en;     span[5] = stat+c0+en+del-1;}   if (acc>0)  { span[6] = stat+c0+en+del; span[7] = stat+c0+en+del+acc-1;}   if (third>0){ span[8] = stat+c0+en+del+acc; span[9] = stat+c0+en+del+acc+third-1;}   if (fourth>0){ span[10] = stat+c0+en+del+acc+third; span[11] = stat+c0+en+del+acc+third+fourth-1;}}/* TotalComps: return the total number of components in a parameter vector   with nStatic components and ParmKind pk */static int TotalComps(int nStatic, ParmKind pk){   int n,x;      n = nStatic;   if (pk&HASENERGY) ++n;   if (pk&HASZEROC)  ++n;   x = n;   if (pk&HASDELTA){      n += x;      if (pk&HASACCS) {        n += x;        if (pk&HASTHIRD) {           n += x;           if (highDiff == TRUE){              n += x;           }        }      }   }   return n;   }/* NumStatic: return the number of static components in a parameter vector   with nTotal components and ParmKind pk */static int NumStatic(int nTotal, ParmKind pk){   short span[12];      FindSpans(span,pk,nTotal);   return span[1]-span[0]+1;  }/* NumEnergy: return the number of energy components in a parameter vector   with nTotal components and ParmKind pk */static int NumEnergy(ParmKind pk){   int e;      if (!(pk&(HASENERGY|HASZEROC))) return 0;   e = 1;   if (pk&HASDELTA){      ++e;      if (pk&HASACCS) {        ++e;        if (pk&HASTHIRD){           ++e;           if (highDiff == TRUE){              ++e;           }        }      }   }   return e;   }/* EqualKind: return true if kinds are internally compatible */static Boolean EqualKind(ParmKind a, ParmKind b){   /* Energy suppression only occurs at observation level */   a = a&(~HASNULLE); b = b&(~HASNULLE);   return a==b;}/* --------------- Parameter Conversion Routines ----------------- *//* All of the routines in this section operate on a table of floats.     Typically the same operation is applied to each row.  Source slice   is indexed by si relative to start of that row, target slice is   indexed by ti relative to start of that row   data   v   ................................... ^   si              ti             |   .....xxxxxxxxxxx.....xxxxxxxxxxx... nRows   <--- d --->     <--- d --->    |   ................................... v   <--------------nCols-------------->*//* AddDiffs: target slice of each row are regression coeffs corresponding   to source slice.  Regression is calculated over rows   -winSize to +winSize. This assumes that hdMargin valid rows are stored   before the parameter block, and tlMargin valid rows are stored after   the parameter block.  When applied to tables these will be both zero.   For buffers, they may be positive. */      /* Note that unlike before this function really will process nRows of data *//* And will not automagically do extra (which was a necessary and probably *//* unintended side effect of the way the function worked previously) */static void AddDiffs(float *data, int nRows, int nCols, int si, int ti, int d,                      int winSize, int hdMargin, int tlMargin, Boolean v1Compat, Boolean simpDiffs){   float *p;   int n,offset = ti-si;   int head,tail;   if (hdMargin<0) hdMargin=0;   if (hdMargin>winSize) head = 0;   else head = winSize - hdMargin;   if (tlMargin<0) tlMargin=0;   if (tlMargin>winSize) tail = 0;   else tail = winSize - (tlMargin>0?tlMargin:0);   p = data+si; n=nRows-(head+tail);   if (n<=0) {      if (head>0 && tail>0) {         /* Special case to cope with ultra short buffers */         AddRegression(p,d,nRows,nCols,offset,winSize,                       hdMargin,tlMargin,simpDiffs);         head=tail=n=0; return;      }      else if (tail==0) head=nRows,n=0; /* Just do head rows */      else if (head==0) tail=nRows,n=0; /* Just do tail rows */   }   /* Make sure have winSize before and after columns to qualify */   if (head>0) {      if (v1Compat)         AddHeadRegress(p,d,head,nCols,offset,0,simpDiffs);      else         AddRegression(p,d,head,nCols,offset,winSize,                       hdMargin,winSize,simpDiffs);      p += head*nCols;   }   if (n>0) {      AddRegression(p,d,n,nCols,offset,winSize,winSize,winSize,simpDiffs);      p += n*nCols;   }   if (tail>0) {      if (v1Compat)         AddTailRegress(p,d,tail,nCols,offset,0,simpDiffs);      else         AddRegression(p,d,tail,nCols,offset,winSize,                       winSize,tlMargin,simpDiffs);   }}/* DeleteColumns: delete source slice (NB: nCols is not changed ) */static void DeleteColumn(float *data, int nUsed, int si, int d){   int rest;   char *p1,*p2;      p1 = (char *)data + si*sizeof(float);   p2 = p1 + d*sizeof(float);   rest = (nUsed - (si+d))*sizeof(float);   memmove(p1,p2,rest);}/* AddQualifiers: add quals needed to get from cf->curPK to cf->tgtPK. *//*  Ensures that nRows of data are valid and fully qualified. *//*  This means that delta coefs may be calculated beyond this range *//*  Values of hd/tlValid indicate that margin of static data exists at *//*  start/end of nRows */static void AddQualifiers(ParmBuf pbuf,float *data, int nRows, IOConfig cf,                           int hdValid, int tlValid){   char buf[100],buff1[256],buff2[256];   int si,ti,d=0,ds,de, i, j, step, size;   short span[12];   float *fp, mean, scale;   ParmKind tgtBase;   Vector tmp;   LinXForm *xf;   if (highDiff && ((cf->curPK&HASDELTA) || (cf->curPK&HASACCS) || (cf->curPK&HASTHIRD)))       HError (6371, "AddQualifiers: HIGHDIFF=T not supported with source features that contain derivatives already");   if ((cf->curPK == cf->tgtPK) && (cf->MatTranFN == NULL)) return;   if (trace&T_QUA)      printf("HParm:  adding Qualifiers to %s ...",ParmKind2Str(cf->curPK,buf));   if (cf->MatTranFN != NULL) { /* Do the generic checks that the matrix is appropriate */      if (((cf->matPK&BASEMASK)&(cf->curPK&BASEMASK)) != (cf->matPK&BASEMASK))         HError(6371, "AddQualifiers: Incorrect source parameter type (%s %s)",ParmKind2Str(cf->curPK,buff1),                ParmKind2Str(cf->matPK,buff2));      if ((HasEnergy(cf->matPK) && !(HasEnergy(cf->curPK))) || (!(HasEnergy(cf->matPK)) && (HasEnergy(cf->curPK))) ||          (HasZeroc(cf->matPK) && !(HasZeroc(cf->curPK))) || (HasZeroc(cf->curPK) && !(HasZeroc(cf->matPK))))         HError(6371,"AddQualifiers: Incorrect qualifiers in parameter type (%s %s)",ParmKind2Str(cf->curPK,buff1),ParmKind2Str(cf->matPK,buff2));   }   if ((cf->MatTranFN != NULL) && (cf->preQual)) {      if ((HasZerom(cf->matPK) && !(HasZerom(cf->curPK))) || (HasZerom(cf->curPK) && !(HasZerom(cf->matPK))))         HError(6371, "AddQualifiers: Incorrect qualifiers in parameter type (%s %s)",ParmKind2Str(cf->curPK,buff1),ParmKind2Str(cf->matPK,buff2));      ApplyStaticMat(cf,data,cf->MatTran,cf->nCols,nRows,0,0);      pbuf->main.nRows -= (cf->postFrames + cf->preFrames);      nRows = pbuf->main.nRows;      cf->nSamples = pbuf->main.nRows;   }   if ((cf->MatTranFN != NULL) && (!cf->preQual)) {       tgtBase = cf->tgtPK&BASEMASK;      if ((cf->curPK&BASEMASK)!=tgtBase && (tgtBase==LPCEPSTRA || tgtBase==MFCC || tgtBase==PLP))         size = TotalComps(

⌨️ 快捷键说明

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