Fix NoiseSuppression initialization behavior. This was changed when removing the ProcessingComponent inheritance in https://codereview.webrtc.org/1507683006/.
BUG=webrtc:5298 Review URL: https://codereview.webrtc.org/1523323002 Cr-Commit-Position: refs/heads/master@{#11043}
This commit is contained in:
@ -54,21 +54,26 @@ NoiseSuppressionImpl::~NoiseSuppressionImpl() {}
|
|||||||
|
|
||||||
void NoiseSuppressionImpl::Initialize(int channels, int sample_rate_hz) {
|
void NoiseSuppressionImpl::Initialize(int channels, int sample_rate_hz) {
|
||||||
RTC_DCHECK_LE(0, channels);
|
RTC_DCHECK_LE(0, channels);
|
||||||
std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors(channels);
|
rtc::CritScope cs(crit_);
|
||||||
|
channels_ = channels;
|
||||||
|
sample_rate_hz_ = sample_rate_hz;
|
||||||
|
std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors;
|
||||||
|
if (enabled_) {
|
||||||
|
new_suppressors.resize(channels);
|
||||||
for (int i = 0; i < channels; i++) {
|
for (int i = 0; i < channels; i++) {
|
||||||
new_suppressors[i].reset(new Suppressor(sample_rate_hz));
|
new_suppressors[i].reset(new Suppressor(sample_rate_hz));
|
||||||
}
|
}
|
||||||
rtc::CritScope cs(crit_);
|
}
|
||||||
suppressors_.swap(new_suppressors);
|
suppressors_.swap(new_suppressors);
|
||||||
set_level(level_);
|
set_level(level_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
||||||
RTC_DCHECK(audio);
|
RTC_DCHECK(audio);
|
||||||
#if defined(WEBRTC_NS_FLOAT)
|
#if defined(WEBRTC_NS_FLOAT)
|
||||||
rtc::CritScope cs(crit_);
|
rtc::CritScope cs(crit_);
|
||||||
if (!enabled_) {
|
if (!enabled_) {
|
||||||
return AudioProcessing::kNoError;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
|
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
|
||||||
@ -79,14 +84,13 @@ int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
|||||||
audio->split_bands_const_f(i)[kBand0To8kHz]);
|
audio->split_bands_const_f(i)[kBand0To8kHz]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return AudioProcessing::kNoError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
||||||
RTC_DCHECK(audio);
|
RTC_DCHECK(audio);
|
||||||
rtc::CritScope cs(crit_);
|
rtc::CritScope cs(crit_);
|
||||||
if (!enabled_) {
|
if (!enabled_) {
|
||||||
return AudioProcessing::kNoError;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
|
RTC_DCHECK_GE(160u, audio->num_frames_per_band());
|
||||||
@ -105,12 +109,14 @@ int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
|||||||
audio->split_bands(i));
|
audio->split_bands(i));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return AudioProcessing::kNoError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int NoiseSuppressionImpl::Enable(bool enable) {
|
int NoiseSuppressionImpl::Enable(bool enable) {
|
||||||
rtc::CritScope cs(crit_);
|
rtc::CritScope cs(crit_);
|
||||||
|
if (enabled_ != enable) {
|
||||||
enabled_ = enable;
|
enabled_ = enable;
|
||||||
|
Initialize(channels_, sample_rate_hz_);
|
||||||
|
}
|
||||||
return AudioProcessing::kNoError;
|
return AudioProcessing::kNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +126,6 @@ bool NoiseSuppressionImpl::is_enabled() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int NoiseSuppressionImpl::set_level(Level level) {
|
int NoiseSuppressionImpl::set_level(Level level) {
|
||||||
rtc::CritScope cs(crit_);
|
|
||||||
int policy = 1;
|
int policy = 1;
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case NoiseSuppression::kLow:
|
case NoiseSuppression::kLow:
|
||||||
@ -138,6 +143,7 @@ int NoiseSuppressionImpl::set_level(Level level) {
|
|||||||
default:
|
default:
|
||||||
RTC_NOTREACHED();
|
RTC_NOTREACHED();
|
||||||
}
|
}
|
||||||
|
rtc::CritScope cs(crit_);
|
||||||
level_ = level;
|
level_ = level;
|
||||||
for (auto& suppressor : suppressors_) {
|
for (auto& suppressor : suppressors_) {
|
||||||
int error = NS_SET_POLICY(suppressor->state(), policy);
|
int error = NS_SET_POLICY(suppressor->state(), policy);
|
||||||
|
@ -27,8 +27,8 @@ class NoiseSuppressionImpl : public NoiseSuppression {
|
|||||||
|
|
||||||
// TODO(peah): Fold into ctor, once public API is removed.
|
// TODO(peah): Fold into ctor, once public API is removed.
|
||||||
void Initialize(int channels, int sample_rate_hz);
|
void Initialize(int channels, int sample_rate_hz);
|
||||||
int AnalyzeCaptureAudio(AudioBuffer* audio);
|
void AnalyzeCaptureAudio(AudioBuffer* audio);
|
||||||
int ProcessCaptureAudio(AudioBuffer* audio);
|
void ProcessCaptureAudio(AudioBuffer* audio);
|
||||||
|
|
||||||
// NoiseSuppression implementation.
|
// NoiseSuppression implementation.
|
||||||
int Enable(bool enable) override;
|
int Enable(bool enable) override;
|
||||||
@ -42,6 +42,8 @@ class NoiseSuppressionImpl : public NoiseSuppression {
|
|||||||
rtc::CriticalSection* const crit_;
|
rtc::CriticalSection* const crit_;
|
||||||
bool enabled_ GUARDED_BY(crit_) = false;
|
bool enabled_ GUARDED_BY(crit_) = false;
|
||||||
Level level_ GUARDED_BY(crit_) = kModerate;
|
Level level_ GUARDED_BY(crit_) = kModerate;
|
||||||
|
int channels_ GUARDED_BY(crit_) = 0;
|
||||||
|
int sample_rate_hz_ GUARDED_BY(crit_) = 0;
|
||||||
std::vector<rtc::scoped_ptr<Suppressor>> suppressors_ GUARDED_BY(crit_);
|
std::vector<rtc::scoped_ptr<Suppressor>> suppressors_ GUARDED_BY(crit_);
|
||||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(NoiseSuppressionImpl);
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(NoiseSuppressionImpl);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user