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

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

Issue 2320053003: webrtc/modules/audio_processing: Use RTC_DCHECK() instead of assert() (Closed)
Patch Set: 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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/agc_manager_direct.h" 11 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h"
12 12
13 #include <cassert> 13 #include <cassert>
aleloi 2016/09/12 10:04:56 This should be removed as well.
kwiberg-webrtc 2016/09/13 11:15:00 Thanks.
14 #include <cmath> 14 #include <cmath>
15 15
16 #ifdef WEBRTC_AGC_DEBUG_DUMP 16 #ifdef WEBRTC_AGC_DEBUG_DUMP
17 #include <cstdio> 17 #include <cstdio>
18 #endif 18 #endif
19 19
20 #include "webrtc/base/checks.h"
20 #include "webrtc/modules/audio_processing/agc/gain_map_internal.h" 21 #include "webrtc/modules/audio_processing/agc/gain_map_internal.h"
21 #include "webrtc/modules/audio_processing/gain_control_impl.h" 22 #include "webrtc/modules/audio_processing/gain_control_impl.h"
22 #include "webrtc/modules/include/module_common_types.h" 23 #include "webrtc/modules/include/module_common_types.h"
23 #include "webrtc/system_wrappers/include/logging.h" 24 #include "webrtc/system_wrappers/include/logging.h"
24 25
25 namespace webrtc { 26 namespace webrtc {
26 27
27 namespace { 28 namespace {
28 29
29 // Lowest the microphone level can be lowered due to clipping. 30 // Lowest the microphone level can be lowered due to clipping.
(...skipping 24 matching lines...) Expand all
54 55
55 // Maximum additional gain allowed to compensate for microphone level 56 // Maximum additional gain allowed to compensate for microphone level
56 // restrictions from clipping events. 57 // restrictions from clipping events.
57 const int kSurplusCompressionGain = 6; 58 const int kSurplusCompressionGain = 6;
58 59
59 int ClampLevel(int mic_level) { 60 int ClampLevel(int mic_level) {
60 return std::min(std::max(kMinMicLevel, mic_level), kMaxMicLevel); 61 return std::min(std::max(kMinMicLevel, mic_level), kMaxMicLevel);
61 } 62 }
62 63
63 int LevelFromGainError(int gain_error, int level) { 64 int LevelFromGainError(int gain_error, int level) {
64 assert(level >= 0 && level <= kMaxMicLevel); 65 RTC_DCHECK_GE(level, 0);
66 RTC_DCHECK_LE(level, kMaxMicLevel);
65 if (gain_error == 0) { 67 if (gain_error == 0) {
66 return level; 68 return level;
67 } 69 }
68 // TODO(ajm): Could be made more efficient with a binary search. 70 // TODO(ajm): Could be made more efficient with a binary search.
69 int new_level = level; 71 int new_level = level;
70 if (gain_error > 0) { 72 if (gain_error > 0) {
71 while (kGainMap[new_level] - kGainMap[level] < gain_error && 73 while (kGainMap[new_level] - kGainMap[level] < gain_error &&
72 new_level < kMaxMicLevel) { 74 new_level < kMaxMicLevel) {
73 ++new_level; 75 ++new_level;
74 } 76 }
75 } else { 77 } else {
76 while (kGainMap[new_level] - kGainMap[level] > gain_error && 78 while (kGainMap[new_level] - kGainMap[level] > gain_error &&
77 new_level > kMinMicLevel) { 79 new_level > kMinMicLevel) {
78 --new_level; 80 --new_level;
79 } 81 }
80 } 82 }
81 return new_level; 83 return new_level;
82 } 84 }
83 85
84 } // namespace 86 } // namespace
85 87
86 // Facility for dumping debug audio files. All methods are no-ops in the 88 // Facility for dumping debug audio files. All methods are no-ops in the
87 // default case where WEBRTC_AGC_DEBUG_DUMP is undefined. 89 // default case where WEBRTC_AGC_DEBUG_DUMP is undefined.
88 class DebugFile { 90 class DebugFile {
89 #ifdef WEBRTC_AGC_DEBUG_DUMP 91 #ifdef WEBRTC_AGC_DEBUG_DUMP
90 public: 92 public:
91 explicit DebugFile(const char* filename) 93 explicit DebugFile(const char* filename)
92 : file_(fopen(filename, "wb")) { 94 : file_(fopen(filename, "wb")) {
93 assert(file_); 95 RTC_DCHECK(file_);
94 } 96 }
95 ~DebugFile() { 97 ~DebugFile() {
96 fclose(file_); 98 fclose(file_);
97 } 99 }
98 void Write(const int16_t* data, size_t length_samples) { 100 void Write(const int16_t* data, size_t length_samples) {
99 fwrite(data, 1, length_samples * sizeof(int16_t), file_); 101 fwrite(data, 1, length_samples * sizeof(int16_t), file_);
100 } 102 }
101 private: 103 private:
102 FILE* file_; 104 FILE* file_;
103 #else 105 #else
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 240
239 if (check_volume_on_next_process_) { 241 if (check_volume_on_next_process_) {
240 check_volume_on_next_process_ = false; 242 check_volume_on_next_process_ = false;
241 // We have to wait until the first process call to check the volume, 243 // We have to wait until the first process call to check the volume,
242 // because Chromium doesn't guarantee it to be valid any earlier. 244 // because Chromium doesn't guarantee it to be valid any earlier.
243 CheckVolumeAndReset(); 245 CheckVolumeAndReset();
244 } 246 }
245 247
246 if (agc_->Process(audio, length, sample_rate_hz) != 0) { 248 if (agc_->Process(audio, length, sample_rate_hz) != 0) {
247 LOG(LS_ERROR) << "Agc::Process failed"; 249 LOG(LS_ERROR) << "Agc::Process failed";
248 assert(false); 250 RTC_NOTREACHED();
249 } 251 }
250 252
251 UpdateGain(); 253 UpdateGain();
252 UpdateCompressor(); 254 UpdateCompressor();
253 255
254 file_postproc_->Write(audio, length); 256 file_postproc_->Write(audio, length);
255 } 257 }
256 258
257 void AgcManagerDirect::SetLevel(int new_level) { 259 void AgcManagerDirect::SetLevel(int new_level) {
258 int voe_level = volume_callbacks_->GetMicVolume(); 260 int voe_level = volume_callbacks_->GetMicVolume();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 292 }
291 293
292 volume_callbacks_->SetMicVolume(new_level); 294 volume_callbacks_->SetMicVolume(new_level);
293 LOG(LS_INFO) << "[agc] voe_level=" << voe_level << ", " 295 LOG(LS_INFO) << "[agc] voe_level=" << voe_level << ", "
294 << "level_=" << level_ << ", " 296 << "level_=" << level_ << ", "
295 << "new_level=" << new_level; 297 << "new_level=" << new_level;
296 level_ = new_level; 298 level_ = new_level;
297 } 299 }
298 300
299 void AgcManagerDirect::SetMaxLevel(int level) { 301 void AgcManagerDirect::SetMaxLevel(int level) {
300 assert(level >= kClippedLevelMin); 302 RTC_DCHECK_GE(level, kClippedLevelMin);
301 max_level_ = level; 303 max_level_ = level;
302 // Scale the |kSurplusCompressionGain| linearly across the restricted 304 // Scale the |kSurplusCompressionGain| linearly across the restricted
303 // level range. 305 // level range.
304 max_compression_gain_ = kMaxCompressionGain + std::floor( 306 max_compression_gain_ = kMaxCompressionGain + std::floor(
305 (1.f * kMaxMicLevel - max_level_) / (kMaxMicLevel - kClippedLevelMin) * 307 (1.f * kMaxMicLevel - max_level_) / (kMaxMicLevel - kClippedLevelMin) *
306 kSurplusCompressionGain + 0.5f); 308 kSurplusCompressionGain + 0.5f);
307 LOG(LS_INFO) << "[agc] max_level_=" << max_level_ 309 LOG(LS_INFO) << "[agc] max_level_=" << max_level_
308 << ", max_compression_gain_=" << max_compression_gain_; 310 << ", max_compression_gain_=" << max_compression_gain_;
309 } 311 }
310 312
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 compression_ = new_compression; 436 compression_ = new_compression;
435 compression_accumulator_ = new_compression; 437 compression_accumulator_ = new_compression;
436 if (gctrl_->set_compression_gain_db(compression_) != 0) { 438 if (gctrl_->set_compression_gain_db(compression_) != 0) {
437 LOG(LS_ERROR) << "set_compression_gain_db(" << compression_ 439 LOG(LS_ERROR) << "set_compression_gain_db(" << compression_
438 << ") failed."; 440 << ") failed.";
439 } 441 }
440 } 442 }
441 } 443 }
442 444
443 } // namespace webrtc 445 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/agc/agc.cc ('k') | webrtc/modules/audio_processing/agc/loudness_histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698