annotate src/Modules/Profile/ModuleScaler.cc @ 20:fff25824d1d1

-Added a module to scale output values by the channel centre frequency -Fixed file input to support loading and processing of multiple files -Updated the aimc main file to generate profiles like in the recognition experiments
author tomwalters
date Mon, 22 Feb 2010 17:51:27 +0000
parents
children c5f5e9569863
rev   line source
tomwalters@20 1 // Copyright 2010, Thomas Walters
tomwalters@20 2 //
tomwalters@20 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@20 4 // http://www.acousticscale.org/AIMC
tomwalters@20 5 //
tomwalters@20 6 // This program is free software: you can redistribute it and/or modify
tomwalters@20 7 // it under the terms of the GNU General Public License as published by
tomwalters@20 8 // the Free Software Foundation, either version 3 of the License, or
tomwalters@20 9 // (at your option) any later version.
tomwalters@20 10 //
tomwalters@20 11 // This program is distributed in the hope that it will be useful,
tomwalters@20 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@20 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@20 14 // GNU General Public License for more details.
tomwalters@20 15 //
tomwalters@20 16 // You should have received a copy of the GNU General Public License
tomwalters@20 17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@20 18
tomwalters@20 19 /*!
tomwalters@20 20 * \author Thomas Walters <tom@acousticscale.org>
tomwalters@20 21 * \date created 2010/02/22
tomwalters@20 22 * \version \$Id$
tomwalters@20 23 */
tomwalters@20 24
tomwalters@20 25 #include "Modules/Profile/ModuleScaler.h"
tomwalters@20 26
tomwalters@20 27 namespace aimc {
tomwalters@20 28 ModuleScaler::ModuleScaler(Parameters *params) : Module(params) {
tomwalters@20 29 module_description_ = "Scale each value by the channel centre frequency";
tomwalters@20 30 module_identifier_ = "scaler";
tomwalters@20 31 module_type_ = "profile";
tomwalters@20 32 module_version_ = "$Id$";
tomwalters@20 33 }
tomwalters@20 34
tomwalters@20 35 ModuleScaler::~ModuleScaler() {
tomwalters@20 36 }
tomwalters@20 37
tomwalters@20 38 bool ModuleScaler::InitializeInternal(const SignalBank &input) {
tomwalters@20 39 // Copy the parameters of the input signal bank into internal variables, so
tomwalters@20 40 // that they can be checked later.
tomwalters@20 41 sample_rate_ = input.sample_rate();
tomwalters@20 42 buffer_length_ = input.buffer_length();
tomwalters@20 43 channel_count_ = input.channel_count();
tomwalters@20 44 output_.Initialize(channel_count_, buffer_length_, sample_rate_);
tomwalters@20 45 return true;
tomwalters@20 46 }
tomwalters@20 47
tomwalters@20 48 void ModuleScaler::ResetInternal() {
tomwalters@20 49 }
tomwalters@20 50
tomwalters@20 51 void ModuleScaler::Process(const SignalBank &input) {
tomwalters@20 52 // Check to see if the module has been initialized. If not, processing
tomwalters@20 53 // should not continue.
tomwalters@20 54 if (!initialized_) {
tomwalters@20 55 LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str());
tomwalters@20 56 return;
tomwalters@20 57 }
tomwalters@20 58
tomwalters@20 59 // Check that ths input this time is the same as the input passed to
tomwalters@20 60 // Initialize()
tomwalters@20 61 if (buffer_length_ != input.buffer_length()
tomwalters@20 62 || channel_count_ != input.channel_count()) {
tomwalters@20 63 LOG_ERROR(_T("Mismatch between input to Initialize() and input to "
tomwalters@20 64 "Process() in module %s."), module_identifier_.c_str());
tomwalters@20 65 return;
tomwalters@20 66 }
tomwalters@20 67
tomwalters@20 68 output_.set_start_time(input.start_time());
tomwalters@20 69
tomwalters@20 70 for (int ch = 0; ch < input.channel_count(); ++ch) {
tomwalters@20 71 float cf = input.centre_frequency(ch);
tomwalters@20 72 for (int i = 0; i < input.buffer_length(); ++i) {
tomwalters@20 73 output_.set_sample(ch, i, cf * input.sample(ch, i));
tomwalters@20 74 }
tomwalters@20 75 }
tomwalters@20 76 PushOutput();
tomwalters@20 77 }
tomwalters@20 78 } // namespace aimc
tomwalters@20 79