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