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

Side by Side Diff: webrtc/modules/audio_coding/neteq/time_stretch.cc

Issue 2714063002: Introduce dchecked_cast, and start using it (Closed)
Patch Set: Created 3 years, 9 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
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (background_noise_.initialized()) { 187 if (background_noise_.initialized()) {
188 right_side = background_noise_.Energy(master_channel_); 188 right_side = background_noise_.Energy(master_channel_);
189 } else { 189 } else {
190 // If noise parameters have not been estimated, use a fixed threshold. 190 // If noise parameters have not been estimated, use a fixed threshold.
191 right_side = 75000; 191 right_side = 75000;
192 } 192 }
193 int right_scale = 16 - WebRtcSpl_NormW32(right_side); 193 int right_scale = 16 - WebRtcSpl_NormW32(right_side);
194 right_scale = std::max(0, right_scale); 194 right_scale = std::max(0, right_scale);
195 left_side = left_side >> right_scale; 195 left_side = left_side >> right_scale;
196 right_side = 196 right_side =
197 rtc::checked_cast<int32_t>(peak_index) * (right_side >> right_scale); 197 rtc::dchecked_cast<int32_t>(peak_index) * (right_side >> right_scale);
198 198
199 // Scale |left_side| properly before comparing with |right_side|. 199 // Scale |left_side| properly before comparing with |right_side|.
200 // (|scaling| is the scale factor before energy calculation, thus the scale 200 // (|scaling| is the scale factor before energy calculation, thus the scale
201 // factor for the energy is 2 * scaling.) 201 // factor for the energy is 2 * scaling.)
202 if (WebRtcSpl_NormW32(left_side) < 2 * scaling) { 202 if (WebRtcSpl_NormW32(left_side) < 2 * scaling) {
203 // Cannot scale only |left_side|, must scale |right_side| too. 203 // Cannot scale only |left_side|, must scale |right_side| too.
204 int temp_scale = WebRtcSpl_NormW32(left_side); 204 int temp_scale = WebRtcSpl_NormW32(left_side);
205 left_side = left_side << temp_scale; 205 left_side = left_side << temp_scale;
206 right_side = right_side >> (2 * scaling - temp_scale); 206 right_side = right_side >> (2 * scaling - temp_scale);
207 } else { 207 } else {
208 left_side = left_side << 2 * scaling; 208 left_side = left_side << 2 * scaling;
209 } 209 }
210 return left_side > right_side; 210 return left_side > right_side;
211 } 211 }
212 212
213 } // namespace webrtc 213 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698