comparison trunk/src/Modules/Output/FileOutputHTK.h @ 277:6b4921704eb1

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