annotate trunk/src/Modules/Output/FileOutputHTK.h @ 279:f469d936337f

- Replacing tabs with spaces for indentation
author tomwalters
date Thu, 18 Feb 2010 20:04:04 +0000
parents 6b4921704eb1
children e55d0c225a57
rev   line source
tomwalters@277 1 /*!
tomwalters@277 2 * \file
tomwalters@277 3 * \brief File output to HTK format class definition
tomwalters@277 4 *
tomwalters@277 5 * \author Tom Walters <tcw24@cam.ac.uk> and Willem van Engen <cnbh@willem.engen.nl>
tomwalters@277 6 * \date created 2006/10/30
tomwalters@277 7 * \version \$Header$
tomwalters@277 8 */
tomwalters@277 9 /* (c) 2006, University of Cambridge, Medical Research Council
tomwalters@277 10 * http://www.pdn.cam.ac.uk/groups/cnbh/aimmanual
tomwalters@277 11 */
tomwalters@277 12 #ifndef _AIMC_MODULE_OUTPUT_HTK_H_
tomwalters@277 13 #define _AIMC_MODULE_OUTPUT_HTK_H_
tomwalters@277 14
tomwalters@277 15 #include "Support/Module.h"
tomwalters@277 16 #include "Support/SignalBank.h"
tomwalters@277 17
tomwalters@277 18
tomwalters@277 19 // Defines taken from HTKwrite.c and The HTK Book
tomwalters@279 20 #define H_WAVEFORM 0 //sampled waveform
tomwalters@279 21 #define H_LPC 1 //linear prediction filter coefficients
tomwalters@279 22 #define H_LPREFC 2 //linear prediction reflection coefficients
tomwalters@279 23 #define H_LPCEPSTRA 3 //LPC cepstral coefficients
tomwalters@279 24 #define H_LPDELCEP 4 //LPC cepstra plus delta coefficients
tomwalters@279 25 #define H_IREFC 5 //LPC reflection coef in 16 bit integer format
tomwalters@279 26 #define H_MFCC 6 //mel-frequency cepstral coefficients
tomwalters@279 27 #define H_FBANK 7 //log mel-filter bank channel outputs
tomwalters@279 28 #define H_MELSPEC 8 //linear mel-filter bank channel outputs
tomwalters@279 29 #define H_USER 9 //user defined sample kind
tomwalters@279 30 #define H_DISCRETE 10 //vector quantised data
tomwalters@279 31 #define H_PLP 11 // Perceptual Linear Prediction
tomwalters@279 32 #define H_ANON 12
tomwalters@277 33
tomwalters@277 34 #define H_E 64 //has energy
tomwalters@277 35 #define H_N 128 //absolute energy suppressed
tomwalters@277 36 #define H_D 256 //has delta coefficients
tomwalters@277 37 #define H_A 512 //has acceleration coefficients
tomwalters@277 38 #define H_C 1024 //is compressed
tomwalters@277 39 #define H_Z 2048 //has zero mean static coef.
tomwalters@277 40 #define H_K 4096 //has CRC checksum
tomwalters@277 41 #define H_O 8192 //has 0th cepstral coef.
tomwalters@277 42 #define H_V 16384 // Attach vq index
tomwalters@277 43 #define H_T 32768 // Attach delta-delta-delta index
tomwalters@277 44
tomwalters@277 45 // HTK fomat is big-endian...
tomwalters@277 46 #define ByteSwap16(n) \
tomwalters@277 47 ( ((((uint16_t) n) << 8) & 0xFF00) | \
tomwalters@277 48 ((((uint16_t) n) >> 8) & 0x00FF) )
tomwalters@277 49
tomwalters@277 50 #define ByteSwap32(n) \
tomwalters@277 51 ( ((((uint32_t) n) << 24) & 0xFF000000) | \
tomwalters@277 52 ((((uint32_t) n) << 8) & 0x00FF0000) | \
tomwalters@277 53 ((((uint32_t) n) >> 8) & 0x0000FF00) | \
tomwalters@277 54 ((((uint32_t) n) >> 24) & 0x000000FF) )
tomwalters@277 55
tomwalters@277 56 /*!
tomwalters@277 57 * \class FileOutputHTK "Output/FileOutputHTK.h"
tomwalters@277 58 * \brief File output to HTK class
tomwalters@277 59 *
tomwalters@277 60 * This class gives a method for saving either a signal or a profile to HTK format.
tomwalters@277 61 * \sa Signal, SignalBank
tomwalters@277 62 */
tomwalters@277 63 namespace aimc {
tomwalters@277 64 class FileOutputHTK : public Module {
tomwalters@277 65 public:
tomwalters@279 66 /*! \brief Create a new file output for an HTK format file. Use of this
tomwalters@279 67 * class only really makes sense for the output of 1-D frames.
tomwalters@279 68 */
tomwalters@279 69 FileOutputHTK(Parameters *pParam);
tomwalters@279 70 ~FileOutputHTK();
tomwalters@277 71
tomwalters@279 72 /*! \brief Initialize the output to HTK.
tomwalters@279 73 * \param *filename Filename of the ouptut file to be created.
tomwalters@279 74 * If the file exists it will be overwritten
tomwalters@279 75 * \return Returns true on success of initialization.
tomwalters@279 76 */
tomwalters@279 77 bool OpenFile(const char *filename, float frame_period_ms);
tomwalters@277 78 bool CloseFile();
tomwalters@277 79 virtual void Process(const SignalBank &input);
tomwalters@279 80 private:
tomwalters@277 81 virtual bool InitializeInternal(const SignalBank &input);
tomwalters@277 82 virtual void ResetInternal();
tomwalters@277 83
tomwalters@277 84 float ByteSwapFloat(float d);
tomwalters@277 85
tomwalters@279 86 void WriteHeader(int nelements, float sampPeriod);
tomwalters@277 87
tomwalters@279 88 //! \brief Whether initialization is done or not
tomwalters@279 89 bool header_written_;
tomwalters@277 90
tomwalters@279 91 //! \brief Filename
tomwalters@279 92 char filename_[PATH_MAX];
tomwalters@279 93 //! \brief Internal pointer to the output file
tomwalters@279 94 FILE *file_handle_;
tomwalters@277 95
tomwalters@279 96 //! \brief Count of the number of samples in the file, written on close
tomwalters@279 97 int sample_count_;
tomwalters@277 98
tomwalters@277 99 int channel_count_;
tomwalters@277 100 int buffer_length_;
tomwalters@277 101 float frame_period_ms_;
tomwalters@277 102 };
tomwalters@277 103 } // namespace aimc
tomwalters@277 104
tomwalters@277 105 #endif // _AIMC_MODULE_OUTPUT_HTK_H_
tomwalters@277 106