comparison src/Support/Module.h @ 0:582cbe817f2c

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