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@0
|
62
|
tomwalters@8
|
63 /*! \brief Sets the general filterbank coefficients
|
tomwalters@8
|
64 */
|
tomwalters@0
|
65 bool SetPZBankCoeffs();
|
tomwalters@0
|
66
|
tomwalters@8
|
67 /*! \brief Automatic Gain Control
|
tomwalters@8
|
68 */
|
tomwalters@0
|
69 void AGCDampStep();
|
tomwalters@0
|
70
|
tomwalters@8
|
71 /*! \brief Detector function - halfwave rectification etc. Used internally,
|
tomwalters@8
|
72 * but not applied to the output.
|
tomwalters@8
|
73 */
|
tomwalters@0
|
74 float DetectFun(float fIN);
|
tomwalters@0
|
75
|
tomwalters@8
|
76 /*! \brief Minimum
|
tomwalters@8
|
77 */
|
tomwalters@0
|
78 inline float Minimum(float a, float b);
|
tomwalters@0
|
79
|
tomwalters@0
|
80 int channel_count_;
|
tomwalters@0
|
81 int buffer_length_;
|
tomwalters@0
|
82 int agc_stage_count_;
|
tomwalters@0
|
83 float sample_rate_;
|
tomwalters@0
|
84 float last_input_;
|
tomwalters@0
|
85
|
tomwalters@0
|
86 // Parameters
|
tomwalters@0
|
87 // User-settable scalars
|
tomwalters@0
|
88 float pole_damping_;
|
tomwalters@0
|
89 float zero_damping_;
|
tomwalters@0
|
90 float zero_factor_;
|
tomwalters@0
|
91 float step_factor_;
|
tomwalters@0
|
92 float bandwidth_over_cf_;
|
tomwalters@0
|
93 float min_bandwidth_hz_;
|
tomwalters@0
|
94 float agc_factor_;
|
tomwalters@0
|
95 float cf_max_;
|
tomwalters@0
|
96 float cf_min_;
|
tomwalters@0
|
97 float mindamp_;
|
tomwalters@0
|
98 float maxdamp_;
|
tomwalters@0
|
99 bool do_agc_step_;
|
tomwalters@0
|
100
|
tomwalters@0
|
101 // Internal Buffers
|
tomwalters@0
|
102 // Initialised once
|
tomwalters@0
|
103 vector<float> pole_dampings_;
|
tomwalters@0
|
104 vector<float> agc_epsilons_;
|
tomwalters@0
|
105 vector<float> agc_gains_;
|
tomwalters@0
|
106 vector<float> pole_frequencies_;
|
tomwalters@0
|
107 vector<float> za0_;
|
tomwalters@0
|
108 vector<float> za1_;
|
tomwalters@0
|
109 vector<float> za2_;
|
tomwalters@0
|
110 vector<float> rmin_;
|
tomwalters@0
|
111 vector<float> rmax_;
|
tomwalters@0
|
112 vector<float> xmin_;
|
tomwalters@0
|
113 vector<float> xmax_;
|
tomwalters@0
|
114
|
tomwalters@0
|
115 // Modified by algorithm at each time step
|
tomwalters@0
|
116 vector<float> detect_;
|
tomwalters@0
|
117 vector<vector<float> > agc_state_;
|
tomwalters@0
|
118 vector<float> state_1_;
|
tomwalters@0
|
119 vector<float> state_2_;
|
tomwalters@0
|
120 vector<float> previous_out_;
|
tomwalters@0
|
121 vector<float> pole_damps_mod_;
|
tomwalters@0
|
122 vector<float> inputs_;
|
tomwalters@0
|
123 };
|
tomwalters@0
|
124 }
|
tomwalters@0
|
125
|
tomwalters@0
|
126 #endif // _AIMC_MODULES_BMM_PZFC_H_
|