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