annotate src/Support/Module.h @ 11:bd370910aa05

-Added modules template -Changed header guard style to be more consistent with the Google style guide -Added Doyxfile to generate doxygen documentation -Added structure diagram -Updated swig script to reflect new modules -Changes Gaussians back to using floats and changed tolerance on tests - doubles are unnecessary here
author tomwalters
date Fri, 19 Feb 2010 12:15:56 +0000
parents 3078854c634a
children 491b1b1d1dc5
rev   line source
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 /*! \author: Thomas Walters <tom@acousticscale.org>
tomwalters@0 24 * \date 2010/01/23
tomwalters@0 25 * \version \$Id: Module.h 4 2010-02-03 18:44:58Z tcw $
tomwalters@0 26 */
tomwalters@0 27
tomwalters@11 28 #ifndef AIMC_SUPPORT_MODULE_H_
tomwalters@11 29 #define AIMC_SUPPORT_MODULE_H_
tomwalters@0 30
tomwalters@0 31 #include <set>
tomwalters@0 32 #include <string>
tomwalters@0 33
tomwalters@0 34 #include "Support/Common.h"
tomwalters@0 35 #include "Support/Parameters.h"
tomwalters@0 36 #include "Support/SignalBank.h"
tomwalters@0 37
tomwalters@0 38 namespace aimc {
tomwalters@0 39 using std::set;
tomwalters@0 40 using std::string;
tomwalters@9 41
tomwalters@9 42 /*! \brief Base class for all AIM-C modules.
tomwalters@9 43 *
tomwalters@9 44 * Module() is a base class, from which all AIM-C modules are derived.
tomwalters@9 45 * Classes deriving from module need to implement, at minimum, the pure
tomwalters@9 46 * virtual public function Module::Process() and the pure virtual private
tomwalters@9 47 * functions Module::InitializeInternal() and Module::ResetInternal().
tomwalters@9 48 * (Note: this is in contravention of
tomwalters@9 49 * <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Inheritance#Inheritance">
tomwalters@9 50 * this rule on inheritance</a> in the Google style guide, but it is designed
tomwalters@9 51 * to make the implementation of modules as simple as possible.)
tomwalters@9 52 *
tomwalters@9 53 * The module constructor is called with a pointer to a set of Parameters.
tomwalters@9 54 * In the constructor, the module sets the defaults for its various
tomwalters@9 55 * parameters.
tomwalters@9 56 * A module is initialized with a reference to a valid SignalBank. After the
tomwalters@9 57 * Initialize(SignalBank*) function has been called, a call to GetOutputBank()
tomwalters@9 58 * returns a pointer to a SignalBank in which the results
tomwalters@9 59 * of the module's processing will be placed. Modules can use the output_
tomwalters@9 60 * SignalBank to store their output, or leave it uninitialized if they do not
tomwalters@9 61 * produce an output.
tomwalters@9 62 * At each call to Process(input), the module takes the
tomwalters@9 63 * SignalBank 'input' (which must, unless otherwise specified, have the same
tomwalters@9 64 * number of channels, sample rate, buffer size and centre frequencies as the
tomwalters@9 65 * SignalBank which was passed to Initialize()), processes it, and places the
tomwalters@9 66 * output in the internal SignalBank output_.
tomwalters@9 67 * Modules can have an arbitrary number of unique targets. Each
tomwalters@9 68 * completed output frame is 'pushed' to all of the targets of the module
tomwalters@9 69 * in turn when PushOutput() is called. To achieve this, after each complete
tomwalters@9 70 * output SignalBank is filled, the module calls the Process() function of
tomwalters@9 71 * each of its targets in turn.
tomwalters@9 72 * When Initialize() is first called. The module Initialize()s all of its
tomwalters@9 73 * targets with its ouptut_ SignalBank, if its output bank has been set up.
tomwalters@9 74 *
tomwalters@9 75 */
tomwalters@0 76 class Module {
tomwalters@0 77 public:
tomwalters@0 78 explicit Module(Parameters *parameters);
tomwalters@0 79
tomwalters@0 80 virtual ~Module();
tomwalters@0 81
tomwalters@9 82 /* \brief Initialize the module, including calling InitializeInternal().
tomwalters@9 83 * Validate this module's output SignalBank, and initialize
tomwalters@0 84 * any targets of the module if necessary.
tomwalters@0 85 * \param input Input SignalBank.
tomwalters@9 86 * \return true on success, false on failure.
tomwalters@3 87 *
tomwalters@9 88 * A call to Initialize() will first validate the input SignalBank passed to
tomwalters@9 89 * it. If this SignalBank is valid, then it will call the
tomwalters@9 90 * InitializeInternal() function of the child class; this will set up the
tomwalters@9 91 * child class, and may, if the module produces an output, initialize the
tomwalters@9 92 * member variable SignalBank output_. If output_ is initialized after the
tomwalters@9 93 * call to InitializeInternal(), the module will Initialize its targets with
tomwalters@9 94 * the output. In this way, it is possible to initialize an entire module
tomwalters@9 95 * tree with a single call to the Initialize() function of the root.
tomwalters@9 96 *
tomwalters@9 97 * This function is declared virtual in order to deal with the edge case of
tomwalters@9 98 * input modules which do not take a SignalBank as input, but rather
tomwalters@9 99 * generate their own input. In this case, it is better to be able to
tomwalters@9 100 * override the default Initialize function. When creating a new module, do
tomwalters@9 101 * not create a new version of Initialize uness you're sure you know what
tomwalters@9 102 * you're doing!
tomwalters@0 103 */
tomwalters@3 104 virtual bool Initialize(const SignalBank &input);
tomwalters@0 105
tomwalters@9 106 /*! \brief Returns true if the module has been correctly initialized
tomwalters@9 107 * \return true if module has been initialized, false otherwise
tomwalters@0 108 */
tomwalters@0 109 bool initialized() const;
tomwalters@0 110
tomwalters@0 111 /* \brief Add a target to this module. Whenever it generates a new
tomwalters@0 112 * output, this module will push its output to all its targets.
tomwalters@9 113 * \param target_module Pointer to a target Module to add.
tomwalters@9 114 * \return true on success, false on failure.
tomwalters@9 115 *
tomwalters@9 116 * When a pointer is passed as a target to the module, the caller retains
tomwalters@9 117 * ownership of the module that it points to. The pointed-to module must
tomwalters@9 118 * continue to exist until it is deleted from the target list by a call
tomwalters@9 119 * to DeleteTarget() or DeleteAllTargets(), or the current module is
tomwalters@9 120 * destroyed. Bad things will happen if the Module pointed to is deleted
tomwalters@9 121 * and Initialize(), Reset() or Process() is subsequently called.
tomwalters@0 122 */
tomwalters@0 123 bool AddTarget(Module* target_module);
tomwalters@0 124
tomwalters@9 125 /*! \brief Remove a previously added target module from the list of targets
tomwalters@9 126 * for this module.
tomwalters@9 127 * \param target_module Pointer to the module to remove. This must be a
tomwalters@9 128 * pointer that was previously passed to AddTarget()
tomwalters@9 129 * \return true on success, false on failure.
tomwalters@0 130 */
tomwalters@9 131 bool RemoveTarget(Module* target_module);
tomwalters@0 132
tomwalters@9 133 /*! \brief Remove all previously added target modules from the list of
tomwalters@9 134 * targets for this module.
tomwalters@0 135 */
tomwalters@9 136 void RemoveAllTargets();
tomwalters@0 137
tomwalters@9 138 /*! \brief Process a buffer.
tomwalters@9 139 * \param input SignalBank of the form which was passed to Initialize()
tomwalters@9 140 *
tomwalters@9 141 * Process is called once for each input SignalBank. When implemented in
tomwalters@9 142 * classes inheriting from aimc::Module, P
tomwalters@9 143 * this SignalBank contains the (read-only) input to the module. It is
tomwalters@9 144 * expected that the input SignalBank will have the same number of channels,
tomwalters@9 145 * buffer length and sample rate as the SignalBank passed to Initialize.
tomwalters@0 146 */
tomwalters@0 147 virtual void Process(const SignalBank &input) = 0;
tomwalters@0 148
tomwalters@3 149 /*! \brief Reset the internal state of this module and all its children to
tomwalters@3 150 * their initial state.
tomwalters@9 151 *
tomwalters@9 152 * Like a call to Initialize() will cause all target modules to be
tomwalters@9 153 * initialized, a call to Reset() will cause all target modules to be reset.
tomwalters@0 154 */
tomwalters@8 155 void Reset();
tomwalters@0 156
tomwalters@9 157 /*! \brief Return a pointer to the output SignalBank_ for this class.
tomwalters@9 158 * \return pointer to the SignalBank that this module uses to store its
tomwalters@9 159 * output.
tomwalters@0 160 */
tomwalters@0 161 const SignalBank* GetOutputBank() const;
tomwalters@0 162
tomwalters@0 163 protected:
tomwalters@0 164 void PushOutput();
tomwalters@0 165
tomwalters@3 166 virtual void ResetInternal() = 0;
tomwalters@3 167
tomwalters@0 168 virtual bool InitializeInternal(const SignalBank &input) = 0;
tomwalters@0 169
tomwalters@0 170 bool initialized_;
tomwalters@0 171 set<Module*> targets_;
tomwalters@0 172 SignalBank output_;
tomwalters@0 173 Parameters* parameters_;
tomwalters@0 174
tomwalters@0 175 string module_identifier_;
tomwalters@0 176 string module_type_;
tomwalters@0 177 string module_description_;
tomwalters@0 178 string module_version_;
tomwalters@0 179
tomwalters@0 180 private:
tomwalters@0 181 DISALLOW_COPY_AND_ASSIGN(Module);
tomwalters@0 182 };
tomwalters@0 183 }
tomwalters@0 184
tomwalters@11 185 #endif // AIMC_SUPPORT_MODULE_H_