annotate src/Support/Module.h @ 8:fcbf85ce59fb

- Lots of changes to make cpplint happy. It still complains about header guards, but that's pretty much it now.
author tomwalters
date Thu, 18 Feb 2010 21:12:41 +0000
parents decdac21cfc2
children 3078854c634a
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 /*! 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@3 75 *
tomwalters@3 76 * Note that in most instances when creating a new module, it is better to
tomwalters@3 77 * simply implement the pure virtual function InitializeInternal(), rather
tomwalters@3 78 * than refining a new Initialize. The only reason that Initialize() is made
tomwalters@3 79 * virtual is to deal with the edge case of input modules which do not take
tomwalters@3 80 * a SignalBank as input, but rather generate their own input.
tomwalters@0 81 */
tomwalters@3 82 virtual bool Initialize(const SignalBank &input);
tomwalters@0 83
tomwalters@0 84 /*! \brief
tomwalters@0 85 */
tomwalters@0 86 bool initialized() const;
tomwalters@0 87
tomwalters@0 88 /* \brief Add a target to this module. Whenever it generates a new
tomwalters@0 89 * output, this module will push its output to all its targets.
tomwalters@0 90 * \param input Target module to add.
tomwalters@0 91 * \param output true on success, false on failure.
tomwalters@0 92 */
tomwalters@0 93 bool AddTarget(Module* target_module);
tomwalters@0 94
tomwalters@0 95 /*! \brief
tomwalters@0 96 */
tomwalters@0 97 bool DeleteTarget(Module* target_module);
tomwalters@0 98
tomwalters@0 99 /*! \brief
tomwalters@0 100 */
tomwalters@0 101 void DeleteAllTargets();
tomwalters@0 102
tomwalters@0 103 /*! \brief Process a buffer
tomwalters@0 104 */
tomwalters@0 105 virtual void Process(const SignalBank &input) = 0;
tomwalters@0 106
tomwalters@3 107 /*! \brief Reset the internal state of this module and all its children to
tomwalters@3 108 * their initial state.
tomwalters@0 109 */
tomwalters@8 110 void Reset();
tomwalters@0 111
tomwalters@0 112 /*! \brief
tomwalters@0 113 */
tomwalters@0 114 const SignalBank* GetOutputBank() const;
tomwalters@0 115
tomwalters@0 116 protected:
tomwalters@0 117 void PushOutput();
tomwalters@0 118
tomwalters@3 119 virtual void ResetInternal() = 0;
tomwalters@3 120
tomwalters@0 121 virtual bool InitializeInternal(const SignalBank &input) = 0;
tomwalters@0 122
tomwalters@0 123 bool initialized_;
tomwalters@0 124 set<Module*> targets_;
tomwalters@0 125 SignalBank output_;
tomwalters@0 126 Parameters* parameters_;
tomwalters@0 127
tomwalters@0 128 string module_identifier_;
tomwalters@0 129 string module_type_;
tomwalters@0 130 string module_description_;
tomwalters@0 131 string module_version_;
tomwalters@0 132
tomwalters@0 133 private:
tomwalters@0 134 DISALLOW_COPY_AND_ASSIGN(Module);
tomwalters@0 135 };
tomwalters@0 136 }
tomwalters@0 137
tomwalters@0 138 #endif // _AIMC_SUPPORT_MODULE_H_