コード例 #1
0
/* LoadFile: load whole file or segments and accumulate variance */
static void LoadFile(char *fn)
{
   ParmBuf pbuf;
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;  
   int i,j,ncas,nObs;
   LLink p;
   
   if (segId == NULL)  {   /* load whole parameter file */
      if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
         HError(2050,"LoadFile: Config parameters invalid");
      GetBufferInfo(pbuf,&info);
      CheckData(fn,info);
      nObs = ObsInBuffer(pbuf);
      for (i=0; i<nObs; i++){
         ReadAsTable(pbuf,i,&obs);
         AccVar(obs);  
      }
      if (trace&T_LOAD) {
         printf(" %d observations loaded from %s\n",nObs,fn);
         fflush(stdout);
      }        
      CloseBuffer(pbuf);
   }
   else {                  /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&iStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
            HError(2050,"LoadFile: Config parameters invalid");
         GetBufferInfo(pbuf,&info);
         CheckData(fn,info);
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx= (long) (p->start/info.tgtSampRate);
            segEnIdx  = (long) (p->end/info.tgtSampRate);
            if (trace&T_SEGS)
               printf(" loading seg %s [%ld->%ld]\n",
                      segId->name,segStIdx,segEnIdx);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx >= segStIdx) {
               for (j=segStIdx;j<=segEnIdx;j++) {
                  ReadAsTable(pbuf,j,&obs);
                  AccVar(obs); ++nObs;
               }
            }
         }        
         CloseBuffer(pbuf);
         if (trace&T_LOAD)
            printf(" %d observations loaded from %s\n",nObs,fn);
      }  
   }
   ResetHeap(&iStack);
}
コード例 #2
0
ファイル: Tool_HCopy.c プロジェクト: cfxccn/HTKLib
/* AppendParm: append the src file to current Buffer pb. Return appended len */
HTime AppendParm(char *src)
{  
   int i;
   char bf1[MAXSTRLEN]; 
   char bf2[MAXSTRLEN]; 
   short swidth[SMAX];
   Boolean eSep;
   ParmBuf b, cb;
   Observation o;
   BufferInfo info;

   if((b =  OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(1050,"AppendParm: Config parameters invalid");
   GetBufferInfo(b,&info);
   if(trace & T_KINDS ){
      printf("Appending file %s format: %s [%s]->[%s]\n",src,
             Format2Str(info.srcFF), ParmKind2Str(info.srcPK,bf1),
             ParmKind2Str(info.tgtPK,bf2));
   }
   if  (tgtSampRate != info.tgtSampRate)
      HError(1032,"AppendParm: Input file %s has inconsistent sample rate",src);
   if ( BaseParmKind(tgtPK) != BaseParmKind(info.tgtPK))
      HError(1032,"AppendParm: Input file %s has inconsistent tgt format",src);
   cb = (chopF)?ChopParm(b,st,en,info.tgtSampRate) : b;
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&iStack, swidth, info.tgtPK, saveAsVQ, eSep);
   for (i=0; i < ObsInBuffer(cb); i++){
      ReadAsTable(cb, i, &o);
      AddToBuffer(pb, o);
   }
   CloseBuffer(cb);
   return(i*info.tgtSampRate);
}
コード例 #3
0
ファイル: HQuant.c プロジェクト: nlphacker/OpenSpeech
/* Initialise: set up global data storage */
void Initialise(char *datafn)
{
   ParmBuf pbuf;
   int s;
   Boolean eSep;

   CreateHeap(&iStack,"inBuf",     MSTAK, 1, 0.5, 100000, LONG_MAX);
   CreateHeap(&dStack,"seqStack",  MSTAK, 1, 0.5, 100000, LONG_MAX);
   CreateHeap(&cStack,"clustStack",MSTAK, 1, 0.5, 100000, LONG_MAX);

   /* Peek at first data file to get observation format */
   if((pbuf = OpenBuffer(&iStack, datafn, 0, UNDEFF, FALSE_dup, FALSE_dup))==NULL)
      HError(2550,"Initialise: Config parameters invalid");
   GetBufferInfo(pbuf, &info);
   CloseBuffer(pbuf);
   ResetHeap(&iStack);

   /* set/validate stream widths */
   if(swidth[0] > 0)
      CheckStreamWidths(info);
   else
      ZeroStreamWidths(1,swidth);

   /* Create an observation to hold the input parameters */
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   obs = MakeObservation(&gstack,swidth,info.tgtPK,FALSE,eSep);

   if (segLab != NULL)
      segId = GetLabId(segLab,TRUE);

   /* Create sequences to hold all data*/
   for (s=1;s<=swidth[0];s++)
      dSeq[s] = CreateSequence(&dStack,4096);
}
コード例 #4
0
gfx::IntSize
ImageDataSerializerBase::GetSize() const
{
  MOZ_ASSERT(IsValid());
  SurfaceBufferInfo* info = GetBufferInfo(mData);
  return gfx::IntSize(info->width, info->height);
}
コード例 #5
0
ファイル: HVite.c プロジェクト: 2hanson/voice_dialling
/* DoOnlineAdaptation: Perform unsupervised online adaptation
   using the recognition hypothesis as the transcription */
int DoOnlineAdaptation(Lattice *lat, ParmBuf pbuf, int nFrames)
{
   Transcription *modelTrans, *trans;
   BufferInfo pbinfo;
   Lattice *alignLat, *wordNet;
   Network *alignNet;
   int i;

   GetBufferInfo(pbuf,&pbinfo);
   trans=TranscriptionFromLattice(&netHeap,lat,1);
   wordNet=LatticeFromLabels(GetLabelList(trans,1),bndId,
                             &vocab,&netHeap);
   alignNet=ExpandWordNet(&netHeap,wordNet,&vocab,&hset);

   StartRecognition(alignvri,alignNet,0.0,0.0,0.0);     

   /* do forced alignment */
   for (i = 0; i < nFrames; i++) {
      ReadAsTable(pbuf, i, &obs);
      ProcessObservation(alignvri,&obs,-1,xfInfo.inXForm);
   }
    
   alignLat=CompleteRecognition(alignvri,
                                pbinfo.tgtSampRate/10000000.0,
                                &netHeap);
        
   if (alignvri->noTokenSurvived) {
      Dispose(&netHeap, trans);
      /* Return value 0 to indicate zero frames process failed */
      return 0;
   }
   modelTrans=TranscriptionFromLattice(&netHeap,alignLat,1);
      
   /* format the transcription so that it contains just the models */
   FormatTranscription(modelTrans,pbinfo.tgtSampRate,FALSE,TRUE,
                       FALSE,FALSE,TRUE,FALSE,TRUE,TRUE, FALSE);

   /* Now do the frame/state alignment accumulating MLLR statistics */
   /* set the various values in the utterance storage */
   utt->tr = modelTrans;
   utt->pbuf = pbuf;
   utt->Q = CountLabs(utt->tr->head);
   utt->T = nFrames;
   utt->ot = obs;
  
   /* do frame state alignment and accumulate statistics */
   fbInfo->inXForm = xfInfo.inXForm;
   fbInfo->al_inXForm = xfInfo.inXForm;
   fbInfo->paXForm = xfInfo.paXForm;
   if (!FBFile(fbInfo, utt, NULL))
     nFrames = 0;

   Dispose(&netHeap, trans);

   if (trace&T_TOP) {
      printf("Accumulated statistics...\n"); 
      fflush(stdout);
   }
   return nFrames;
} 
コード例 #6
0
void
ImageDataSerializer::InitializeBufferInfo(gfx::IntSize aSize,
                                          gfx::SurfaceFormat aFormat)
{
  SurfaceBufferInfo* info = GetBufferInfo(mData);
  info->width = aSize.width;
  info->height = aSize.height;
  info->format = aFormat;
}
コード例 #7
0
/* Accumulate stats from an utterance file */
SpkrAcc *AccGenUtt(char *SpkrPattern, char *UttFileName, SpkrAcc *sa)
{
   char SpkrName[MAXSTRLEN];
   ParmBuf pbuf;
   BufferInfo info;
   short swidth[SMAX];
   Boolean eSep;
   Vector tempV;
   int i;

   if (MaskMatch(SpkrPattern,SpkrName,UttFileName)==TRUE){
      /* open buffer and construct observation */
      pbuf = OpenBuffer(&iStack,UttFileName,0,dff,FALSE_dup,FALSE_dup);
      GetBufferInfo(pbuf,&info);
      if ((info.tgtPK & HASZEROM) && strchr(oflags,'m')) {
         HError(-2021,"HCompV: AccGenUtt: qualifier _Z not appropriate when calculating means!\n");
      }
      /* treat as single stream system though a bit weird */
      ZeroStreamWidths(1,swidth);
      SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
      obs = MakeObservation(&gstack,swidth,info.tgtPK,FALSE,eSep);
      if (info.tgtVecSize != vSize){
         vSize = info.tgtVecSize;
         /* if needed init a SpkrAcc */
         sa = InitSpkrAcc();
         fprintf(stdout,"Target observation vector size set to %d ......\n",info.tgtVecSize);
         fflush(stdout);
      }
      ParmKind2Str(info.tgtPK,TargetPKStr);
      /* accumulate stats for current utterance file */
      StartBuffer(pbuf);
      while (BufferStatus(pbuf) != PB_CLEARED) 
         {
            /* copy current observation and set vector ptr to first stream */
            ReadAsBuffer(pbuf,&obs);
            tempV = obs.fv[1];
            for (i=1;i<=vSize;i++){
               sa->meanSum[i] += tempV[i];
               sa->squareSum[i] += tempV[i]*tempV[i];
            }
            sa->NumFrame += 1;
         }
      CloseBuffer(pbuf);
      strcpy(sa->SpkrName,SpkrName);
      if (trace&T_CMV){
         fprintf(stdout,"Utterance %s accumulate generated for speaker %s\n",UttFileName,sa->SpkrName);
         fflush(stdout);
      }
      ResetHeap(&iStack);
      return sa;
   }
   else {
      HError(2039,"HCompV: AccGenUtt: speaker pattern matching failure on file: %s\n",UttFileName);
      return NULL;
   }
}
コード例 #8
0
TemporaryRef<gfx::DataSourceSurface>
ImageDataSerializerBase::GetAsSurface()
{
  MOZ_ASSERT(IsValid());
  SurfaceBufferInfo* info = GetBufferInfo(mData);
  gfx::IntSize size(info->width, info->height);
  uint32_t stride = gfxASurface::BytesPerPixel(
    gfx::SurfaceFormatToImageFormat(GetFormat())) * info->width;
  RefPtr<gfx::DataSourceSurface> surf =
    gfx::Factory::CreateWrappingDataSourceSurface(GetData(), stride, size, GetFormat());
  return surf.forget();
}
コード例 #9
0
TemporaryRef<gfxImageSurface>
ImageDataSerializerBase::GetAsThebesSurface()
{
  MOZ_ASSERT(IsValid());
  SurfaceBufferInfo* info = GetBufferInfo(mData);
  uint32_t stride = gfxASurface::BytesPerPixel(
    gfx::SurfaceFormatToImageFormat(GetFormat())) * info->width;
  gfxIntSize size(info->width, info->height);
  RefPtr<gfxImageSurface> surf =
    new gfxImageSurface(GetData(), size, stride,
                        gfx::SurfaceFormatToImageFormat(GetFormat()));
  return surf.forget();
}
コード例 #10
0
ファイル: Tool_HCopy.c プロジェクト: cfxccn/HTKLib
/* ChopParm: return parm chopped to st and end. end = 0 means all */
ParmBuf ChopParm(ParmBuf b, HTime start, HTime end, HTime sampRate)
{  
   int stObs, endObs, nObs, i;
   HTime length;
   short swidth[SMAX];
   Boolean eSep;
   ParmBuf cb;
   Observation o;
   BufferInfo info;

   length =  ObsInBuffer(b) * sampRate;
   ClampStEn(length,&start,&end);
   if(start >= length)
      HError(1030,"ChopParm: Src file too short to get data from %.0f",start);
   if(trace & T_SEGMENT)
      printf("ChopParm: Extracting segment %.0f to %.0f\n",start,end);
   stObs = (int) (start/sampRate);
   endObs = (int) (end/sampRate);
   nObs = endObs -stObs;
   if(nObs <= 0)
      HError(1030,"ChopParm: Truncation options result in zero-length file");
   GetBufferInfo(b,&info);
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&cStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   cb =  EmptyBuffer(&cStack, nObs, o, info);
   for (i=stObs; i < endObs; i++){
      ReadAsTable(b, i, &o);
      AddToBuffer(cb, o);
   }
   CloseBuffer(b);
   if(chopF && labF) ChopLabs(tr,start,end);
   return(cb);
}
コード例 #11
0
ファイル: Tool_HCopy.c プロジェクト: cfxccn/HTKLib
/* OpenParmFile: open source parm file and return length */
HTime OpenParmFile(char *src)
{
   int i;
   ParmBuf b, cb;
   short swidth[SMAX];
   Boolean eSep;
   Observation o;
   BufferInfo info;

   if((b =  OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(1050,"OpenParmFile: Config parameters invalid");
   GetBufferInfo(b,&info);
   srcSampRate = info.srcSampRate;
   tgtSampRate = info.tgtSampRate;
   srcPK = info.srcPK; tgtPK = info.tgtPK;
   cb = chopF?ChopParm(b,st,en,info.tgtSampRate):b;
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&oStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   pb =  EmptyBuffer(&oStack, ObsInBuffer(cb), o, info);
   for(i=0; i < ObsInBuffer(cb); i++){
      ReadAsTable(cb, i, &o);
      AddToBuffer(pb, o);
   }
   CloseBuffer(cb);
   if( info.nSamples > 0 )
      return(info.nSamples*srcSampRate);
   else
      return(ObsInBuffer(pb)*info.tgtSampRate);
}
コード例 #12
0
ファイル: HList.c プロジェクト: BackupTheBerlios/artbody-svn
   barwidth = itemWidth*(nItems+1);

}



/* PrintHeading: print the info in given HeadInfo record */

void PrintHeading(HeadInfo h)

{

   char buf[MAXSTRLEN];

   

   if (h.isSource){

      if (h.isAudio)

         strcpy(buf,"Source: Direct Audio");    

      else

         sprintf(buf,"Source: %s", h.name);

   }else

      strcpy(buf,"Target");

   PrBar(buf);

   printf("  Sample Bytes:  %-7d", h.sampSize);

   if (barwidth < 60 ) printf("\n");

   printf("  Sample Kind:   %s\n", ParmKind2Str(h.kind,buf));

   printf("  Num Comps:     %-7d", h.numComps);

   if (barwidth < 60 ) printf("\n");

   printf("  Sample Period: %.1f us\n", h.period/10.0);     

   if (!h.isAudio) {

      printf("  Num Samples:   %-7ld", h.nSamples);

      if (barwidth < 60 ) printf("\n");

      printf("  File Format:   %s\n", Format2Str(h.fmt));

   }

}



/* PrintWaveLine: print line of waveform samples */

void PrintWaveLine(short *data, int nItems, long idx)

{

   int i;

   

   if (!rawOut) printf("%5ld: ",idx);

   for (i=0; i<nItems; i++)  printf("%7d",*data++);

   printf("\n");

}



/* PrintRawVec: print vector components */

void PrintRawVec(Vector v)

{

   int i;

   

   for (i=1; i<=VectorSize(v); i++)  printf("%e ",v[i]);

   printf("\n");
コード例 #13
0
static bool GetParameterInfo(Cursor* cur, Py_ssize_t index, PyObject* param, ParamInfo& info)
{
    // Determines the type of SQL parameter that will be used for this parameter based on the Python data type.
    //
    // Populates `info`.

    // TODO: if the param is a SQLParameter object, then bind to the wrapped value and use the input/output type from that

    // Hold a reference to param until info is freed, because info will often be holding data borrowed from param.
    if (PyObject_TypeCheck(param, (PyTypeObject*)SQLParameter_type))
    {
        info.pParam = ((SQLParameter*)param)->value;
        info.InputOutputType = ((SQLParameter*)param)->type;
    }
    else
    {
        info.pParam = param;
        info.InputOutputType = SQL_PARAM_INPUT;
    }

    if (info.pParam == Py_None)
        return GetNullInfo(cur, index, info);

    if (info.pParam == null_binary)
        return GetNullBinaryInfo(cur, index, info);

    if (PyBytes_Check(info.pParam))
        return GetBytesInfo(cur, index, info.pParam, info);

    if (PyUnicode_Check(info.pParam))
        return GetUnicodeInfo(cur, index, info.pParam, info);

    if (PyBool_Check(info.pParam))
        return GetBooleanInfo(cur, index, info.pParam, info);

    if (PyDateTime_Check(info.pParam))
        return GetDateTimeInfo(cur, index, info.pParam, info);

    if (PyDate_Check(info.pParam))
        return GetDateInfo(cur, index, info.pParam, info);

    if (PyTime_Check(info.pParam))
        return GetTimeInfo(cur, index, info.pParam, info);

    if (PyLong_Check(info.pParam))
        return GetLongInfo(cur, index, info.pParam, info);

    if (PyFloat_Check(info.pParam))
        return GetFloatInfo(cur, index, info.pParam, info);

    if (PyDecimal_Check(info.pParam))
        return GetDecimalInfo(cur, index, info.pParam, info);

#if PY_VERSION_HEX >= 0x02060000
    if (PyByteArray_Check(info.pParam))
        return GetByteArrayInfo(cur, index, info.pParam, info);
#endif

#if PY_MAJOR_VERSION < 3
    if (PyInt_Check(info.pParam))
        return GetIntInfo(cur, index, info.pParam, info);

    if (PyBuffer_Check(info.pParam))
        return GetBufferInfo(cur, index, info.pParam, info);
#endif

    RaiseErrorV("HY105", ProgrammingError, "Invalid parameter type.  param-index=%zd param-type=%s", index, Py_TYPE(info.pParam)->tp_name);
    return false;
}
コード例 #14
0
ファイル: HQuant.c プロジェクト: nlphacker/OpenSpeech
/* LoadFile: load whole file or segments and accumulate variance */
void LoadFile(char *fn)
{
   ParmBuf pbuf;
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;  
   int i,s,j,ncas,nObs=0;
   LLink p;

   if (segId == NULL)  {   /* load whole parameter file */
      if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
         HError(2550,"LoadFile: Config parameters invalid");
      GetBufferInfo(pbuf,&info);
      CheckData(fn,info);
      nObs = ObsInBuffer(pbuf);
      
      for (i=0; i<nObs; i++) {
         for(s=1;s<=swidth[0];s++)
            obs.fv[s] = CreateVector(&dStack,swidth[s]);
         ReadAsTable(pbuf,i,&obs);
         for(s=1;s<=swidth[0];s++)
            StoreItem(dSeq[s],(Ptr)obs.fv[s]);
      }
      CloseBuffer(pbuf);
   }
   else { /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&iStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
            HError(2550,"LoadFile: Config parameters invalid");
         GetBufferInfo(pbuf,&info);
         CheckData(fn,info);
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx= (long) (p->start/info.tgtSampRate);
            segEnIdx  = (long) (p->end/info.tgtSampRate);
            if (trace&T_SEGS)
               printf(" loading seg %s [%ld->%ld]\n",
                      segId->name,segStIdx,segEnIdx);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx >= segStIdx) {
               for (j=segStIdx;j<=segEnIdx;j++) {
                  /* SJY: The HInit code I copied this from had no */
                  /* SJY: CreateVector call here -- a bug? */
                  for(s=1;s<=swidth[0];s++)
                     obs.fv[s] = CreateVector(&dStack,swidth[s]);
                  ReadAsTable(pbuf,j,&obs);
                  for(s=1;s<=swidth[0];s++)
                     StoreItem(dSeq[s],(Ptr)obs.fv[s]);
                  ++nObs;
               }
            }
         }        
         CloseBuffer(pbuf);
      }  
   }
   ResetHeap(&iStack);
   if (trace&T_LOAD) {
      printf(" %5d obs loaded from %s, streams: ",nObs,fn);
      for(s=1;s<=swidth[0];s++) printf("[%d]" ,swidth[s]);
      printf("\n"); fflush(stdout);
   }        
}
コード例 #15
0
ファイル: HVite.c プロジェクト: 2hanson/voice_dialling
/* ProcessFile: process given file. If fn=NULL then direct audio */
Boolean ProcessFile(char *fn, Network *net, int utterNum, LogDouble currGenBeam, Boolean restartable)
{
   FILE *file;
   ParmBuf pbuf;
   BufferInfo pbinfo;
   NetNode *d;
   Lattice *lat;
   LArc *arc,*cur;
   LNode *node;
   Transcription *trans;
   MLink m;
   LogFloat lmlk,aclk;
   int s,j,tact,nFrames;
   LatFormat form;
   char *p,lfn[255],buf1[80],buf2[80],thisFN[MAXSTRLEN];
   Boolean enableOutput = TRUE, isPipe;

   if (fn!=NULL)
      strcpy(thisFN,fn);
   else if (fn==NULL && saveAudioOut)
      CounterFN(roPrefix,roSuffix,++roCounter,4,thisFN);
   else 
      enableOutput = FALSE;
      
   if((pbuf = OpenBuffer(&bufHeap,fn,50,dfmt,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(3250,"ProcessFile: Config parameters invalid");   

   /* Check pbuf same as hset */
   GetBufferInfo(pbuf,&pbinfo);
   if (pbinfo.tgtPK!=hset.pkind)
      HError(3231,"ProcessFile: Incompatible sample kind %s vs %s",
             ParmKind2Str(pbinfo.tgtPK,buf1),
             ParmKind2Str(hset.pkind,buf2));
   if (pbinfo.a != NULL && replay)  AttachReplayBuf(pbinfo.a, (int) (3*(1.0E+07/pbinfo.srcSampRate)));

   StartRecognition(vri,net,lmScale,wordPen,prScale);
   SetPruningLevels(vri,maxActive,currGenBeam,wordBeam,nBeam,tmBeam);
 
   tact=0;nFrames=0;
   StartBuffer(pbuf);
   while(BufferStatus(pbuf)!=PB_CLEARED) {
      ReadAsBuffer(pbuf,&obs);
      if (trace&T_OBS) PrintObservation(nFrames,&obs,13);      

      if (hset.hsKind==DISCRETEHS){
         for (s=1; s<=hset.swidth[0]; s++){
            if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s]))
               HError(3250,"ProcessFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn);
         }
      }

      ProcessObservation(vri,&obs,-1,xfInfo.inXForm);
      
      if (trace & T_FRS) {
         for (d=vri->genMaxNode,j=0;j<30;d=d->links[0].node,j++)
            if (d->type==n_word) break;
         if (d->type==n_word){
            if (d->info.pron==NULL) p=":bound:";
            else p=d->info.pron->word->wordName->name;
         }
         else p=":external:";
         m=FindMacroStruct(&hset,'h',vri->genMaxNode->info.hmm);
         printf("Optimum @%-4d HMM: %s (%s)  %d %5.3f\n",
                vri->frame,m->id->name,p,
                vri->nact,vri->genMaxTok.like/vri->frame);
         fflush(stdout);
      }
      nFrames++;
      tact+=vri->nact;
   }
   lat=CompleteRecognition(vri,pbinfo.tgtSampRate/10000000.0,&ansHeap);
   
   if (lat==NULL) {
      if ((trace & T_TOP) && fn != NULL){
         if (restartable)
            printf("No tokens survived to final node of network at beam %.1f\n", currGenBeam);
         else
            printf("No tokens survived to final node of network\n");
         fflush(stdout);
      } else if (fn==NULL){
         printf("Sorry [%d frames]?\n",nFrames);fflush(stdout);
      }      
      if (pbinfo.a != NULL && replay)  ReplayAudio(pbinfo);
      CloseBuffer(pbuf);
      return FALSE;
   }
   
   if (vri->noTokenSurvived && restartable)
      return FALSE;

   if (vri->noTokenSurvived && trace & T_TOP) {
      printf("No tokens survived to final node of network\n");
      printf("  Output most likely partial hypothesis within network\n");
      fflush(stdout);
   }

   lat->utterance=thisFN;
   lat->net=wdNetFn;
   lat->vocab=dictFn;
   
   if (trace & T_TOP || fn==NULL) {
      node=NULL;
      for (j=0;j<lat->nn;j++) {
         node=lat->lnodes+j;
         if (node->pred==NULL) break;
         node=NULL;
      }
      aclk=lmlk=0.0;
      while(node!=NULL) {
         for (arc=NULL,cur=node->foll;cur!=NULL;cur=cur->farc) arc=cur;
         if (arc==NULL) break;
         if (arc->end->word!=NULL)
            printf("%s ",arc->end->word->wordName->name);
         aclk+=arc->aclike+arc->prlike*lat->prscale;
         lmlk+=arc->lmlike*lat->lmscale+lat->wdpenalty;
         node=arc->end;
      }
      printf(" ==  [%d frames] %.4f [Ac=%.1f LM=%.1f] (Act=%.1f)\n",nFrames,
             (aclk+lmlk)/nFrames, aclk,lmlk,(float)tact/nFrames);
      fflush(stdout);
   }
   if (pbinfo.a != NULL && replay)  ReplayAudio(pbinfo);
   
   /* accumulate stats for online unsupervised adaptation 
      only if a token survived */
   if ((lat != NULL) &&  (!vri->noTokenSurvived) && ((update > 0) || (xfInfo.useOutXForm)))
      DoOnlineAdaptation(lat, pbuf, nFrames);

   if (enableOutput){
      if (nToks>1 && latExt!=NULL) {
         MakeFN(thisFN,labDir,latExt,lfn);
         if ((file=FOpen(lfn,NetOFilter,&isPipe))==NULL) 
            HError(3211,"ProcessFile: Could not open file %s for lattice output",lfn);
         if (latForm==NULL)
            form=HLAT_DEFAULT;
         else {
            for (p=latForm,form=0;*p!=0;p++) {
               switch (*p) {
               case 'A': form|=HLAT_ALABS; break;
               case 'B': form|=HLAT_LBIN; break;
               case 't': form|=HLAT_TIMES; break;
               case 'v': form|=HLAT_PRON; break;
               case 'a': form|=HLAT_ACLIKE; break;
               case 'l': form|=HLAT_LMLIKE; break;
               case 'd': form|=HLAT_ALIGN; break;
               case 'm': form|=HLAT_ALDUR; break;
               case 'n': form|=HLAT_ALLIKE; break;
               case 'r': form|=HLAT_PRLIKE; break;
               }
            }
         }
         if(WriteLattice(lat,file,form)<SUCCESS)
            HError(3214,"ProcessFile: WriteLattice failed");

         FClose(file,isPipe);
      }

      /* only output 1-best transcription if generating lattices */
      if (nTrans > 1 && latExt != NULL) 
         trans=TranscriptionFromLattice(&ansHeap,lat,1);
      /* output N-best transcriptions as usual */
      else
      trans=TranscriptionFromLattice(&ansHeap,lat,nTrans);
      
      if (labForm!=NULL)
         FormatTranscription(trans,pbinfo.tgtSampRate,states,models,
                             strchr(labForm,'X')!=NULL,
                             strchr(labForm,'N')!=NULL,strchr(labForm,'S')!=NULL,
                             strchr(labForm,'C')!=NULL,strchr(labForm,'T')!=NULL,
                             strchr(labForm,'W')!=NULL,strchr(labForm,'M')!=NULL);

      MakeFN(thisFN,labDir,labExt,lfn);
      /* if(LSave(lfn,trans,ofmt)<SUCCESS)
         HError(3214,"ProcessFile: Cannot save file %s", lfn); */
      LSave(lfn,trans,ofmt);
      Dispose(&ansHeap,trans);
   }
   Dispose(&ansHeap,lat);
   CloseBuffer(pbuf);
   if (trace & T_MMU){
      printf("Memory State after utter %d\n",utterNum);
      PrintAllHeapStats();
   }

   return !vri->noTokenSurvived;
}
コード例 #16
0
gfx::SurfaceFormat
ImageDataSerializerBase::GetFormat() const
{
  MOZ_ASSERT(IsValid());
  return GetBufferInfo(mData)->format;
}
コード例 #17
0
ファイル: HInit.c プロジェクト: songzhengxuan/kata
/* LoadFile: load whole file or segments into segStore */
void LoadFile(char *fn)
{
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;
   static int segIdx=1;  /* Between call handle on latest seg in segStore */  
   static int prevSegIdx=1;
   HTime tStart, tEnd;
   int i,k,s,ncas,nObs=0,segLen;
   LLink p;
   Observation obs;

   if((pbuf=OpenBuffer(&bufferStack, fn, 10, dff, FALSE_dup, FALSE_dup))==NULL)
      HError(2150,"LoadFile: Config parameters invalid");
   GetBufferInfo(pbuf,&info);
   CheckData(fn,info);
   if (firstTime) InitSegStore(&info);

   if (segId == NULL)  {   /* load whole parameter file */
      nObs = ObsInBuffer(pbuf);
      tStart = 0.0;
      tEnd = (info.tgtSampRate * nObs);
      LoadSegment(segStore, tStart, tEnd, pbuf);
      segIdx++;
   }
   else {                  /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&transStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         for (i=1,nObs=0; i<=ncas; i++) {
            p = GetCase(trans->head,segId,i);
            segStIdx = (long)(p->start/info.tgtSampRate);
            segEnIdx = (long)(p->end/info.tgtSampRate);
            if (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx - segStIdx + 1 >= nStates-2) {
               LoadSegment(segStore, p->start, p->end, pbuf);
               if (trace&T_LD1)
                  printf("  loading seg %s %f[%ld]->%f[%ld]\n",segId->name,
                         p->start,segStIdx,p->end,segEnIdx);
               nObs += SegLength(segStore, segIdx);
               segIdx++;
            }else if (trace&T_LD1)
               printf("   seg %s %f->%f ignored\n",segId->name,
                      p->start,p->end);
         }        
      }  
   }
   if (hset.hsKind == DISCRETEHS){
      for (k=prevSegIdx; k<segIdx; k++){
         segLen = SegLength(segStore, k);
         for (i=1; i<=segLen; i++){
            obs = GetSegObs(segStore, k, i);
            for (s=1; s<=nStreams; s++){
               if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s]))
                  HError(2150,"LoadFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn);
            }
         }
      }
      prevSegIdx=segIdx;
   }

   if (trace&T_LD0)
      printf(" %d observations loaded from %s\n",nObs,fn);
   CloseBuffer(pbuf);
   ResetHeap(&transStack);
}
コード例 #18
0
ファイル: HERest.c プロジェクト: BackupTheBerlios/artbody-svn
                       printf("Loading alignment HMM set %s\n",q);

                   }

                   AddMMF(&al_hset,q);

                   if (eos)

                       break;

                   q=p+1;

               }

               p++;

           }

       }

       if (strlen(al_hmmLst) > 0 ) 

           MakeHMMSet(&al_hset, al_hmmLst );

       else /* use same hmmList */

           MakeHMMSet(&al_hset, hmmListFn );

       if (strlen(al_hmmDir) > 0 )

           LoadHMMSet(&al_hset,al_hmmDir,al_hmmExt);

       else

           LoadHMMSet(&al_hset,NULL,NULL);



       /* switch model set */

       UseAlignHMMSet(fbInfo,x,&al_hset);

       if (parMode != 0) {

	  ConvDiagC(&al_hset,TRUE);

	  ConvLogWt(&al_hset);

       }



       /* and echo status */

       if (trace&T_TOP) { 

           if (strlen(al_hmmDir) > 0 )

               printf(" HMM Dir %s",al_hmmDir);

           if (strlen(al_hmmExt) > 0 )

               printf(" Ext %s",al_hmmExt);