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

Side by Side Diff: webrtc/modules/audio_coding/neteq/time_stretch.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
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time_stretch.h" 11 #include "webrtc/modules/audio_coding/neteq/time_stretch.h"
12 12
13 #include <algorithm> // min, max 13 #include <algorithm> // min, max
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/base/safe_conversions.h" 16 #include "webrtc/base/safe_conversions.h"
17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
18 #include "webrtc/modules/audio_coding/neteq/background_noise.h" 18 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
19 #include "webrtc/modules/audio_coding/neteq/cross_correlation.h"
20 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" 19 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h"
21 20
22 namespace webrtc { 21 namespace webrtc {
23 22
24 TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input, 23 TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
25 size_t input_len, 24 size_t input_len,
26 bool fast_mode, 25 bool fast_mode,
27 AudioMultiVector* output, 26 AudioMultiVector* output,
28 size_t* length_change_samples) { 27 size_t* length_change_samples) {
29 // Pre-calculate common multiplication with |fs_mult_|. 28 // Pre-calculate common multiplication with |fs_mult_|.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 break; 151 break;
153 case kNoStretch: 152 case kNoStretch:
154 case kError: 153 case kError:
155 *length_change_samples = 0; 154 *length_change_samples = 0;
156 break; 155 break;
157 } 156 }
158 return return_value; 157 return return_value;
159 } 158 }
160 159
161 void TimeStretch::AutoCorrelation() { 160 void TimeStretch::AutoCorrelation() {
161 // Set scaling factor for cross correlation to protect against overflow.
162 int scaling = kLogCorrelationLen - WebRtcSpl_NormW32(
163 max_input_value_ * max_input_value_);
164 scaling = std::max(0, scaling);
165
162 // Calculate correlation from lag kMinLag to lag kMaxLag in 4 kHz domain. 166 // Calculate correlation from lag kMinLag to lag kMaxLag in 4 kHz domain.
163 int32_t auto_corr[kCorrelationLen]; 167 int32_t auto_corr[kCorrelationLen];
164 CrossCorrelationWithAutoShift( 168 WebRtcSpl_CrossCorrelation(auto_corr, &downsampled_input_[kMaxLag],
165 &downsampled_input_[kMaxLag], &downsampled_input_[kMaxLag - kMinLag], 169 &downsampled_input_[kMaxLag - kMinLag],
166 kCorrelationLen, kMaxLag - kMinLag, -1, auto_corr); 170 kCorrelationLen, kMaxLag - kMinLag, scaling, -1);
167 171
168 // Normalize correlation to 14 bits and write to |auto_correlation_|. 172 // Normalize correlation to 14 bits and write to |auto_correlation_|.
169 int32_t max_corr = WebRtcSpl_MaxAbsValueW32(auto_corr, kCorrelationLen); 173 int32_t max_corr = WebRtcSpl_MaxAbsValueW32(auto_corr, kCorrelationLen);
170 int scaling = std::max(0, 17 - WebRtcSpl_NormW32(max_corr)); 174 scaling = std::max(0, 17 - WebRtcSpl_NormW32(max_corr));
171 WebRtcSpl_VectorBitShiftW32ToW16(auto_correlation_, kCorrelationLen, 175 WebRtcSpl_VectorBitShiftW32ToW16(auto_correlation_, kCorrelationLen,
172 auto_corr, scaling); 176 auto_corr, scaling);
173 } 177 }
174 178
175 bool TimeStretch::SpeechDetection(int32_t vec1_energy, int32_t vec2_energy, 179 bool TimeStretch::SpeechDetection(int32_t vec1_energy, int32_t vec2_energy,
176 size_t peak_index, int scaling) const { 180 size_t peak_index, int scaling) const {
177 // Check if the signal seems to be active speech or not (simple VAD). 181 // Check if the signal seems to be active speech or not (simple VAD).
178 // If (vec1_energy + vec2_energy) / (2 * peak_index) <= 182 // If (vec1_energy + vec2_energy) / (2 * peak_index) <=
179 // 8 * background_noise_energy, then we say that the signal contains no 183 // 8 * background_noise_energy, then we say that the signal contains no
180 // active speech. 184 // active speech.
(...skipping 23 matching lines...) Expand all
204 int temp_scale = WebRtcSpl_NormW32(left_side); 208 int temp_scale = WebRtcSpl_NormW32(left_side);
205 left_side = left_side << temp_scale; 209 left_side = left_side << temp_scale;
206 right_side = right_side >> (2 * scaling - temp_scale); 210 right_side = right_side >> (2 * scaling - temp_scale);
207 } else { 211 } else {
208 left_side = left_side << 2 * scaling; 212 left_side = left_side << 2 * scaling;
209 } 213 }
210 return left_side > right_side; 214 return left_side > right_side;
211 } 215 }
212 216
213 } // namespace webrtc 217 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698