tomwalters@280
|
1 // Copyright 2006-2010, Thomas Walters, Willem van Engen
|
tomwalters@280
|
2 //
|
tomwalters@280
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@280
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@280
|
5 //
|
tomwalters@280
|
6 // This program is free software: you can redistribute it and/or modify
|
tomwalters@280
|
7 // it under the terms of the GNU General Public License as published by
|
tomwalters@280
|
8 // the Free Software Foundation, either version 3 of the License, or
|
tomwalters@280
|
9 // (at your option) any later version.
|
tomwalters@280
|
10 //
|
tomwalters@280
|
11 // This program is distributed in the hope that it will be useful,
|
tomwalters@280
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
tomwalters@280
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
tomwalters@280
|
14 // GNU General Public License for more details.
|
tomwalters@280
|
15 //
|
tomwalters@280
|
16 // You should have received a copy of the GNU General Public License
|
tomwalters@280
|
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
tomwalters@280
|
18
|
tomwalters@277
|
19 /*!
|
tomwalters@277
|
20 * \file
|
tomwalters@281
|
21 * \brief File output to HTK format
|
tomwalters@277
|
22 *
|
tomwalters@283
|
23 * \author Thomas Walters <tom@acousticscale.org>
|
tomwalters@280
|
24 * \author Willem van Engen <cnbh@willem.engen.nl>
|
tomwalters@277
|
25 * \date created 2006/10/30
|
tomwalters@277
|
26 * \version \$Header$
|
tomwalters@277
|
27 */
|
tomwalters@280
|
28
|
tomwalters@283
|
29 #ifndef AIMC_MODULES_OUTPUT_HTK_H_
|
tomwalters@283
|
30 #define AIMC_MODULES_OUTPUT_HTK_H_
|
tomwalters@277
|
31
|
tomwalters@277
|
32 #include "Support/Module.h"
|
tomwalters@277
|
33 #include "Support/SignalBank.h"
|
tomwalters@277
|
34
|
tomwalters@280
|
35 // Defines taken from HTKwrite.c and The HTK Book
|
tomwalters@280
|
36 #define H_WAVEFORM 0 // sampled waveform
|
tomwalters@280
|
37 #define H_LPC 1 // linear prediction filter coefficients
|
tomwalters@280
|
38 #define H_LPREFC 2 // linear prediction reflection coefficients
|
tomwalters@280
|
39 #define H_LPCEPSTRA 3 // LPC cepstral coefficients
|
tomwalters@280
|
40 #define H_LPDELCEP 4 // LPC cepstra plus delta coefficients
|
tomwalters@280
|
41 #define H_IREFC 5 // LPC reflection coef in 16 bit integer format
|
tomwalters@280
|
42 #define H_MFCC 6 // mel-frequency cepstral coefficients
|
tomwalters@280
|
43 #define H_FBANK 7 // log mel-filter bank channel outputs
|
tomwalters@280
|
44 #define H_MELSPEC 8 // linear mel-filter bank channel outputs
|
tomwalters@280
|
45 #define H_USER 9 // user defined sample kind
|
tomwalters@280
|
46 #define H_DISCRETE 10 // vector quantised data
|
tomwalters@280
|
47 #define H_PLP 11 // Perceptual Linear Prediction
|
tomwalters@280
|
48 #define H_ANON 12 // Anonymous
|
tomwalters@277
|
49
|
tomwalters@280
|
50 #define H_E 64 // has energy
|
tomwalters@280
|
51 #define H_N 128 // absolute energy suppressed
|
tomwalters@280
|
52 #define H_D 256 // has delta coefficients
|
tomwalters@280
|
53 #define H_A 512 // has acceleration coefficients
|
tomwalters@280
|
54 #define H_C 1024 // is compressed
|
tomwalters@280
|
55 #define H_Z 2048 // has zero mean static coef.
|
tomwalters@280
|
56 #define H_K 4096 // has CRC checksum
|
tomwalters@280
|
57 #define H_O 8192 // has 0th cepstral coef.
|
tomwalters@280
|
58 #define H_V 16384 // Attach vq index
|
tomwalters@280
|
59 #define H_T 32768 // Attach delta-delta-delta index
|
tomwalters@277
|
60
|
tomwalters@277
|
61 // HTK fomat is big-endian...
|
tomwalters@277
|
62 #define ByteSwap16(n) \
|
tomwalters@277
|
63 ( ((((uint16_t) n) << 8) & 0xFF00) | \
|
tomwalters@277
|
64 ((((uint16_t) n) >> 8) & 0x00FF) )
|
tomwalters@277
|
65
|
tomwalters@277
|
66 #define ByteSwap32(n) \
|
tomwalters@277
|
67 ( ((((uint32_t) n) << 24) & 0xFF000000) | \
|
tomwalters@277
|
68 ((((uint32_t) n) << 8) & 0x00FF0000) | \
|
tomwalters@277
|
69 ((((uint32_t) n) >> 8) & 0x0000FF00) | \
|
tomwalters@277
|
70 ((((uint32_t) n) >> 24) & 0x000000FF) )
|
tomwalters@277
|
71
|
tomwalters@277
|
72 namespace aimc {
|
tomwalters@277
|
73 class FileOutputHTK : public Module {
|
tomwalters@277
|
74 public:
|
tomwalters@279
|
75 /*! \brief Create a new file output for an HTK format file. Use of this
|
tomwalters@279
|
76 * class only really makes sense for the output of 1-D frames.
|
tomwalters@279
|
77 */
|
tomwalters@280
|
78 explicit FileOutputHTK(Parameters *pParam);
|
tomwalters@279
|
79 ~FileOutputHTK();
|
tomwalters@277
|
80
|
tomwalters@279
|
81 /*! \brief Initialize the output to HTK.
|
tomwalters@279
|
82 * \param *filename Filename of the ouptut file to be created.
|
tomwalters@279
|
83 * If the file exists it will be overwritten
|
tomwalters@279
|
84 * \return Returns true on success of initialization.
|
tomwalters@279
|
85 */
|
tomwalters@279
|
86 bool OpenFile(const char *filename, float frame_period_ms);
|
tomwalters@277
|
87 bool CloseFile();
|
tomwalters@277
|
88 virtual void Process(const SignalBank &input);
|
tomwalters@279
|
89 private:
|
tomwalters@277
|
90 virtual bool InitializeInternal(const SignalBank &input);
|
tomwalters@277
|
91 virtual void ResetInternal();
|
tomwalters@277
|
92
|
tomwalters@277
|
93 float ByteSwapFloat(float d);
|
tomwalters@277
|
94
|
tomwalters@279
|
95 void WriteHeader(int nelements, float sampPeriod);
|
tomwalters@277
|
96
|
tomwalters@280
|
97 /*! \brief Whether initialization is done or not
|
tomwalters@280
|
98 */
|
tomwalters@279
|
99 bool header_written_;
|
tomwalters@277
|
100
|
tomwalters@280
|
101 /*! \brief Filename
|
tomwalters@280
|
102 */
|
tomwalters@279
|
103 char filename_[PATH_MAX];
|
tomwalters@280
|
104
|
tomwalters@280
|
105 /*! \brief Internal pointer to the output file
|
tomwalters@280
|
106 */
|
tomwalters@279
|
107 FILE *file_handle_;
|
tomwalters@277
|
108
|
tomwalters@280
|
109 /*! \brief Count of the number of samples in the file, written on close
|
tomwalters@280
|
110 */
|
tomwalters@279
|
111 int sample_count_;
|
tomwalters@277
|
112
|
tomwalters@277
|
113 int channel_count_;
|
tomwalters@277
|
114 int buffer_length_;
|
tomwalters@277
|
115 float frame_period_ms_;
|
tomwalters@277
|
116 };
|
tomwalters@277
|
117 } // namespace aimc
|
tomwalters@277
|
118
|
tomwalters@283
|
119 #endif // AIMC_MODULES_OUTPUT_HTK_H_
|
tomwalters@277
|
120
|