tomwalters@280: // Copyright 2006-2010, Thomas Walters, Willem van Engen tomwalters@280: // tomwalters@280: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@280: // http://www.acousticscale.org/AIMC tomwalters@280: // tomwalters@318: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: // you may not use this file except in compliance with the License. tomwalters@318: // You may obtain a copy of the License at tomwalters@280: // tomwalters@318: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@280: // tomwalters@318: // Unless required by applicable law or agreed to in writing, software tomwalters@318: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: // See the License for the specific language governing permissions and tomwalters@318: // limitations under the License. tomwalters@280: tomwalters@277: /*! tomwalters@277: * \file tomwalters@281: * \brief File output to HTK format tomwalters@277: * tomwalters@283: * \author Thomas Walters tomwalters@280: * \author Willem van Engen tomwalters@277: * \date created 2006/10/30 tomwalters@277: * \version \$Header$ tomwalters@277: */ tomwalters@280: tomwalters@283: #ifndef AIMC_MODULES_OUTPUT_HTK_H_ tomwalters@283: #define AIMC_MODULES_OUTPUT_HTK_H_ tomwalters@277: tomwalters@402: #include tomwalters@402: tomwalters@277: #include "Support/Module.h" tomwalters@277: #include "Support/SignalBank.h" tomwalters@277: tomwalters@402: // Defines from HTKwrite.c and The HTK Book tomwalters@280: #define H_WAVEFORM 0 // sampled waveform tomwalters@280: #define H_LPC 1 // linear prediction filter coefficients tomwalters@280: #define H_LPREFC 2 // linear prediction reflection coefficients tomwalters@280: #define H_LPCEPSTRA 3 // LPC cepstral coefficients tomwalters@280: #define H_LPDELCEP 4 // LPC cepstra plus delta coefficients tomwalters@280: #define H_IREFC 5 // LPC reflection coef in 16 bit integer format tomwalters@280: #define H_MFCC 6 // mel-frequency cepstral coefficients tomwalters@280: #define H_FBANK 7 // log mel-filter bank channel outputs tomwalters@280: #define H_MELSPEC 8 // linear mel-filter bank channel outputs tomwalters@280: #define H_USER 9 // user defined sample kind tomwalters@280: #define H_DISCRETE 10 // vector quantised data tomwalters@280: #define H_PLP 11 // Perceptual Linear Prediction tomwalters@280: #define H_ANON 12 // Anonymous tomwalters@277: tomwalters@280: #define H_E 64 // has energy tomwalters@280: #define H_N 128 // absolute energy suppressed tomwalters@280: #define H_D 256 // has delta coefficients tomwalters@280: #define H_A 512 // has acceleration coefficients tomwalters@280: #define H_C 1024 // is compressed tomwalters@280: #define H_Z 2048 // has zero mean static coef. tomwalters@280: #define H_K 4096 // has CRC checksum tomwalters@280: #define H_O 8192 // has 0th cepstral coef. tomwalters@280: #define H_V 16384 // Attach vq index tomwalters@280: #define H_T 32768 // Attach delta-delta-delta index tomwalters@277: tomwalters@277: // HTK fomat is big-endian... tomwalters@277: #define ByteSwap16(n) \ tomwalters@277: ( ((((uint16_t) n) << 8) & 0xFF00) | \ tomwalters@277: ((((uint16_t) n) >> 8) & 0x00FF) ) tomwalters@277: tomwalters@277: #define ByteSwap32(n) \ tomwalters@277: ( ((((uint32_t) n) << 24) & 0xFF000000) | \ tomwalters@277: ((((uint32_t) n) << 8) & 0x00FF0000) | \ tomwalters@277: ((((uint32_t) n) >> 8) & 0x0000FF00) | \ tomwalters@277: ((((uint32_t) n) >> 24) & 0x000000FF) ) tomwalters@277: tomwalters@277: namespace aimc { tomwalters@402: using std::string; tomwalters@277: class FileOutputHTK : public Module { tomwalters@277: public: tomwalters@279: /*! \brief Create a new file output for an HTK format file. Use of this tomwalters@279: * class only really makes sense for the output of 1-D frames. tomwalters@279: */ tomwalters@280: explicit FileOutputHTK(Parameters *pParam); tomwalters@279: ~FileOutputHTK(); tomwalters@277: tomwalters@279: /*! \brief Initialize the output to HTK. tomwalters@279: * \param *filename Filename of the ouptut file to be created. tomwalters@279: * If the file exists it will be overwritten tomwalters@279: * \return Returns true on success of initialization. tomwalters@279: */ tomwalters@277: bool CloseFile(); tomwalters@277: virtual void Process(const SignalBank &input); tomwalters@279: private: tomwalters@277: virtual bool InitializeInternal(const SignalBank &input); tomwalters@277: virtual void ResetInternal(); tomwalters@277: tomwalters@277: float ByteSwapFloat(float d); tomwalters@277: tom@421: void WriteHeader(int nelements); tomwalters@277: tomwalters@280: /*! \brief Whether initialization is done or not tomwalters@280: */ tomwalters@279: bool header_written_; tomwalters@277: tomwalters@280: /*! \brief Internal pointer to the output file tomwalters@280: */ tomwalters@279: FILE *file_handle_; tomwalters@277: tomwalters@280: /*! \brief Count of the number of samples in the file, written on close tomwalters@280: */ tomwalters@279: int sample_count_; tomwalters@402: string file_suffix_; tomwalters@277: tomwalters@277: int channel_count_; tomwalters@277: int buffer_length_; tomwalters@277: float frame_period_ms_; tomwalters@402: int previous_start_time_; tomwalters@277: }; tomwalters@277: } // namespace aimc tomwalters@277: tomwalters@283: #endif // AIMC_MODULES_OUTPUT_HTK_H_ tomwalters@277: