📄 hlist.c
字号:
/* PrintDataBar: print bar before data */void PrintDataBar(long st, long en){ char buf[MAXSTRLEN]; sprintf(buf,"Samples: %ld->%ld", st<0?0:st,en); PrBar(buf);}/* ---------------- Data Access Routines ------------------- *//* IsWave: check config parms to see if target is a waveform */Boolean IsWave(char *srcFile){ FILE *f; long nSamp,sampP, hdrS; short sampS,kind; Boolean isPipe,bSwap,isWave; char buf[MAXSTRLEN]; ParmKind tgtPK=ANON; FileFormat srcFF=HTK; Boolean isEXF; /* srcFile is extended file */ char actfname[MAXFNAMELEN]; /* actual filename */ long stIndex, enIndex; /* start and end indices */ if (ff!=UNDEFF) srcFF = ff; /* Read all configuration params and get target */ if (GetConfStr(cParm,nParm,"TARGETKIND",buf)) tgtPK = Str2ParmKind(buf); isWave = tgtPK == WAVEFORM; if (tgtPK == ANON){ if ((srcFF == HTK || srcFF == ESIG) && srcFile != NULL){ strncpy (actfname, srcFile, MAXFNAMELEN); isEXF = GetFileNameExt (srcFile, actfname, &stIndex, &enIndex); if ((f = FOpen (actfname, WaveFilter, &isPipe)) == NULL) HError(1110,"IsWave: cannot open File %s",srcFile); switch (srcFF) { case HTK: if (!ReadHTKHeader(f,&nSamp,&sampP,&sampS,&kind,&bSwap)) HError(1113, "IsWave: cannot read HTK Header in File %s", srcFile); break; case ESIG: if (!ReadEsignalHeader(f, &nSamp, &sampP, &sampS, &kind, &bSwap, &hdrS, isPipe)) HError(1113, "IsWave: cannot read Esignal Header in File %s", srcFile); break; } isWave = kind == WAVEFORM; FClose(f,isPipe); } else isWave = TRUE; } return isWave;}#define AUDIO_BSIZE 1000 /* Audio Buffer Size *//* ListWavefromAudio: list wave from audio device */void ListWavefromAudio(void){ AudioIn a; AudioOut b; HeadInfo hi; int avail,bsize,nrows,idx=0,np; short buf[AUDIO_BSIZE],*p; static MemHeap x,y; static Boolean heapsCreated=FALSE; if (trace&T_TOP) printf(" Listing Waveform from Audio Source\n"); if (!heapsCreated) { CreateHeap(&x,"AudioIn", MSTAK, 1, 0.5, 100000, 5000000); CreateHeap(&y,"AudioOut", MSTAK, 1, 0.0, 100000, 500000); heapsCreated = TRUE; } else { ResetHeap(&x); ResetHeap(&y); } nrows = AUDIO_BSIZE / nItems; bsize = nrows * nItems; a = OpenAudioInput(&x,&sampPeriod, 0.0, 0.0); if (a==NULL) HError(1106,"ListWavefromAudio: No audio support"); if (replay) AttachReplayBuf(a,100000); SetBarWidth(7); if (srcHdr) { hi.period = sampPeriod; hi.isAudio = TRUE; hi.isSource = TRUE; hi.kind = WAVEFORM; hi.sampSize = 2; hi.numComps = 1; PrintHeading(hi); } if (prData || gst>-1 || gen>-1) { StartAudioInput(a,audSignal); while (GetAIStatus(a) != AI_CLEARED) { avail = bsize; GetRawAudio(a, avail, buf); p = buf; while (avail>0){ np = (avail>nItems)?nItems:avail; if (idx >= gst && (idx <= gen || gen==-1)) PrintWaveLine(p,np,idx); p += np; idx += np; avail -= np; } } if (replay){ b = OpenAudioOutput(&y,&sampPeriod); PlayReplayBuffer(b,a); while (SamplesToPlay(b) > 0 ); CloseAudioOutput(b); } } CloseAudioInput(a);}/* ListWavefromFile: list wave from file */void ListWavefromFile(char *src){ Wave w; HeadInfo hi; short *data; long ns,np,idx = 0; static MemHeap x; static Boolean heapsCreated = FALSE; if (trace&T_TOP) printf(" Listing Waveform from File %s\n",src); if (!heapsCreated) { CreateHeap(&x,"WaveIn", MSTAK, 1, 0.5, 100000, 5000000); heapsCreated = TRUE; } else { ResetHeap(&x); } if((w = OpenWaveInput(&x,src,ff,0.0,0.0,&sampPeriod))==NULL) HError(1113,"ListWavefromFile: OpenWaveInput failed"); data = GetWaveDirect(w,&(hi.nSamples)); SetBarWidth(7); if (srcHdr) { hi.period = sampPeriod; hi.name = src; hi.fmt = WaveFormat(w); hi.isAudio = FALSE; hi.isSource = TRUE; hi.kind = WAVEFORM; hi.sampSize = 2; hi.numComps = 1; PrintHeading(hi); } if (prData || gst>-1 || gen >-1) { ns = hi.nSamples; if (gst>-1) { idx = gst; data += gst; ns -= gst; } if (gen>-1 && ns > gen-gst+1) ns = gen-gst+1; PrintDataBar(idx,idx+ns-1); while (ns>0){ np = (ns>nItems)?nItems:ns; PrintWaveLine(data,np,idx); data += np; idx += np; ns -= np; } } CloseWaveInput(w);}/* ListParms: list param data derived from file or audio */void ListParms(char *src){ ParmBuf pbuf; AudioOut b; Observation o; HeadInfo hi,ho; long idx = 0; Boolean eSep; short swidth[SMAX]; BufferInfo info; static MemHeap x,y; static Boolean heapsCreated = FALSE; if (trace&T_TOP) printf(" Listing Parameter Vectors from %s\n", src==NULL?"audio":src); if (!heapsCreated) { CreateHeap(&x,"BufferIn", MSTAK, 1, 0.5, 100000, 5000000); CreateHeap(&y,"AudioOut", MSTAK, 1, 0.0, 100000, 100000); heapsCreated = TRUE; } else { ResetHeap(&x); ResetHeap(&y); } if((pbuf = OpenBuffer(&x,src,50,ff,TRI_UNDEF,TRI_UNDEF))==NULL) HError(1150,"ListParms: Config parameters invalid"); GetBufferInfo(pbuf,&info); SetBarWidth(8); hi.isAudio = src==NULL; if (replay && hi.isAudio) AttachReplayBuf(info.a,100000); if (srcHdr) { hi.name = hi.isAudio ? (char *) "audio" : src; hi.fmt = info.srcFF; hi.isSource = TRUE; hi.kind = info.srcPK; if (hi.kind == WAVEFORM){ hi.nSamples = info.nSamples; hi.numComps = 1; hi.sampSize = 2; }else{ hi.nSamples = hi.isAudio?0:ObsInBuffer(pbuf); hi.numComps = info.srcVecSize; hi.sampSize = hi.numComps*sizeof(float); if (HasCompx(info.srcPK) || BaseParmKind(info.srcPK) == IREFC || BaseParmKind(info.srcPK) == DISCRETE) hi.sampSize /= 2; } hi.period = info.srcSampRate; PrintHeading(hi); } ho.nSamples = hi.isAudio?0:ObsInBuffer(pbuf); if (tgtHdr) { ho.name = ""; ho.fmt = info.tgtFF; ho.isAudio = FALSE; ho.isSource = FALSE; ho.kind = info.tgtPK; ho.numComps = info.tgtVecSize; ho.sampSize = ho.numComps*sizeof(float); if (BaseParmKind(info.tgtPK) == DISCRETE) ho.sampSize /= 2; ho.period = info.tgtSampRate; PrintHeading(ho); } ZeroStreamWidths(numS,swidth); SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep); o = MakeObservation(&gstack,swidth,info.tgtPK,frcDisc,eSep); if (obsFmt) PrintObsFmt(&o); if (prData || gst>-1 || gen >-1) { PrintDataBar(gst,gen); StartBuffer(pbuf); while (BufferStatus(pbuf) != PB_CLEARED){ ReadAsBuffer(pbuf,&o); if (idx >= gst && (idx <= gen || gen==-1)){ if (rawOut) PrintRawVec(o.fv[1]); else PrintObservation((int)idx,&o,nItems); fflush(stdout); } if (gen>-1 && idx==gen && hi.isAudio) StopBuffer(pbuf); ++idx; } if (replay && hi.isAudio){ b = OpenAudioOutput(&y,&sampPeriod); PlayReplayBuffer(b,info.a); while (SamplesToPlay(b) > 0 ); CloseAudioOutput(b); } } CloseBuffer(pbuf);}/* ListSpeech: top level control routine */void ListSpeech(char *src){ if (IsWave(src)){ if (src==NULL) ListWavefromAudio(); else ListWavefromFile(src); } else ListParms(src); PrBar("END");}/* ----------------------------------------------------------- *//* END: HList.c *//* ----------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -