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

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

Issue 1424663003: Lock scheme #8: Introduced the new locking scheme (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@add_threadcheckers_CL
Patch Set: Created 5 years, 1 month 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/noise_suppression_impl.h" 11 #include "webrtc/modules/audio_processing/noise_suppression_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "webrtc/base/criticalsection.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h" 16 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #if defined(WEBRTC_NS_FLOAT) 17 #if defined(WEBRTC_NS_FLOAT)
17 #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h" 18 #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h"
18 #elif defined(WEBRTC_NS_FIXED) 19 #elif defined(WEBRTC_NS_FIXED)
19 #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h" 20 #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h"
20 #endif 21 #endif
21 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
22 22
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 #if defined(WEBRTC_NS_FLOAT) 26 #if defined(WEBRTC_NS_FLOAT)
27 typedef NsHandle Handle; 27 typedef NsHandle Handle;
28 #elif defined(WEBRTC_NS_FIXED) 28 #elif defined(WEBRTC_NS_FIXED)
29 typedef NsxHandle Handle; 29 typedef NsxHandle Handle;
30 #endif 30 #endif
31 31
32 namespace { 32 namespace {
33 int MapSetting(NoiseSuppression::Level level) { 33 int MapSetting(NoiseSuppression::Level level) {
34 switch (level) { 34 switch (level) {
35 case NoiseSuppression::kLow: 35 case NoiseSuppression::kLow:
36 return 0; 36 return 0;
37 case NoiseSuppression::kModerate: 37 case NoiseSuppression::kModerate:
38 return 1; 38 return 1;
39 case NoiseSuppression::kHigh: 39 case NoiseSuppression::kHigh:
40 return 2; 40 return 2;
41 case NoiseSuppression::kVeryHigh: 41 case NoiseSuppression::kVeryHigh:
42 return 3; 42 return 3;
43 } 43 }
44 assert(false); 44 assert(false);
45 return -1; 45 return -1;
46 } 46 }
47 } // namespace 47 } // namespace
48 48
49 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm, 49 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm,
50 CriticalSectionWrapper* crit, 50 rtc::CriticalSection* crit,
51 rtc::ThreadChecker* capture_thread) 51 rtc::ThreadChecker* capture_thread)
52 : ProcessingComponent(), 52 : ProcessingComponent(),
53 apm_(apm), 53 apm_(apm),
54 crit_(crit), 54 crit_(crit),
55 capture_thread_(capture_thread), 55 capture_thread_(capture_thread),
56 level_(kModerate) {} 56 level_(kModerate) {}
57 57
58 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} 58 NoiseSuppressionImpl::~NoiseSuppressionImpl() {}
59 59
60 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { 60 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 WebRtcNsx_Process(my_handle, 94 WebRtcNsx_Process(my_handle,
95 audio->split_bands_const(i), 95 audio->split_bands_const(i),
96 audio->num_bands(), 96 audio->num_bands(),
97 audio->split_bands(i)); 97 audio->split_bands(i));
98 #endif 98 #endif
99 } 99 }
100 return apm_->kNoError; 100 return apm_->kNoError;
101 } 101 }
102 102
103 int NoiseSuppressionImpl::Enable(bool enable) { 103 int NoiseSuppressionImpl::Enable(bool enable) {
104 CriticalSectionScoped crit_scoped(crit_); 104 rtc::CritScope cs(crit_);
105 return EnableComponent(enable); 105 return EnableComponent(enable);
106 } 106 }
107 107
108 bool NoiseSuppressionImpl::is_enabled() const { 108 bool NoiseSuppressionImpl::is_enabled() const {
109 rtc::CritScope cs(crit_);
109 return is_component_enabled(); 110 return is_component_enabled();
110 } 111 }
111 112
112 int NoiseSuppressionImpl::set_level(Level level) { 113 int NoiseSuppressionImpl::set_level(Level level) {
113 CriticalSectionScoped crit_scoped(crit_); 114 rtc::CritScope cs(crit_);
114 if (MapSetting(level) == -1) { 115 if (MapSetting(level) == -1) {
115 return apm_->kBadParameterError; 116 return apm_->kBadParameterError;
116 } 117 }
117 118
118 level_ = level; 119 level_ = level;
119 return Configure(); 120 return Configure();
120 } 121 }
121 122
122 NoiseSuppression::Level NoiseSuppressionImpl::level() const { 123 NoiseSuppression::Level NoiseSuppressionImpl::level() const {
124 rtc::CritScope cs(crit_);
123 return level_; 125 return level_;
124 } 126 }
125 127
126 float NoiseSuppressionImpl::speech_probability() const { 128 float NoiseSuppressionImpl::speech_probability() const {
129 rtc::CritScope cs(crit_);
127 #if defined(WEBRTC_NS_FLOAT) 130 #if defined(WEBRTC_NS_FLOAT)
128 float probability_average = 0.0f; 131 float probability_average = 0.0f;
129 for (int i = 0; i < num_handles(); i++) { 132 for (int i = 0; i < num_handles(); i++) {
130 Handle* my_handle = static_cast<Handle*>(handle(i)); 133 Handle* my_handle = static_cast<Handle*>(handle(i));
131 probability_average += WebRtcNs_prior_speech_probability(my_handle); 134 probability_average += WebRtcNs_prior_speech_probability(my_handle);
132 } 135 }
133 return probability_average / num_handles(); 136 return probability_average / num_handles();
134 #elif defined(WEBRTC_NS_FIXED) 137 #elif defined(WEBRTC_NS_FIXED)
135 // Currently not available for the fixed point implementation. 138 // Currently not available for the fixed point implementation.
136 return apm_->kUnsupportedFunctionError; 139 return apm_->kUnsupportedFunctionError;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 int NoiseSuppressionImpl::num_handles_required() const { 179 int NoiseSuppressionImpl::num_handles_required() const {
177 return apm_->num_output_channels(); 180 return apm_->num_output_channels();
178 } 181 }
179 182
180 int NoiseSuppressionImpl::GetHandleError(void* handle) const { 183 int NoiseSuppressionImpl::GetHandleError(void* handle) const {
181 // The NS has no get_error() function. 184 // The NS has no get_error() function.
182 assert(handle != NULL); 185 assert(handle != NULL);
183 return apm_->kUnspecifiedError; 186 return apm_->kUnspecifiedError;
184 } 187 }
185 } // namespace webrtc 188 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698