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