From 27bd76bcb294c3c127ef75be61d1024ea25fe4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Tue, 26 Nov 2019 09:23:45 +0100 Subject: [PATCH] DCHECKing for deprecated 8kHz support in AGC and changing fuzzer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds a DCHECK for the deprecated 8 kHz rate in APM. It also updates the agc fuzzer code to properly do band-split on the signals, and not send 8 kHz signals into the AGC. Bug: chromium:1028092,chromium:1028172 Change-Id: I1e7c8d721834310e94b0e21efea07f75da837cab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160600 Reviewed-by: Sam Zackrisson Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#29914} --- modules/audio_processing/gain_control_impl.cc | 3 +++ test/fuzzers/agc_fuzzer.cc | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/audio_processing/gain_control_impl.cc b/modules/audio_processing/gain_control_impl.cc index d3573f85a0..841d901933 100644 --- a/modules/audio_processing/gain_control_impl.cc +++ b/modules/audio_processing/gain_control_impl.cc @@ -375,6 +375,9 @@ int GainControlImpl::enable_limiter(bool enable) { void GainControlImpl::Initialize(size_t num_proc_channels, int sample_rate_hz) { data_dumper_->InitiateNewSetOfRecordings(); + RTC_DCHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000 || + sample_rate_hz == 48000); + num_proc_channels_ = num_proc_channels; sample_rate_hz_ = sample_rate_hz; diff --git a/test/fuzzers/agc_fuzzer.cc b/test/fuzzers/agc_fuzzer.cc index 10de3b85c5..ac3f83b36e 100644 --- a/test/fuzzers/agc_fuzzer.cc +++ b/test/fuzzers/agc_fuzzer.cc @@ -20,7 +20,9 @@ namespace webrtc { namespace { -void FillAudioBuffer(test::FuzzDataHelper* fuzz_data, AudioBuffer* buffer) { +void FillAudioBuffer(size_t sample_rate_hz, + test::FuzzDataHelper* fuzz_data, + AudioBuffer* buffer) { float* const* channels = buffer->channels_f(); for (size_t i = 0; i < buffer->num_channels(); ++i) { for (size_t j = 0; j < buffer->num_frames(); ++j) { @@ -28,6 +30,10 @@ void FillAudioBuffer(test::FuzzDataHelper* fuzz_data, AudioBuffer* buffer) { static_cast(fuzz_data->ReadOrDefaultValue(0)); } } + + if (sample_rate_hz != 16000) { + buffer->SplitIntoFrequencyBands(); + } } // This function calls the GainControl functions that are overriden as private @@ -76,8 +82,8 @@ void FuzzGainControllerConfig(test::FuzzDataHelper* fuzz_data, void FuzzGainController(test::FuzzDataHelper* fuzz_data, GainControlImpl* gci) { using Rate = ::webrtc::AudioProcessing::NativeRate; - const Rate rate_kinds[] = {Rate::kSampleRate8kHz, Rate::kSampleRate16kHz, - Rate::kSampleRate32kHz, Rate::kSampleRate48kHz}; + const Rate rate_kinds[] = {Rate::kSampleRate16kHz, Rate::kSampleRate32kHz, + Rate::kSampleRate48kHz}; const auto sample_rate_hz = static_cast(fuzz_data->SelectOneOf(rate_kinds)); @@ -94,13 +100,13 @@ void FuzzGainController(test::FuzzDataHelper* fuzz_data, GainControlImpl* gci) { std::vector packed_render_audio(samples_per_frame); while (fuzz_data->CanReadBytes(1)) { - FillAudioBuffer(fuzz_data, &audio); + FillAudioBuffer(sample_rate_hz, fuzz_data, &audio); const bool stream_has_echo = fuzz_data->ReadOrDefaultValue(true); gci->AnalyzeCaptureAudio(audio); gci->ProcessCaptureAudio(&audio, stream_has_echo); - FillAudioBuffer(fuzz_data, &audio); + FillAudioBuffer(sample_rate_hz, fuzz_data, &audio); gci->PackRenderAudioBuffer(audio, &packed_render_audio); gci->ProcessRenderAudio(packed_render_audio);