📄 hlist.c
字号:
/* ----------------------------------------------------------- *//* *//* ___ *//* |_| | |_/ SPEECH *//* | | | | \ RECOGNITION *//* ========= SOFTWARE */ /* *//* *//* ----------------------------------------------------------- *//* developed at: *//* *//* Speech Vision and Robotics group *//* Cambridge University Engineering Department *//* http://svr-www.eng.cam.ac.uk/ *//* *//* Entropic Cambridge Research Laboratory *//* (now part of Microsoft) *//* *//* ----------------------------------------------------------- *//* Copyright: Microsoft Corporation *//* 1995-2000 Redmond, Washington USA *//* http://www.microsoft.com *//* *//* 2002 Cambridge University *//* Engineering Department *//* *//* Use of this software is governed by a License Agreement *//* ** See the file License for the Conditions of Use ** *//* ** This banner notice must not be removed ** *//* *//* ----------------------------------------------------------- *//* File: HList.c: List a Speech File or Audio Source *//* ----------------------------------------------------------- */char *hlist_version = "!HVER!HList: 3.3 [CUED 28/04/05]";char *hlist_vc_id = "$Id: HList.c,v 1.1.1.1 2005/05/12 10:52:54 jal58 Exp $";#include "HShell.h"#include "HMem.h"#include "HMath.h"#include "HSigP.h"#include "HAudio.h"#include "HWave.h"#include "HVQ.h"#include "HParm.h"#include "HLabel.h"#include "HModel.h"/* -------------------------- Trace Flags ------------------------ */static int trace = 0;#define T_TOP 0001 /* Top Level tracing *//* ---------------------- Global Variables ----------------------- */static Boolean srcHdr = FALSE; /* print source header info */static Boolean tgtHdr = FALSE; /* print target header info */static Boolean obsFmt = FALSE; /* print observation format */static Boolean prData = TRUE; /* print data */static Boolean rawOut = FALSE; /* raw output i.e no numbering */static Boolean replay = FALSE; /* replay audio */static Boolean frcDisc = FALSE; /* List VQ symbols from cont file */static FileFormat ff = UNDEFF; /* Source File format */static long gst = -1; /* start sample to list */static long gen = -1; /* end sample to list */static int numS = 1; /* number of streams */static int nItems = 10; /* num items per line */static int barwidth; /* width of printed bars */static char barc = '-'; /* bar character *//* ---------------- Configuration Parameters --------------------- */static ConfParam *cParm[MAXGLOBS];static int nParm = 0; /* total num params */static HTime sampPeriod; /* raw audio input only */static int audSignal;/* ---------------- Process Command Line ------------------------- *//* SetConfParms: set conf parms relevant to this tool */void SetConfParms(void){ int i; double d; sampPeriod = 0.0; audSignal = NULLSIG; nParm = GetConfig("HLIST", TRUE, cParm, MAXGLOBS); if (nParm>0){ if (GetConfInt(cParm,nParm,"AUDIOSIG",&i)) audSignal = i; if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i; if (GetConfFlt(cParm,nParm,"SOURCERATE",&d)) sampPeriod = d; }}void ReportUsage(void){ printf("\nUSAGE: HList [options] file ...\n\n"); printf(" Option Default\n\n"); printf(" -d Coerce observation to VQ symbols off\n"); printf(" -e N End at sample N 0\n"); printf(" -h Print source header info off\n"); printf(" -i N Set items per line to N 10\n"); printf(" -n N Set num streams to N 1\n"); printf(" -o Print observation structure off\n"); printf(" -p Playback audio off\n"); printf(" -r Write raw output off\n"); printf(" -s N Start at sample N 0\n"); printf(" -t Print target header info off\n"); printf(" -z Suppress printing data on\n"); PrintStdOpts("F"); printf("\n\n");} int main(int argc, char *argv[]){ char *s,buf[MAXSTRLEN]; void ListSpeech(char *src); if(InitShell(argc,argv,hlist_version,hlist_vc_id)<SUCCESS) HError(1100,"HList: InitShell failed"); InitMem(); InitMath(); InitSigP(); InitWave(); InitAudio(); InitVQ(); InitLabel(); InitModel(); if(InitParm()<SUCCESS) HError(1100,"HList: InitParm failed"); SetConfParms(); if (GetConfStr(cParm,nParm,"SOURCEFORMAT",buf)) ff = Str2Format(buf); if (!InfoPrinted() && NumArgs() == 0 && ff != HAUDIO) ReportUsage(); if (NumArgs() == 0 && ff != HAUDIO) Exit(0); while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s) !=1 ) HError(1119,"HList: Bad switch %s; must be single letter",s); switch(s[0]){ case 'd': frcDisc = TRUE; break; case 'e': gen = GetChkedLong(gst,LONG_MAX,s); break; case 'h': srcHdr = TRUE; break; case 'i': nItems = GetChkedInt(1,100,s); break; case 'n': numS = GetChkedInt(1,SMAX-1,s); break; case 'o': obsFmt = TRUE; break; case 'p': replay = TRUE; break; case 'r': rawOut = TRUE; break; case 's': gst = GetChkedLong(0,LONG_MAX,s); break; case 't': tgtHdr = TRUE; break; case 'z': prData = FALSE; break; case 'F': if (NextArg() != STRINGARG) HError(1119,"HList: File format expected"); if((ff = Str2Format(GetStrArg())) == ALIEN) HError(-1189,"HList: Warning ALIEN src file format set"); break; case 'T': trace = GetChkedInt(0,077,s); break; default: HError(1119,"HList: Unknown switch %s",s); } } if (NumArgs() == 0 ) ListSpeech(NULL); else while (NumArgs() > 0 ) { if (NextArg() != STRINGARG) HError(1119,"HList: List file name expected"); ListSpeech(GetStrArg()); } Exit(0); return (0); /* never reached -- make compiler happy */}/* -------------------- Display Routines ------------------- */typedef struct{ /* gather together basic header info */ char *name; Boolean isSource; Boolean isAudio; FileFormat fmt; ParmKind kind; HTime period; int sampSize; int numComps; long nSamples;}HeadInfo;/* PrBar: print a horizantal bar of length n including title */void PrBar(char *title){ int i,len,n; if (rawOut) return; len = strlen(title); n = (barwidth - len)/2; for (i=1; i<n; i++) putchar(barc); printf(" %s ",title); n = barwidth - n - len; for (i=1; i<n; i++) putchar(barc); putchar('\n');} /* SetBarWidth: set bar width according to nItems and item type */void SetBarWidth(int itemWidth){ 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");}/* PrintObsFmt: print observation structure */void PrintObsFmt(Observation *o){ PrBar("Observation Structure"); ExplainObservation(o,nItems);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -