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

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 a threadsafe wrapper for the random generator in the locktest. Fixed an unprotected variabl… Created 5 years 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/modules/audio_processing/audio_buffer.h" 15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #if defined(WEBRTC_NS_FLOAT) 16 #if defined(WEBRTC_NS_FLOAT)
17 #include "webrtc/modules/audio_processing/ns/noise_suppression.h" 17 #include "webrtc/modules/audio_processing/ns/noise_suppression.h"
18 #elif defined(WEBRTC_NS_FIXED) 18 #elif defined(WEBRTC_NS_FIXED)
19 #include "webrtc/modules/audio_processing/ns/noise_suppression_x.h" 19 #include "webrtc/modules/audio_processing/ns/noise_suppression_x.h"
20 #endif 20 #endif
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 21
23 22
24 namespace webrtc { 23 namespace webrtc {
25 24
26 #if defined(WEBRTC_NS_FLOAT) 25 #if defined(WEBRTC_NS_FLOAT)
27 typedef NsHandle Handle; 26 typedef NsHandle Handle;
28 #elif defined(WEBRTC_NS_FIXED) 27 #elif defined(WEBRTC_NS_FIXED)
29 typedef NsxHandle Handle; 28 typedef NsxHandle Handle;
30 #endif 29 #endif
31 30
32 namespace { 31 namespace {
33 int MapSetting(NoiseSuppression::Level level) { 32 int MapSetting(NoiseSuppression::Level level) {
34 switch (level) { 33 switch (level) {
35 case NoiseSuppression::kLow: 34 case NoiseSuppression::kLow:
36 return 0; 35 return 0;
37 case NoiseSuppression::kModerate: 36 case NoiseSuppression::kModerate:
38 return 1; 37 return 1;
39 case NoiseSuppression::kHigh: 38 case NoiseSuppression::kHigh:
40 return 2; 39 return 2;
41 case NoiseSuppression::kVeryHigh: 40 case NoiseSuppression::kVeryHigh:
42 return 3; 41 return 3;
43 } 42 }
44 assert(false); 43 assert(false);
45 return -1; 44 return -1;
46 } 45 }
47 } // namespace 46 } // namespace
48 47
49 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm, 48 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm,
50 CriticalSectionWrapper* crit) 49 rtc::CriticalSection* crit)
51 : ProcessingComponent(), 50 : ProcessingComponent(), apm_(apm), crit_(crit), level_(kModerate) {
52 apm_(apm), 51 RTC_DCHECK(apm);
53 crit_(crit), 52 RTC_DCHECK(crit);
54 level_(kModerate) {} 53 }
55 54
56 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} 55 NoiseSuppressionImpl::~NoiseSuppressionImpl() {}
57 56
58 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { 57 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
59 #if defined(WEBRTC_NS_FLOAT) 58 #if defined(WEBRTC_NS_FLOAT)
60 if (!is_component_enabled()) { 59 if (!is_component_enabled()) {
61 return apm_->kNoError; 60 return AudioProcessing::kNoError;
62 } 61 }
63 assert(audio->num_frames_per_band() <= 160); 62 assert(audio->num_frames_per_band() <= 160);
64 assert(audio->num_channels() == num_handles()); 63 assert(audio->num_channels() == num_handles());
65 64
66 for (int i = 0; i < num_handles(); ++i) { 65 for (int i = 0; i < num_handles(); ++i) {
67 Handle* my_handle = static_cast<Handle*>(handle(i)); 66 Handle* my_handle = static_cast<Handle*>(handle(i));
68 67
69 WebRtcNs_Analyze(my_handle, audio->split_bands_const_f(i)[kBand0To8kHz]); 68 WebRtcNs_Analyze(my_handle, audio->split_bands_const_f(i)[kBand0To8kHz]);
70 } 69 }
71 #endif 70 #endif
72 return apm_->kNoError; 71 return AudioProcessing::kNoError;
73 } 72 }
74 73
75 int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { 74 int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
75 rtc::CritScope cs(crit_);
76 if (!is_component_enabled()) { 76 if (!is_component_enabled()) {
77 return apm_->kNoError; 77 return AudioProcessing::kNoError;
78 } 78 }
79 assert(audio->num_frames_per_band() <= 160); 79 assert(audio->num_frames_per_band() <= 160);
80 assert(audio->num_channels() == num_handles()); 80 assert(audio->num_channels() == num_handles());
81 81
82 for (int i = 0; i < num_handles(); ++i) { 82 for (int i = 0; i < num_handles(); ++i) {
83 Handle* my_handle = static_cast<Handle*>(handle(i)); 83 Handle* my_handle = static_cast<Handle*>(handle(i));
84 #if defined(WEBRTC_NS_FLOAT) 84 #if defined(WEBRTC_NS_FLOAT)
85 WebRtcNs_Process(my_handle, 85 WebRtcNs_Process(my_handle,
86 audio->split_bands_const_f(i), 86 audio->split_bands_const_f(i),
87 audio->num_bands(), 87 audio->num_bands(),
88 audio->split_bands_f(i)); 88 audio->split_bands_f(i));
89 #elif defined(WEBRTC_NS_FIXED) 89 #elif defined(WEBRTC_NS_FIXED)
90 WebRtcNsx_Process(my_handle, 90 WebRtcNsx_Process(my_handle,
91 audio->split_bands_const(i), 91 audio->split_bands_const(i),
92 audio->num_bands(), 92 audio->num_bands(),
93 audio->split_bands(i)); 93 audio->split_bands(i));
94 #endif 94 #endif
95 } 95 }
96 return apm_->kNoError; 96 return AudioProcessing::kNoError;
97 } 97 }
98 98
99 int NoiseSuppressionImpl::Enable(bool enable) { 99 int NoiseSuppressionImpl::Enable(bool enable) {
100 CriticalSectionScoped crit_scoped(crit_); 100 rtc::CritScope cs(crit_);
101 return EnableComponent(enable); 101 return EnableComponent(enable);
102 } 102 }
103 103
104 bool NoiseSuppressionImpl::is_enabled() const { 104 bool NoiseSuppressionImpl::is_enabled() const {
105 rtc::CritScope cs(crit_);
105 return is_component_enabled(); 106 return is_component_enabled();
106 } 107 }
107 108
108 int NoiseSuppressionImpl::set_level(Level level) { 109 int NoiseSuppressionImpl::set_level(Level level) {
109 CriticalSectionScoped crit_scoped(crit_); 110 rtc::CritScope cs(crit_);
110 if (MapSetting(level) == -1) { 111 if (MapSetting(level) == -1) {
111 return apm_->kBadParameterError; 112 return AudioProcessing::kBadParameterError;
112 } 113 }
113 114
114 level_ = level; 115 level_ = level;
115 return Configure(); 116 return Configure();
116 } 117 }
117 118
118 NoiseSuppression::Level NoiseSuppressionImpl::level() const { 119 NoiseSuppression::Level NoiseSuppressionImpl::level() const {
120 rtc::CritScope cs(crit_);
119 return level_; 121 return level_;
120 } 122 }
121 123
122 float NoiseSuppressionImpl::speech_probability() const { 124 float NoiseSuppressionImpl::speech_probability() const {
125 rtc::CritScope cs(crit_);
123 #if defined(WEBRTC_NS_FLOAT) 126 #if defined(WEBRTC_NS_FLOAT)
124 float probability_average = 0.0f; 127 float probability_average = 0.0f;
125 for (int i = 0; i < num_handles(); i++) { 128 for (int i = 0; i < num_handles(); i++) {
126 Handle* my_handle = static_cast<Handle*>(handle(i)); 129 Handle* my_handle = static_cast<Handle*>(handle(i));
127 probability_average += WebRtcNs_prior_speech_probability(my_handle); 130 probability_average += WebRtcNs_prior_speech_probability(my_handle);
128 } 131 }
129 return probability_average / num_handles(); 132 return probability_average / num_handles();
130 #elif defined(WEBRTC_NS_FIXED) 133 #elif defined(WEBRTC_NS_FIXED)
131 // Currently not available for the fixed point implementation. 134 // Currently not available for the fixed point implementation.
132 return apm_->kUnsupportedFunctionError; 135 return AudioProcessing::kUnsupportedFunctionError;
133 #endif 136 #endif
134 } 137 }
135 138
136 void* NoiseSuppressionImpl::CreateHandle() const { 139 void* NoiseSuppressionImpl::CreateHandle() const {
137 #if defined(WEBRTC_NS_FLOAT) 140 #if defined(WEBRTC_NS_FLOAT)
138 return WebRtcNs_Create(); 141 return WebRtcNs_Create();
139 #elif defined(WEBRTC_NS_FIXED) 142 #elif defined(WEBRTC_NS_FIXED)
140 return WebRtcNsx_Create(); 143 return WebRtcNsx_Create();
141 #endif 144 #endif
142 } 145 }
(...skipping 10 matching lines...) Expand all
153 #if defined(WEBRTC_NS_FLOAT) 156 #if defined(WEBRTC_NS_FLOAT)
154 return WebRtcNs_Init(static_cast<Handle*>(handle), 157 return WebRtcNs_Init(static_cast<Handle*>(handle),
155 apm_->proc_sample_rate_hz()); 158 apm_->proc_sample_rate_hz());
156 #elif defined(WEBRTC_NS_FIXED) 159 #elif defined(WEBRTC_NS_FIXED)
157 return WebRtcNsx_Init(static_cast<Handle*>(handle), 160 return WebRtcNsx_Init(static_cast<Handle*>(handle),
158 apm_->proc_sample_rate_hz()); 161 apm_->proc_sample_rate_hz());
159 #endif 162 #endif
160 } 163 }
161 164
162 int NoiseSuppressionImpl::ConfigureHandle(void* handle) const { 165 int NoiseSuppressionImpl::ConfigureHandle(void* handle) const {
166 rtc::CritScope cs(crit_);
163 #if defined(WEBRTC_NS_FLOAT) 167 #if defined(WEBRTC_NS_FLOAT)
164 return WebRtcNs_set_policy(static_cast<Handle*>(handle), 168 return WebRtcNs_set_policy(static_cast<Handle*>(handle),
165 MapSetting(level_)); 169 MapSetting(level_));
166 #elif defined(WEBRTC_NS_FIXED) 170 #elif defined(WEBRTC_NS_FIXED)
167 return WebRtcNsx_set_policy(static_cast<Handle*>(handle), 171 return WebRtcNsx_set_policy(static_cast<Handle*>(handle),
168 MapSetting(level_)); 172 MapSetting(level_));
169 #endif 173 #endif
170 } 174 }
171 175
172 int NoiseSuppressionImpl::num_handles_required() const { 176 int NoiseSuppressionImpl::num_handles_required() const {
173 return apm_->num_output_channels(); 177 return apm_->num_output_channels();
174 } 178 }
175 179
176 int NoiseSuppressionImpl::GetHandleError(void* handle) const { 180 int NoiseSuppressionImpl::GetHandleError(void* handle) const {
177 // The NS has no get_error() function. 181 // The NS has no get_error() function.
178 assert(handle != NULL); 182 assert(handle != NULL);
179 return apm_->kUnspecifiedError; 183 return AudioProcessing::kUnspecifiedError;
180 } 184 }
181 } // namespace webrtc 185 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/noise_suppression_impl.h ('k') | webrtc/modules/audio_processing/voice_detection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698