# HG changeset patch # User tomwalters # Date 1266584874 0 # Node ID fb52ca0e633976cdc18978c18e30303e95bc6b98 # Parent ef14c9f2c1d2b6116f2a9170788b5789b0711dec -Profile module for taking slices of an SAI or SSI (or anything else for that matter) -Stub SSI module - not yet complete -Fixes to the module template diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/SConstruct --- a/trunk/SConstruct Fri Feb 19 12:15:56 2010 +0000 +++ b/trunk/SConstruct Fri Feb 19 13:07:54 2010 +0000 @@ -102,6 +102,8 @@ 'Modules/NAP/ModuleHCL.cc', 'Modules/Strobes/ModuleParabola.cc', 'Modules/SAI/ModuleSAI.cc', + 'Modules/SSI/ModuleSSI.cc', + 'Modules/Profile/ModuleSlice.cc', 'Modules/Features/ModuleGaussians.cc', 'Modules/Output/FileOutputHTK.cc'] diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/doc/ModuleTemplate.cc --- a/trunk/doc/ModuleTemplate.cc Fri Feb 19 12:15:56 2010 +0000 +++ b/trunk/doc/ModuleTemplate.cc Fri Feb 19 13:07:54 2010 +0000 @@ -40,7 +40,7 @@ // returned. // Examples: // integer_param_ = parameters_->DefaultInt("module.param_name", 4); - // boolean_param_ = parameters_->DefaultBool("module.param_name", True); + // boolean_param_ = parameters_->DefaultBool("module.param_name", true); // float_param_ = parameters_->DefaultFloat("module.param_name", 4.4f); } @@ -71,7 +71,7 @@ // Check to see if the module has been initialized. If not, processing // should not continue. if (!initialized_) { - LOG_ERROR(_T("Module #MODULE_NAME# not initialized.")); + LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str()); return; } @@ -80,7 +80,7 @@ if (buffer_length_ != input.buffer_length() || channel_count_ != input.channel_count()) { LOG_ERROR(_T("Mismatch between input to Initialize() and input to " - "Process() in module %s", module_identifier_)); + "Process() in module %s."), module_identifier_.c_str()); return; } diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/src/Modules/Profile/ModuleSlice.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/Profile/ModuleSlice.cc Fri Feb 19 13:07:54 2010 +0000 @@ -0,0 +1,139 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/*! + * \author Thomas Walters + * \date created 2010/02/19 + * \version \$Id$ + */ + +#include "Modules/Profile/ModuleSlice.h" + +namespace aimc { +ModuleSlice::ModuleSlice(Parameters *params) : Module(params) { + module_description_ = "Temporal or spectral slice of a 2D image"; + module_identifier_ = "slice"; + module_type_ = "profile"; + module_version_ = "$Id$"; + + // This module will compute the spectral profile unless told otherwise here + temporal_profile_ = parameters_->DefaultBool("slice.temporal", false); + // Set slice.all to true to take the profile of the entire image + take_all_ = parameters_->DefaultBool("slice.all", true); + // If not taking all, then these give the lower and upper indices of the + // section to take. They are bounds-checked. + lower_limit_ = parameters_->DefaultInt("slice.lower_index", 0); + upper_limit_ = parameters_->DefaultInt("slice.upper_index", 1000); + // Set to true to normalize the slice taken (ie take the mean value) + normalize_slice_ = parameters_->DefaultBool("slice.normalize", false); +} + +ModuleSlice::~ModuleSlice() { +} + +bool ModuleSlice::InitializeInternal(const SignalBank &input) { + // Copy the parameters of the input signal bank into internal variables, so + // that they can be checked later. + sample_rate_ = input.sample_rate(); + buffer_length_ = input.buffer_length(); + channel_count_ = input.channel_count(); + + if (lower_limit_ < 0) { + lower_limit_ = 0; + } + + if (upper_limit_ < 0) { + upper_limit_ = 0; + } + + if (temporal_profile_) { + if (upper_limit_ > channel_count_) { + upper_limit_ = channel_count_; + } + if (lower_limit_ > channel_count_) { + lower_limit_ = channel_count_; + } + } else { + if (upper_limit_ > buffer_length_) { + upper_limit_ = buffer_length_; + } + if (lower_limit_ > buffer_length_) { + lower_limit_ = buffer_length_; + } + } + + slice_length_ = upper_limit_ - lower_limit_; + if (slice_length_ < 1) { + slice_length_ = 1; + } + + if (temporal_profile_) { + output_.Initialize(1, buffer_length_, sample_rate_); + } else { + output_.Initialize(channel_count_, 1, sample_rate_); + } + return true; +} + +void ModuleSlice::ResetInternal() { +} + +void ModuleSlice::Process(const SignalBank &input) { + // Check to see if the module has been initialized. If not, processing + // should not continue. + if (!initialized_) { + LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str()); + return; + } + + // Check that ths input this time is the same as the input passed to + // Initialize() + if (buffer_length_ != input.buffer_length() + || channel_count_ != input.channel_count()) { + LOG_ERROR(_T("Mismatch between input to Initialize() and input to " + "Process() in module %s."), module_identifier_.c_str()); + return; + } + + if (temporal_profile_) { + for (int i = 0; i < input.buffer_length(); ++i) { + float val = 0.0f; + for (int ch = lower_limit_; ch < upper_limit_; ++ch) { + val += input.sample(ch, i); + } + if (normalize_slice_) { + val /= static_cast(slice_length_); + } + output_.set_sample(0, i, val); + } + } else { + for (int ch = 0; ch < input.channel_count(); ++ch) { + float val = 0.0f; + for (int i = lower_limit_; i < upper_limit_; ++i) { + val += input.sample(ch, i); + } + if (normalize_slice_) { + val /= static_cast(slice_length_); + } + output_.set_sample(ch, 0, val); + } + } + PushOutput(); +} +} // namespace aimc + diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/src/Modules/Profile/ModuleSlice.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/Profile/ModuleSlice.h Fri Feb 19 13:07:54 2010 +0000 @@ -0,0 +1,65 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/*! + * \author Thomas Walters + * \date created 2010/02/19 + * \version \$Id$ + */ + +#ifndef AIMC_MODULES_PROFILE_SLICE_H_ +#define AIMC_MODULES_PROFILE_SLICE_H_ + +#include "Support/Module.h" + +namespace aimc { +using std::vector; +class ModuleSlice : public Module { + public: + explicit ModuleSlice(Parameters *pParam); + virtual ~ModuleSlice(); + + /*! \brief Process a buffer + */ + virtual void Process(const SignalBank &input); + + private: + /*! \brief Reset the internal state of the module + */ + virtual void ResetInternal(); + + /*! \brief Prepare the module + * \param input Input signal + * \param output true on success false on failure + */ + virtual bool InitializeInternal(const SignalBank &input); + + float sample_rate_; + int buffer_length_; + int channel_count_; + + bool temporal_profile_; + bool take_all_; + int lower_limit_; + int upper_limit_; + bool normalize_slice_; + int slice_length_; +}; +} // namespace aimc + +#endif // AIMC_MODULES_PROFILE_SLICE_H_ diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/src/Modules/SSI/ModuleSSI.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/SSI/ModuleSSI.cc Fri Feb 19 13:07:54 2010 +0000 @@ -0,0 +1,87 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/*! + * \author Thomas Walters + * \date created 2010/02/19 + * \version \$Id$ + */ + +#include "Modules/SSI/ModuleSSI.h" + +namespace aimc { +ModuleSSI::ModuleSSI(Parameters *params) : Module(params) { + module_description_ = "Size-shape image (aka the 'sscAI')"; + module_identifier_ = "ssi"; + module_type_ = "ssi"; + module_version_ = "$Id$"; + + do_pitch_cutoff_ = parameters_->DefaultBool("ssi.pitch_cutoff", false); +} + +ModuleSSI::~ModuleSSI() { +} + +bool ModuleSSI::InitializeInternal(const SignalBank &input) { + // Copy the parameters of the input signal bank into internal variables, so + // that they can be checked later. + sample_rate_ = input.sample_rate(); + buffer_length_ = input.buffer_length(); + channel_count_ = input.channel_count(); + + // If this module produces any output, then the output signal bank needs to + // be initialized here. + // Example: + // output_.Initialize(channel_count, buffer_length, sample_rate); + return true; +} + +void ModuleSSI::ResetInternal() { + // Reset any internal state variables to their default values here. After a + // call to ResetInternal(), the module should be in the same state as it is + // just after a call to InitializeInternal(). +} + +void ModuleSSI::Process(const SignalBank &input) { + // Check to see if the module has been initialized. If not, processing + // should not continue. + if (!initialized_) { + LOG_ERROR(_T("Module ModuleSSI not initialized.")); + return; + } + + // Check that ths input this time is the same as the input passed to + // Initialize() + if (buffer_length_ != input.buffer_length() + || channel_count_ != input.channel_count()) { + LOG_ERROR(_T("Mismatch between input to Initialize() and input to " + "Process() in module %s"), module_identifier_.c_str()); + return; + } + + // Input is read from the input signal bank using calls like + // float value = input_.sample(channel_number, sample_index); + + // Output is fed into the output signal bank (assuming that it was + // initialized during the call to InitializeInternal()) like this: + // output_.set_sample(channel_number, sample_index, sample_value); + + PushOutput(); +} +} // namespace aimc + diff -r ef14c9f2c1d2 -r fb52ca0e6339 trunk/src/Modules/SSI/ModuleSSI.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/SSI/ModuleSSI.h Fri Feb 19 13:07:54 2010 +0000 @@ -0,0 +1,60 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/*! + * \author Thomas Walters + * \date created 2010/02/19 + * \version \$Id$ + */ + +#ifndef AIMC_MODULES_SSI_SSI_H_ +#define AIMC_MODULES_SSI_SSI_H_ + +#include "Support/Module.h" + +namespace aimc { +using std::vector; +class ModuleSSI : public Module { + public: + explicit ModuleSSI(Parameters *pParam); + virtual ~ModuleSSI(); + + /*! \brief Process a buffer + */ + virtual void Process(const SignalBank &input); + + private: + /*! \brief Reset the internal state of the module + */ + virtual void ResetInternal(); + + /*! \brief Prepare the module + * \param input Input signal + * \param output true on success false on failure + */ + virtual bool InitializeInternal(const SignalBank &input); + + float sample_rate_; + int buffer_length_; + int channel_count_; + + bool do_pitch_cutoff_; +}; +} // namespace aimc + +#endif // AIMC_MODULES_SSI_SSI_H_