annotate trunk/src/Modules/Profile/ModuleScaler.cc @ 311:02cea9301d84

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