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@318: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: // you may not use this file except in compliance with the License. tomwalters@318: // You may obtain a copy of the License at tomwalters@292: // tomwalters@318: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@292: // tomwalters@318: // Unless required by applicable law or agreed to in writing, software tomwalters@318: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: // See the License for the specific language governing permissions and tomwalters@318: // limitations under the License. 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: