tomwalters@282: // Copyright 2008-2010, Thomas Walters tomwalters@268: // tomwalters@268: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@268: // http://www.acousticscale.org/AIMC tomwalters@268: // tomwalters@318: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: // you may not use this file except in compliance with the License. tomwalters@318: // You may obtain a copy of the License at tomwalters@268: // tomwalters@318: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@268: // tomwalters@318: // Unless required by applicable law or agreed to in writing, software tomwalters@318: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: // See the License for the specific language governing permissions and tomwalters@318: // limitations under the License. tomwalters@268: tomwalters@280: /*! \file tomwalters@280: * \brief Dick Lyon's Pole-Zero Filter Cascade - implemented in C++ by Tom tomwalters@280: * Walters from the AIM-MAT module based on Dick Lyon's code. tomwalters@280: * tomwalters@280: * \author Thomas Walters tomwalters@280: * \date created 2008/02/05 tomwalters@296: * \version \$Id$ tomwalters@280: */ tomwalters@280: tomwalters@268: #ifndef _AIMC_MODULES_BMM_PZFC_H_ tomwalters@268: #define _AIMC_MODULES_BMM_PZFC_H_ tomwalters@268: tomwalters@268: #include tomwalters@268: tomwalters@268: #include "Support/Module.h" tomwalters@268: #include "Support/Parameters.h" tomwalters@268: #include "Support/SignalBank.h" tomwalters@268: tomwalters@268: namespace aimc { tomwalters@268: using std::vector; tomwalters@268: class ModulePZFC : public Module { tomwalters@268: public: tomwalters@280: explicit ModulePZFC(Parameters *pParam); tomwalters@268: virtual ~ModulePZFC(); tomwalters@268: tomwalters@280: /*! \brief Process a buffer tomwalters@280: */ tomwalters@268: virtual void Process(const SignalBank &input); tomwalters@268: tomwalters@275: private: tomwalters@280: /*! \brief Reset all internal state variables to their initial values tomwalters@280: */ tomwalters@280: virtual void ResetInternal(); tomwalters@268: tomwalters@280: /*! \brief Prepare the module tomwalters@280: * \param input Input SignalBank tomwalters@280: * \param output true on success false on failure tomwalters@280: */ tomwalters@268: virtual bool InitializeInternal(const SignalBank &input); tomwalters@268: tomwalters@280: /*! \brief Set the filterbank parameters according to a fit matrix from Unoki tomwalters@280: * and Lyon's fitting routine tomwalters@280: */ tomwalters@268: bool SetPZBankCoeffsERBFitted(); tomwalters@321: tomwalters@321: /*! \brief Set the filterbank parameters using the non-fitted parameter tomwalters@321: * values, spaced along an ERB scale tomwalters@321: */ tomwalters@321: bool SetPZBankCoeffsERB(); tomwalters@321: tomwalters@321: /*! \brief Set the filterbank parameters using the non-fitted parameter tomwalters@321: * values, using the Greenwood formula (?) for channel spacing. tomwalters@321: */ tomwalters@321: bool SetPZBankCoeffsOrig(); tomwalters@321: tomwalters@280: /*! \brief Sets the general filterbank coefficients tomwalters@280: */ tomwalters@268: bool SetPZBankCoeffs(); tomwalters@268: tomwalters@280: /*! \brief Automatic Gain Control tomwalters@280: */ tomwalters@268: void AGCDampStep(); tomwalters@268: tomwalters@280: /*! \brief Detector function - halfwave rectification etc. Used internally, tomwalters@280: * but not applied to the output. tomwalters@280: */ tomwalters@268: float DetectFun(float fIN); tomwalters@268: tomwalters@280: /*! \brief Minimum tomwalters@280: */ tomwalters@268: inline float Minimum(float a, float b); tomwalters@268: tomwalters@268: int channel_count_; tomwalters@268: int buffer_length_; tomwalters@268: int agc_stage_count_; tomwalters@268: float sample_rate_; tomwalters@268: float last_input_; tomwalters@268: tomwalters@268: // Parameters tomwalters@321: // User-settable values tomwalters@268: float pole_damping_; tomwalters@268: float zero_damping_; tomwalters@268: float zero_factor_; tomwalters@268: float step_factor_; tomwalters@268: float bandwidth_over_cf_; tomwalters@268: float min_bandwidth_hz_; tomwalters@268: float agc_factor_; tomwalters@268: float cf_max_; tomwalters@268: float cf_min_; tomwalters@268: float mindamp_; tomwalters@268: float maxdamp_; tomwalters@268: bool do_agc_step_; tomwalters@321: bool use_fitted_parameters_; tomwalters@268: tomwalters@268: // Internal Buffers tomwalters@268: // Initialised once tomwalters@268: vector pole_dampings_; tomwalters@268: vector agc_epsilons_; tomwalters@268: vector agc_gains_; tomwalters@268: vector pole_frequencies_; tomwalters@268: vector za0_; tomwalters@268: vector za1_; tomwalters@268: vector za2_; tomwalters@268: vector rmin_; tomwalters@268: vector rmax_; tomwalters@268: vector xmin_; tomwalters@268: vector xmax_; tomwalters@268: tomwalters@268: // Modified by algorithm at each time step tomwalters@268: vector detect_; tomwalters@268: vector > agc_state_; tomwalters@268: vector state_1_; tomwalters@268: vector state_2_; tomwalters@268: vector previous_out_; tomwalters@268: vector pole_damps_mod_; tomwalters@268: vector inputs_; tomwalters@268: }; tomwalters@268: } tomwalters@268: tomwalters@268: #endif // _AIMC_MODULES_BMM_PZFC_H_