tomwalters@283
|
1 // Copyright #YEAR#, #AUTHOR_NAME#
|
tomwalters@283
|
2 //
|
tomwalters@283
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@283
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@283
|
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@283
|
9 //
|
tomwalters@318
|
10 // http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@283
|
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@283
|
17
|
tomwalters@283
|
18 /*!
|
tomwalters@283
|
19 * \author #AUTHOR_NAME# <#AUTHOR_EMAIL_ADDRESS#>
|
tomwalters@283
|
20 * \date created #TODAYS_DATE#
|
tomwalters@283
|
21 * \version \$Id$
|
tomwalters@283
|
22 */
|
tomwalters@283
|
23
|
tomwalters@283
|
24 #include "Modules/#MODULE_TYPE#/#MODULE_NAME#.h"
|
tomwalters@283
|
25
|
tomwalters@283
|
26 namespace aimc {
|
tomwalters@283
|
27 #MODULE_NAME#::#MODULE_NAME#(Parameters *params) : Module(params) {
|
tomwalters@283
|
28 module_description_ = "TODO: Short Description of the module";
|
tomwalters@283
|
29 module_identifier_ = "TODO: one-word id for the module";
|
tomwalters@283
|
30 module_type_ = "TODO: type code eg. bmm, sai";
|
tomwalters@283
|
31 module_version_ = "$Id$";
|
tomwalters@283
|
32
|
tomwalters@283
|
33 // Read parameter values from the parameter store. Setting any default
|
tomwalters@283
|
34 // values as necessary. The module should set defaults for all parameters
|
tomwalters@283
|
35 // that is uses here. The parameters_->DefaultType() methods look for a
|
tomwalters@283
|
36 // parameter with a given name. If it already exists in the parameter
|
tomwalters@283
|
37 // store, they return the current value. If the parameter doesn't already
|
tomwalters@283
|
38 // exist, it is added, set to the default value given, and that value is
|
tomwalters@283
|
39 // returned.
|
tomwalters@283
|
40 // Examples:
|
tomwalters@283
|
41 // integer_param_ = parameters_->DefaultInt("module.param_name", 4);
|
tomwalters@284
|
42 // boolean_param_ = parameters_->DefaultBool("module.param_name", true);
|
tomwalters@283
|
43 // float_param_ = parameters_->DefaultFloat("module.param_name", 4.4f);
|
tomwalters@283
|
44 }
|
tomwalters@283
|
45
|
tomwalters@283
|
46 #MODULE_NAME#::~#MODULE_NAME#() {
|
tomwalters@283
|
47 }
|
tomwalters@283
|
48
|
tomwalters@283
|
49 bool #MODULE_NAME#::InitializeInternal(const SignalBank &input) {
|
tomwalters@283
|
50 // Copy the parameters of the input signal bank into internal variables, so
|
tomwalters@283
|
51 // that they can be checked later.
|
tomwalters@283
|
52 sample_rate_ = input.sample_rate();
|
tomwalters@283
|
53 buffer_length_ = input.buffer_length();
|
tomwalters@283
|
54 channel_count_ = input.channel_count();
|
tomwalters@283
|
55
|
tomwalters@283
|
56 // If this module produces any output, then the output signal bank needs to
|
tomwalters@283
|
57 // be initialized here.
|
tomwalters@283
|
58 // Example:
|
tomwalters@283
|
59 // output_.Initialize(channel_count, buffer_length, sample_rate);
|
tomwalters@283
|
60 return true;
|
tomwalters@283
|
61 }
|
tomwalters@283
|
62
|
tomwalters@283
|
63 void #MODULE_NAME#::ResetInternal() {
|
tomwalters@283
|
64 // Reset any internal state variables to their default values here. After a
|
tomwalters@283
|
65 // call to ResetInternal(), the module should be in the same state as it is
|
tomwalters@283
|
66 // just after a call to InitializeInternal().
|
tomwalters@283
|
67 }
|
tomwalters@283
|
68
|
tomwalters@283
|
69 void #MODULE_NAME#::Process(const SignalBank &input) {
|
tomwalters@283
|
70 // Check to see if the module has been initialized. If not, processing
|
tomwalters@283
|
71 // should not continue.
|
tomwalters@283
|
72 if (!initialized_) {
|
tomwalters@284
|
73 LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str());
|
tomwalters@283
|
74 return;
|
tomwalters@283
|
75 }
|
tomwalters@283
|
76
|
tomwalters@283
|
77 // Check that ths input this time is the same as the input passed to
|
tomwalters@283
|
78 // Initialize()
|
tomwalters@283
|
79 if (buffer_length_ != input.buffer_length()
|
tomwalters@283
|
80 || channel_count_ != input.channel_count()) {
|
tomwalters@283
|
81 LOG_ERROR(_T("Mismatch between input to Initialize() and input to "
|
tomwalters@284
|
82 "Process() in module %s."), module_identifier_.c_str());
|
tomwalters@283
|
83 return;
|
tomwalters@283
|
84 }
|
tomwalters@283
|
85
|
tomwalters@283
|
86 // Input is read from the input signal bank using calls like
|
tomwalters@283
|
87 // float value = input_.sample(channel_number, sample_index);
|
tomwalters@283
|
88
|
tomwalters@283
|
89 // Output is fed into the output signal bank (assuming that it was
|
tomwalters@283
|
90 // initialized during the call to InitializeInternal()) like this:
|
tomwalters@283
|
91 // output_.set_sample(channel_number, sample_index, sample_value);
|
tomwalters@283
|
92
|
tomwalters@283
|
93 // If the output bank is set up, a call to PushOutput() will pass the output
|
tomwalters@283
|
94 // on to all the target modules of this module. PushOutput() can be called
|
tomwalters@283
|
95 // multiple times within each call to Process().
|
tomwalters@283
|
96 // Example:
|
tomwalters@283
|
97 // PushOutput();
|
tomwalters@283
|
98 }
|
tomwalters@283
|
99 } // namespace aimc
|
tomwalters@283
|
100
|