OLD | NEW |
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), | |
53 crit_(crit), | |
54 level_(kModerate) {} | |
55 | 51 |
56 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} | 52 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} |
57 | 53 |
58 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 54 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
59 #if defined(WEBRTC_NS_FLOAT) | 55 #if defined(WEBRTC_NS_FLOAT) |
60 if (!is_component_enabled()) { | 56 if (!is_component_enabled()) { |
61 return apm_->kNoError; | 57 return apm_->kNoError; |
62 } | 58 } |
63 assert(audio->num_frames_per_band() <= 160); | 59 assert(audio->num_frames_per_band() <= 160); |
64 assert(audio->num_channels() == num_handles()); | 60 assert(audio->num_channels() == num_handles()); |
(...skipping 25 matching lines...) Expand all Loading... |
90 WebRtcNsx_Process(my_handle, | 86 WebRtcNsx_Process(my_handle, |
91 audio->split_bands_const(i), | 87 audio->split_bands_const(i), |
92 audio->num_bands(), | 88 audio->num_bands(), |
93 audio->split_bands(i)); | 89 audio->split_bands(i)); |
94 #endif | 90 #endif |
95 } | 91 } |
96 return apm_->kNoError; | 92 return apm_->kNoError; |
97 } | 93 } |
98 | 94 |
99 int NoiseSuppressionImpl::Enable(bool enable) { | 95 int NoiseSuppressionImpl::Enable(bool enable) { |
100 CriticalSectionScoped crit_scoped(crit_); | 96 rtc::CritScope cs(crit_); |
101 return EnableComponent(enable); | 97 return EnableComponent(enable); |
102 } | 98 } |
103 | 99 |
104 bool NoiseSuppressionImpl::is_enabled() const { | 100 bool NoiseSuppressionImpl::is_enabled() const { |
| 101 rtc::CritScope cs(crit_); |
105 return is_component_enabled(); | 102 return is_component_enabled(); |
106 } | 103 } |
107 | 104 |
108 int NoiseSuppressionImpl::set_level(Level level) { | 105 int NoiseSuppressionImpl::set_level(Level level) { |
109 CriticalSectionScoped crit_scoped(crit_); | 106 rtc::CritScope cs(crit_); |
110 if (MapSetting(level) == -1) { | 107 if (MapSetting(level) == -1) { |
111 return apm_->kBadParameterError; | 108 return apm_->kBadParameterError; |
112 } | 109 } |
113 | 110 |
114 level_ = level; | 111 level_ = level; |
115 return Configure(); | 112 return Configure(); |
116 } | 113 } |
117 | 114 |
118 NoiseSuppression::Level NoiseSuppressionImpl::level() const { | 115 NoiseSuppression::Level NoiseSuppressionImpl::level() const { |
| 116 rtc::CritScope cs(crit_); |
119 return level_; | 117 return level_; |
120 } | 118 } |
121 | 119 |
122 float NoiseSuppressionImpl::speech_probability() const { | 120 float NoiseSuppressionImpl::speech_probability() const { |
| 121 rtc::CritScope cs(crit_); |
123 #if defined(WEBRTC_NS_FLOAT) | 122 #if defined(WEBRTC_NS_FLOAT) |
124 float probability_average = 0.0f; | 123 float probability_average = 0.0f; |
125 for (int i = 0; i < num_handles(); i++) { | 124 for (int i = 0; i < num_handles(); i++) { |
126 Handle* my_handle = static_cast<Handle*>(handle(i)); | 125 Handle* my_handle = static_cast<Handle*>(handle(i)); |
127 probability_average += WebRtcNs_prior_speech_probability(my_handle); | 126 probability_average += WebRtcNs_prior_speech_probability(my_handle); |
128 } | 127 } |
129 return probability_average / num_handles(); | 128 return probability_average / num_handles(); |
130 #elif defined(WEBRTC_NS_FIXED) | 129 #elif defined(WEBRTC_NS_FIXED) |
131 // Currently not available for the fixed point implementation. | 130 // Currently not available for the fixed point implementation. |
132 return apm_->kUnsupportedFunctionError; | 131 return apm_->kUnsupportedFunctionError; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 int NoiseSuppressionImpl::num_handles_required() const { | 171 int NoiseSuppressionImpl::num_handles_required() const { |
173 return apm_->num_output_channels(); | 172 return apm_->num_output_channels(); |
174 } | 173 } |
175 | 174 |
176 int NoiseSuppressionImpl::GetHandleError(void* handle) const { | 175 int NoiseSuppressionImpl::GetHandleError(void* handle) const { |
177 // The NS has no get_error() function. | 176 // The NS has no get_error() function. |
178 assert(handle != NULL); | 177 assert(handle != NULL); |
179 return apm_->kUnspecifiedError; | 178 return apm_->kUnspecifiedError; |
180 } | 179 } |
181 } // namespace webrtc | 180 } // namespace webrtc |
OLD | NEW |