tomwalters@0
|
1 // Copyright 2010, Thomas Walters
|
tomwalters@0
|
2 //
|
tomwalters@0
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@0
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@0
|
5 //
|
tomwalters@0
|
6 // This program is free software: you can redistribute it and/or modify
|
tomwalters@0
|
7 // it under the terms of the GNU General Public License as published by
|
tomwalters@0
|
8 // the Free Software Foundation, either version 3 of the License, or
|
tomwalters@0
|
9 // (at your option) any later version.
|
tomwalters@0
|
10 //
|
tomwalters@0
|
11 // This program is distributed in the hope that it will be useful,
|
tomwalters@0
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
tomwalters@0
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
tomwalters@0
|
14 // GNU General Public License for more details.
|
tomwalters@0
|
15 //
|
tomwalters@0
|
16 // You should have received a copy of the GNU General Public License
|
tomwalters@0
|
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
tomwalters@0
|
18
|
tomwalters@0
|
19 /*! \file
|
tomwalters@0
|
20 * \brief Base class for all AIM-C modules.
|
tomwalters@0
|
21 */
|
tomwalters@0
|
22
|
tomwalters@0
|
23 /*! The module construcor is called with a pointer to a set of Parameters.
|
tomwalters@0
|
24 * In the constructor, the module sets the defaults for its various
|
tomwalters@0
|
25 * parameters.
|
tomwalters@0
|
26 * A module is initialized with a pointer to a valid SignalBank
|
tomwalters@0
|
27 * (source modules can be initialized with the NULL pointer). After the
|
tomwalters@0
|
28 * Initialize(SignalBank*) function has been called, a call to GetOutputBank()
|
tomwalters@0
|
29 * returns a pointer to a SignalBank in which the results
|
tomwalters@0
|
30 * of the module's processing will be placed. Modules can use the output_
|
tomwalters@0
|
31 * SignalBank to store their output, or leave it uninitialized if they do not
|
tomwalters@0
|
32 * produce an output.
|
tomwalters@0
|
33 * At each call to Process(input), the module takes the
|
tomwalters@0
|
34 * SignalBank 'input' (which must, unless otherwise specified, have the same
|
tomwalters@0
|
35 * number of channels, sample rate, buffer size and centre frequencies as the
|
tomwalters@0
|
36 * SignalBank which was passed to Initialize()), processes it, and places the
|
tomwalters@0
|
37 * output in the internal SignalBank output_.
|
tomwalters@0
|
38 * Modules can have an arbitrary number of unique targets. Each
|
tomwalters@0
|
39 * completed output frame is 'pushed' to all of the targets of the module
|
tomwalters@0
|
40 * in turn when PushOutput() is called. To achieve this, after each complete
|
tomwalters@0
|
41 * output SignalBank is filled, the module calls the Process() function of
|
tomwalters@0
|
42 * each of its targets in turn.
|
tomwalters@0
|
43 * When Initialize() is first called. The module Initialize()s all of its
|
tomwalters@0
|
44 * targets with its ouptut_ SignalBank, if it's output bank has been set up.
|
tomwalters@0
|
45 */
|
tomwalters@0
|
46
|
tomwalters@0
|
47 /*! \author: Thomas Walters <tom@acousticscale.org>
|
tomwalters@0
|
48 * \date 2010/01/23
|
tomwalters@0
|
49 * \version \$Id: Module.h 4 2010-02-03 18:44:58Z tcw $
|
tomwalters@0
|
50 */
|
tomwalters@0
|
51
|
tomwalters@0
|
52 #ifndef _AIMC_SUPPORT_MODULE_H_
|
tomwalters@0
|
53 #define _AIMC_SUPPORT_MODULE_H_
|
tomwalters@0
|
54
|
tomwalters@0
|
55 #include <set>
|
tomwalters@0
|
56 #include <string>
|
tomwalters@0
|
57
|
tomwalters@0
|
58 #include "Support/Common.h"
|
tomwalters@0
|
59 #include "Support/Parameters.h"
|
tomwalters@0
|
60 #include "Support/SignalBank.h"
|
tomwalters@0
|
61
|
tomwalters@0
|
62 namespace aimc {
|
tomwalters@0
|
63 using std::set;
|
tomwalters@0
|
64 using std::string;
|
tomwalters@0
|
65 class Module {
|
tomwalters@0
|
66 public:
|
tomwalters@0
|
67 explicit Module(Parameters *parameters);
|
tomwalters@0
|
68
|
tomwalters@0
|
69 virtual ~Module();
|
tomwalters@0
|
70
|
tomwalters@0
|
71 /* \brief Validate this module's output SignalBank, and initialize
|
tomwalters@0
|
72 * any targets of the module if necessary.
|
tomwalters@0
|
73 * \param input Input SignalBank.
|
tomwalters@0
|
74 * \param output true on success, false on failure.
|
tomwalters@0
|
75 */
|
tomwalters@0
|
76 bool Initialize(const SignalBank &input);
|
tomwalters@0
|
77
|
tomwalters@0
|
78 /*! \brief
|
tomwalters@0
|
79 */
|
tomwalters@0
|
80 bool initialized() const;
|
tomwalters@0
|
81
|
tomwalters@0
|
82 /* \brief Add a target to this module. Whenever it generates a new
|
tomwalters@0
|
83 * output, this module will push its output to all its targets.
|
tomwalters@0
|
84 * \param input Target module to add.
|
tomwalters@0
|
85 * \param output true on success, false on failure.
|
tomwalters@0
|
86 */
|
tomwalters@0
|
87 bool AddTarget(Module* target_module);
|
tomwalters@0
|
88
|
tomwalters@0
|
89 /*! \brief
|
tomwalters@0
|
90 */
|
tomwalters@0
|
91 bool DeleteTarget(Module* target_module);
|
tomwalters@0
|
92
|
tomwalters@0
|
93 /*! \brief
|
tomwalters@0
|
94 */
|
tomwalters@0
|
95 void DeleteAllTargets();
|
tomwalters@0
|
96
|
tomwalters@0
|
97 /*! \brief Process a buffer
|
tomwalters@0
|
98 */
|
tomwalters@0
|
99 virtual void Process(const SignalBank &input) = 0;
|
tomwalters@0
|
100
|
tomwalters@0
|
101 /*! \brief Reset the internal state of the module to that when it was
|
tomwalters@0
|
102 * initialised
|
tomwalters@0
|
103 */
|
tomwalters@0
|
104 virtual void Reset() = 0;
|
tomwalters@0
|
105
|
tomwalters@0
|
106 /*! \brief
|
tomwalters@0
|
107 */
|
tomwalters@0
|
108 const SignalBank* GetOutputBank() const;
|
tomwalters@0
|
109
|
tomwalters@0
|
110 protected:
|
tomwalters@0
|
111 void PushOutput();
|
tomwalters@0
|
112
|
tomwalters@0
|
113 virtual bool InitializeInternal(const SignalBank &input) = 0;
|
tomwalters@0
|
114
|
tomwalters@0
|
115 bool initialized_;
|
tomwalters@0
|
116 set<Module*> targets_;
|
tomwalters@0
|
117 SignalBank output_;
|
tomwalters@0
|
118 Parameters* parameters_;
|
tomwalters@0
|
119
|
tomwalters@0
|
120 string module_identifier_;
|
tomwalters@0
|
121 string module_type_;
|
tomwalters@0
|
122 string module_description_;
|
tomwalters@0
|
123 string module_version_;
|
tomwalters@0
|
124
|
tomwalters@0
|
125 private:
|
tomwalters@0
|
126 DISALLOW_COPY_AND_ASSIGN(Module);
|
tomwalters@0
|
127 };
|
tomwalters@0
|
128 }
|
tomwalters@0
|
129
|
tomwalters@0
|
130 #endif // _AIMC_SUPPORT_MODULE_H_
|