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

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

Issue 1227213002: Update audio code to use size_t more correctly, webrtc/modules/audio_processing/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 10 matching lines...) Expand all
21 : sum_square_(0), 21 : sum_square_(0),
22 sample_count_(0) {} 22 sample_count_(0) {}
23 23
24 RMSLevel::~RMSLevel() {} 24 RMSLevel::~RMSLevel() {}
25 25
26 void RMSLevel::Reset() { 26 void RMSLevel::Reset() {
27 sum_square_ = 0; 27 sum_square_ = 0;
28 sample_count_ = 0; 28 sample_count_ = 0;
29 } 29 }
30 30
31 void RMSLevel::Process(const int16_t* data, int length) { 31 void RMSLevel::Process(const int16_t* data, size_t length) {
32 for (int i = 0; i < length; ++i) { 32 for (size_t i = 0; i < length; ++i) {
33 sum_square_ += data[i] * data[i]; 33 sum_square_ += data[i] * data[i];
34 } 34 }
35 sample_count_ += length; 35 sample_count_ += length;
36 } 36 }
37 37
38 void RMSLevel::ProcessMuted(int length) { 38 void RMSLevel::ProcessMuted(size_t length) {
39 sample_count_ += length; 39 sample_count_ += length;
40 } 40 }
41 41
42 int RMSLevel::RMS() { 42 int RMSLevel::RMS() {
43 if (sample_count_ == 0 || sum_square_ == 0) { 43 if (sample_count_ == 0 || sum_square_ == 0) {
44 Reset(); 44 Reset();
45 return kMinLevel; 45 return kMinLevel;
46 } 46 }
47 47
48 // Normalize by the max level. 48 // Normalize by the max level.
49 float rms = sum_square_ / (sample_count_ * kMaxSquaredLevel); 49 float rms = sum_square_ / (sample_count_ * kMaxSquaredLevel);
50 // 20log_10(x^0.5) = 10log_10(x) 50 // 20log_10(x^0.5) = 10log_10(x)
51 rms = 10 * log10(rms); 51 rms = 10 * log10(rms);
52 assert(rms <= 0); 52 assert(rms <= 0);
53 if (rms < -kMinLevel) 53 if (rms < -kMinLevel)
54 rms = -kMinLevel; 54 rms = -kMinLevel;
55 55
56 rms = -rms; 56 rms = -rms;
57 Reset(); 57 Reset();
58 return static_cast<int>(rms + 0.5); 58 return static_cast<int>(rms + 0.5);
59 } 59 }
60 60
61 } // namespace webrtc 61 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/rms_level.h ('k') | webrtc/modules/audio_processing/splitting_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698