| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Suppressor); | 45 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Suppressor); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 NoiseSuppressionImpl::NoiseSuppressionImpl(rtc::CriticalSection* crit) | 48 NoiseSuppressionImpl::NoiseSuppressionImpl(rtc::CriticalSection* crit) |
| 49 : crit_(crit) { | 49 : crit_(crit) { |
| 50 RTC_DCHECK(crit); | 50 RTC_DCHECK(crit); |
| 51 } | 51 } |
| 52 | 52 |
| 53 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} | 53 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} |
| 54 | 54 |
| 55 void NoiseSuppressionImpl::Initialize(int channels, int sample_rate_hz) { | 55 void NoiseSuppressionImpl::Initialize(size_t channels, int sample_rate_hz) { |
| 56 RTC_DCHECK_LE(0, channels); | |
| 57 rtc::CritScope cs(crit_); | 56 rtc::CritScope cs(crit_); |
| 58 channels_ = channels; | 57 channels_ = channels; |
| 59 sample_rate_hz_ = sample_rate_hz; | 58 sample_rate_hz_ = sample_rate_hz; |
| 60 std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors; | 59 std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors; |
| 61 if (enabled_) { | 60 if (enabled_) { |
| 62 new_suppressors.resize(channels); | 61 new_suppressors.resize(channels); |
| 63 for (int i = 0; i < channels; i++) { | 62 for (size_t i = 0; i < channels; i++) { |
| 64 new_suppressors[i].reset(new Suppressor(sample_rate_hz)); | 63 new_suppressors[i].reset(new Suppressor(sample_rate_hz)); |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 suppressors_.swap(new_suppressors); | 66 suppressors_.swap(new_suppressors); |
| 68 set_level(level_); | 67 set_level(level_); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 70 void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
| 72 RTC_DCHECK(audio); | 71 RTC_DCHECK(audio); |
| 73 #if defined(WEBRTC_NS_FLOAT) | 72 #if defined(WEBRTC_NS_FLOAT) |
| 74 rtc::CritScope cs(crit_); | 73 rtc::CritScope cs(crit_); |
| 75 if (!enabled_) { | 74 if (!enabled_) { |
| 76 return; | 75 return; |
| 77 } | 76 } |
| 78 | 77 |
| 79 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | 78 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 80 RTC_DCHECK_EQ(suppressors_.size(), | 79 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels()); |
| 81 static_cast<size_t>(audio->num_channels())); | |
| 82 for (size_t i = 0; i < suppressors_.size(); i++) { | 80 for (size_t i = 0; i < suppressors_.size(); i++) { |
| 83 WebRtcNs_Analyze(suppressors_[i]->state(), | 81 WebRtcNs_Analyze(suppressors_[i]->state(), |
| 84 audio->split_bands_const_f(i)[kBand0To8kHz]); | 82 audio->split_bands_const_f(i)[kBand0To8kHz]); |
| 85 } | 83 } |
| 86 #endif | 84 #endif |
| 87 } | 85 } |
| 88 | 86 |
| 89 void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { | 87 void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
| 90 RTC_DCHECK(audio); | 88 RTC_DCHECK(audio); |
| 91 rtc::CritScope cs(crit_); | 89 rtc::CritScope cs(crit_); |
| 92 if (!enabled_) { | 90 if (!enabled_) { |
| 93 return; | 91 return; |
| 94 } | 92 } |
| 95 | 93 |
| 96 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | 94 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 97 RTC_DCHECK_EQ(suppressors_.size(), | 95 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels()); |
| 98 static_cast<size_t>(audio->num_channels())); | |
| 99 for (size_t i = 0; i < suppressors_.size(); i++) { | 96 for (size_t i = 0; i < suppressors_.size(); i++) { |
| 100 #if defined(WEBRTC_NS_FLOAT) | 97 #if defined(WEBRTC_NS_FLOAT) |
| 101 WebRtcNs_Process(suppressors_[i]->state(), | 98 WebRtcNs_Process(suppressors_[i]->state(), |
| 102 audio->split_bands_const_f(i), | 99 audio->split_bands_const_f(i), |
| 103 audio->num_bands(), | 100 audio->num_bands(), |
| 104 audio->split_bands_f(i)); | 101 audio->split_bands_f(i)); |
| 105 #elif defined(WEBRTC_NS_FIXED) | 102 #elif defined(WEBRTC_NS_FIXED) |
| 106 WebRtcNsx_Process(suppressors_[i]->state(), | 103 WebRtcNsx_Process(suppressors_[i]->state(), |
| 107 audio->split_bands_const(i), | 104 audio->split_bands_const(i), |
| 108 audio->num_bands(), | 105 audio->num_bands(), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 probability_average /= suppressors_.size(); | 166 probability_average /= suppressors_.size(); |
| 170 } | 167 } |
| 171 return probability_average; | 168 return probability_average; |
| 172 #elif defined(WEBRTC_NS_FIXED) | 169 #elif defined(WEBRTC_NS_FIXED) |
| 173 // TODO(peah): Returning error code as a float! Remove this. | 170 // TODO(peah): Returning error code as a float! Remove this. |
| 174 // Currently not available for the fixed point implementation. | 171 // Currently not available for the fixed point implementation. |
| 175 return AudioProcessing::kUnsupportedFunctionError; | 172 return AudioProcessing::kUnsupportedFunctionError; |
| 176 #endif | 173 #endif |
| 177 } | 174 } |
| 178 } // namespace webrtc | 175 } // namespace webrtc |
| OLD | NEW |