annotate src/Modules/BMM/ModulePZFC.h @ 611:0fbaf443ec82

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