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