annotate src/Modules/Output/FileOutputHTK.h @ 25:e361baf69120

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