/* ----------------------------------------------------------- */
/* */
/* ___ */
/* |_| | |_/ 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 */
/* */
/* 2001-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: HParm.c: Speech Parameter File Input/Output */
/* ----------------------------------------------------------- */
char *hparm_version = "!HVER!HParm: 3.4 [CUED 25/04/06]";
char *hparm_vc_id = "$Id: HParm.c,v 1.1.1.1 2006/10/11 09:54:58 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"
#include "esignal.h"
#ifdef UNIX
#include <sys/ioctl.h>
#endif
/* ----------------------------- Trace Flags ------------------------- */
static int trace = 0;
#define T_TOP 0001 /* Top Level tracing */
#define T_BUF 0002 /* Buffer operations */
#define T_CPX 0004 /* Compression/Decompression */
#define T_PBS 0010 /* Buffer status */
#define T_QUA 0020 /* Qualifier operations */
#define T_OBS 0040 /* Observation extraction */
#define T_DET 0100 /* Silence detector operation */
#define T_MAT 0200 /* Matrix operations */
/* --------------------- Global Variables ------------------- */
static bool natWriteOrder = FALSE; /* Preserve natural write byte order*/
extern bool vaxOrder; /* true if byteswapping needed to
preserve SUNSO */
/* varScale stuff: acts as a cache to stop the scaling file being re-read
on each file opening */
static float varScale[100];
static int varScaleDim=0;
static char varScaleFN[MAXFNAMELEN] = "\0";
static bool highDiff = FALSE; /* compute higher oder differentials, only up to fourth */
static bool UseOldXFormCVN = FALSE; /* this allows us to go back to the old version with broken CVN */
static ParmKind ForcePKind = ANON; /* force to output a customized parm kind to make older versions
happy for all the parm kind types supported here */
static HMMSet *hset = NULL; /* hmmset to be used for frontend */
/* ------------------------------------------------------------------- */
/*
Parameter layout in tables/buffers is
Static [C0] [E] Deltas Accs
_N option is ignored everywhere except when copying from buffer
or table into an observation (ie in ExtractObservation) and in
GetBufferInfo() which returns the observation vector size in
tgtvecSize taking into account _N.
When _0 is used alone it behaves exactly like _E. When _0_E,
C0 is placed immediately before energy and in this case deltas
are not allowed.
*/
/* ----------------- Configuration Information ----------------- */
/*
An IOConfig record specifies the mapping from the source
to the target parameterisation. Its built in defaults
can be overridden using configuration parameters.
*/
typedef enum { FFTbased, LPCbased, VQbased} CodeStyle;
typedef struct {
/* ------- Overrideable parameters ------- */
ParmKind srcPK; /* Source ParmKind */
FileFormat srcFF; /* Source File format */
HTime srcSampRate; /* Source Sample Rate */
bool zMeanSrc; /* Zero Mean the Source */
ParmKind tgtPK; /* Target ParmKind */
FileFormat tgtFF; /* Target File format */
HTime tgtSampRate; /* Target Sample Rate */
bool saveCompressed; /* If LPREFC save as IREFC else _C */
bool saveWithCRC; /* Append check sum on save */
HTime winDur; /* Source window duration */
bool useHam; /* Use Hamming Window */
float preEmph; /* PreEmphasis Coef */
bool usePower; /* Use power instead of Magnitude */
int numChans; /* Number of filter bank channels */
float loFBankFreq; /* Fbank lo frequency cut-off */
float hiFBankFreq; /* Fbank hi frequency cut-off */
float warpFreq; /* Warp freq axis for vocal tract normalisation */
float warpLowerCutOff; /* lower and upper threshold frequencies */
float warpUpperCutOff; /* for linear frequency warping */
int lpcOrder; /* Order of lpc analysis */
float compressFact; /* Compression factor for PLP */
int cepLifter; /* Cepstral liftering coef */
int numCepCoef; /* Number of cepstral coef */
float cepScale; /* Scaling factor to avoid arithmetic problems */
bool rawEnergy; /* Use raw energy before preEmp and ham */
bool eNormalise; /* Normalise log energy */
float eScale; /* Energy scale factor */
float silFloor; /* Silence floor in dBs */
int delWin; /* Delta window halfsize */
int accWin; /* Accel window halfsize */
bool simpleDiffs; /* Use simple differences for delta calcs */
/* Silence detector parameters */
bool useSilDet; /* Use Silence Detector */
int selfCalSilDet; /* Self calibrating silence detection */
float spThresh; /* Speech Threshold (in dB above sil level) */
float silDiscard; /* Calibrate discard level */
float silMean; /* Mean silence energy (in dB) */
int spcSeqCount; /* Number of frames for speech window */
int spcGlchCount; /* of spc in sil acceptable as glitches */
int silGlchCount; /* of sil in spc acceptable as glitches */
int silSeqCount; /* of silence before stopping */
int marginCount; /* of sil around speech to process */
bool measureSil; /* Measure Silence */
bool outSilWarn; /* Give Warning when SilMeas */
/* Misc */
int audSignal; /* Signal Number for Audio Control */
bool v1Compat; /* V1 compatibility mode */
char *vqTabFN; /* Name of