comparison src/Modules/BMM/ModuleGammatone.cc @ 8:fcbf85ce59fb

- Lots of changes to make cpplint happy. It still complains about header guards, but that's pretty much it now.
author tomwalters
date Thu, 18 Feb 2010 21:12:41 +0000
parents 3c782dec2fc0
children b4cafba48e9d
comparison
equal deleted inserted replaced
7:1a1988ec40e7 8:fcbf85ce59fb
22 * \author Thomas Walters <tom@acousticscale.org> 22 * \author Thomas Walters <tom@acousticscale.org>
23 * \date created 2009/11/13 23 * \date created 2009/11/13
24 * \version \$Id$ 24 * \version \$Id$
25 */ 25 */
26 26
27 #include <math.h>
27 #include <complex> 28 #include <complex>
28 #include <math.h>
29 #include "Support/ERBTools.h" 29 #include "Support/ERBTools.h"
30 30
31 #include "Modules/BMM/ModuleGammatone.h" 31 #include "Modules/BMM/ModuleGammatone.h"
32 32
33 namespace aimc { 33 namespace aimc {
62 62
63 centre_frequencies_.resize(num_channels_); 63 centre_frequencies_.resize(num_channels_);
64 float erb_current = erb_min; 64 float erb_current = erb_min;
65 65
66 for (int i = 0; i < num_channels_; ++i) { 66 for (int i = 0; i < num_channels_; ++i) {
67 centre_frequencies_[i] = ERBTools::ERB2Freq(erb_current); 67 centre_frequencies_[i] = ERBTools::ERB2Freq(erb_current);
68 erb_current += delta_erb; 68 erb_current += delta_erb;
69 } 69 }
70 70
71 forward_.resize(num_channels_); 71 forward_.resize(num_channels_);
72 back_.resize(num_channels_); 72 back_.resize(num_channels_);
73 state_.resize(num_channels_); 73 state_.resize(num_channels_);
80 float dt = 1.0f / input.sample_rate(); 80 float dt = 1.0f / input.sample_rate();
81 81
82 // Bandwidth parameter 82 // Bandwidth parameter
83 float b = 1.019f * 2.0f * M_PI * erb; 83 float b = 1.019f * 2.0f * M_PI * erb;
84 84
85 // All of the following expressions are derived in Apple TR #35, "An 85 // All of the following expressions are derived in Apple TR #35, "An
86 // Efficient Implementation of the Patterson-Holdsworth Cochlear 86 // Efficient Implementation of the Patterson-Holdsworth Cochlear
87 // Filter Bank". 87 // Filter Bank".
88 88
89 // Calculate the gain: 89 // Calculate the gain:
90 float cpt = cf * M_PI * dt; 90 float cpt = cf * M_PI * dt;
91 complex<float> exponent(0.0f, 2.0f * cpt); 91 complex<float> exponent(0.0f, 2.0f * cpt);
150 vector<vector<float> >::iterator a = back_.begin(); 150 vector<vector<float> >::iterator a = back_.begin();
151 vector<vector<float> >::iterator s = state_.begin(); 151 vector<vector<float> >::iterator s = state_.begin();
152 152
153 for (int ch = 0; ch < num_channels_; ++ch, ++a, ++b, ++s) { 153 for (int ch = 0; ch < num_channels_; ++ch, ++a, ++b, ++s) {
154 for (int i = 0; i < input.buffer_length(); ++i) { 154 for (int i = 0; i < input.buffer_length(); ++i) {
155 // Direct-form-II IIR filter 155 // Direct-form-II IIR filter
156 float in = input.sample(audio_channel, i); 156 float in = input.sample(audio_channel, i);
157 float out = (*b)[0] * in + (*s)[0]; 157 float out = (*b)[0] * in + (*s)[0];
158 for (unsigned int stage = 1; stage < s->size(); ++stage) 158 for (unsigned int stage = 1; stage < s->size(); ++stage)
159 (*s)[stage - 1] = (*b)[stage] * in - (*a)[stage] * out + (*s)[stage]; 159 (*s)[stage - 1] = (*b)[stage] * in - (*a)[stage] * out + (*s)[stage];
160 output_.set_sample(ch, i, out); 160 output_.set_sample(ch, i, out);
161 } 161 }
162 } 162 }
163 PushOutput(); 163 PushOutput();
164 } 164 }
165 165
166 } // namespace aimc 166 } // namespace aimc