annotate src/Modules/Profile/ModuleScaler.cc @ 113:9d12efd43513

- Bash scripting is rubbish.
author tomwalters
date Tue, 14 Sep 2010 01:41:19 +0000
parents c5f5e9569863
children
rev   line source
tomwalters@20 1 // Copyright 2010, Thomas Walters
tomwalters@20 2 //
tomwalters@20 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@20 4 // http://www.acousticscale.org/AIMC
tomwalters@20 5 //
tomwalters@45 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@45 7 // you may not use this file except in compliance with the License.
tomwalters@45 8 // You may obtain a copy of the License at
tomwalters@20 9 //
tomwalters@45 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@20 11 //
tomwalters@45 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@45 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@45 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@45 15 // See the License for the specific language governing permissions and
tomwalters@45 16 // limitations under the License.
tomwalters@20 17
tomwalters@20 18 /*!
tomwalters@20 19 * \author Thomas Walters <tom@acousticscale.org>
tomwalters@20 20 * \date created 2010/02/22
tomwalters@20 21 * \version \$Id$
tomwalters@20 22 */
tomwalters@20 23
tomwalters@20 24 #include "Modules/Profile/ModuleScaler.h"
tomwalters@20 25
tomwalters@20 26 namespace aimc {
tomwalters@20 27 ModuleScaler::ModuleScaler(Parameters *params) : Module(params) {
tomwalters@20 28 module_description_ = "Scale each value by the channel centre frequency";
tomwalters@20 29 module_identifier_ = "scaler";
tomwalters@20 30 module_type_ = "profile";
tomwalters@20 31 module_version_ = "$Id$";
tomwalters@20 32 }
tomwalters@20 33
tomwalters@20 34 ModuleScaler::~ModuleScaler() {
tomwalters@20 35 }
tomwalters@20 36
tomwalters@20 37 bool ModuleScaler::InitializeInternal(const SignalBank &input) {
tomwalters@20 38 // Copy the parameters of the input signal bank into internal variables, so
tomwalters@20 39 // that they can be checked later.
tomwalters@20 40 sample_rate_ = input.sample_rate();
tomwalters@20 41 buffer_length_ = input.buffer_length();
tomwalters@20 42 channel_count_ = input.channel_count();
tomwalters@20 43 output_.Initialize(channel_count_, buffer_length_, sample_rate_);
tomwalters@20 44 return true;
tomwalters@20 45 }
tomwalters@20 46
tomwalters@20 47 void ModuleScaler::ResetInternal() {
tomwalters@20 48 }
tomwalters@20 49
tomwalters@20 50 void ModuleScaler::Process(const SignalBank &input) {
tomwalters@20 51 // Check to see if the module has been initialized. If not, processing
tomwalters@20 52 // should not continue.
tomwalters@20 53 if (!initialized_) {
tomwalters@20 54 LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str());
tomwalters@20 55 return;
tomwalters@20 56 }
tomwalters@20 57
tomwalters@20 58 // Check that ths input this time is the same as the input passed to
tomwalters@20 59 // Initialize()
tomwalters@20 60 if (buffer_length_ != input.buffer_length()
tomwalters@20 61 || channel_count_ != input.channel_count()) {
tomwalters@20 62 LOG_ERROR(_T("Mismatch between input to Initialize() and input to "
tomwalters@20 63 "Process() in module %s."), module_identifier_.c_str());
tomwalters@20 64 return;
tomwalters@20 65 }
tomwalters@20 66
tomwalters@20 67 output_.set_start_time(input.start_time());
tomwalters@20 68
tomwalters@20 69 for (int ch = 0; ch < input.channel_count(); ++ch) {
tomwalters@20 70 float cf = input.centre_frequency(ch);
tomwalters@20 71 for (int i = 0; i < input.buffer_length(); ++i) {
tomwalters@20 72 output_.set_sample(ch, i, cf * input.sample(ch, i));
tomwalters@20 73 }
tomwalters@20 74 }
tomwalters@20 75 PushOutput();
tomwalters@20 76 }
tomwalters@20 77 } // namespace aimc
tomwalters@20 78