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

Side by Side Diff: webrtc/modules/audio_processing/agc/loudness_histogram.cc

Issue 2320053003: webrtc/modules/audio_processing: Use RTC_DCHECK() instead of assert() (Closed)
Patch Set: rebase 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
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_processing/agc/loudness_histogram.h" 11 #include "webrtc/modules/audio_processing/agc/loudness_histogram.h"
12 12
13 #include <cmath> 13 #include <cmath>
14 #include <cstring> 14 #include <cstring>
15 15
16 #include "webrtc/base/checks.h"
16 #include "webrtc/modules/include/module_common_types.h" 17 #include "webrtc/modules/include/module_common_types.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 20
20 static const double kHistBinCenters[] = { 21 static const double kHistBinCenters[] = {
21 7.59621091765857e-02, 9.02036021061016e-02, 1.07115112009343e-01, 22 7.59621091765857e-02, 9.02036021061016e-02, 1.07115112009343e-01,
22 1.27197217770508e-01, 1.51044347572047e-01, 1.79362373905283e-01, 23 1.27197217770508e-01, 1.51044347572047e-01, 1.79362373905283e-01,
23 2.12989507320644e-01, 2.52921107370304e-01, 3.00339145144454e-01, 24 2.12989507320644e-01, 2.52921107370304e-01, 3.00339145144454e-01,
24 3.56647189489147e-01, 4.23511952494003e-01, 5.02912623991786e-01, 25 3.56647189489147e-01, 4.23511952494003e-01, 5.02912623991786e-01,
25 5.97199455365749e-01, 7.09163326739184e-01, 8.42118356728544e-01, 26 5.97199455365749e-01, 7.09163326739184e-01, 8.42118356728544e-01,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Find the corresponding bin. 95 // Find the corresponding bin.
95 int hist_index = GetBinIndex(rms); 96 int hist_index = GetBinIndex(rms);
96 // To Q10 domain. 97 // To Q10 domain.
97 int prob_q10 = 98 int prob_q10 =
98 static_cast<int16_t>(floor(activity_probaility * kProbQDomain)); 99 static_cast<int16_t>(floor(activity_probaility * kProbQDomain));
99 InsertNewestEntryAndUpdate(prob_q10, hist_index); 100 InsertNewestEntryAndUpdate(prob_q10, hist_index);
100 } 101 }
101 102
102 // Doing nothing if buffer is not full, yet. 103 // Doing nothing if buffer is not full, yet.
103 void LoudnessHistogram::RemoveOldestEntryAndUpdate() { 104 void LoudnessHistogram::RemoveOldestEntryAndUpdate() {
104 assert(len_circular_buffer_ > 0); 105 RTC_DCHECK_GT(len_circular_buffer_, 0);
105 // Do nothing if circular buffer is not full. 106 // Do nothing if circular buffer is not full.
106 if (!buffer_is_full_) 107 if (!buffer_is_full_)
107 return; 108 return;
108 109
109 int oldest_prob = activity_probability_[buffer_index_]; 110 int oldest_prob = activity_probability_[buffer_index_];
110 int oldest_hist_index = hist_bin_index_[buffer_index_]; 111 int oldest_hist_index = hist_bin_index_[buffer_index_];
111 UpdateHist(-oldest_prob, oldest_hist_index); 112 UpdateHist(-oldest_prob, oldest_hist_index);
112 } 113 }
113 114
114 void LoudnessHistogram::RemoveTransient() { 115 void LoudnessHistogram::RemoveTransient() {
115 // Don't expect to be here if high-activity region is longer than 116 // Don't expect to be here if high-activity region is longer than
116 // |kTransientWidthThreshold| or there has not been any transient. 117 // |kTransientWidthThreshold| or there has not been any transient.
117 assert(len_high_activity_ <= kTransientWidthThreshold); 118 RTC_DCHECK_LE(len_high_activity_, kTransientWidthThreshold);
118 int index = 119 int index =
119 (buffer_index_ > 0) ? (buffer_index_ - 1) : len_circular_buffer_ - 1; 120 (buffer_index_ > 0) ? (buffer_index_ - 1) : len_circular_buffer_ - 1;
120 while (len_high_activity_ > 0) { 121 while (len_high_activity_ > 0) {
121 UpdateHist(-activity_probability_[index], hist_bin_index_[index]); 122 UpdateHist(-activity_probability_[index], hist_bin_index_[index]);
122 activity_probability_[index] = 0; 123 activity_probability_[index] = 0;
123 index = (index > 0) ? (index - 1) : (len_circular_buffer_ - 1); 124 index = (index > 0) ? (index - 1) : (len_circular_buffer_ - 1);
124 len_high_activity_--; 125 len_high_activity_--;
125 } 126 }
126 } 127 }
127 128
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 p = static_cast<double>(bin_count_q10_[n]) * p_total_inverse; 220 p = static_cast<double>(bin_count_q10_[n]) * p_total_inverse;
220 mean_val += p * kHistBinCenters[n]; 221 mean_val += p * kHistBinCenters[n];
221 } 222 }
222 } else { 223 } else {
223 mean_val = kHistBinCenters[0]; 224 mean_val = kHistBinCenters[0];
224 } 225 }
225 return mean_val; 226 return mean_val;
226 } 227 }
227 228
228 } // namespace webrtc 229 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/agc/agc_manager_direct.cc ('k') | webrtc/modules/audio_processing/audio_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698