annotate trunk/src/Modules/BMM/ModulePZFC.h @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents e7bcaf1e87d5
children
rev   line source
tomwalters@282 1 // Copyright 2008-2010, Thomas Walters
tomwalters@268 2 //
tomwalters@268 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@268 4 // http://www.acousticscale.org/AIMC
tomwalters@268 5 //
tomwalters@318 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@318 7 // you may not use this file except in compliance with the License.
tomwalters@318 8 // You may obtain a copy of the License at
tomwalters@268 9 //
tomwalters@318 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@268 11 //
tomwalters@318 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@318 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@318 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@318 15 // See the License for the specific language governing permissions and
tomwalters@318 16 // limitations under the License.
tomwalters@268 17
tomwalters@280 18 /*! \file
tomwalters@280 19 * \brief Dick Lyon's Pole-Zero Filter Cascade - implemented in C++ by Tom
tomwalters@280 20 * Walters from the AIM-MAT module based on Dick Lyon's code.
tomwalters@280 21 *
tomwalters@280 22 * \author Thomas Walters <tom@acousticscale.org>
tomwalters@280 23 * \date created 2008/02/05
tomwalters@296 24 * \version \$Id$
tomwalters@280 25 */
tomwalters@280 26
tomwalters@268 27 #ifndef _AIMC_MODULES_BMM_PZFC_H_
tomwalters@268 28 #define _AIMC_MODULES_BMM_PZFC_H_
tomwalters@268 29
tomwalters@268 30 #include <vector>
tomwalters@268 31
tomwalters@268 32 #include "Support/Module.h"
tomwalters@268 33 #include "Support/Parameters.h"
tomwalters@268 34 #include "Support/SignalBank.h"
tomwalters@268 35
tomwalters@268 36 namespace aimc {
tomwalters@268 37 using std::vector;
tomwalters@268 38 class ModulePZFC : public Module {
tomwalters@268 39 public:
tomwalters@280 40 explicit ModulePZFC(Parameters *pParam);
tomwalters@268 41 virtual ~ModulePZFC();
tomwalters@268 42
tomwalters@280 43 /*! \brief Process a buffer
tomwalters@280 44 */
tomwalters@268 45 virtual void Process(const SignalBank &input);
tomwalters@268 46
tomwalters@275 47 private:
tomwalters@280 48 /*! \brief Reset all internal state variables to their initial values
tomwalters@280 49 */
tomwalters@280 50 virtual void ResetInternal();
tomwalters@268 51
tomwalters@280 52 /*! \brief Prepare the module
tomwalters@280 53 * \param input Input SignalBank
tomwalters@280 54 * \param output true on success false on failure
tomwalters@280 55 */
tomwalters@268 56 virtual bool InitializeInternal(const SignalBank &input);
tomwalters@268 57
tomwalters@280 58 /*! \brief Set the filterbank parameters according to a fit matrix from Unoki
tomwalters@280 59 * and Lyon's fitting routine
tomwalters@280 60 */
tomwalters@268 61 bool SetPZBankCoeffsERBFitted();
tomwalters@321 62
tomwalters@321 63 /*! \brief Set the filterbank parameters using the non-fitted parameter
tomwalters@321 64 * values, spaced along an ERB scale
tomwalters@321 65 */
tomwalters@321 66 bool SetPZBankCoeffsERB();
tomwalters@321 67
tomwalters@321 68 /*! \brief Set the filterbank parameters using the non-fitted parameter
tomwalters@321 69 * values, using the Greenwood formula (?) for channel spacing.
tomwalters@321 70 */
tomwalters@321 71 bool SetPZBankCoeffsOrig();
tomwalters@321 72
tomwalters@280 73 /*! \brief Sets the general filterbank coefficients
tomwalters@280 74 */
tomwalters@268 75 bool SetPZBankCoeffs();
tomwalters@268 76
tomwalters@280 77 /*! \brief Automatic Gain Control
tomwalters@280 78 */
tomwalters@268 79 void AGCDampStep();
tomwalters@268 80
tomwalters@280 81 /*! \brief Detector function - halfwave rectification etc. Used internally,
tomwalters@280 82 * but not applied to the output.
tomwalters@280 83 */
tomwalters@268 84 float DetectFun(float fIN);
tomwalters@268 85
tomwalters@280 86 /*! \brief Minimum
tomwalters@280 87 */
tomwalters@268 88 inline float Minimum(float a, float b);
tomwalters@268 89
tomwalters@268 90 int channel_count_;
tomwalters@268 91 int buffer_length_;
tomwalters@268 92 int agc_stage_count_;
tomwalters@268 93 float sample_rate_;
tomwalters@268 94 float last_input_;
tomwalters@268 95
tomwalters@268 96 // Parameters
tomwalters@321 97 // User-settable values
tomwalters@268 98 float pole_damping_;
tomwalters@268 99 float zero_damping_;
tomwalters@268 100 float zero_factor_;
tomwalters@268 101 float step_factor_;
tomwalters@268 102 float bandwidth_over_cf_;
tomwalters@268 103 float min_bandwidth_hz_;
tomwalters@268 104 float agc_factor_;
tomwalters@268 105 float cf_max_;
tomwalters@268 106 float cf_min_;
tomwalters@268 107 float mindamp_;
tomwalters@268 108 float maxdamp_;
tomwalters@268 109 bool do_agc_step_;
tomwalters@321 110 bool use_fitted_parameters_;
tomwalters@268 111
tomwalters@268 112 // Internal Buffers
tomwalters@268 113 // Initialised once
tomwalters@268 114 vector<float> pole_dampings_;
tomwalters@268 115 vector<float> agc_epsilons_;
tomwalters@268 116 vector<float> agc_gains_;
tomwalters@268 117 vector<float> pole_frequencies_;
tomwalters@268 118 vector<float> za0_;
tomwalters@268 119 vector<float> za1_;
tomwalters@268 120 vector<float> za2_;
tomwalters@268 121 vector<float> rmin_;
tomwalters@268 122 vector<float> rmax_;
tomwalters@268 123 vector<float> xmin_;
tomwalters@268 124 vector<float> xmax_;
tomwalters@268 125
tomwalters@268 126 // Modified by algorithm at each time step
tomwalters@268 127 vector<float> detect_;
tomwalters@268 128 vector<vector<float> > agc_state_;
tomwalters@268 129 vector<float> state_1_;
tomwalters@268 130 vector<float> state_2_;
tomwalters@268 131 vector<float> previous_out_;
tomwalters@268 132 vector<float> pole_damps_mod_;
tomwalters@268 133 vector<float> inputs_;
tomwalters@268 134 };
tomwalters@268 135 }
tomwalters@268 136
tomwalters@268 137 #endif // _AIMC_MODULES_BMM_PZFC_H_