Mercurial > hg > aimc
changeset 279:f469d936337f
- Replacing tabs with spaces for indentation
author | tomwalters |
---|---|
date | Thu, 18 Feb 2010 20:04:04 +0000 |
parents | 5b8b9ea1218a |
children | e55d0c225a57 |
files | trunk/src/Modules/Input/ModuleFileInput.cc trunk/src/Modules/Input/ModuleFileInput.h trunk/src/Modules/Output/FileOutputHTK.cc trunk/src/Modules/Output/FileOutputHTK.h trunk/src/Modules/Strobes/ModuleParabola.cc trunk/src/Modules/Strobes/ModuleParabola.h |
diffstat | 6 files changed, 184 insertions(+), 185 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Modules/Input/ModuleFileInput.cc Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Input/ModuleFileInput.cc Thu Feb 18 20:04:04 2010 +0000 @@ -36,8 +36,8 @@ module_type_ = "input"; module_version_ = "$Id$"; - file_handle_ = NULL; - buffer_length_ = parameters_->DefaultInt("input.buffersize", 1024); + file_handle_ = NULL; + buffer_length_ = parameters_->DefaultInt("input.buffersize", 1024); file_position_samples_ = 0; file_loaded_ = false; @@ -47,7 +47,7 @@ ModuleFileInput::~ModuleFileInput() { if (file_handle_) - sf_close(file_handle_); + sf_close(file_handle_); } void ModuleFileInput::ResetInternal() { @@ -56,29 +56,29 @@ } bool ModuleFileInput::LoadFile(const char* filename) { - // Open the file - SF_INFO sfinfo; - memset((void*)&sfinfo, 0, sizeof(SF_INFO)); - file_handle_ = sf_open(filename, SFM_READ, &sfinfo); + // Open the file + SF_INFO sfinfo; + memset((void*)&sfinfo, 0, sizeof(SF_INFO)); + file_handle_ = sf_open(filename, SFM_READ, &sfinfo); - if (file_handle_ == NULL) { - //! \todo Also display error reason - LOG_ERROR(_T("Couldn't read audio file '%s'"), filename); - return false; - } + if (file_handle_ == NULL) { + //! \todo Also display error reason + LOG_ERROR(_T("Couldn't read audio file '%s'"), filename); + return false; + } file_loaded_ = true; audio_channels_ = sfinfo.channels; sample_rate_ = sfinfo.samplerate; - file_position_samples_ = 0; + file_position_samples_ = 0; // A dummy signal bank to be passed to the Initialize() function. SignalBank s; s.Initialize(1, 1, 1); - // Self-initialize by calling Module::Initialize() explicitly. - // The Initialize() call in this subclass is overloaded to prevent it from - // being called drectly. + // Self-initialize by calling Module::Initialize() explicitly. + // The Initialize() call in this subclass is overloaded to prevent it from + // being called drectly. return Module::Initialize(s); } @@ -109,19 +109,19 @@ return false; } ResetInternal(); - return true; + return true; } void ModuleFileInput::Process() { if (!file_loaded_) return; - sf_count_t read; + sf_count_t read; vector<float> buffer; buffer.resize(buffer_length_ * audio_channels_); while (true) { - // Read buffersize bytes into buffer - read = sf_readf_float(file_handle_, &buffer[0], buffer_length_); + // Read buffersize bytes into buffer + read = sf_readf_float(file_handle_, &buffer[0], buffer_length_); // Place the contents of the buffer into the signal bank int counter = 0; @@ -132,24 +132,23 @@ } } - // If the number of saples read is less than the buffer length, the end - // of the file has been reached. - if (read < buffer_length_) { - // Zero samples at end - for (int c = 0; c < audio_channels_; ++c) { + // If the number of saples read is less than the buffer length, the end + // of the file has been reached. + if (read < buffer_length_) { + // Zero samples at end + for (int c = 0; c < audio_channels_; ++c) { for (int i = read; i < buffer_length_; ++i) { output_.set_sample(c, i, 0.0f); } } - // When we're past the end of the buffer, stop looping. - if (read == 0) + // When we're past the end of the buffer, stop looping. + if (read == 0) break; - } + } - // Update time - output_.set_start_time(file_position_samples_); - file_position_samples_ += read; - + // Update time + output_.set_start_time(file_position_samples_); + file_position_samples_ += read; PushOutput(); } }
--- a/trunk/src/Modules/Input/ModuleFileInput.h Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Input/ModuleFileInput.h Thu Feb 18 20:04:04 2010 +0000 @@ -37,14 +37,14 @@ namespace aimc { class ModuleFileInput : public Module { public: - ModuleFileInput(Parameters *pParam); - virtual ~ModuleFileInput(); + ModuleFileInput(Parameters *pParam); + virtual ~ModuleFileInput(); - /*! \brief Initializes this input device using an audio file - * \param sFilename Path of the file to load - * \return true on success, false on error - */ - bool LoadFile(const char *sFilename); + /*! \brief Initializes this input device using an audio file + * \param sFilename Path of the file to load + * \return true on success, false on error + */ + bool LoadFile(const char *sFilename); //! \brief Process the loaded file. void Process(); @@ -52,7 +52,7 @@ //! \brief Dummy Initialize function. Call LoadFile instead. virtual bool Initialize(const SignalBank &input); - //! \brief Dummy funciton to comply with the Module specification. Gives an + //! \brief Dummy funciton to comply with the Module specification. Gives an // error message when called. virtual void Process(const SignalBank &input); @@ -65,10 +65,10 @@ //! \brief Rewind to the start of the file virtual void ResetInternal(); - //! \brief File descriptor - SNDFILE *file_handle_; + //! \brief File descriptor + SNDFILE *file_handle_; - //! \brief Current position in time of the file + //! \brief Current position in time of the file int file_position_samples_; bool file_loaded_; int audio_channels_;
--- a/trunk/src/Modules/Output/FileOutputHTK.cc Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Output/FileOutputHTK.cc Thu Feb 18 20:04:04 2010 +0000 @@ -18,19 +18,19 @@ /*! * \file - * \brief File output in the HTK format. + * \brief File output in the HTK format. * - * \author Tom Walters <tom@acousticscale.org> + * \author Tom Walters <tom@acousticscale.org> * \author Willem van Engen <cnbh@willem.engen.nl> * \date created 2006/10/30 * \version \$Id$ */ #ifdef _WINDOWS -# include <direct.h> // for _mkdir&_rmdir +# include <direct.h> // for _mkdir&_rmdir #else -# include <sys/types.h> -# include <dirent.h> // for opendir&friends +# include <sys/types.h> +# include <dirent.h> // for opendir&friends #endif #include <stdio.h> #include <string.h> @@ -45,47 +45,47 @@ module_type_ = "output"; module_version_ = "$Id$"; - file_handle_ = NULL; - header_written_ = false; + file_handle_ = NULL; + header_written_ = false; filename_[0] = '\0'; frame_period_ms_ = 0.0f; } FileOutputHTK::~FileOutputHTK() { - if (file_handle_ != NULL) - CloseFile(); + if (file_handle_ != NULL) + CloseFile(); } bool FileOutputHTK::OpenFile(const char* filename, float frame_period_ms) { - if (file_handle_ != NULL) { - LOG_ERROR(_T("Couldn't open output file. A file is already open.")); - return false; - } + if (file_handle_ != NULL) { + LOG_ERROR(_T("Couldn't open output file. A file is already open.")); + return false; + } - // Check that the output file exists and is writeable - if ((file_handle_ = fopen(filename, "wb"))==NULL ) { - LOG_ERROR(_T("Couldn't open output file '%s' for writing."), filename); - return false; - } - strcpy(filename_, filename); - sample_count_ = 0; + // Check that the output file exists and is writeable + if ((file_handle_ = fopen(filename, "wb"))==NULL ) { + LOG_ERROR(_T("Couldn't open output file '%s' for writing."), filename); + return false; + } + strcpy(filename_, filename); + sample_count_ = 0; frame_period_ms_ = frame_period_ms; header_written_ = false; - return true; + return true; } bool FileOutputHTK::InitializeInternal(const SignalBank &input) { if (file_handle_ == NULL) { LOG_ERROR(_T("Couldn't initialize file output. " "Please call FileOutputHTK::OpenFile first")); - return false; + return false; } if (header_written_) { LOG_ERROR(_T("A header has already been written on the output file." "Please call FileOutputHTK::CloseFile to close that file, " "and FileOutputHTK::OpenFile to open an new one before " "calling FileOutputHTK::Initialize again.")); - return false; + return false; } channel_count_ = input.channel_count(); buffer_length_ = input.buffer_length(); @@ -100,41 +100,41 @@ } void FileOutputHTK::WriteHeader(int num_elements, float period_ms) { - if (header_written_) - return; + if (header_written_) + return; - /* HTK format file: (taken from the HTK book - section 5.10.1) - * Header: 12 bytes in total, contains: - * sample_count - number of samples in file (4-byte integer)(long) - * sample_period - sample period in 100ns units (4-byte integer)(long) - * sample_size - number of bytes per sample (2-byte integer)(short) - * parameter_kind - a code indicating the sample kind (2-byte integer)(short) - */ + /* HTK format file: (taken from the HTK book - section 5.10.1) + * Header: 12 bytes in total, contains: + * sample_count - number of samples in file (4-byte integer)(long) + * sample_period - sample period in 100ns units (4-byte integer)(long) + * sample_size - number of bytes per sample (2-byte integer)(short) + * parameter_kind - a code indicating the sample kind (2-byte integer)(short) + */ - // To be filled in when the file is done - int32_t sample_count = 0; + // To be filled in when the file is done + int32_t sample_count = 0; int32_t sample_period = floor(1e4 * period_ms); int16_t sample_size = num_elements * sizeof(float); // User-defined coefficients with energy term - int16_t parameter_kind = H_USER + H_E; + int16_t parameter_kind = H_USER + H_E; - // Fix endianness - sample_count = ByteSwap32(sample_count); - sample_period = ByteSwap32(sample_period); - sample_size = ByteSwap16(sample_size); - parameter_kind = ByteSwap16(parameter_kind); + // Fix endianness + sample_count = ByteSwap32(sample_count); + sample_period = ByteSwap32(sample_period); + sample_size = ByteSwap16(sample_size); + parameter_kind = ByteSwap16(parameter_kind); // Enter header values. sample_count is a dummy value which is filled in on // file close - fwrite(&sample_count, sizeof(sample_count), 1, file_handle_); - fwrite(&sample_period, sizeof(sample_period), 1, file_handle_); - fwrite(&sample_size, sizeof(sample_size), 1, file_handle_); - fwrite(¶meter_kind, sizeof(parameter_kind), 1, file_handle_); - fflush(file_handle_); + fwrite(&sample_count, sizeof(sample_count), 1, file_handle_); + fwrite(&sample_period, sizeof(sample_period), 1, file_handle_); + fwrite(&sample_size, sizeof(sample_size), 1, file_handle_); + fwrite(¶meter_kind, sizeof(parameter_kind), 1, file_handle_); + fflush(file_handle_); - header_written_ = true; + header_written_ = true; } @@ -142,44 +142,44 @@ if (file_handle_ == NULL) { LOG_ERROR(_T("Couldn't process file output. No file is open." "Please call FileOutputHTK::OpenFile first")); - return; + return; } if (!header_written_) { LOG_ERROR(_T("No header has been written on the output file yet. Please" "call FileOutputHTK::Initialize() before calling " "FileOutputHTK::Process()")); - return; + return; } - float s; + float s; - for (int ch = 0; ch < input.channel_count(); ch++) { + for (int ch = 0; ch < input.channel_count(); ch++) { for (int i = 0; i < input.buffer_length(); i++) { s = input.sample(ch, i); s = ByteSwapFloat(s); fwrite(&s, sizeof(float), 1, file_handle_); } } - sample_count_++; + sample_count_++; } bool FileOutputHTK::CloseFile() { - if (file_handle_ == NULL) + if (file_handle_ == NULL) return false; - // Write the first 4 bytes of the file - // with how many samples there are in the file - fflush(file_handle_); - rewind(file_handle_); - fflush(file_handle_); + // Write the first 4 bytes of the file + // with how many samples there are in the file + fflush(file_handle_); + rewind(file_handle_); + fflush(file_handle_); int32_t samples = sample_count_; - samples = ByteSwap32(samples); - fwrite(&samples, sizeof(samples), 1, file_handle_); + samples = ByteSwap32(samples); + fwrite(&samples, sizeof(samples), 1, file_handle_); - // And close the file - fclose(file_handle_); - file_handle_ = NULL; - return true; + // And close the file + fclose(file_handle_); + file_handle_ = NULL; + return true; } float FileOutputHTK::ByteSwapFloat(float d) {
--- a/trunk/src/Modules/Output/FileOutputHTK.h Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Output/FileOutputHTK.h Thu Feb 18 20:04:04 2010 +0000 @@ -17,19 +17,19 @@ // Defines taken from HTKwrite.c and The HTK Book -#define H_WAVEFORM 0 //sampled waveform -#define H_LPC 1 //linear prediction filter coefficients -#define H_LPREFC 2 //linear prediction reflection coefficients -#define H_LPCEPSTRA 3 //LPC cepstral coefficients -#define H_LPDELCEP 4 //LPC cepstra plus delta coefficients -#define H_IREFC 5 //LPC reflection coef in 16 bit integer format -#define H_MFCC 6 //mel-frequency cepstral coefficients -#define H_FBANK 7 //log mel-filter bank channel outputs -#define H_MELSPEC 8 //linear mel-filter bank channel outputs -#define H_USER 9 //user defined sample kind -#define H_DISCRETE 10 //vector quantised data -#define H_PLP 11 // Perceptual Linear Prediction -#define H_ANON 12 +#define H_WAVEFORM 0 //sampled waveform +#define H_LPC 1 //linear prediction filter coefficients +#define H_LPREFC 2 //linear prediction reflection coefficients +#define H_LPCEPSTRA 3 //LPC cepstral coefficients +#define H_LPDELCEP 4 //LPC cepstra plus delta coefficients +#define H_IREFC 5 //LPC reflection coef in 16 bit integer format +#define H_MFCC 6 //mel-frequency cepstral coefficients +#define H_FBANK 7 //log mel-filter bank channel outputs +#define H_MELSPEC 8 //linear mel-filter bank channel outputs +#define H_USER 9 //user defined sample kind +#define H_DISCRETE 10 //vector quantised data +#define H_PLP 11 // Perceptual Linear Prediction +#define H_ANON 12 #define H_E 64 //has energy #define H_N 128 //absolute energy suppressed @@ -63,38 +63,38 @@ namespace aimc { class FileOutputHTK : public Module { public: - /*! \brief Create a new file output for an HTK format file. Use of this - * class only really makes sense for the output of 1-D frames. - */ - FileOutputHTK(Parameters *pParam); - ~FileOutputHTK(); + /*! \brief Create a new file output for an HTK format file. Use of this + * class only really makes sense for the output of 1-D frames. + */ + FileOutputHTK(Parameters *pParam); + ~FileOutputHTK(); - /*! \brief Initialize the output to HTK. - * \param *filename Filename of the ouptut file to be created. - * If the file exists it will be overwritten - * \return Returns true on success of initialization. - */ - bool OpenFile(const char *filename, float frame_period_ms); + /*! \brief Initialize the output to HTK. + * \param *filename Filename of the ouptut file to be created. + * If the file exists it will be overwritten + * \return Returns true on success of initialization. + */ + bool OpenFile(const char *filename, float frame_period_ms); bool CloseFile(); virtual void Process(const SignalBank &input); -protected: + private: virtual bool InitializeInternal(const SignalBank &input); virtual void ResetInternal(); float ByteSwapFloat(float d); - void WriteHeader(int nelements, float sampPeriod); + void WriteHeader(int nelements, float sampPeriod); - //! \brief Whether initialization is done or not - bool header_written_; + //! \brief Whether initialization is done or not + bool header_written_; - //! \brief Filename - char filename_[PATH_MAX]; - //! \brief Internal pointer to the output file - FILE *file_handle_; + //! \brief Filename + char filename_[PATH_MAX]; + //! \brief Internal pointer to the output file + FILE *file_handle_; - //! \brief Count of the number of samples in the file, written on close - int sample_count_; + //! \brief Count of the number of samples in the file, written on close + int sample_count_; int channel_count_; int buffer_length_;
--- a/trunk/src/Modules/Strobes/ModuleParabola.cc Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Strobes/ModuleParabola.cc Thu Feb 18 20:04:04 2010 +0000 @@ -105,38 +105,38 @@ // Copy input signal to output signal output_.set_sample(ch, i, input.sample(ch, i)); - if (curr_sample_[ch] >= threshold_[ch]) { - threshold_[ch] = curr_sample_[ch]; - if (prev_sample_[ch] < curr_sample_[ch] - && next_sample_[ch] < curr_sample_[ch]) { - // We have a strobe: set threshold and add strobe to the list - output_.AddStrobe(ch, i - 1); - last_threshold_[ch] = threshold_[ch]; - parab_var_samples_[ch] = - floor(input.sample_rate() - * (parab_wnull_[ch] - (threshold_[ch] - - 2.0f * parab_a_[ch] *parab_b_[ch]) - / (2.0f * parab_a_[ch]))); - } + if (curr_sample_[ch] >= threshold_[ch]) { + threshold_[ch] = curr_sample_[ch]; + if (prev_sample_[ch] < curr_sample_[ch] + && next_sample_[ch] < curr_sample_[ch]) { + // We have a strobe: set threshold and add strobe to the list + output_.AddStrobe(ch, i - 1); + last_threshold_[ch] = threshold_[ch]; + parab_var_samples_[ch] = + floor(input.sample_rate() + * (parab_wnull_[ch] - (threshold_[ch] + - 2.0f * parab_a_[ch] *parab_b_[ch]) + / (2.0f * parab_a_[ch]))); + } } - if (output_.strobe_count(ch) > 0) { + if (output_.strobe_count(ch) > 0) { samples_since_last_strobe_[ch] = (i - 1) - output_.strobe(ch, output_.strobe_count(ch) - 1); } else { - samples_since_last_strobe_[ch] = UINT_MAX; + samples_since_last_strobe_[ch] = UINT_MAX; } - if (samples_since_last_strobe_[ch] > parab_var_samples_[ch]) { - decay_constant = last_threshold_[ch] / strobe_decay_samples_; - if (threshold_[ch] > decay_constant) - threshold_[ch] -= decay_constant; - else - threshold_[ch] = 0.0f; + if (samples_since_last_strobe_[ch] > parab_var_samples_[ch]) { + decay_constant = last_threshold_[ch] / strobe_decay_samples_; + if (threshold_[ch] > decay_constant) + threshold_[ch] -= decay_constant; + else + threshold_[ch] = 0.0f; } else { - threshold_[ch] = last_threshold_[ch] - * (parab_a_[ch] * pow((samples_since_last_strobe_[ch] - / input.sample_rate() + parab_b_[ch]), - 2.0f) + height_); + threshold_[ch] = last_threshold_[ch] + * (parab_a_[ch] * pow((samples_since_last_strobe_[ch] + / input.sample_rate() + parab_b_[ch]), + 2.0f) + height_); } } }
--- a/trunk/src/Modules/Strobes/ModuleParabola.h Thu Feb 18 19:35:07 2010 +0000 +++ b/trunk/src/Modules/Strobes/ModuleParabola.h Thu Feb 18 20:04:04 2010 +0000 @@ -42,33 +42,33 @@ using std::vector; class ModuleParabola : public Module { public: - ModuleParabola(Parameters *params); - virtual ~ModuleParabola(); - void Process(const SignalBank& input); + ModuleParabola(Parameters *params); + virtual ~ModuleParabola(); + void Process(const SignalBank& input); private: /*! \brief Prepare the module - * \param input Input signal bank - * \param output true on success false on failure - */ - virtual bool InitializeInternal(const SignalBank& input); + * \param input Input signal bank + * \param output true on success false on failure + */ + virtual bool InitializeInternal(const SignalBank& input); - virtual void ResetInternal(); + virtual void ResetInternal(); - //! \brief Number of samples over which the strobe should be decayed to zero - int strobe_decay_samples_; + //! \brief Number of samples over which the strobe should be decayed to zero + int strobe_decay_samples_; - /*! \brief Current strobe thresholds, one for each bank channel. - * - * This value is decayed over time. - */ - vector<float> threshold_; + /*! \brief Current strobe thresholds, one for each bank channel. + * + * This value is decayed over time. + */ + vector<float> threshold_; - /*! \brief Signal value at the last strobe, one for each bank channel. - * - * This value is not decayed over time. - */ - vector<float> last_threshold_; + /*! \brief Signal value at the last strobe, one for each bank channel. + * + * This value is not decayed over time. + */ + vector<float> last_threshold_; //! \brief Parabola height parameter float height_;