tomwalters@292: // Copyright 2010, Thomas Walters tomwalters@292: // tomwalters@292: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@292: // http://www.acousticscale.org/AIMC tomwalters@292: // tomwalters@292: // This program is free software: you can redistribute it and/or modify tomwalters@292: // it under the terms of the GNU General Public License as published by tomwalters@292: // the Free Software Foundation, either version 3 of the License, or tomwalters@292: // (at your option) any later version. tomwalters@292: // tomwalters@292: // This program is distributed in the hope that it will be useful, tomwalters@292: // but WITHOUT ANY WARRANTY; without even the implied warranty of tomwalters@292: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tomwalters@292: // GNU General Public License for more details. tomwalters@292: // tomwalters@292: // You should have received a copy of the GNU General Public License tomwalters@292: // along with this program. If not, see . tomwalters@292: tomwalters@292: /*! tomwalters@292: * \author Thomas Walters tomwalters@292: * \date created 2010/02/22 tomwalters@292: * \version \$Id$ tomwalters@292: */ tomwalters@292: tomwalters@292: #include "Modules/Profile/ModuleScaler.h" tomwalters@292: tomwalters@292: namespace aimc { tomwalters@292: ModuleScaler::ModuleScaler(Parameters *params) : Module(params) { tomwalters@292: module_description_ = "Scale each value by the channel centre frequency"; tomwalters@292: module_identifier_ = "scaler"; tomwalters@292: module_type_ = "profile"; tomwalters@292: module_version_ = "$Id$"; tomwalters@292: } tomwalters@292: tomwalters@292: ModuleScaler::~ModuleScaler() { tomwalters@292: } tomwalters@292: tomwalters@292: bool ModuleScaler::InitializeInternal(const SignalBank &input) { tomwalters@292: // Copy the parameters of the input signal bank into internal variables, so tomwalters@292: // that they can be checked later. tomwalters@292: sample_rate_ = input.sample_rate(); tomwalters@292: buffer_length_ = input.buffer_length(); tomwalters@292: channel_count_ = input.channel_count(); tomwalters@292: output_.Initialize(channel_count_, buffer_length_, sample_rate_); tomwalters@292: return true; tomwalters@292: } tomwalters@292: tomwalters@292: void ModuleScaler::ResetInternal() { tomwalters@292: } tomwalters@292: tomwalters@292: void ModuleScaler::Process(const SignalBank &input) { tomwalters@292: // Check to see if the module has been initialized. If not, processing tomwalters@292: // should not continue. tomwalters@292: if (!initialized_) { tomwalters@292: LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str()); tomwalters@292: return; tomwalters@292: } tomwalters@292: tomwalters@292: // Check that ths input this time is the same as the input passed to tomwalters@292: // Initialize() tomwalters@292: if (buffer_length_ != input.buffer_length() tomwalters@292: || channel_count_ != input.channel_count()) { tomwalters@292: LOG_ERROR(_T("Mismatch between input to Initialize() and input to " tomwalters@292: "Process() in module %s."), module_identifier_.c_str()); tomwalters@292: return; tomwalters@292: } tomwalters@292: tomwalters@292: output_.set_start_time(input.start_time()); tomwalters@292: tomwalters@292: for (int ch = 0; ch < input.channel_count(); ++ch) { tomwalters@292: float cf = input.centre_frequency(ch); tomwalters@292: for (int i = 0; i < input.buffer_length(); ++i) { tomwalters@292: output_.set_sample(ch, i, cf * input.sample(ch, i)); tomwalters@292: } tomwalters@292: } tomwalters@292: PushOutput(); tomwalters@292: } tomwalters@292: } // namespace aimc tomwalters@292: