📄 hquant.c
字号:
/* ----------------------------------------------------------- *//* *//* ___ *//* |_| | |_/ SPEECH *//* | | | | \ RECOGNITION *//* ========= SOFTWARE */ /* *//* *//* ----------------------------------------------------------- *//* Copyright: Microsoft Corporation *//* 1995-2000 Redmond, Washington USA *//* http://www.microsoft.com *//* *//* 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: HQuant.c: VQ table generation *//* ----------------------------------------------------------- */char *hquant_version = "!HVER!HQuant: 3.3 [CUED 28/04/05]";char *hquant_vc_id = "$Id: HQuant.c,v 1.1.1.1 2005/05/12 10:52:54 jal58 Exp $";/* This program calculates a vector quantisation table from a sequence of training files.*/ #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"#include "HTrain.h"/* ------------------- Trace Flags & Vars ------------------------ */#define T_TOP 0001 /* basic progress reporting */#define T_MEAN 0002 /* dump global mean and cov */#define T_LOAD 0004 /* trace data loading */#define T_SEGS 0010 /* list label segments */#define T_CLUST 0020 /* dump clusters */#define T_TAB 0040 /* dump vq table */static int trace = 0; /* trace level */static ConfParam *cParm[MAXGLOBS]; /* configuration parameters */static int nParm = 0; /* total num params *//* ---------------------- Global Variables ----------------------- */#define DEF_NCLUST 256 /* default codebook size */static BufferInfo info; /* global observation format, etc. */static int cbSizes[SMAX]; /* codebook sizes, per stream */static short swidth[SMAX]; /* stream widths */static TreeType tType = linTree; /* codebook structure */static char *vqfn = NULL; /* filename for output VQ table */static char *segLab = NULL; /* segment label, if any */static LabId segId = NULL; /* and its id */static char *labDir = NULL; /* label file directory */static char *labExt = "lab"; /* label file extension */static FileFormat dff=UNDEFF; /* data file format */static FileFormat lff=UNDEFF; /* label file format */static MemHeap iStack; /* input buffer */static MemHeap dStack; /* sequence stack */static MemHeap cStack; /* cluster stack */Sequence dSeq[SMAX]; /* main data pools; one per stream */ClusterSet *cs[SMAX]; /* stores vector clusters */CovKind ck = NULLC; /* determines distance metric */Vector mean[SMAX]; /* Global stream mean */Covariance cov[SMAX]; /* Global stream covariance */Boolean widthSet = FALSE; /* true if width of any stream is set */static Observation obs; /* storage for observations */static Boolean globClustVar = FALSE;/*Output global variance of data to codebook in place of individual vars*//* ------------- Process Command Line and Check Data ------------ *//* SetConfParms: set conf parms relevant to HQuant */void SetConfParms(void){ int i; nParm = GetConfig("HQUANT", TRUE, cParm, MAXGLOBS); if (nParm>0) { if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i; }}/* InitStreamVars: set initial values of stream-indexed variables */void InitStreamVars(void){ int s; swidth[0] = cbSizes[0] = 0; for(s=1;s<SMAX;s++) { swidth[s] = 0; cbSizes[s] = DEF_NCLUST; mean[s] = NULL; }}void ReportUsage(void){ printf("\nUSAGE: HQuant [options] vqFile trainFiles...\n\n" ); printf(" Option Default\n\n"); printf(" -d Use diagonal cov Mahalanobis Euclidean\n"); printf(" -f Use full covariance Mahalanobis Euclidean\n"); printf(" -g Output global covar to codebook off\n"); printf(" -l s Set segment label to s none\n"); printf(" -n S N Set codebook size for stream S to N N=%d\n",DEF_NCLUST); printf(" -s N Set number of streams to N 1\n"); printf(" -t Create tree-stuctured codebooks linear\n"); printf(" -w S N Set width of stream S to N default\n"); PrintStdOpts("FGILX"); printf("\n\n");}int main(int argc, char *argv[]){ char *datafn, *s; int stream = 0; void Initialise(char *datafn); void LoadFile(char *fn); void CalcMeanCov(Sequence seq[], int s); void ClusterVecs(Sequence seq[], int s); void WriteVQTable(ClusterSet *cs[], char *fn); if(InitShell(argc,argv,hquant_version,hquant_vc_id)<SUCCESS) HError(2500,"HQuant: InitShell failed"); InitMem(); InitLabel(); InitMath(); InitSigP(); InitWave(); InitAudio(); InitVQ(); InitModel(); if(InitParm()<SUCCESS) HError(2500,"HQuant: InitParm failed"); InitTrain(); if (!InfoPrinted() && NumArgs() == 0) ReportUsage(); if (NumArgs() == 0) Exit(0); SetConfParms(); InitStreamVars(); while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1) HError(2519,"HQuant: Bad switch %s; must be single letter",s); switch(s[0]){ case 'd': if ( ck != NULLC) HError(2519,"HQuant: Specify one of -d or -f, not both"); ck = INVDIAGC; break; case 'f': if ( ck != NULLC) HError(2519,"HQuant: Specify one of -d or -f, not both"); ck = FULLC; break; case 'g': globClustVar = TRUE; break; case 'l': if (NextArg() != STRINGARG) HError(2519,"HQuant: Segment label expected"); segLab = GetStrArg(); break; case 'n': if (NextArg() != INTARG) HError(2519,"HQuant: Stream number expected"); stream = GetChkedInt(1,SMAX,s); if (NextArg() != INTARG) HError(2519,"HQuant: Codebook size expected"); cbSizes[stream]= GetChkedInt(1,32768,s); break; case 's': if (NextArg() != INTARG) HError(2519,"HQuant: Number of streams expected"); swidth[0] = GetChkedInt(1,SMAX,s); break; case 't': tType = binTree; break; case 'w': if (NextArg() != INTARG) HError(2519,"HQuant: Stream number expected"); stream = GetChkedInt(1,SMAX,s); if(swidth[0] < stream) swidth[0] = stream; widthSet = TRUE; if (NextArg() != INTARG) HError(2519,"HQuant: Stream width expected"); swidth[stream]= GetChkedInt(1,256,s); break; case 'F': if (NextArg() != STRINGARG) HError(2519,"HQuant: Data File format expected"); if((dff = Str2Format(GetStrArg())) == ALIEN) HError(-2589,"HQuant: Warning ALIEN Data file format set"); break; case 'G': if (NextArg() != STRINGARG) HError(2519,"HQuant: Label File format expected"); if((lff = Str2Format(GetStrArg())) == ALIEN) HError(-2589,"HQuant: Warning ALIEN Label file format set"); break; case 'I': if (NextArg() != STRINGARG) HError(2519,"HQuant: MLF file name expected"); LoadMasterFile(GetStrArg()); break; case 'L': if (NextArg()!=STRINGARG) HError(2519,"HQuant: Label file directory expected"); labDir = GetStrArg(); break; case 'T': if (NextArg() != INTARG) HError(2519,"HQuant: Trace value expected"); trace = GetChkedInt(0,077,s); break; case 'X': if (NextArg()!=STRINGARG) HError(2519,"HQuant: Label file extension expected"); labExt = GetStrArg(); break; default: HError(2519,"HQuant: Unknown switch %s",s); } } if (NextArg()!=STRINGARG) HError(2519,"HQuant: Output VQ table file name expected"); vqfn = GetStrArg(); if (NextArg()!=STRINGARG) HError(2519,"HQuant: Training data file name expected"); datafn = GetStrArg(); Initialise(datafn); LoadFile(datafn); while (NumArgs()>0) { if (NextArg()!=STRINGARG) HError(2519,"HQuant: Training data file name expected"); datafn = GetStrArg(); LoadFile(datafn); } for (stream=1;stream<=swidth[0];stream++){ if (trace&T_TOP) printf("%s-clustering data for stream %d (width %d)\n", (tType==linTree)?"Flat":"Tree",stream,swidth[stream]); CalcMeanCov(dSeq,stream); ClusterVecs(dSeq,stream); } WriteVQTable(cs,vqfn); Exit(0); return (0); /* never reached -- make compiler happy */}/* Determine global mean and covariance of data in sequence s */void CalcMeanCov(Sequence seq[], int s){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -