Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: webrtc/modules/audio_processing/agc/agc_audio_proc.cc

Issue 1192863006: Revert "Pull the Voice Activity Detector out from the AGC" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/vad/vad_audio_proc.h" 11 #include "webrtc/modules/audio_processing/agc/agc_audio_proc.h"
12 12
13 #include <math.h> 13 #include <math.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 15
16 #include "webrtc/common_audio/fft4g.h" 16 #include "webrtc/common_audio/fft4g.h"
17 #include "webrtc/modules/audio_processing/vad/vad_audio_proc_internal.h" 17 #include "webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h"
18 #include "webrtc/modules/audio_processing/vad/pitch_internal.h" 18 #include "webrtc/modules/audio_processing/agc/pitch_internal.h"
19 #include "webrtc/modules/audio_processing/vad/pole_zero_filter.h" 19 #include "webrtc/modules/audio_processing/agc/pole_zero_filter.h"
20 extern "C" { 20 extern "C" {
21 #include "webrtc/modules/audio_coding/codecs/isac/main/source/codec.h" 21 #include "webrtc/modules/audio_coding/codecs/isac/main/source/codec.h"
22 #include "webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h" 22 #include "webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h"
23 #include "webrtc/modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" 23 #include "webrtc/modules/audio_coding/codecs/isac/main/source/pitch_estimator.h"
24 #include "webrtc/modules/audio_coding/codecs/isac/main/source/structs.h" 24 #include "webrtc/modules/audio_coding/codecs/isac/main/source/structs.h"
25 } 25 }
26 #include "webrtc/modules/interface/module_common_types.h" 26 #include "webrtc/modules/interface/module_common_types.h"
27 27
28 namespace webrtc { 28 namespace webrtc {
29 29
30 // The following structures are declared anonymous in iSAC's structs.h. To 30 // The following structures are declared anonymous in iSAC's structs.h. To
31 // forward declare them, we use this derived class trick. 31 // forward declare them, we use this derived class trick.
32 struct VadAudioProc::PitchAnalysisStruct : public ::PitchAnalysisStruct {}; 32 struct AgcAudioProc::PitchAnalysisStruct : public ::PitchAnalysisStruct {};
33 struct VadAudioProc::PreFiltBankstr : public ::PreFiltBankstr {}; 33 struct AgcAudioProc::PreFiltBankstr : public ::PreFiltBankstr {};
34 34
35 static const float kFrequencyResolution = 35 static const float kFrequencyResolution = kSampleRateHz /
36 kSampleRateHz / static_cast<float>(VadAudioProc::kDftSize); 36 static_cast<float>(AgcAudioProc::kDftSize);
37 static const int kSilenceRms = 5; 37 static const int kSilenceRms = 5;
38 38
39 // TODO(turajs): Make a Create or Init for VadAudioProc. 39 // TODO(turajs): Make a Create or Init for AgcAudioProc.
40 VadAudioProc::VadAudioProc() 40 AgcAudioProc::AgcAudioProc()
41 : audio_buffer_(), 41 : audio_buffer_(),
42 num_buffer_samples_(kNumPastSignalSamples), 42 num_buffer_samples_(kNumPastSignalSamples),
43 log_old_gain_(-2), 43 log_old_gain_(-2),
44 old_lag_(50), // Arbitrary but valid as pitch-lag (in samples). 44 old_lag_(50), // Arbitrary but valid as pitch-lag (in samples).
45 pitch_analysis_handle_(new PitchAnalysisStruct), 45 pitch_analysis_handle_(new PitchAnalysisStruct),
46 pre_filter_handle_(new PreFiltBankstr), 46 pre_filter_handle_(new PreFiltBankstr),
47 high_pass_filter_(PoleZeroFilter::Create(kCoeffNumerator, 47 high_pass_filter_(PoleZeroFilter::Create(
48 kFilterOrder, 48 kCoeffNumerator, kFilterOrder, kCoeffDenominator, kFilterOrder)) {
49 kCoeffDenominator,
50 kFilterOrder)) {
51 static_assert(kNumPastSignalSamples + kNumSubframeSamples == 49 static_assert(kNumPastSignalSamples + kNumSubframeSamples ==
52 sizeof(kLpcAnalWin) / sizeof(kLpcAnalWin[0]), 50 sizeof(kLpcAnalWin) / sizeof(kLpcAnalWin[0]),
53 "lpc analysis window incorrect size"); 51 "lpc analysis window incorrect size");
54 static_assert(kLpcOrder + 1 == sizeof(kCorrWeight) / sizeof(kCorrWeight[0]), 52 static_assert(kLpcOrder + 1 == sizeof(kCorrWeight) / sizeof(kCorrWeight[0]),
55 "correlation weight incorrect size"); 53 "correlation weight incorrect size");
56 54
57 // TODO(turajs): Are we doing too much in the constructor? 55 // TODO(turajs): Are we doing too much in the constructor?
58 float data[kDftSize]; 56 float data[kDftSize];
59 // Make FFT to initialize. 57 // Make FFT to initialize.
60 ip_[0] = 0; 58 ip_[0] = 0;
61 WebRtc_rdft(kDftSize, 1, data, ip_, w_fft_); 59 WebRtc_rdft(kDftSize, 1, data, ip_, w_fft_);
62 // TODO(turajs): Need to initialize high-pass filter. 60 // TODO(turajs): Need to initialize high-pass filter.
63 61
64 // Initialize iSAC components. 62 // Initialize iSAC components.
65 WebRtcIsac_InitPreFilterbank(pre_filter_handle_.get()); 63 WebRtcIsac_InitPreFilterbank(pre_filter_handle_.get());
66 WebRtcIsac_InitPitchAnalysis(pitch_analysis_handle_.get()); 64 WebRtcIsac_InitPitchAnalysis(pitch_analysis_handle_.get());
67 } 65 }
68 66
69 VadAudioProc::~VadAudioProc() { 67 AgcAudioProc::~AgcAudioProc() {}
70 }
71 68
72 void VadAudioProc::ResetBuffer() { 69 void AgcAudioProc::ResetBuffer() {
73 memcpy(audio_buffer_, &audio_buffer_[kNumSamplesToProcess], 70 memcpy(audio_buffer_, &audio_buffer_[kNumSamplesToProcess],
74 sizeof(audio_buffer_[0]) * kNumPastSignalSamples); 71 sizeof(audio_buffer_[0]) * kNumPastSignalSamples);
75 num_buffer_samples_ = kNumPastSignalSamples; 72 num_buffer_samples_ = kNumPastSignalSamples;
76 } 73 }
77 74
78 int VadAudioProc::ExtractFeatures(const int16_t* frame, 75 int AgcAudioProc::ExtractFeatures(const int16_t* frame,
79 int length, 76 int length,
80 AudioFeatures* features) { 77 AudioFeatures* features) {
81 features->num_frames = 0; 78 features->num_frames = 0;
82 if (length != kNumSubframeSamples) { 79 if (length != kNumSubframeSamples) {
83 return -1; 80 return -1;
84 } 81 }
85 82
86 // High-pass filter to remove the DC component and very low frequency content. 83 // High-pass filter to remove the DC component and very low frequency content.
87 // We have experienced that this high-pass filtering improves voice/non-voiced 84 // We have experienced that this high-pass filtering improves voice/non-voiced
88 // classification. 85 // classification.
89 if (high_pass_filter_->Filter(frame, kNumSubframeSamples, 86 if (high_pass_filter_->Filter(frame, kNumSubframeSamples,
90 &audio_buffer_[num_buffer_samples_]) != 0) { 87 &audio_buffer_[num_buffer_samples_]) != 0) {
91 return -1; 88 return -1;
92 } 89 }
93 90
94 num_buffer_samples_ += kNumSubframeSamples; 91 num_buffer_samples_ += kNumSubframeSamples;
95 if (num_buffer_samples_ < kBufferLength) { 92 if (num_buffer_samples_ < kBufferLength) {
96 return 0; 93 return 0;
97 } 94 }
98 assert(num_buffer_samples_ == kBufferLength); 95 assert(num_buffer_samples_ == kBufferLength);
99 features->num_frames = kNum10msSubframes; 96 features->num_frames = kNum10msSubframes;
100 features->silence = false; 97 features->silence = false;
101 98
102 Rms(features->rms, kMaxNumFrames); 99 Rms(features->rms, kMaxNumFrames);
103 for (int i = 0; i < kNum10msSubframes; ++i) { 100 for (int i = 0; i < kNum10msSubframes; ++i) {
104 if (features->rms[i] < kSilenceRms) { 101 if (features->rms[i] < kSilenceRms) {
105 // PitchAnalysis can cause NaNs in the pitch gain if it's fed silence. 102 // PitchAnalysis can cause NaNs in the pitch gain if it's fed silence.
106 // Bail out here instead. 103 // Bail out here instead.
107 features->silence = true; 104 features->silence = true;
108 ResetBuffer(); 105 ResetBuffer();
109 return 0; 106 return 0;
110 } 107 }
111 } 108 }
112 109
113 PitchAnalysis(features->log_pitch_gain, features->pitch_lag_hz, 110 PitchAnalysis(features->log_pitch_gain, features->pitch_lag_hz,
114 kMaxNumFrames); 111 kMaxNumFrames);
115 FindFirstSpectralPeaks(features->spectral_peak, kMaxNumFrames); 112 FindFirstSpectralPeaks(features->spectral_peak, kMaxNumFrames);
116 ResetBuffer(); 113 ResetBuffer();
117 return 0; 114 return 0;
118 } 115 }
119 116
120 // Computes |kLpcOrder + 1| correlation coefficients. 117 // Computes |kLpcOrder + 1| correlation coefficients.
121 void VadAudioProc::SubframeCorrelation(double* corr, 118 void AgcAudioProc::SubframeCorrelation(double* corr, int length_corr,
122 int length_corr,
123 int subframe_index) { 119 int subframe_index) {
124 assert(length_corr >= kLpcOrder + 1); 120 assert(length_corr >= kLpcOrder + 1);
125 double windowed_audio[kNumSubframeSamples + kNumPastSignalSamples]; 121 double windowed_audio[kNumSubframeSamples + kNumPastSignalSamples];
126 int buffer_index = subframe_index * kNumSubframeSamples; 122 int buffer_index = subframe_index * kNumSubframeSamples;
127 123
128 for (int n = 0; n < kNumSubframeSamples + kNumPastSignalSamples; n++) 124 for (int n = 0; n < kNumSubframeSamples + kNumPastSignalSamples; n++)
129 windowed_audio[n] = audio_buffer_[buffer_index++] * kLpcAnalWin[n]; 125 windowed_audio[n] = audio_buffer_[buffer_index++] * kLpcAnalWin[n];
130 126
131 WebRtcIsac_AutoCorr(corr, windowed_audio, 127 WebRtcIsac_AutoCorr(corr, windowed_audio, kNumSubframeSamples +
132 kNumSubframeSamples + kNumPastSignalSamples, kLpcOrder); 128 kNumPastSignalSamples, kLpcOrder);
133 } 129 }
134 130
135 // Compute |kNum10msSubframes| sets of LPC coefficients, one per 10 ms input. 131 // Compute |kNum10msSubframes| sets of LPC coefficients, one per 10 ms input.
136 // The analysis window is 15 ms long and it is centered on the first half of 132 // The analysis window is 15 ms long and it is centered on the first half of
137 // each 10ms sub-frame. This is equivalent to computing LPC coefficients for the 133 // each 10ms sub-frame. This is equivalent to computing LPC coefficients for the
138 // first half of each 10 ms subframe. 134 // first half of each 10 ms subframe.
139 void VadAudioProc::GetLpcPolynomials(double* lpc, int length_lpc) { 135 void AgcAudioProc::GetLpcPolynomials(double* lpc, int length_lpc) {
140 assert(length_lpc >= kNum10msSubframes * (kLpcOrder + 1)); 136 assert(length_lpc >= kNum10msSubframes * (kLpcOrder + 1));
141 double corr[kLpcOrder + 1]; 137 double corr[kLpcOrder + 1];
142 double reflec_coeff[kLpcOrder]; 138 double reflec_coeff[kLpcOrder];
143 for (int i = 0, offset_lpc = 0; i < kNum10msSubframes; 139 for (int i = 0, offset_lpc = 0; i < kNum10msSubframes;
144 i++, offset_lpc += kLpcOrder + 1) { 140 i++, offset_lpc += kLpcOrder + 1) {
145 SubframeCorrelation(corr, kLpcOrder + 1, i); 141 SubframeCorrelation(corr, kLpcOrder + 1, i);
146 corr[0] *= 1.0001; 142 corr[0] *= 1.0001;
147 // This makes Lev-Durb a bit more stable. 143 // This makes Lev-Durb a bit more stable.
148 for (int k = 0; k < kLpcOrder + 1; k++) { 144 for (int k = 0; k < kLpcOrder + 1; k++) {
149 corr[k] *= kCorrWeight[k]; 145 corr[k] *= kCorrWeight[k];
150 } 146 }
151 WebRtcIsac_LevDurb(&lpc[offset_lpc], reflec_coeff, corr, kLpcOrder); 147 WebRtcIsac_LevDurb(&lpc[offset_lpc], reflec_coeff, corr, kLpcOrder);
152 } 148 }
153 } 149 }
154 150
155 // Fit a second order curve to these 3 points and find the location of the 151 // Fit a second order curve to these 3 points and find the location of the
156 // extremum. The points are inverted before curve fitting. 152 // extremum. The points are inverted before curve fitting.
157 static float QuadraticInterpolation(float prev_val, 153 static float QuadraticInterpolation(float prev_val, float curr_val,
158 float curr_val,
159 float next_val) { 154 float next_val) {
160 // Doing the interpolation in |1 / A(z)|^2. 155 // Doing the interpolation in |1 / A(z)|^2.
161 float fractional_index = 0; 156 float fractional_index = 0;
162 next_val = 1.0f / next_val; 157 next_val = 1.0f / next_val;
163 prev_val = 1.0f / prev_val; 158 prev_val = 1.0f / prev_val;
164 curr_val = 1.0f / curr_val; 159 curr_val = 1.0f / curr_val;
165 160
166 fractional_index = 161 fractional_index = -(next_val - prev_val) * 0.5f / (next_val + prev_val -
167 -(next_val - prev_val) * 0.5f / (next_val + prev_val - 2.f * curr_val); 162 2.f * curr_val);
168 assert(fabs(fractional_index) < 1); 163 assert(fabs(fractional_index) < 1);
169 return fractional_index; 164 return fractional_index;
170 } 165 }
171 166
172 // 1 / A(z), where A(z) is defined by |lpc| is a model of the spectral envelope 167 // 1 / A(z), where A(z) is defined by |lpc| is a model of the spectral envelope
173 // of the input signal. The local maximum of the spectral envelope corresponds 168 // of the input signal. The local maximum of the spectral envelope corresponds
174 // with the local minimum of A(z). It saves complexity, as we save one 169 // with the local minimum of A(z). It saves complexity, as we save one
175 // inversion. Furthermore, we find the first local maximum of magnitude squared, 170 // inversion. Furthermore, we find the first local maximum of magnitude squared,
176 // to save on one square root. 171 // to save on one square root.
177 void VadAudioProc::FindFirstSpectralPeaks(double* f_peak, int length_f_peak) { 172 void AgcAudioProc::FindFirstSpectralPeaks(double* f_peak, int length_f_peak) {
178 assert(length_f_peak >= kNum10msSubframes); 173 assert(length_f_peak >= kNum10msSubframes);
179 double lpc[kNum10msSubframes * (kLpcOrder + 1)]; 174 double lpc[kNum10msSubframes * (kLpcOrder + 1)];
180 // For all sub-frames. 175 // For all sub-frames.
181 GetLpcPolynomials(lpc, kNum10msSubframes * (kLpcOrder + 1)); 176 GetLpcPolynomials(lpc, kNum10msSubframes * (kLpcOrder + 1));
182 177
183 const int kNumDftCoefficients = kDftSize / 2 + 1; 178 const int kNumDftCoefficients = kDftSize / 2 + 1;
184 float data[kDftSize]; 179 float data[kDftSize];
185 180
186 for (int i = 0; i < kNum10msSubframes; i++) { 181 for (int i = 0; i < kNum10msSubframes; i++) {
187 // Convert to float with zero pad. 182 // Convert to float with zero pad.
188 memset(data, 0, sizeof(data)); 183 memset(data, 0, sizeof(data));
189 for (int n = 0; n < kLpcOrder + 1; n++) { 184 for (int n = 0; n < kLpcOrder + 1; n++) {
190 data[n] = static_cast<float>(lpc[i * (kLpcOrder + 1) + n]); 185 data[n] = static_cast<float>(lpc[i * (kLpcOrder + 1) + n]);
191 } 186 }
192 // Transform to frequency domain. 187 // Transform to frequency domain.
193 WebRtc_rdft(kDftSize, 1, data, ip_, w_fft_); 188 WebRtc_rdft(kDftSize, 1, data, ip_, w_fft_);
194 189
195 int index_peak = 0; 190 int index_peak = 0;
196 float prev_magn_sqr = data[0] * data[0]; 191 float prev_magn_sqr = data[0] * data[0];
197 float curr_magn_sqr = data[2] * data[2] + data[3] * data[3]; 192 float curr_magn_sqr = data[2] * data[2] + data[3] * data[3];
198 float next_magn_sqr; 193 float next_magn_sqr;
199 bool found_peak = false; 194 bool found_peak = false;
200 for (int n = 2; n < kNumDftCoefficients - 1; n++) { 195 for (int n = 2; n < kNumDftCoefficients - 1; n++) {
201 next_magn_sqr = 196 next_magn_sqr = data[2 * n] * data[2 * n] +
202 data[2 * n] * data[2 * n] + data[2 * n + 1] * data[2 * n + 1]; 197 data[2 * n + 1] * data[2 * n + 1];
203 if (curr_magn_sqr < prev_magn_sqr && curr_magn_sqr < next_magn_sqr) { 198 if (curr_magn_sqr < prev_magn_sqr && curr_magn_sqr < next_magn_sqr) {
204 found_peak = true; 199 found_peak = true;
205 index_peak = n - 1; 200 index_peak = n - 1;
206 break; 201 break;
207 } 202 }
208 prev_magn_sqr = curr_magn_sqr; 203 prev_magn_sqr = curr_magn_sqr;
209 curr_magn_sqr = next_magn_sqr; 204 curr_magn_sqr = next_magn_sqr;
210 } 205 }
211 float fractional_index = 0; 206 float fractional_index = 0;
212 if (!found_peak) { 207 if (!found_peak) {
213 // Checking if |kNumDftCoefficients - 1| is the local minimum. 208 // Checking if |kNumDftCoefficients - 1| is the local minimum.
214 next_magn_sqr = data[1] * data[1]; 209 next_magn_sqr = data[1] * data[1];
215 if (curr_magn_sqr < prev_magn_sqr && curr_magn_sqr < next_magn_sqr) { 210 if (curr_magn_sqr < prev_magn_sqr && curr_magn_sqr < next_magn_sqr) {
216 index_peak = kNumDftCoefficients - 1; 211 index_peak = kNumDftCoefficients - 1;
217 } 212 }
218 } else { 213 } else {
219 // A peak is found, do a simple quadratic interpolation to get a more 214 // A peak is found, do a simple quadratic interpolation to get a more
220 // accurate estimate of the peak location. 215 // accurate estimate of the peak location.
221 fractional_index = 216 fractional_index = QuadraticInterpolation(prev_magn_sqr, curr_magn_sqr,
222 QuadraticInterpolation(prev_magn_sqr, curr_magn_sqr, next_magn_sqr); 217 next_magn_sqr);
223 } 218 }
224 f_peak[i] = (index_peak + fractional_index) * kFrequencyResolution; 219 f_peak[i] = (index_peak + fractional_index) * kFrequencyResolution;
225 } 220 }
226 } 221 }
227 222
228 // Using iSAC functions to estimate pitch gains & lags. 223 // Using iSAC functions to estimate pitch gains & lags.
229 void VadAudioProc::PitchAnalysis(double* log_pitch_gains, 224 void AgcAudioProc::PitchAnalysis(double* log_pitch_gains, double* pitch_lags_hz,
230 double* pitch_lags_hz,
231 int length) { 225 int length) {
232 // TODO(turajs): This can be "imported" from iSAC & and the next two 226 // TODO(turajs): This can be "imported" from iSAC & and the next two
233 // constants. 227 // constants.
234 assert(length >= kNum10msSubframes); 228 assert(length >= kNum10msSubframes);
235 const int kNumPitchSubframes = 4; 229 const int kNumPitchSubframes = 4;
236 double gains[kNumPitchSubframes]; 230 double gains[kNumPitchSubframes];
237 double lags[kNumPitchSubframes]; 231 double lags[kNumPitchSubframes];
238 232
239 const int kNumSubbandFrameSamples = 240; 233 const int kNumSubbandFrameSamples = 240;
240 const int kNumLookaheadSamples = 24; 234 const int kNumLookaheadSamples = 24;
241 235
242 float lower[kNumSubbandFrameSamples]; 236 float lower[kNumSubbandFrameSamples];
243 float upper[kNumSubbandFrameSamples]; 237 float upper[kNumSubbandFrameSamples];
244 double lower_lookahead[kNumSubbandFrameSamples]; 238 double lower_lookahead[kNumSubbandFrameSamples];
245 double upper_lookahead[kNumSubbandFrameSamples]; 239 double upper_lookahead[kNumSubbandFrameSamples];
246 double lower_lookahead_pre_filter[kNumSubbandFrameSamples + 240 double lower_lookahead_pre_filter[kNumSubbandFrameSamples +
247 kNumLookaheadSamples]; 241 kNumLookaheadSamples];
248 242
249 // Split signal to lower and upper bands 243 // Split signal to lower and upper bands
250 WebRtcIsac_SplitAndFilterFloat(&audio_buffer_[kNumPastSignalSamples], lower, 244 WebRtcIsac_SplitAndFilterFloat(&audio_buffer_[kNumPastSignalSamples],
251 upper, lower_lookahead, upper_lookahead, 245 lower, upper, lower_lookahead, upper_lookahead,
252 pre_filter_handle_.get()); 246 pre_filter_handle_.get());
253 WebRtcIsac_PitchAnalysis(lower_lookahead, lower_lookahead_pre_filter, 247 WebRtcIsac_PitchAnalysis(lower_lookahead, lower_lookahead_pre_filter,
254 pitch_analysis_handle_.get(), lags, gains); 248 pitch_analysis_handle_.get(), lags, gains);
255 249
256 // Lags are computed on lower-band signal with sampling rate half of the 250 // Lags are computed on lower-band signal with sampling rate half of the
257 // input signal. 251 // input signal.
258 GetSubframesPitchParameters( 252 GetSubframesPitchParameters(kSampleRateHz / 2, gains, lags,
259 kSampleRateHz / 2, gains, lags, kNumPitchSubframes, kNum10msSubframes, 253 kNumPitchSubframes, kNum10msSubframes,
260 &log_old_gain_, &old_lag_, log_pitch_gains, pitch_lags_hz); 254 &log_old_gain_, &old_lag_,
255 log_pitch_gains, pitch_lags_hz);
261 } 256 }
262 257
263 void VadAudioProc::Rms(double* rms, int length_rms) { 258 void AgcAudioProc::Rms(double* rms, int length_rms) {
264 assert(length_rms >= kNum10msSubframes); 259 assert(length_rms >= kNum10msSubframes);
265 int offset = kNumPastSignalSamples; 260 int offset = kNumPastSignalSamples;
266 for (int i = 0; i < kNum10msSubframes; i++) { 261 for (int i = 0; i < kNum10msSubframes; i++) {
267 rms[i] = 0; 262 rms[i] = 0;
268 for (int n = 0; n < kNumSubframeSamples; n++, offset++) 263 for (int n = 0; n < kNumSubframeSamples; n++, offset++)
269 rms[i] += audio_buffer_[offset] * audio_buffer_[offset]; 264 rms[i] += audio_buffer_[offset] * audio_buffer_[offset];
270 rms[i] = sqrt(rms[i] / kNumSubframeSamples); 265 rms[i] = sqrt(rms[i] / kNumSubframeSamples);
271 } 266 }
272 } 267 }
273 268
274 } // namespace webrtc 269 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/agc/agc_audio_proc.h ('k') | webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698