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

Side by Side Diff: webrtc/modules/audio_processing/level_controller/level_controller.cc

Issue 2268163004: Fix error when accumulating floats in an int. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Actually fix the problem. Created 4 years, 3 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 | « no previous file | 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 17 matching lines...) Expand all
28 #include "webrtc/system_wrappers/include/metrics.h" 28 #include "webrtc/system_wrappers/include/metrics.h"
29 29
30 namespace webrtc { 30 namespace webrtc {
31 namespace { 31 namespace {
32 32
33 void UpdateAndRemoveDcLevel(float forgetting_factor, 33 void UpdateAndRemoveDcLevel(float forgetting_factor,
34 float* dc_level, 34 float* dc_level,
35 rtc::ArrayView<float> x) { 35 rtc::ArrayView<float> x) {
36 RTC_DCHECK(!x.empty()); 36 RTC_DCHECK(!x.empty());
37 float mean = 37 float mean =
38 std::accumulate(x.begin(), x.end(), 0) / static_cast<float>(x.size()); 38 std::accumulate(x.begin(), x.end(), 0.0f) / static_cast<float>(x.size());
39 *dc_level += forgetting_factor * (mean - *dc_level); 39 *dc_level += forgetting_factor * (mean - *dc_level);
40 40
41 for (float& v : x) { 41 for (float& v : x) {
42 v -= *dc_level; 42 v -= *dc_level;
43 } 43 }
44 } 44 }
45 45
46 float FrameEnergy(const AudioBuffer& audio) { 46 float FrameEnergy(const AudioBuffer& audio) {
47 float energy = 0.f; 47 float energy = 0.f;
48 for (size_t k = 0; k < audio.num_channels(); ++k) { 48 for (size_t k = 0; k < audio.num_channels(); ++k) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); 221 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_);
222 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); 222 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy);
223 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level); 223 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level);
224 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); 224 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain);
225 225
226 data_dumper_->DumpWav("lc_output", audio->num_frames(), 226 data_dumper_->DumpWav("lc_output", audio->num_frames(),
227 audio->channels_f()[0], *sample_rate_hz_, 1); 227 audio->channels_f()[0], *sample_rate_hz_, 1);
228 } 228 }
229 229
230 } // namespace webrtc 230 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698