tomwalters@0: // Copyright 2010, Thomas Walters tomwalters@0: // tomwalters@0: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@0: // http://www.acousticscale.org/AIMC tomwalters@0: // tomwalters@0: // This program is free software: you can redistribute it and/or modify tomwalters@0: // it under the terms of the GNU General Public License as published by tomwalters@0: // the Free Software Foundation, either version 3 of the License, or tomwalters@0: // (at your option) any later version. tomwalters@0: // tomwalters@0: // This program is distributed in the hope that it will be useful, tomwalters@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of tomwalters@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tomwalters@0: // GNU General Public License for more details. tomwalters@0: // tomwalters@0: // You should have received a copy of the GNU General Public License tomwalters@0: // along with this program. If not, see . tomwalters@0: tomwalters@0: /*! \file tomwalters@0: * \brief Base class for all AIM-C modules. tomwalters@0: */ tomwalters@0: tomwalters@0: /*! The module construcor is called with a pointer to a set of Parameters. tomwalters@0: * In the constructor, the module sets the defaults for its various tomwalters@0: * parameters. tomwalters@0: * A module is initialized with a pointer to a valid SignalBank tomwalters@0: * (source modules can be initialized with the NULL pointer). After the tomwalters@0: * Initialize(SignalBank*) function has been called, a call to GetOutputBank() tomwalters@0: * returns a pointer to a SignalBank in which the results tomwalters@0: * of the module's processing will be placed. Modules can use the output_ tomwalters@0: * SignalBank to store their output, or leave it uninitialized if they do not tomwalters@0: * produce an output. tomwalters@0: * At each call to Process(input), the module takes the tomwalters@0: * SignalBank 'input' (which must, unless otherwise specified, have the same tomwalters@0: * number of channels, sample rate, buffer size and centre frequencies as the tomwalters@0: * SignalBank which was passed to Initialize()), processes it, and places the tomwalters@0: * output in the internal SignalBank output_. tomwalters@0: * Modules can have an arbitrary number of unique targets. Each tomwalters@0: * completed output frame is 'pushed' to all of the targets of the module tomwalters@0: * in turn when PushOutput() is called. To achieve this, after each complete tomwalters@0: * output SignalBank is filled, the module calls the Process() function of tomwalters@0: * each of its targets in turn. tomwalters@0: * When Initialize() is first called. The module Initialize()s all of its tomwalters@0: * targets with its ouptut_ SignalBank, if it's output bank has been set up. tomwalters@0: */ tomwalters@0: tomwalters@0: /*! \author: Thomas Walters tomwalters@0: * \date 2010/01/23 tomwalters@0: * \version \$Id: Module.h 4 2010-02-03 18:44:58Z tcw $ tomwalters@0: */ tomwalters@0: tomwalters@0: #ifndef _AIMC_SUPPORT_MODULE_H_ tomwalters@0: #define _AIMC_SUPPORT_MODULE_H_ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "Support/Common.h" tomwalters@0: #include "Support/Parameters.h" tomwalters@0: #include "Support/SignalBank.h" tomwalters@0: tomwalters@0: namespace aimc { tomwalters@0: using std::set; tomwalters@0: using std::string; tomwalters@0: class Module { tomwalters@0: public: tomwalters@0: explicit Module(Parameters *parameters); tomwalters@0: tomwalters@0: virtual ~Module(); tomwalters@0: tomwalters@0: /* \brief Validate this module's output SignalBank, and initialize tomwalters@0: * any targets of the module if necessary. tomwalters@0: * \param input Input SignalBank. tomwalters@0: * \param output true on success, false on failure. tomwalters@0: */ tomwalters@0: bool Initialize(const SignalBank &input); tomwalters@0: tomwalters@0: /*! \brief tomwalters@0: */ tomwalters@0: bool initialized() const; tomwalters@0: tomwalters@0: /* \brief Add a target to this module. Whenever it generates a new tomwalters@0: * output, this module will push its output to all its targets. tomwalters@0: * \param input Target module to add. tomwalters@0: * \param output true on success, false on failure. tomwalters@0: */ tomwalters@0: bool AddTarget(Module* target_module); tomwalters@0: tomwalters@0: /*! \brief tomwalters@0: */ tomwalters@0: bool DeleteTarget(Module* target_module); tomwalters@0: tomwalters@0: /*! \brief tomwalters@0: */ tomwalters@0: void DeleteAllTargets(); tomwalters@0: tomwalters@0: /*! \brief Process a buffer tomwalters@0: */ tomwalters@0: virtual void Process(const SignalBank &input) = 0; tomwalters@0: tomwalters@0: /*! \brief Reset the internal state of the module to that when it was tomwalters@0: * initialised tomwalters@0: */ tomwalters@0: virtual void Reset() = 0; tomwalters@0: tomwalters@0: /*! \brief tomwalters@0: */ tomwalters@0: const SignalBank* GetOutputBank() const; tomwalters@0: tomwalters@0: protected: tomwalters@0: void PushOutput(); tomwalters@0: tomwalters@0: virtual bool InitializeInternal(const SignalBank &input) = 0; tomwalters@0: tomwalters@0: bool initialized_; tomwalters@0: set targets_; tomwalters@0: SignalBank output_; tomwalters@0: Parameters* parameters_; tomwalters@0: tomwalters@0: string module_identifier_; tomwalters@0: string module_type_; tomwalters@0: string module_description_; tomwalters@0: string module_version_; tomwalters@0: tomwalters@0: private: tomwalters@0: DISALLOW_COPY_AND_ASSIGN(Module); tomwalters@0: }; tomwalters@0: } tomwalters@0: tomwalters@0: #endif // _AIMC_SUPPORT_MODULE_H_