📄 hparm.c
字号:
} else { /* there is a config transform specified, so check that it is compatble with the model set MMFId */ if ((hset->hmmSetId != NULL) && (!MaskMatch(cfg_xf->mmfIdMask,buf,hset->hmmSetId))) HError(6396,"HMM Set %s is not compatible with InputXForm",hset->hmmSetId); /* also need to ensure that the transform from the cofig option is converted into a macro. */ id = GetLabId(cfg_xf->xformName,TRUE); NewMacro(hset,-1,'j',id,(Ptr)cfg_xf); cfg_xf->nUse++; hset->xf = cfg_xf; } } else { /* transform needs to be set-up from the model set. Also need to reload the variance floor. */ if (hmm_xf != NULL) { SetInputXFormConfig(&(defChan->cf),hmm_xf); if ((hset->hmmSetId != NULL) && (!MaskMatch(hmm_xf->mmfIdMask,buf,hset->hmmSetId))) HError(6396,"HMM Set %s is not compatible with InputXForm",hset->hmmSetId); } if (defChan->cf.varScaleFN != NULL){ strcpy (varScaleFN,"\0"); LoadVarScale(&gcheap,&(defChan->cf)); } } } else { /* somehow this is happening prior to InitParm ... */ HError(6396,"Calling SetParmHMMSet prior to InitParm"); }}/* Load a global feature transform given in the channel config setup via a function defined in HModel since the transform is also treated as a macro. Afterwards check the consistency between the transform's model id. If the channel global feature transform setup is empty the pass on all the information from the loaded transform*/static void LoadMat (MemHeap *x, IOConfig cf) /*static??*/{ InputXForm *xf; char macroname[MAXSTRLEN]; xf = LoadInputXForm(hset,NameOf(cf->MatTranFN,macroname),cf->MatTranFN); if (xf == NULL) HError(999,"Cannot correctly load input transform from file %s",cf->MatTranFN); if (cf->xform == NULL) { /* No transform from model set */ SetInputXFormConfig(cf,xf); } else { /* check that transform is the same as the model one */ if (strcmp(xf->xformName,cf->xform->xformName)) { HRError(999,"Possibly incompatible XForm macros in MMF and config file %s and %s", xf->xformName,cf->xform->xformName); SetInputXFormConfig(cf,xf); } }}/* Rather than put this all in InitParm and in InitChannel we abstract it into a separate function.*/char *GS(char *s){static char b[100]; GetConfStr(cParm,nParm,s,b); return b;}int GI(char *s){int i; GetConfInt(cParm,nParm,s,&i); return i;}double GF(char *s){double d; GetConfFlt(cParm,nParm,s,&d); return d;}Boolean GB(char *s){Boolean b; GetConfBool(cParm,nParm,s,&b); return b;}/* ReadIOConfig: Create an IOConfig object. Initial values are copied from defCon and then updated from configuration parameters. */static IOConfig ReadIOConfig(IOConfig p){ IOConfParm i; char *s; for (i=SOURCEKIND; i<CFGSIZE; i=(IOConfParm) (i+1)){ s = ioConfName[i]; if (HasConfParm(cParm,nParm,s)) switch (i) { case SOURCEKIND: p->srcPK = Str2ParmKind(GS(s)); break; case SOURCEFORMAT: p->srcFF = Str2Format(GS(s)); break; case SOURCERATE: p->srcSampRate = GF(s); break; case ZMEANSOURCE: p->zMeanSrc = GB(s); break; case TARGETKIND: p->tgtPK = Str2ParmKind(GS(s)); break; case TARGETFORMAT: p->tgtFF = Str2Format(GS(s)); break; case TARGETRATE: p->tgtSampRate = GF(s); break; case SAVECOMPRESSED: p->saveCompressed = GB(s); break; case SAVEWITHCRC: p->saveWithCRC = GB(s); break; case WINDOWSIZE: p->winDur = GF(s); break; case USEHAMMING: p->useHam = GB(s); break; case PREEMCOEF: p->preEmph = GF(s); break; case USEPOWER: p->usePower = GB(s); break; case NUMCHANS: p->numChans = GI(s); break; case CEPSCALE: p->cepScale = GF(s); break; case LOFREQ: p->loFBankFreq = GF(s); break; case HIFREQ: p->hiFBankFreq = GF(s); break; case WARPFREQ: p->warpFreq = GF(s); break; case WARPLCUTOFF: p->warpLowerCutOff = GF(s); break; case WARPUCUTOFF: p->warpUpperCutOff = GF(s); break; case LPCORDER: p->lpcOrder = GI(s); break; case COMPRESSFACT: p->compressFact = GF(s); break; case CEPLIFTER: p->cepLifter= GI(s); break; case NUMCEPS: p->numCepCoef = GI(s); break; case RAWENERGY: p->rawEnergy = GB(s); break; case ENORMALISE: p->eNormalise = GB(s); break; case ESCALE: p->eScale = GF(s); break; case SILFLOOR: p->silFloor = GF(s); break; case DELTAWINDOW: p->delWin = GI(s); break; case ACCWINDOW: p->accWin = GI(s); break; case SIMPLEDIFFS: p->simpleDiffs = GB(s); break; case USESILDET: p->useSilDet = GB(s); break; case SELFCALSILDET: p->selfCalSilDet = GI(s); break; case SPEECHTHRESH: p->spThresh = GF(s); break; case SILDISCARD: p->silDiscard = GF(s); break; case SILENERGY: p->silMean = GF(s); break; case SPCSEQCOUNT: p->spcSeqCount = GI(s); break; case SPCGLCHCOUNT: p->spcGlchCount = GI(s); break; case SILGLCHCOUNT: p->silGlchCount = GI(s); break; case SILSEQCOUNT: p->silSeqCount = GI(s); break; case SILMARGIN: p->marginCount = GI(s); break; case MEASURESIL: p->measureSil = GB(s); break; case OUTSILWARN: p->outSilWarn = GB(s); break; case AUDIOSIG: p->audSignal = GI(s); break; case V1COMPAT: p->v1Compat = GB(s); break; case VQTABLE: p->vqTabFN = CopyString(&gcheap,GS(s)); break; case ADDDITHER: p->addDither = GF(s); break; case DOUBLEFFT: p->doubleFFT = GB(s); break; /* side based normalisation */ case VARSCALEFN: p->varScaleFN= CopyString(&gcheap, GS(s)); break; case VARSCALEDIR: p->varScaleDN = CopyString(&gcheap,GS(s)); break; case VARSCALEMASK: p->varScaleMask = CopyString(&gcheap,GS(s)); break; case CMEANDIR: p->cMeanDN = CopyString(&gcheap,GS(s)); break; case CMEANMASK: p->cMeanMask = CopyString(&gcheap,GS(s)); break; case MATTRANFN: p->MatTranFN= CopyString(&gcheap, GS(s)); break; case THIRDWINDOW: p->thirdWin = GI(s); break; case FOURTHWINDOW: p->fourthWin = GI(s); break; } } if (p->MatTranFN != NULL){ LoadMat (&gcheap,p); } if (p->varScaleFN != NULL){ LoadVarScale(&gcheap,p); } return p;}/* Read channel files once only */static ReturnStatus ReadChanFiles(ChannelInfo *chan){ /* Load VQ table if needed */ if (chan->cf.tgtPK&HASVQ) { if (chan->cf.vqTabFN==NULL){ HRError(6350,"ReadChanFiles: No VQ Table Given in Configuration"); return(FAIL); } if (trace&T_TOP) printf("HParm: Loading VQ table %s\n",chan->cf.vqTabFN); chan->cf.vqTab = LoadVQTab(chan->cf.vqTabFN, chan->cf.tgtPK&(~HASVQ)); } else chan->cf.vqTabFN=NULL,chan->cf.vqTab=NULL; return(SUCCESS);} /* EXPORT->InitParm: initialise memory and configuration parameters */ReturnStatus InitParm(void){ Boolean b; int i; char buf[MAXSTRLEN]; CreateHeap(&parmHeap, "HPARM C Heap", MSTAK, 1, 1.0, 20000, 80000 ); Register(hparm_version,hparm_vc_id); nParm = GetConfig("HPARM", TRUE, cParm, MAXGLOBS); if (nParm>0){ if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i; if (GetConfBool(cParm,nParm,"NATURALWRITEORDER",&b)) natWriteOrder = b; if (GetConfBool(cParm,nParm,"HIGHDIFF",&b)) highDiff = b; if (GetConfBool(cParm,nParm,"BROKENCVN",&b)) BrokenCVN = b; if (GetConfStr(cParm,nParm,"FORCEPKIND",buf)) ForcePKind = Str2ParmKind(buf); } defChan=curChan= (ChannelInfo *) New(&gcheap,sizeof(ChannelInfo)); defChan->confName=CopyString(&gcheap,"HPARM"); defChan->fCnt=defChan->sCnt=defChan->oCnt=0; defChan->chOffset=defChan->chPeak=-1.0; defChan->spDetThresh=defChan->spDetSil=defChan->spDetSNR=-1.0; defChan->spDetSp=0.0; defChan->spDetParmsSet=FALSE; defChan->next=NULL; /* Set up configuration parameters - once only now */ defChan->cf=defConf; ReadIOConfig(&defChan->cf); if(ReadChanFiles(defChan)<SUCCESS){ HRError(6350,"InitParm: ReadChanFiles failed"); return(FAIL); } return(SUCCESS);} /* EXPORT->SetNewConfig: Sets config parms for libmod */ReturnStatus SetChannel(char *confName){ char buf[MAXSTRLEN],*in,*out; Boolean b; if (confName==NULL) curChan=defChan; else { for (in=confName,out=buf;*in!=0;in++,out++) *out=toupper(*in); *out=0; for(curChan=defChan;curChan!=NULL;curChan=curChan->next) if (strcmp(curChan->confName,buf)==0) break; } if (curChan==NULL) { curChan= (ChannelInfo *) New(&gcheap,sizeof(ChannelInfo)); curChan->confName=CopyString(&gcheap,buf); curChan->fCnt=curChan->sCnt=0; curChan->chOffset=curChan->chPeak=-1.0; curChan->spDetThresh=curChan->spDetSil=curChan->spDetSNR=-1.0; curChan->spDetParmsSet=FALSE; curChan->next=NULL; /* Set up configuration parameters */ nParm = GetConfig(curChan->confName, FALSE, cParm, MAXGLOBS); if (nParm>0){ if (GetConfBool(cParm,nParm,"HIGHDIFF",&b)) highDiff = b; } /* Default are the standard HPARM parameters */ curChan->cf=defChan->cf; ReadIOConfig(&curChan->cf); /* This should be after setting the model up. Set input xform */ hset->xf = (curChan->cf).xform; if (hset->xf != NULL) hset->xf->nUse++; if(ReadChanFiles(curChan)<SUCCESS){ HRError(6350,"SetChannel: ReadChanFiles for new channel failed"); return(FAIL); } /* Link new channel into list */ curChan->next=defChan->next; defChan->next=curChan; /* Revert to normal config parameters */ nParm = GetConfig("HPARM", TRUE, cParm, MAXGLOBS); } return(SUCCESS);}/* EXPORT->ResetChannelSession: Force reinitialisation of running cepMean */void ResetChannelSession(char *confName){ ChannelInfo *chan; if (confName==NULL) chan=defChan; else for (chan=defChan;chan!=NULL;chan=chan->next) if (strcmp(chan->confName,confName)==0) break; if (chan==NULL) chan=defChan; chan->sCnt=chan->oCnt=0; /* Recalibrate selfCalSilDet every session */ if (chan->cf.selfCalSilDet!=0) chan->spDetParmsSet=FALSE;}/* Keep the next two functions solely for compatibility */void SetNewConfig(char *confName){ SetChannel(confName);}/* ------------------- Buffer Status Operations --------------- */static void FillBufFromChannel(ParmBuf pbuf,int minRows);static char * pbStatMap[] = { "PB_INIT","PB_WAITING","PB_STOPPING","PB_FILLING","PB_STOPPED","PB_CLEARED" };/* ChangeState: change state of buffer and trace if enabled */static void ChangeState(ParmBuf pbuf, PBStatus newState){ if (trace&T_PBS) printf("HParm: %s -> %s\n",pbStatMap[pbuf->status],pbStatMap[newState]); pbuf->status = newState;}/* CheckBuffer: update status of given buffer */static void CheckBuffer(ParmBuf pbuf){ Boolean started=FALSE; /* Speech detected */ Boolean finished=FALSE; /* Silence detected */ Boolean cleared=FALSE; /* Source of data is clear */ Boolean empty=FALSE; /* ParmBuf is empty */ if (pbuf->outRow==pbuf->spDetEn) empty=TRUE; if (pbuf->status>PB_INIT && pbuf->chClear) cleared=TRUE; if (pbuf->spDetEn<=pbuf->inRow) finished=TRUE; if (pbuf->spDetSt<=pbuf->inRow) started=TRUE; switch(pbuf->status){ case PB_INIT: break; case PB_WAITING: if (started) ChangeState(pbuf,PB_STOPPING); else break; case PB_STOPPING: if (finished) ChangeState(pbuf,PB_STOPPED); break; case PB_FILLING: if (cleared) ChangeState(pbuf,PB_STOPPED); break; case PB_STOPPED: if (empty) { ChangeState(pbuf,PB_CLEARED); pbuf->lastRow=pbuf->outRow; } break; case PB_CLEARED:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -