diff --git a/webrtc/media/engine/fakewebrtcvoiceengine.h b/webrtc/media/engine/fakewebrtcvoiceengine.h index f27810cefe..c8fb9cfe02 100644 --- a/webrtc/media/engine/fakewebrtcvoiceengine.h +++ b/webrtc/media/engine/fakewebrtcvoiceengine.h @@ -93,7 +93,6 @@ class FakeAudioProcessing : public webrtc::AudioProcessing { WEBRTC_STUB_CONST(stream_delay_ms, ()); WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ()); WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed)); - WEBRTC_VOID_STUB(SetLevelControllerInitialLevel, (float level)); WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset)); WEBRTC_STUB_CONST(delay_offset_ms, ()); WEBRTC_STUB(StartDebugRecording, diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index 750bcb6fd3..3b3a9518b1 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -992,11 +992,6 @@ void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { capture_.key_pressed = key_pressed; } -void AudioProcessingImpl::SetLevelControllerInitialLevel(float level) { - rtc::CritScope cs(&crit_capture_); - private_submodules_->level_controller->SetInitialLevel(level); -} - void AudioProcessingImpl::set_delay_offset_ms(int offset) { rtc::CritScope cs(&crit_capture_); capture_.delay_offset_ms = offset; diff --git a/webrtc/modules/audio_processing/audio_processing_impl.h b/webrtc/modules/audio_processing/audio_processing_impl.h index 5ba3638e21..4b9011dc88 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.h +++ b/webrtc/modules/audio_processing/audio_processing_impl.h @@ -82,7 +82,6 @@ class AudioProcessingImpl : public AudioProcessing { void set_delay_offset_ms(int offset) override; int delay_offset_ms() const override; void set_stream_key_pressed(bool key_pressed) override; - void SetLevelControllerInitialLevel(float level) override; // Render-side exclusive methods possibly running APM in a // multi-threaded manner. Acquire the render lock. diff --git a/webrtc/modules/audio_processing/include/audio_processing.h b/webrtc/modules/audio_processing/include/audio_processing.h index 2f1ae99b93..09e5d5be1c 100644 --- a/webrtc/modules/audio_processing/include/audio_processing.h +++ b/webrtc/modules/audio_processing/include/audio_processing.h @@ -410,11 +410,6 @@ class AudioProcessing { // with this chunk of audio. virtual void set_stream_key_pressed(bool key_pressed) = 0; - // Sets the initial peak level to use inside the level controller in order - // to compute the signal gain. The unit for the peak level is dBFS and - // the allowed range is [-100, 0]. - virtual void SetLevelControllerInitialLevel(float level) = 0; - // Sets a delay |offset| in ms to add to the values passed in through // set_stream_delay_ms(). May be positive or negative. // diff --git a/webrtc/modules/audio_processing/level_controller/gain_selector.cc b/webrtc/modules/audio_processing/level_controller/gain_selector.cc index 80d9c0f1c5..2accd7180c 100644 --- a/webrtc/modules/audio_processing/level_controller/gain_selector.cc +++ b/webrtc/modules/audio_processing/level_controller/gain_selector.cc @@ -42,12 +42,10 @@ void GainSelector::Initialize(int sample_rate_hz) { float GainSelector::GetNewGain(float peak_level, float noise_energy, float saturating_gain, - bool gain_jumpstart, SignalClassifier::SignalType signal_type) { RTC_DCHECK_LT(0.f, peak_level); - if (signal_type == SignalClassifier::SignalType::kHighlyNonStationary || - gain_jumpstart) { + if (signal_type == SignalClassifier::SignalType::kHighlyNonStationary) { highly_nonstationary_signal_hold_counter_ = 100; } else { highly_nonstationary_signal_hold_counter_ = diff --git a/webrtc/modules/audio_processing/level_controller/gain_selector.h b/webrtc/modules/audio_processing/level_controller/gain_selector.h index 78b9101500..3d00499652 100644 --- a/webrtc/modules/audio_processing/level_controller/gain_selector.h +++ b/webrtc/modules/audio_processing/level_controller/gain_selector.h @@ -24,7 +24,6 @@ class GainSelector { float GetNewGain(float peak_level, float noise_energy, float saturating_gain, - bool gain_jumpstart, SignalClassifier::SignalType signal_type); private: diff --git a/webrtc/modules/audio_processing/level_controller/level_controller.cc b/webrtc/modules/audio_processing/level_controller/level_controller.cc index 07618e3ba7..a9fed9bf95 100644 --- a/webrtc/modules/audio_processing/level_controller/level_controller.cc +++ b/webrtc/modules/audio_processing/level_controller/level_controller.cc @@ -155,11 +155,6 @@ LevelController::LevelController() LevelController::~LevelController() {} -void LevelController::SetInitialLevel(float level) { - peak_level_estimator_.SetInitialPeakLevel(level); - gain_jumpstart_ = true; -} - void LevelController::Initialize(int sample_rate_hz) { RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || sample_rate_hz == AudioProcessing::kSampleRate16kHz || @@ -211,11 +206,8 @@ void LevelController::Process(AudioBuffer* audio) { float saturating_gain = saturating_gain_estimator_.GetGain(); // Compute the new gain to apply. - last_gain_ = gain_selector_.GetNewGain( - peak_level, noise_energy, saturating_gain, gain_jumpstart_, signal_type); - - // Unflag the jumpstart of the gain as it should only happen once. - gain_jumpstart_ = false; + last_gain_ = gain_selector_.GetNewGain(peak_level, noise_energy, + saturating_gain, signal_type); // Apply the gain to the signal. int num_saturations = gain_applier_.Process(last_gain_, audio); diff --git a/webrtc/modules/audio_processing/level_controller/level_controller.h b/webrtc/modules/audio_processing/level_controller/level_controller.h index 1d7f174562..3d203f908d 100644 --- a/webrtc/modules/audio_processing/level_controller/level_controller.h +++ b/webrtc/modules/audio_processing/level_controller/level_controller.h @@ -38,11 +38,6 @@ class LevelController { void Process(AudioBuffer* audio); float GetLastGain() { return last_gain_; } - // Sets the initial peak level to use inside the level controller in order - // to compute the signal gain. The unit for the peak level is dBFS and - // the allowed range is [-100, 0]. - void SetInitialLevel(float level); - private: class Metrics { public: @@ -76,7 +71,6 @@ class LevelController { float dc_level_[2]; float dc_forgetting_factor_; float last_gain_; - bool gain_jumpstart_ = false; RTC_DISALLOW_COPY_AND_ASSIGN(LevelController); }; diff --git a/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc b/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc index 74d129f323..c470c2fad7 100644 --- a/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc +++ b/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc @@ -12,7 +12,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/array_view.h" -#include "webrtc/base/optional.h" #include "webrtc/modules/audio_processing/audio_buffer.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/level_controller/level_controller.h" @@ -28,13 +27,9 @@ const int kNumFramesToProcess = 1000; // any errors. void RunBitexactnessTest(int sample_rate_hz, size_t num_channels, - rtc::Optional initial_level, rtc::ArrayView output_reference) { LevelController level_controller; level_controller.Initialize(sample_rate_hz); - if (initial_level) { - level_controller.SetInitialLevel(*initial_level); - } int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); const StreamConfig capture_config(sample_rate_hz, num_channels, false); @@ -76,19 +71,19 @@ void RunBitexactnessTest(int sample_rate_hz, TEST(LevelControlBitExactnessTest, DISABLED_Mono8kHz) { const float kOutputReference[] = {-0.013939f, -0.012154f, -0.009054f}; RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Mono16kHz) { const float kOutputReference[] = {-0.013706f, -0.013215f, -0.013018f}; RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Mono32kHz) { const float kOutputReference[] = {-0.014495f, -0.016425f, -0.016085f}; RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, - rtc::Optional(), kOutputReference); + kOutputReference); } // TODO(peah): Investigate why this particular testcase differ between Android @@ -101,41 +96,35 @@ TEST(LevelControlBitExactnessTest, DISABLED_Mono48kHz) { const float kOutputReference[] = {-0.015949f, -0.016957f, -0.019478f}; #endif RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Stereo8kHz) { const float kOutputReference[] = {-0.014063f, -0.008450f, -0.012159f, -0.051967f, -0.023202f, -0.047858f}; RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Stereo16kHz) { const float kOutputReference[] = {-0.012714f, -0.005896f, -0.012220f, -0.053306f, -0.024549f, -0.051527f}; RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Stereo32kHz) { const float kOutputReference[] = {-0.011737f, -0.007018f, -0.013446f, -0.053505f, -0.026292f, -0.056221f}; RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, - rtc::Optional(), kOutputReference); + kOutputReference); } TEST(LevelControlBitExactnessTest, DISABLED_Stereo48kHz) { const float kOutputReference[] = {-0.010643f, -0.006334f, -0.011377f, -0.049088f, -0.023600f, -0.050465f}; RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, - rtc::Optional(), kOutputReference); -} - -TEST(LevelControlBitExactnessTest, DISABLED_MonoInitial48kHz) { - const float kOutputReference[] = {-0.013753f, -0.014623f, -0.016797f}; - RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, - rtc::Optional(2000), kOutputReference); + kOutputReference); } diff --git a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc index 9d4fe3312c..2ba806c8ee 100644 --- a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc +++ b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc @@ -13,14 +13,10 @@ #include #include "webrtc/modules/audio_processing/audio_buffer.h" +#include "webrtc/modules/audio_processing/level_controller/lc_constants.h" #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" namespace webrtc { -namespace { - -const float kMinLevel = 30.f; - -} // namespace PeakLevelEstimator::PeakLevelEstimator() { Initialize(); @@ -29,26 +25,15 @@ PeakLevelEstimator::PeakLevelEstimator() { PeakLevelEstimator::~PeakLevelEstimator() {} void PeakLevelEstimator::Initialize() { - peak_level_ = initial_peak_level_; + peak_level_ = kTargetLcPeakLevel; hold_counter_ = 0; initialization_phase_ = true; } -void PeakLevelEstimator::SetInitialPeakLevel(float level) { - RTC_DCHECK_LE(-100.f, level); - RTC_DCHECK_GE(0.f, level); - - float linear_level = std::pow(10.f, level / 20.f) * 32768.f; - - // Limit the supplied level to the level range used internally. - initial_peak_level_ = std::max(linear_level, kMinLevel); - Initialize(); -} - float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, float frame_peak_level) { if (frame_peak_level == 0) { - RTC_DCHECK_LE(kMinLevel, peak_level_); + RTC_DCHECK_LE(30.f, peak_level_); return peak_level_; } @@ -72,7 +57,7 @@ float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, } } - peak_level_ = std::max(peak_level_, kMinLevel); + peak_level_ = std::max(peak_level_, 30.f); return peak_level_; } diff --git a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.h b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.h index 941dd36be3..270bbc3ad0 100644 --- a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.h +++ b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.h @@ -12,7 +12,6 @@ #define WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_CONTROLLER_PEAK_LEVEL_ESTIMATOR_H_ #include "webrtc/base/constructormagic.h" -#include "webrtc/modules/audio_processing/level_controller/lc_constants.h" #include "webrtc/modules/audio_processing/level_controller/signal_classifier.h" namespace webrtc { @@ -24,11 +23,9 @@ class PeakLevelEstimator { void Initialize(); float Analyze(SignalClassifier::SignalType signal_type, float frame_peak_level); - void SetInitialPeakLevel(float level); private: float peak_level_; - float initial_peak_level_ = kTargetLcPeakLevel; int hold_counter_; bool initialization_phase_;