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