Reland "Reland Process 8 kHz audio as 16 kHz internally of the audio processing module"

This is a reland of b7b8e30cb44c41f51dbbefb9a9160e6dfe869c5b

Original change's description:
> Reland Process 8 kHz audio as 16 kHz internally of the audio processing module
> 
> This CL relands the code from the CL "Process 8 kHz audio as 16 kHz internally
> of the audio processing module" which by mistake was reverted via a rebase in
> another CL.
> 
> The CL changes the behavior of APM for 8 kHz so that it is internally
> processed as 16 kHz.
> 
> Bug: webrtc:10863
> Change-Id: I32a57b2d279c2134125667c19b09cfda381a33c3
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150221
> Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
> Commit-Queue: Per Åhgren <peah@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#28944}

Bug: webrtc:10863
Change-Id: Ic626b99b099248f0d8a677dc4cfe1505e14ae7cd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150330
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28949}
This commit is contained in:
Per Åhgren
2019-08-23 15:49:51 +02:00
committed by Commit Bot
parent 7c4b0c56bf
commit c8626b6072
5 changed files with 18 additions and 19 deletions

View File

@ -84,22 +84,17 @@ bool SampleRateSupportsMultiBand(int sample_rate_hz) {
sample_rate_hz == AudioProcessing::kSampleRate48kHz; sample_rate_hz == AudioProcessing::kSampleRate48kHz;
} }
int FindNativeProcessRateToUse(int minimum_rate, bool band_splitting_required) { // Identify the native processing rate that best handles a sample rate.
int SuitableProcessRate(int minimum_rate, bool band_splitting_required) {
#ifdef WEBRTC_ARCH_ARM_FAMILY #ifdef WEBRTC_ARCH_ARM_FAMILY
constexpr int kMaxSplittingNativeProcessRate = constexpr int kMaxSplittingRate = 32000;
AudioProcessing::kSampleRate32kHz;
#else #else
constexpr int kMaxSplittingNativeProcessRate = constexpr int kMaxSplittingRate = 48000;
AudioProcessing::kSampleRate48kHz;
#endif #endif
static_assert( static_assert(kMaxSplittingRate <= 48000, "");
kMaxSplittingNativeProcessRate <= AudioProcessing::kMaxNativeSampleRateHz, const int uppermost_native_rate =
""); band_splitting_required ? kMaxSplittingRate : 48000;
const int uppermost_native_rate = band_splitting_required for (auto rate : {16000, 32000, 48000}) {
? kMaxSplittingNativeProcessRate
: AudioProcessing::kSampleRate48kHz;
for (auto rate : AudioProcessing::kNativeSampleRatesHz) {
if (rate >= uppermost_native_rate) { if (rate >= uppermost_native_rate) {
return uppermost_native_rate; return uppermost_native_rate;
} }
@ -595,18 +590,19 @@ int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
formats_.api_format = config; formats_.api_format = config;
int capture_processing_rate = FindNativeProcessRateToUse( int capture_processing_rate = SuitableProcessRate(
std::min(formats_.api_format.input_stream().sample_rate_hz(), std::min(formats_.api_format.input_stream().sample_rate_hz(),
formats_.api_format.output_stream().sample_rate_hz()), formats_.api_format.output_stream().sample_rate_hz()),
submodule_states_.CaptureMultiBandSubModulesActive() || submodule_states_.CaptureMultiBandSubModulesActive() ||
submodule_states_.RenderMultiBandSubModulesActive()); submodule_states_.RenderMultiBandSubModulesActive());
RTC_DCHECK_NE(8000, capture_processing_rate);
capture_nonlocked_.capture_processing_format = capture_nonlocked_.capture_processing_format =
StreamConfig(capture_processing_rate); StreamConfig(capture_processing_rate);
int render_processing_rate; int render_processing_rate;
if (!capture_nonlocked_.echo_controller_enabled) { if (!capture_nonlocked_.echo_controller_enabled) {
render_processing_rate = FindNativeProcessRateToUse( render_processing_rate = SuitableProcessRate(
std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(), std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(),
formats_.api_format.reverse_output_stream().sample_rate_hz()), formats_.api_format.reverse_output_stream().sample_rate_hz()),
submodule_states_.CaptureMultiBandSubModulesActive() || submodule_states_.CaptureMultiBandSubModulesActive() ||
@ -634,6 +630,8 @@ int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz)); std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz));
} }
RTC_DCHECK_NE(8000, render_processing_rate);
// Always downmix the render stream to mono for analysis. This has been // Always downmix the render stream to mono for analysis. This has been
// demonstrated to work well for AEC in most practical scenarios. // demonstrated to work well for AEC in most practical scenarios.
if (submodule_states_.RenderMultiBandSubModulesActive()) { if (submodule_states_.RenderMultiBandSubModulesActive()) {

View File

@ -1200,8 +1200,8 @@ TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabled) {
TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabledFloat) { TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabledFloat) {
// Test that ProcessStream copies input to output even with no processing. // Test that ProcessStream copies input to output even with no processing.
const size_t kSamples = 80; const size_t kSamples = 160;
const int sample_rate = 8000; const int sample_rate = 16000;
const float src[kSamples] = {-1.0f, 0.0f, 1.0f}; const float src[kSamples] = {-1.0f, 0.0f, 1.0f};
float dest[kSamples] = {}; float dest[kSamples] = {};

View File

@ -698,6 +698,7 @@ class AudioProcessing : public rtc::RefCountInterface {
kBadStreamParameterWarning = -13 kBadStreamParameterWarning = -13
}; };
// Native rates supported by the AudioFrame interfaces.
enum NativeRate { enum NativeRate {
kSampleRate8kHz = 8000, kSampleRate8kHz = 8000,
kSampleRate16kHz = 16000, kSampleRate16kHz = 16000,

View File

@ -1 +1 @@
7481cf57b2ade2f600d91e8bc77fd9780a56b62e 91f6018874f4cbce414918d053e1d6c36d3e51c4

View File

@ -1 +1 @@
d67b879f3b4a31b3c4f3587bd4418be5f9df5105 4794107799631a85c4aa4671979c6fa7edbef08b