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_coding/neteq/background_noise.cc

Issue 1925053002: Revert of Avoiding overflow in cross correlation in NetEq. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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_coding/neteq/background_noise.h" 11 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> // memcpy 14 #include <string.h> // memcpy
15 15
16 #include <algorithm> // min, max 16 #include <algorithm> // min, max
17 17
18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
19 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" 19 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h"
20 #include "webrtc/modules/audio_coding/neteq/cross_correlation.h"
21 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" 20 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h"
22 21
23 namespace webrtc { 22 namespace webrtc {
24 23
25 // static 24 // static
26 const size_t BackgroundNoise::kMaxLpcOrder; 25 const size_t BackgroundNoise::kMaxLpcOrder;
27 26
28 BackgroundNoise::BackgroundNoise(size_t num_channels) 27 BackgroundNoise::BackgroundNoise(size_t num_channels)
29 : num_channels_(num_channels), 28 : num_channels_(num_channels),
30 channel_parameters_(new ChannelParameters[num_channels_]), 29 channel_parameters_(new ChannelParameters[num_channels_]),
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 assert(channel < num_channels_); 162 assert(channel < num_channels_);
164 return channel_parameters_[channel].scale; 163 return channel_parameters_[channel].scale;
165 } 164 }
166 int16_t BackgroundNoise::ScaleShift(size_t channel) const { 165 int16_t BackgroundNoise::ScaleShift(size_t channel) const {
167 assert(channel < num_channels_); 166 assert(channel < num_channels_);
168 return channel_parameters_[channel].scale_shift; 167 return channel_parameters_[channel].scale_shift;
169 } 168 }
170 169
171 int32_t BackgroundNoise::CalculateAutoCorrelation( 170 int32_t BackgroundNoise::CalculateAutoCorrelation(
172 const int16_t* signal, size_t length, int32_t* auto_correlation) const { 171 const int16_t* signal, size_t length, int32_t* auto_correlation) const {
172 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(signal, length);
173 int correlation_scale = kLogVecLen -
174 WebRtcSpl_NormW32(signal_max * signal_max);
175 correlation_scale = std::max(0, correlation_scale);
176
173 static const int kCorrelationStep = -1; 177 static const int kCorrelationStep = -1;
174 const int correlation_scale = 178 WebRtcSpl_CrossCorrelation(auto_correlation, signal, signal, length,
175 CrossCorrelationWithAutoShift(signal, signal, length, kMaxLpcOrder + 1, 179 kMaxLpcOrder + 1, correlation_scale,
176 kCorrelationStep, auto_correlation); 180 kCorrelationStep);
177 181
178 // Number of shifts to normalize energy to energy/sample. 182 // Number of shifts to normalize energy to energy/sample.
179 int energy_sample_shift = kLogVecLen - correlation_scale; 183 int energy_sample_shift = kLogVecLen - correlation_scale;
180 return auto_correlation[0] >> energy_sample_shift; 184 return auto_correlation[0] >> energy_sample_shift;
181 } 185 }
182 186
183 void BackgroundNoise::IncrementEnergyThreshold(size_t channel, 187 void BackgroundNoise::IncrementEnergyThreshold(size_t channel,
184 int32_t sample_energy) { 188 int32_t sample_energy) {
185 // TODO(hlundin): Simplify the below threshold update. What this code 189 // TODO(hlundin): Simplify the below threshold update. What this code
186 // does is simply "threshold += (increment * threshold) >> 16", but due 190 // does is simply "threshold += (increment * threshold) >> 16", but due
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Add 13 to the |scale_shift_|, since the random numbers table is in 253 // Add 13 to the |scale_shift_|, since the random numbers table is in
250 // Q13. 254 // Q13.
251 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used? 255 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used?
252 parameters.scale_shift = 256 parameters.scale_shift =
253 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2)); 257 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2));
254 258
255 initialized_ = true; 259 initialized_ = true;
256 } 260 }
257 261
258 } // namespace webrtc 262 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698