2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-30 20:51:15 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/audio_processing_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
#include <algorithm>
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <cstdint>
|
2017-05-22 06:57:06 -07:00
|
|
|
#include <string>
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <type_traits>
|
|
|
|
|
#include <utility>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-03-06 04:16:46 +01:00
|
|
|
#include "absl/memory/memory.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "absl/types/optional.h"
|
|
|
|
|
#include "api/array_view.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/audio_converter.h"
|
|
|
|
|
#include "common_audio/include/audio_util.h"
|
2019-03-06 04:16:46 +01:00
|
|
|
#include "modules/audio_processing/aec3/echo_canceller3.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/agc/agc_manager_direct.h"
|
2018-04-16 16:31:22 +02:00
|
|
|
#include "modules/audio_processing/agc2/gain_applier.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/audio_buffer.h"
|
|
|
|
|
#include "modules/audio_processing/common.h"
|
|
|
|
|
#include "modules/audio_processing/echo_cancellation_impl.h"
|
|
|
|
|
#include "modules/audio_processing/echo_control_mobile_impl.h"
|
2019-03-27 13:28:08 +01:00
|
|
|
#include "modules/audio_processing/gain_control_config_proxy.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/gain_control_for_experimental_agc.h"
|
|
|
|
|
#include "modules/audio_processing/gain_control_impl.h"
|
2018-02-16 11:54:07 +01:00
|
|
|
#include "modules/audio_processing/gain_controller2.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/audio_processing/include/audio_frame_view.h"
|
2018-10-02 17:00:59 +02:00
|
|
|
#include "modules/audio_processing/level_estimator_impl.h"
|
2018-02-12 21:42:56 +01:00
|
|
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
2018-10-02 17:00:59 +02:00
|
|
|
#include "modules/audio_processing/low_cut_filter.h"
|
|
|
|
|
#include "modules/audio_processing/noise_suppression_impl.h"
|
2019-01-11 15:10:32 +01:00
|
|
|
#include "modules/audio_processing/noise_suppression_proxy.h"
|
2018-10-02 17:00:59 +02:00
|
|
|
#include "modules/audio_processing/residual_echo_detector.h"
|
|
|
|
|
#include "modules/audio_processing/transient/transient_suppressor.h"
|
|
|
|
|
#include "modules/audio_processing/voice_detection_impl.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/atomic_ops.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ref_counted_object.h"
|
|
|
|
|
#include "rtc_base/time_utils.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/trace_event.h"
|
|
|
|
|
#include "system_wrappers/include/metrics.h"
|
2011-12-03 00:03:31 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
#define RETURN_ON_ERR(expr) \
|
|
|
|
|
do { \
|
|
|
|
|
int err = (expr); \
|
|
|
|
|
if (err != kNoError) { \
|
|
|
|
|
return err; \
|
|
|
|
|
} \
|
2014-01-07 17:45:09 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
2016-03-16 18:26:35 -07:00
|
|
|
|
2016-09-13 07:49:33 -07:00
|
|
|
constexpr int AudioProcessing::kNativeSampleRatesHz[];
|
2018-05-15 10:52:28 +02:00
|
|
|
constexpr int kRuntimeSettingQueueSize = 100;
|
2016-03-16 18:26:35 -07:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
static bool LayoutHasKeyboard(AudioProcessing::ChannelLayout layout) {
|
|
|
|
|
switch (layout) {
|
|
|
|
|
case AudioProcessing::kMono:
|
|
|
|
|
case AudioProcessing::kStereo:
|
|
|
|
|
return false;
|
|
|
|
|
case AudioProcessing::kMonoAndKeyboard:
|
|
|
|
|
case AudioProcessing::kStereoAndKeyboard:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 05:23:22 -07:00
|
|
|
RTC_NOTREACHED();
|
2015-07-23 11:41:39 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-16 18:26:35 -07:00
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool SampleRateSupportsMultiBand(int sample_rate_hz) {
|
2016-03-16 18:26:35 -07:00
|
|
|
return sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
|
|
|
|
|
sample_rate_hz == AudioProcessing::kSampleRate48kHz;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 15:45:07 +02:00
|
|
|
// Identify the native processing rate that best handles a sample rate.
|
|
|
|
|
int SuitableProcessRate(int minimum_rate, bool band_splitting_required) {
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
#ifdef WEBRTC_ARCH_ARM_FAMILY
|
2019-08-21 15:45:07 +02:00
|
|
|
constexpr int kMaxSplittingRate = 32000;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
#else
|
2019-08-21 15:45:07 +02:00
|
|
|
constexpr int kMaxSplittingRate = 48000;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
#endif
|
2019-08-21 15:45:07 +02:00
|
|
|
static_assert(kMaxSplittingRate <= 48000, "");
|
|
|
|
|
|
|
|
|
|
const int uppermost_native_rate =
|
|
|
|
|
band_splitting_required ? kMaxSplittingRate : 48000;
|
|
|
|
|
|
|
|
|
|
for (auto rate : {16000, 32000, 48000}) {
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (rate >= uppermost_native_rate) {
|
|
|
|
|
return uppermost_native_rate;
|
|
|
|
|
}
|
|
|
|
|
if (rate >= minimum_rate) {
|
2016-03-16 18:26:35 -07:00
|
|
|
return rate;
|
|
|
|
|
}
|
|
|
|
|
}
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
return uppermost_native_rate;
|
2016-03-16 18:26:35 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-11 15:10:32 +01:00
|
|
|
NoiseSuppression::Level NsConfigLevelToInterfaceLevel(
|
|
|
|
|
AudioProcessing::Config::NoiseSuppression::Level level) {
|
|
|
|
|
using NsConfig = AudioProcessing::Config::NoiseSuppression;
|
|
|
|
|
switch (level) {
|
|
|
|
|
case NsConfig::kLow:
|
|
|
|
|
return NoiseSuppression::kLow;
|
|
|
|
|
case NsConfig::kModerate:
|
|
|
|
|
return NoiseSuppression::kModerate;
|
|
|
|
|
case NsConfig::kHigh:
|
|
|
|
|
return NoiseSuppression::kHigh;
|
|
|
|
|
case NsConfig::kVeryHigh:
|
|
|
|
|
return NoiseSuppression::kVeryHigh;
|
|
|
|
|
default:
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
GainControl::Mode Agc1ConfigModeToInterfaceMode(
|
|
|
|
|
AudioProcessing::Config::GainController1::Mode mode) {
|
|
|
|
|
using Agc1Config = AudioProcessing::Config::GainController1;
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case Agc1Config::kAdaptiveAnalog:
|
|
|
|
|
return GainControl::kAdaptiveAnalog;
|
|
|
|
|
case Agc1Config::kAdaptiveDigital:
|
|
|
|
|
return GainControl::kAdaptiveDigital;
|
|
|
|
|
case Agc1Config::kFixedDigital:
|
|
|
|
|
return GainControl::kFixedDigital;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 07:19:21 -07:00
|
|
|
// Maximum lengths that frame of samples being passed from the render side to
|
|
|
|
|
// the capture side can have (does not apply to AEC3).
|
|
|
|
|
static const size_t kMaxAllowedValuesOfSamplesPerBand = 160;
|
|
|
|
|
static const size_t kMaxAllowedValuesOfSamplesPerFrame = 480;
|
|
|
|
|
|
2016-10-22 05:04:30 -07:00
|
|
|
// Maximum number of frames to buffer in the render queue.
|
|
|
|
|
// TODO(peah): Decrease this once we properly handle hugely unbalanced
|
|
|
|
|
// reverse and forward call numbers.
|
|
|
|
|
static const size_t kMaxNumFramesToBuffer = 100;
|
2015-07-23 11:41:39 -07:00
|
|
|
} // namespace
|
2014-01-07 17:45:09 +00:00
|
|
|
|
|
|
|
|
// Throughout webrtc, it's assumed that success is represented by zero.
|
2015-01-14 10:51:54 +00:00
|
|
|
static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2017-09-25 12:04:02 +02:00
|
|
|
AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates(
|
2017-12-18 16:02:40 +01:00
|
|
|
bool capture_post_processor_enabled,
|
2018-08-29 10:37:09 +02:00
|
|
|
bool render_pre_processor_enabled,
|
|
|
|
|
bool capture_analyzer_enabled)
|
2017-12-18 16:02:40 +01:00
|
|
|
: capture_post_processor_enabled_(capture_post_processor_enabled),
|
2018-08-29 10:37:09 +02:00
|
|
|
render_pre_processor_enabled_(render_pre_processor_enabled),
|
|
|
|
|
capture_analyzer_enabled_(capture_analyzer_enabled) {}
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::Update(
|
2018-09-28 14:15:09 +02:00
|
|
|
bool high_pass_filter_enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool echo_canceller_enabled,
|
|
|
|
|
bool mobile_echo_controller_enabled,
|
2016-10-28 05:39:16 -07:00
|
|
|
bool residual_echo_detector_enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool noise_suppressor_enabled,
|
|
|
|
|
bool adaptive_gain_controller_enabled,
|
2017-05-22 06:57:06 -07:00
|
|
|
bool gain_controller2_enabled,
|
2018-04-16 16:31:22 +02:00
|
|
|
bool pre_amplifier_enabled,
|
2017-10-16 13:49:04 +02:00
|
|
|
bool echo_controller_enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool voice_activity_detector_enabled,
|
2018-12-21 16:29:27 +01:00
|
|
|
bool private_voice_detector_enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool level_estimator_enabled,
|
|
|
|
|
bool transient_suppressor_enabled) {
|
|
|
|
|
bool changed = false;
|
2018-09-28 14:15:09 +02:00
|
|
|
changed |= (high_pass_filter_enabled != high_pass_filter_enabled_);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
changed |= (echo_canceller_enabled != echo_canceller_enabled_);
|
|
|
|
|
changed |=
|
|
|
|
|
(mobile_echo_controller_enabled != mobile_echo_controller_enabled_);
|
2016-10-28 05:39:16 -07:00
|
|
|
changed |=
|
|
|
|
|
(residual_echo_detector_enabled != residual_echo_detector_enabled_);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
changed |= (noise_suppressor_enabled != noise_suppressor_enabled_);
|
|
|
|
|
changed |=
|
|
|
|
|
(adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_);
|
2019-04-26 11:33:37 +02:00
|
|
|
changed |= (gain_controller2_enabled != gain_controller2_enabled_);
|
2018-04-16 16:31:22 +02:00
|
|
|
changed |= (pre_amplifier_enabled_ != pre_amplifier_enabled);
|
2017-10-16 13:49:04 +02:00
|
|
|
changed |= (echo_controller_enabled != echo_controller_enabled_);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
changed |= (level_estimator_enabled != level_estimator_enabled_);
|
|
|
|
|
changed |=
|
|
|
|
|
(voice_activity_detector_enabled != voice_activity_detector_enabled_);
|
2018-12-21 16:29:27 +01:00
|
|
|
changed |=
|
|
|
|
|
(private_voice_detector_enabled != private_voice_detector_enabled_);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
changed |= (transient_suppressor_enabled != transient_suppressor_enabled_);
|
|
|
|
|
if (changed) {
|
2018-09-28 14:15:09 +02:00
|
|
|
high_pass_filter_enabled_ = high_pass_filter_enabled;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
echo_canceller_enabled_ = echo_canceller_enabled;
|
|
|
|
|
mobile_echo_controller_enabled_ = mobile_echo_controller_enabled;
|
2016-10-28 05:39:16 -07:00
|
|
|
residual_echo_detector_enabled_ = residual_echo_detector_enabled;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
noise_suppressor_enabled_ = noise_suppressor_enabled;
|
|
|
|
|
adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled;
|
2017-05-22 06:57:06 -07:00
|
|
|
gain_controller2_enabled_ = gain_controller2_enabled;
|
2018-04-16 16:31:22 +02:00
|
|
|
pre_amplifier_enabled_ = pre_amplifier_enabled;
|
2017-10-16 13:49:04 +02:00
|
|
|
echo_controller_enabled_ = echo_controller_enabled;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
level_estimator_enabled_ = level_estimator_enabled;
|
|
|
|
|
voice_activity_detector_enabled_ = voice_activity_detector_enabled;
|
2018-12-21 16:29:27 +01:00
|
|
|
private_voice_detector_enabled_ = private_voice_detector_enabled;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
transient_suppressor_enabled_ = transient_suppressor_enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changed |= first_update_;
|
|
|
|
|
first_update_ = false;
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandSubModulesActive()
|
|
|
|
|
const {
|
2018-12-21 16:29:27 +01:00
|
|
|
return CaptureMultiBandProcessingActive() ||
|
|
|
|
|
voice_activity_detector_enabled_ || private_voice_detector_enabled_;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::CaptureMultiBandProcessingActive()
|
|
|
|
|
const {
|
2018-09-28 14:15:09 +02:00
|
|
|
return high_pass_filter_enabled_ || echo_canceller_enabled_ ||
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
mobile_echo_controller_enabled_ || noise_suppressor_enabled_ ||
|
2018-06-14 10:11:35 +02:00
|
|
|
adaptive_gain_controller_enabled_ || echo_controller_enabled_;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 05:33:56 -07:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::CaptureFullBandProcessingActive()
|
|
|
|
|
const {
|
2018-04-16 16:31:22 +02:00
|
|
|
return gain_controller2_enabled_ || capture_post_processor_enabled_ ||
|
|
|
|
|
pre_amplifier_enabled_;
|
2017-05-23 05:33:56 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:37:09 +02:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::CaptureAnalyzerActive() const {
|
|
|
|
|
return capture_analyzer_enabled_;
|
|
|
|
|
}
|
|
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandSubModulesActive()
|
|
|
|
|
const {
|
|
|
|
|
return RenderMultiBandProcessingActive() || echo_canceller_enabled_ ||
|
2016-11-15 05:24:35 -08:00
|
|
|
mobile_echo_controller_enabled_ || adaptive_gain_controller_enabled_ ||
|
2017-10-16 13:49:04 +02:00
|
|
|
echo_controller_enabled_;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-18 16:02:40 +01:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::RenderFullBandProcessingActive()
|
|
|
|
|
const {
|
|
|
|
|
return render_pre_processor_enabled_;
|
|
|
|
|
}
|
|
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::RenderMultiBandProcessingActive()
|
|
|
|
|
const {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 14:15:09 +02:00
|
|
|
bool AudioProcessingImpl::ApmSubmoduleStates::LowCutFilteringRequired() const {
|
|
|
|
|
return high_pass_filter_enabled_ || echo_canceller_enabled_ ||
|
|
|
|
|
mobile_echo_controller_enabled_ || noise_suppressor_enabled_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-08 13:22:33 -08:00
|
|
|
struct AudioProcessingImpl::ApmPublicSubmodules {
|
2016-03-10 21:09:04 -08:00
|
|
|
ApmPublicSubmodules() {}
|
2015-12-08 13:22:33 -08:00
|
|
|
// Accessed externally of APM without any lock acquired.
|
2019-01-11 15:10:32 +01:00
|
|
|
// TODO(bugs.webrtc.org/9947): Move these submodules into private_submodules_
|
|
|
|
|
// when their pointer-to-submodule API functions are gone.
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<LevelEstimatorImpl> level_estimator;
|
|
|
|
|
std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
|
2019-01-11 15:10:32 +01:00
|
|
|
std::unique_ptr<NoiseSuppressionProxy> noise_suppression_proxy;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<VoiceDetectionImpl> voice_detection;
|
2019-03-27 13:28:08 +01:00
|
|
|
std::unique_ptr<GainControlImpl> gain_control;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<GainControlForExperimentalAgc>
|
2016-02-13 16:40:47 -08:00
|
|
|
gain_control_for_experimental_agc;
|
2019-03-27 13:28:08 +01:00
|
|
|
std::unique_ptr<GainControlConfigProxy> gain_control_config_proxy;
|
2015-12-08 13:22:33 -08:00
|
|
|
|
|
|
|
|
// Accessed internally from both render and capture.
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<TransientSuppressor> transient_suppressor;
|
2015-12-08 13:22:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AudioProcessingImpl::ApmPrivateSubmodules {
|
2018-06-21 10:12:24 +02:00
|
|
|
ApmPrivateSubmodules(std::unique_ptr<CustomProcessing> capture_post_processor,
|
2018-01-11 16:08:54 +01:00
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor,
|
2018-08-29 10:37:09 +02:00
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector,
|
|
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
|
2018-06-21 10:12:24 +02:00
|
|
|
: echo_detector(std::move(echo_detector)),
|
2017-12-18 16:02:40 +01:00
|
|
|
capture_post_processor(std::move(capture_post_processor)),
|
2018-08-29 10:37:09 +02:00
|
|
|
render_pre_processor(std::move(render_pre_processor)),
|
|
|
|
|
capture_analyzer(std::move(capture_analyzer)) {}
|
2015-12-08 13:22:33 -08:00
|
|
|
// Accessed internally from capture or during initialization
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<AgcManagerDirect> agc_manager;
|
2017-05-22 06:57:06 -07:00
|
|
|
std::unique_ptr<GainController2> gain_controller2;
|
2016-11-22 07:24:52 -08:00
|
|
|
std::unique_ptr<LowCutFilter> low_cut_filter;
|
2018-06-14 11:02:03 +02:00
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector;
|
2018-11-01 08:59:29 +01:00
|
|
|
std::unique_ptr<EchoCancellationImpl> echo_cancellation;
|
2018-11-05 16:10:00 +01:00
|
|
|
std::unique_ptr<EchoControl> echo_controller;
|
|
|
|
|
std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
|
2017-12-18 16:02:40 +01:00
|
|
|
std::unique_ptr<CustomProcessing> capture_post_processor;
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor;
|
2018-04-16 16:31:22 +02:00
|
|
|
std::unique_ptr<GainApplier> pre_amplifier;
|
2018-08-29 10:37:09 +02:00
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer;
|
2018-11-26 16:18:25 +01:00
|
|
|
std::unique_ptr<LevelEstimatorImpl> output_level_estimator;
|
2018-12-21 16:29:27 +01:00
|
|
|
std::unique_ptr<VoiceDetectionImpl> voice_detector;
|
2015-12-08 13:22:33 -08:00
|
|
|
};
|
|
|
|
|
|
2017-12-22 11:35:59 +01:00
|
|
|
AudioProcessingBuilder::AudioProcessingBuilder() = default;
|
|
|
|
|
AudioProcessingBuilder::~AudioProcessingBuilder() = default;
|
|
|
|
|
|
|
|
|
|
AudioProcessingBuilder& AudioProcessingBuilder::SetCapturePostProcessing(
|
|
|
|
|
std::unique_ptr<CustomProcessing> capture_post_processing) {
|
|
|
|
|
capture_post_processing_ = std::move(capture_post_processing);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessingBuilder& AudioProcessingBuilder::SetRenderPreProcessing(
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processing) {
|
|
|
|
|
render_pre_processing_ = std::move(render_pre_processing);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:37:09 +02:00
|
|
|
AudioProcessingBuilder& AudioProcessingBuilder::SetCaptureAnalyzer(
|
|
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) {
|
|
|
|
|
capture_analyzer_ = std::move(capture_analyzer);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 11:35:59 +01:00
|
|
|
AudioProcessingBuilder& AudioProcessingBuilder::SetEchoControlFactory(
|
|
|
|
|
std::unique_ptr<EchoControlFactory> echo_control_factory) {
|
|
|
|
|
echo_control_factory_ = std::move(echo_control_factory);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:08:54 +01:00
|
|
|
AudioProcessingBuilder& AudioProcessingBuilder::SetEchoDetector(
|
2018-06-14 11:02:03 +02:00
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector) {
|
2018-01-11 16:08:54 +01:00
|
|
|
echo_detector_ = std::move(echo_detector);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 11:35:59 +01:00
|
|
|
AudioProcessing* AudioProcessingBuilder::Create() {
|
|
|
|
|
webrtc::Config config;
|
|
|
|
|
return Create(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessing* AudioProcessingBuilder::Create(const webrtc::Config& config) {
|
2018-01-11 16:08:54 +01:00
|
|
|
AudioProcessingImpl* apm = new rtc::RefCountedObject<AudioProcessingImpl>(
|
|
|
|
|
config, std::move(capture_post_processing_),
|
|
|
|
|
std::move(render_pre_processing_), std::move(echo_control_factory_),
|
2018-08-29 10:37:09 +02:00
|
|
|
std::move(echo_detector_), std::move(capture_analyzer_));
|
2018-01-11 16:08:54 +01:00
|
|
|
if (apm->Initialize() != AudioProcessing::kNoError) {
|
|
|
|
|
delete apm;
|
|
|
|
|
apm = nullptr;
|
|
|
|
|
}
|
|
|
|
|
return apm;
|
2017-12-22 11:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:47:25 -07:00
|
|
|
AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
|
2018-08-29 10:37:09 +02:00
|
|
|
: AudioProcessingImpl(config, nullptr, nullptr, nullptr, nullptr, nullptr) {
|
|
|
|
|
}
|
2015-01-15 18:07:21 +00:00
|
|
|
|
2018-02-12 21:42:56 +01:00
|
|
|
int AudioProcessingImpl::instance_count_ = 0;
|
|
|
|
|
|
2017-09-25 12:04:02 +02:00
|
|
|
AudioProcessingImpl::AudioProcessingImpl(
|
|
|
|
|
const webrtc::Config& config,
|
2017-12-18 16:02:40 +01:00
|
|
|
std::unique_ptr<CustomProcessing> capture_post_processor,
|
|
|
|
|
std::unique_ptr<CustomProcessing> render_pre_processor,
|
2017-10-12 15:13:17 +02:00
|
|
|
std::unique_ptr<EchoControlFactory> echo_control_factory,
|
2018-08-29 10:37:09 +02:00
|
|
|
rtc::scoped_refptr<EchoDetector> echo_detector,
|
|
|
|
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
|
2018-02-12 21:42:56 +01:00
|
|
|
: data_dumper_(
|
|
|
|
|
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
2018-05-15 10:52:28 +02:00
|
|
|
capture_runtime_settings_(kRuntimeSettingQueueSize),
|
|
|
|
|
render_runtime_settings_(kRuntimeSettingQueueSize),
|
|
|
|
|
capture_runtime_settings_enqueuer_(&capture_runtime_settings_),
|
|
|
|
|
render_runtime_settings_enqueuer_(&render_runtime_settings_),
|
2017-10-12 15:13:17 +02:00
|
|
|
echo_control_factory_(std::move(echo_control_factory)),
|
2018-08-29 10:37:09 +02:00
|
|
|
submodule_states_(!!capture_post_processor,
|
|
|
|
|
!!render_pre_processor,
|
|
|
|
|
!!capture_analyzer),
|
2016-11-22 07:24:52 -08:00
|
|
|
public_submodules_(new ApmPublicSubmodules()),
|
2017-09-25 12:04:02 +02:00
|
|
|
private_submodules_(
|
2018-06-21 10:12:24 +02:00
|
|
|
new ApmPrivateSubmodules(std::move(capture_post_processor),
|
2018-01-11 16:08:54 +01:00
|
|
|
std::move(render_pre_processor),
|
2018-08-29 10:37:09 +02:00
|
|
|
std::move(echo_detector),
|
|
|
|
|
std::move(capture_analyzer))),
|
2015-11-28 12:35:15 -08:00
|
|
|
constants_(config.Get<ExperimentalAgc>().startup_min_volume,
|
2016-12-05 09:08:42 -08:00
|
|
|
config.Get<ExperimentalAgc>().clipped_level_min,
|
2014-12-15 09:41:24 +00:00
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2018-09-10 13:59:41 +02:00
|
|
|
/* enabled= */ false,
|
|
|
|
|
/* enabled_agc2_level_estimator= */ false,
|
|
|
|
|
/* digital_adaptive_disabled= */ false,
|
|
|
|
|
/* analyze_before_aec= */ false),
|
2014-12-15 09:41:24 +00:00
|
|
|
#else
|
2018-07-02 13:38:19 +02:00
|
|
|
config.Get<ExperimentalAgc>().enabled,
|
|
|
|
|
config.Get<ExperimentalAgc>().enabled_agc2_level_estimator,
|
2018-09-10 13:59:41 +02:00
|
|
|
config.Get<ExperimentalAgc>().digital_adaptive_disabled,
|
|
|
|
|
config.Get<ExperimentalAgc>().analyze_before_aec),
|
2014-12-15 09:41:24 +00:00
|
|
|
#endif
|
2015-06-24 18:14:14 -07:00
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
2018-06-14 10:11:35 +02:00
|
|
|
capture_(false),
|
2015-06-24 18:14:14 -07:00
|
|
|
#else
|
2018-06-14 10:11:35 +02:00
|
|
|
capture_(config.Get<ExperimentalNs>().enabled),
|
2015-06-24 18:14:14 -07:00
|
|
|
#endif
|
2018-08-30 13:01:34 +02:00
|
|
|
capture_nonlocked_() {
|
2019-02-11 13:39:46 +01:00
|
|
|
// Mark Echo Controller enabled if a factory is injected.
|
|
|
|
|
capture_nonlocked_.echo_controller_enabled =
|
|
|
|
|
static_cast<bool>(echo_control_factory_);
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
public_submodules_->gain_control.reset(new GainControlImpl());
|
2019-02-11 13:39:46 +01:00
|
|
|
public_submodules_->level_estimator.reset(
|
|
|
|
|
new LevelEstimatorImpl(&crit_capture_));
|
|
|
|
|
public_submodules_->noise_suppression.reset(
|
|
|
|
|
new NoiseSuppressionImpl(&crit_capture_));
|
|
|
|
|
public_submodules_->noise_suppression_proxy.reset(new NoiseSuppressionProxy(
|
|
|
|
|
this, public_submodules_->noise_suppression.get()));
|
|
|
|
|
public_submodules_->voice_detection.reset(
|
|
|
|
|
new VoiceDetectionImpl(&crit_capture_));
|
|
|
|
|
public_submodules_->gain_control_for_experimental_agc.reset(
|
2019-03-27 13:28:08 +01:00
|
|
|
new GainControlForExperimentalAgc(
|
|
|
|
|
public_submodules_->gain_control.get()));
|
|
|
|
|
public_submodules_->gain_control_config_proxy.reset(
|
|
|
|
|
new GainControlConfigProxy(&crit_capture_, this, agc1()));
|
2019-02-11 13:39:46 +01:00
|
|
|
|
|
|
|
|
// If no echo detector is injected, use the ResidualEchoDetector.
|
|
|
|
|
if (!private_submodules_->echo_detector) {
|
|
|
|
|
private_submodules_->echo_detector =
|
|
|
|
|
new rtc::RefCountedObject<ResidualEchoDetector>();
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2019-02-11 13:39:46 +01:00
|
|
|
// TODO(alessiob): Move the injected gain controller once injection is
|
|
|
|
|
// implemented.
|
|
|
|
|
private_submodules_->gain_controller2.reset(new GainController2());
|
|
|
|
|
|
|
|
|
|
RTC_LOG(LS_INFO) << "Capture analyzer activated: "
|
|
|
|
|
<< !!private_submodules_->capture_analyzer
|
|
|
|
|
<< "\nCapture post processor activated: "
|
|
|
|
|
<< !!private_submodules_->capture_post_processor
|
|
|
|
|
<< "\nRender pre processor activated: "
|
|
|
|
|
<< !!private_submodules_->render_pre_processor;
|
|
|
|
|
|
2014-01-25 02:09:06 +00:00
|
|
|
SetExtraOptions(config);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::~AudioProcessingImpl() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Depends on gain_control_ and
|
2016-02-13 16:40:47 -08:00
|
|
|
// public_submodules_->gain_control_for_experimental_agc.
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager.reset();
|
|
|
|
|
// Depends on gain_control_.
|
2016-02-13 16:40:47 -08:00
|
|
|
public_submodules_->gain_control_for_experimental_agc.reset();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::Initialize() {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner during initialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2011-07-07 08:21:25 +00:00
|
|
|
return InitializeLocked();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
int AudioProcessingImpl::Initialize(int capture_input_sample_rate_hz,
|
|
|
|
|
int capture_output_sample_rate_hz,
|
|
|
|
|
int render_input_sample_rate_hz,
|
|
|
|
|
ChannelLayout capture_input_layout,
|
|
|
|
|
ChannelLayout capture_output_layout,
|
|
|
|
|
ChannelLayout render_input_layout) {
|
2015-07-23 11:41:39 -07:00
|
|
|
const ProcessingConfig processing_config = {
|
2016-09-16 15:02:15 -07:00
|
|
|
{{capture_input_sample_rate_hz, ChannelsFromLayout(capture_input_layout),
|
|
|
|
|
LayoutHasKeyboard(capture_input_layout)},
|
|
|
|
|
{capture_output_sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(capture_output_layout),
|
|
|
|
|
LayoutHasKeyboard(capture_output_layout)},
|
|
|
|
|
{render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout),
|
|
|
|
|
LayoutHasKeyboard(render_input_layout)},
|
|
|
|
|
{render_input_sample_rate_hz, ChannelsFromLayout(render_input_layout),
|
|
|
|
|
LayoutHasKeyboard(render_input_layout)}}};
|
2015-07-23 11:41:39 -07:00
|
|
|
|
|
|
|
|
return Initialize(processing_config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner during initialization.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-07-23 11:41:39 -07:00
|
|
|
return InitializeLocked(processing_config);
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::MaybeInitializeRender(
|
2015-11-27 02:47:28 -08:00
|
|
|
const ProcessingConfig& processing_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Called from both threads. Thread check is therefore not possible.
|
2019-05-23 14:28:00 +02:00
|
|
|
if (processing_config == formats_.api_format) {
|
2015-11-17 02:16:45 -08:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-11-17 02:16:45 -08:00
|
|
|
return InitializeLocked(processing_config);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int AudioProcessingImpl::InitializeLocked() {
|
2017-06-27 16:00:38 +02:00
|
|
|
UpdateActiveSubmoduleStates();
|
|
|
|
|
|
2019-08-21 15:02:37 +02:00
|
|
|
const int render_audiobuffer_sample_rate_hz =
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_output_stream().num_frames() == 0
|
2019-08-21 15:02:37 +02:00
|
|
|
? formats_.render_processing_format.sample_rate_hz()
|
|
|
|
|
: formats_.api_format.reverse_output_stream().sample_rate_hz();
|
2015-11-28 12:35:15 -08:00
|
|
|
if (formats_.api_format.reverse_input_stream().num_channels() > 0) {
|
|
|
|
|
render_.render_audio.reset(new AudioBuffer(
|
2019-08-21 15:02:37 +02:00
|
|
|
formats_.api_format.reverse_input_stream().sample_rate_hz(),
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_channels(),
|
2019-08-21 15:02:37 +02:00
|
|
|
formats_.render_processing_format.sample_rate_hz(),
|
2016-09-16 15:02:15 -07:00
|
|
|
formats_.render_processing_format.num_channels(),
|
2019-08-21 15:02:37 +02:00
|
|
|
render_audiobuffer_sample_rate_hz));
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (formats_.api_format.reverse_input_stream() !=
|
|
|
|
|
formats_.api_format.reverse_output_stream()) {
|
2016-02-24 05:22:32 -08:00
|
|
|
render_.render_converter = AudioConverter::Create(
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_channels(),
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_frames(),
|
|
|
|
|
formats_.api_format.reverse_output_stream().num_channels(),
|
2016-02-24 05:22:32 -08:00
|
|
|
formats_.api_format.reverse_output_stream().num_frames());
|
2015-08-14 10:35:55 -07:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_converter.reset(nullptr);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio.reset(nullptr);
|
|
|
|
|
render_.render_converter.reset(nullptr);
|
2015-07-23 11:41:39 -07:00
|
|
|
}
|
2017-05-19 01:28:05 -07:00
|
|
|
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_.capture_audio.reset(new AudioBuffer(
|
|
|
|
|
formats_.api_format.input_stream().sample_rate_hz(),
|
|
|
|
|
formats_.api_format.input_stream().num_channels(),
|
|
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz(),
|
|
|
|
|
formats_.api_format.output_stream().num_channels(),
|
|
|
|
|
formats_.api_format.output_stream().sample_rate_hz()));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-10-22 05:04:30 -07:00
|
|
|
AllocateRenderQueue();
|
|
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
public_submodules_->gain_control->Initialize(num_proc_channels(),
|
|
|
|
|
proc_sample_rate_hz());
|
2016-09-16 15:02:15 -07:00
|
|
|
if (constants_.use_experimental_agc) {
|
|
|
|
|
if (!private_submodules_->agc_manager.get()) {
|
|
|
|
|
private_submodules_->agc_manager.reset(new AgcManagerDirect(
|
|
|
|
|
public_submodules_->gain_control.get(),
|
|
|
|
|
public_submodules_->gain_control_for_experimental_agc.get(),
|
2018-07-02 13:38:19 +02:00
|
|
|
constants_.agc_startup_min_volume, constants_.agc_clipped_level_min,
|
|
|
|
|
constants_.use_experimental_agc_agc2_level_estimation,
|
|
|
|
|
constants_.use_experimental_agc_agc2_digital_adaptive));
|
2016-09-16 15:02:15 -07:00
|
|
|
}
|
|
|
|
|
private_submodules_->agc_manager->Initialize();
|
|
|
|
|
private_submodules_->agc_manager->SetCaptureMuted(
|
|
|
|
|
capture_.output_will_be_muted);
|
2016-10-28 03:12:11 -07:00
|
|
|
public_submodules_->gain_control_for_experimental_agc->Initialize();
|
2016-09-16 15:02:15 -07:00
|
|
|
}
|
2015-04-15 11:42:40 +02:00
|
|
|
InitializeTransient();
|
2016-11-22 07:24:52 -08:00
|
|
|
InitializeLowCutFilter();
|
2016-09-16 15:02:15 -07:00
|
|
|
public_submodules_->noise_suppression->Initialize(num_proc_channels(),
|
|
|
|
|
proc_sample_rate_hz());
|
|
|
|
|
public_submodules_->voice_detection->Initialize(proc_split_sample_rate_hz());
|
2018-12-21 16:29:27 +01:00
|
|
|
if (private_submodules_->voice_detector) {
|
|
|
|
|
private_submodules_->voice_detector->Initialize(
|
|
|
|
|
proc_split_sample_rate_hz());
|
|
|
|
|
}
|
2016-09-16 15:02:15 -07:00
|
|
|
public_submodules_->level_estimator->Initialize();
|
2016-10-28 05:39:16 -07:00
|
|
|
InitializeResidualEchoDetector();
|
2017-10-14 08:28:46 +02:00
|
|
|
InitializeEchoController();
|
2017-05-22 06:57:06 -07:00
|
|
|
InitializeGainController2();
|
2018-08-29 10:37:09 +02:00
|
|
|
InitializeAnalyzer();
|
2017-09-25 12:04:02 +02:00
|
|
|
InitializePostProcessor();
|
2017-12-18 16:02:40 +01:00
|
|
|
InitializePreProcessor();
|
2015-12-08 11:07:32 -08:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
2018-08-10 15:38:52 +02:00
|
|
|
aec_dump_->WriteInitMessage(formats_.api_format, rtc::TimeUTCMillis());
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
|
2017-06-27 16:00:38 +02:00
|
|
|
UpdateActiveSubmoduleStates();
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
for (const auto& stream : config.streams) {
|
|
|
|
|
if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) {
|
|
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
Revert of Allow more than 2 input channels in AudioProcessing. (patchset #13 id:240001 of https://codereview.webrtc.org/1226093007/)
Reason for revert:
Breaks Chromium FYI content_browsertest on all platforms. The testcase that fails is WebRtcAecDumpBrowserTest.CallWithAecDump.
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Linux/builds/19388
Sample output:
[ RUN ] WebRtcAecDumpBrowserTest.CallWithAecDump
Xlib: extension "RANDR" missing on display ":9".
[4:14:0722/211548:1282124453:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: ISAC/48000/1 (105)
[4:14:0722/211548:1282124593:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMU/8000/2 (110)
[4:14:0722/211548:1282124700:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: PCMA/8000/2 (118)
[4:14:0722/211548:1282124815:WARNING:webrtcvoiceengine.cc(472)] Unexpected codec: G722/8000/2 (119)
[19745:19745:0722/211548:1282133667:INFO:CONSOLE(64)] "Looking at video in element remote-view-1", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
[19745:19745:0722/211548:1282136892:INFO:CONSOLE(64)] "Looking at video in element remote-view-2", source: http://127.0.0.1:48819/media/webrtc_test_utilities.js (64)
../../content/test/webrtc_content_browsertest_base.cc:62: Failure
Value of: ExecuteScriptAndExtractString( shell()->web_contents(), javascript, &result)
Actual: false
Expected: true
Failed to execute javascript call({video: true, audio: true});.
From javascript: (nothing)
When executing 'call({video: true, audio: true});'
../../content/test/webrtc_content_browsertest_base.cc:75: Failure
Failed
../../content/browser/media/webrtc_aecdump_browsertest.cc:26: Failure
Expected: (base::kNullProcessId) != (*id), actual: 0 vs 0
../../content/browser/media/webrtc_aecdump_browsertest.cc:95: Failure
Value of: GetRenderProcessHostId(&render_process_id)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:99: Failure
Value of: base::PathExists(dump_file)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:101: Failure
Value of: base::GetFileSize(dump_file, &file_size)
Actual: false
Expected: true
../../content/browser/media/webrtc_aecdump_browsertest.cc:102: Failure
Expected: (file_size) > (0), actual: 0 vs 0
[ FAILED ] WebRtcAecDumpBrowserTest.CallWithAecDump, where TypeParam = and GetParam() = (361 ms)
Original issue's description:
> Allow more than 2 input channels in AudioProcessing.
>
> The number of output channels is constrained to be equal to either 1 or the
> number of input channels.
>
> R=aluebs@webrtc.org, andrew@webrtc.org, pbos@webrtc.org
>
> Committed: https://chromium.googlesource.com/external/webrtc/+/c204754b7a0cc801c70e8ce6c689f57f6ce00b3b
TBR=andrew@webrtc.org,aluebs@webrtc.org,ajm@chromium.org,pbos@chromium.org,pbos@webrtc.org,mgraczyk@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.webrtc.org/1253573005
Cr-Commit-Position: refs/heads/master@{#9621}
2015-07-23 04:30:06 -07:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t num_in_channels = config.input_stream().num_channels();
|
|
|
|
|
const size_t num_out_channels = config.output_stream().num_channels();
|
2015-07-23 11:41:39 -07:00
|
|
|
|
|
|
|
|
// Need at least one input channel.
|
|
|
|
|
// Need either one output channel or as many outputs as there are inputs.
|
|
|
|
|
if (num_in_channels == 0 ||
|
|
|
|
|
!(num_out_channels == 1 || num_out_channels == num_in_channels)) {
|
2014-03-10 22:26:12 +00:00
|
|
|
return kBadNumberChannelsError;
|
|
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format = config;
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2019-08-21 15:45:07 +02:00
|
|
|
int capture_processing_rate = SuitableProcessRate(
|
2016-04-09 16:06:52 -07:00
|
|
|
std::min(formats_.api_format.input_stream().sample_rate_hz(),
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
formats_.api_format.output_stream().sample_rate_hz()),
|
|
|
|
|
submodule_states_.CaptureMultiBandSubModulesActive() ||
|
|
|
|
|
submodule_states_.RenderMultiBandSubModulesActive());
|
2019-08-21 15:45:07 +02:00
|
|
|
RTC_DCHECK_NE(8000, capture_processing_rate);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format =
|
|
|
|
|
StreamConfig(capture_processing_rate);
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2017-04-07 03:57:48 -07:00
|
|
|
int render_processing_rate;
|
2017-10-18 12:32:42 +02:00
|
|
|
if (!capture_nonlocked_.echo_controller_enabled) {
|
2019-08-21 15:45:07 +02:00
|
|
|
render_processing_rate = SuitableProcessRate(
|
2017-04-07 03:57:48 -07:00
|
|
|
std::min(formats_.api_format.reverse_input_stream().sample_rate_hz(),
|
|
|
|
|
formats_.api_format.reverse_output_stream().sample_rate_hz()),
|
|
|
|
|
submodule_states_.CaptureMultiBandSubModulesActive() ||
|
|
|
|
|
submodule_states_.RenderMultiBandSubModulesActive());
|
|
|
|
|
} else {
|
|
|
|
|
render_processing_rate = capture_processing_rate;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 15:27:58 -07:00
|
|
|
// TODO(aluebs): Remove this restriction once we figure out why the 3-band
|
|
|
|
|
// splitting filter degrades the AEC performance.
|
2017-04-05 14:18:07 -07:00
|
|
|
if (render_processing_rate > kSampleRate32kHz &&
|
2017-10-18 12:32:42 +02:00
|
|
|
!capture_nonlocked_.echo_controller_enabled) {
|
2016-09-16 15:02:15 -07:00
|
|
|
render_processing_rate = submodule_states_.RenderMultiBandProcessingActive()
|
|
|
|
|
? kSampleRate32kHz
|
|
|
|
|
: kSampleRate16kHz;
|
2016-04-20 15:27:58 -07:00
|
|
|
}
|
2017-04-07 03:57:48 -07:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
// If the forward sample rate is 8 kHz, the render stream is also processed
|
2016-04-20 15:27:58 -07:00
|
|
|
// at this rate.
|
2016-09-16 15:02:15 -07:00
|
|
|
if (capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
|
|
|
|
|
kSampleRate8kHz) {
|
|
|
|
|
render_processing_rate = kSampleRate8kHz;
|
2014-04-22 21:00:04 +00:00
|
|
|
} else {
|
2016-09-16 15:02:15 -07:00
|
|
|
render_processing_rate =
|
|
|
|
|
std::max(render_processing_rate, static_cast<int>(kSampleRate16kHz));
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
2019-08-21 15:45:07 +02:00
|
|
|
RTC_DCHECK_NE(8000, render_processing_rate);
|
2014-03-10 22:26:12 +00:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
// Always downmix the render stream to mono for analysis. This has been
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
// demonstrated to work well for AEC in most practical scenarios.
|
2017-05-19 01:28:05 -07:00
|
|
|
if (submodule_states_.RenderMultiBandSubModulesActive()) {
|
|
|
|
|
formats_.render_processing_format = StreamConfig(render_processing_rate, 1);
|
|
|
|
|
} else {
|
|
|
|
|
formats_.render_processing_format = StreamConfig(
|
|
|
|
|
formats_.api_format.reverse_input_stream().sample_rate_hz(),
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_channels());
|
|
|
|
|
}
|
2014-03-10 22:26:12 +00:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
if (capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
|
|
|
|
|
kSampleRate32kHz ||
|
|
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz() ==
|
|
|
|
|
kSampleRate48kHz) {
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_nonlocked_.split_rate = kSampleRate16kHz;
|
2014-03-10 22:26:12 +00:00
|
|
|
} else {
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_nonlocked_.split_rate =
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz();
|
2014-03-10 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return InitializeLocked();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:47:25 -07:00
|
|
|
void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
|
|
|
|
|
// Run in a single-threaded manner when applying the settings.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
|
2019-03-06 04:16:46 +01:00
|
|
|
const bool aec_config_changed =
|
|
|
|
|
config_.echo_canceller.enabled != config.echo_canceller.enabled ||
|
|
|
|
|
config_.echo_canceller.use_legacy_aec !=
|
|
|
|
|
config.echo_canceller.use_legacy_aec ||
|
|
|
|
|
config_.echo_canceller.mobile_mode != config.echo_canceller.mobile_mode ||
|
|
|
|
|
(config_.echo_canceller.enabled && config.echo_canceller.use_legacy_aec &&
|
|
|
|
|
config_.echo_canceller.legacy_moderate_suppression_level !=
|
|
|
|
|
config.echo_canceller.legacy_moderate_suppression_level);
|
2018-10-10 18:29:07 +02:00
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
const bool agc1_config_changed =
|
|
|
|
|
config_.gain_controller1.enabled != config.gain_controller1.enabled ||
|
|
|
|
|
config_.gain_controller1.mode != config.gain_controller1.mode ||
|
|
|
|
|
config_.gain_controller1.target_level_dbfs !=
|
|
|
|
|
config.gain_controller1.target_level_dbfs ||
|
|
|
|
|
config_.gain_controller1.compression_gain_db !=
|
|
|
|
|
config.gain_controller1.compression_gain_db ||
|
|
|
|
|
config_.gain_controller1.enable_limiter !=
|
|
|
|
|
config.gain_controller1.enable_limiter ||
|
|
|
|
|
config_.gain_controller1.analog_level_minimum !=
|
|
|
|
|
config.gain_controller1.analog_level_minimum ||
|
|
|
|
|
config_.gain_controller1.analog_level_maximum !=
|
|
|
|
|
config.gain_controller1.analog_level_maximum;
|
|
|
|
|
|
2019-03-06 04:16:46 +01:00
|
|
|
config_ = config;
|
2018-08-17 16:26:14 +02:00
|
|
|
|
2019-03-06 04:16:46 +01:00
|
|
|
if (aec_config_changed) {
|
|
|
|
|
InitializeEchoController();
|
|
|
|
|
}
|
2018-09-17 11:05:17 +02:00
|
|
|
|
2019-01-11 15:10:32 +01:00
|
|
|
public_submodules_->noise_suppression->Enable(
|
|
|
|
|
config.noise_suppression.enabled);
|
|
|
|
|
public_submodules_->noise_suppression->set_level(
|
|
|
|
|
NsConfigLevelToInterfaceLevel(config.noise_suppression.level));
|
|
|
|
|
|
2016-11-22 07:24:52 -08:00
|
|
|
InitializeLowCutFilter();
|
|
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Highpass filter activated: "
|
|
|
|
|
<< config_.high_pass_filter.enabled;
|
2016-12-14 01:16:23 -08:00
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
if (agc1_config_changed) {
|
|
|
|
|
ApplyAgc1Config(config_.gain_controller1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 15:59:06 +01:00
|
|
|
const bool config_ok = GainController2::Validate(config_.gain_controller2);
|
2017-05-22 06:57:06 -07:00
|
|
|
if (!config_ok) {
|
2018-02-15 15:16:27 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "AudioProcessing module config error\n"
|
|
|
|
|
"Gain Controller 2: "
|
2017-11-09 11:09:25 +01:00
|
|
|
<< GainController2::ToString(config_.gain_controller2)
|
2018-02-15 15:16:27 +01:00
|
|
|
<< "\nReverting to default parameter set";
|
2017-05-22 06:57:06 -07:00
|
|
|
config_.gain_controller2 = AudioProcessing::Config::GainController2();
|
|
|
|
|
}
|
2017-10-13 11:05:17 +02:00
|
|
|
InitializeGainController2();
|
2018-04-16 16:31:22 +02:00
|
|
|
InitializePreAmplifier();
|
2017-10-13 11:05:17 +02:00
|
|
|
private_submodules_->gain_controller2->ApplyConfig(config_.gain_controller2);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Gain Controller 2 activated: "
|
|
|
|
|
<< config_.gain_controller2.enabled;
|
2018-04-16 13:52:32 +02:00
|
|
|
RTC_LOG(LS_INFO) << "Pre-amplifier activated: "
|
|
|
|
|
<< config_.pre_amplifier.enabled;
|
2018-11-26 16:18:25 +01:00
|
|
|
|
|
|
|
|
if (config_.level_estimation.enabled &&
|
|
|
|
|
!private_submodules_->output_level_estimator) {
|
|
|
|
|
private_submodules_->output_level_estimator.reset(
|
|
|
|
|
new LevelEstimatorImpl(&crit_capture_));
|
|
|
|
|
private_submodules_->output_level_estimator->Enable(true);
|
|
|
|
|
}
|
2018-12-21 16:29:27 +01:00
|
|
|
|
|
|
|
|
if (config_.voice_detection.enabled && !private_submodules_->voice_detector) {
|
|
|
|
|
private_submodules_->voice_detector.reset(
|
|
|
|
|
new VoiceDetectionImpl(&crit_capture_));
|
|
|
|
|
private_submodules_->voice_detector->Enable(true);
|
|
|
|
|
private_submodules_->voice_detector->set_likelihood(
|
|
|
|
|
VoiceDetection::kVeryLowLikelihood);
|
|
|
|
|
private_submodules_->voice_detector->Initialize(
|
|
|
|
|
proc_split_sample_rate_hz());
|
|
|
|
|
}
|
2016-09-12 16:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
void AudioProcessingImpl::ApplyAgc1Config(
|
|
|
|
|
const Config::GainController1& config) {
|
|
|
|
|
GainControl* agc = agc1();
|
|
|
|
|
int error = agc->Enable(config.enabled);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
error = agc->set_mode(Agc1ConfigModeToInterfaceMode(config.mode));
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
error = agc->set_target_level_dbfs(config.target_level_dbfs);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
error = agc->set_compression_gain_db(config.compression_gain_db);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
error = agc->enable_limiter(config.enable_limiter);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
error = agc->set_analog_level_limits(config.analog_level_minimum,
|
|
|
|
|
config.analog_level_maximum);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GainControl* AudioProcessingImpl::agc1() {
|
|
|
|
|
if (constants_.use_experimental_agc) {
|
|
|
|
|
return public_submodules_->gain_control_for_experimental_agc.get();
|
|
|
|
|
}
|
|
|
|
|
return public_submodules_->gain_control.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const GainControl* AudioProcessingImpl::agc1() const {
|
|
|
|
|
if (constants_.use_experimental_agc) {
|
|
|
|
|
return public_submodules_->gain_control_for_experimental_agc.get();
|
|
|
|
|
}
|
|
|
|
|
return public_submodules_->gain_control.get();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 16:47:25 -07:00
|
|
|
void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Run in a single-threaded manner when setting the extra options.
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
capture_nonlocked_.use_aec2_extended_filter =
|
|
|
|
|
config.Get<ExtendedFilter>().enabled;
|
|
|
|
|
capture_nonlocked_.use_aec2_delay_agnostic =
|
|
|
|
|
config.Get<DelayAgnostic>().enabled;
|
|
|
|
|
capture_nonlocked_.use_aec2_refined_adaptive_filter =
|
|
|
|
|
config.Get<RefinedAdaptiveFilter>().enabled;
|
2016-03-05 03:01:14 -08:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled !=
|
|
|
|
|
config.Get<ExperimentalNs>().enabled) {
|
|
|
|
|
capture_.transient_suppressor_enabled =
|
|
|
|
|
config.Get<ExperimentalNs>().enabled;
|
2014-12-15 09:41:24 +00:00
|
|
|
InitializeTransient();
|
|
|
|
|
}
|
2013-07-25 18:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::proc_sample_rate_hz() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
2016-09-16 15:02:15 -07:00
|
|
|
return capture_nonlocked_.capture_processing_format.sample_rate_hz();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::proc_split_sample_rate_hz() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.split_rate;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_reverse_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
2016-09-16 15:02:15 -07:00
|
|
|
return formats_.render_processing_format.num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_input_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return formats_.api_format.input_stream().num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_proc_channels() const {
|
2016-01-11 20:32:29 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
2018-06-14 10:11:35 +02:00
|
|
|
return capture_nonlocked_.echo_controller_enabled ? 1 : num_output_channels();
|
2016-01-11 20:32:29 -08:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioProcessingImpl::num_output_channels() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return formats_.api_format.output_stream().num_channels();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-12 22:28:31 +00:00
|
|
|
void AudioProcessingImpl::set_output_will_be_muted(bool muted) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.output_will_be_muted = muted;
|
|
|
|
|
if (private_submodules_->agc_manager.get()) {
|
|
|
|
|
private_submodules_->agc_manager->SetCaptureMuted(
|
|
|
|
|
capture_.output_will_be_muted);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2014-02-12 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-16 12:10:09 +02:00
|
|
|
void AudioProcessingImpl::SetRuntimeSetting(RuntimeSetting setting) {
|
2018-05-15 10:52:28 +02:00
|
|
|
switch (setting.type()) {
|
|
|
|
|
case RuntimeSetting::Type::kCustomRenderProcessingRuntimeSetting:
|
|
|
|
|
render_runtime_settings_enqueuer_.Enqueue(setting);
|
|
|
|
|
return;
|
|
|
|
|
case RuntimeSetting::Type::kNotSpecified:
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
return;
|
|
|
|
|
case RuntimeSetting::Type::kCapturePreGain:
|
2019-03-27 13:28:08 +01:00
|
|
|
case RuntimeSetting::Type::kCaptureCompressionGain:
|
2019-04-26 11:33:37 +02:00
|
|
|
case RuntimeSetting::Type::kCaptureFixedPostGain:
|
2019-05-10 15:50:02 +02:00
|
|
|
case RuntimeSetting::Type::kPlayoutVolumeChange:
|
2018-05-15 10:52:28 +02:00
|
|
|
capture_runtime_settings_enqueuer_.Enqueue(setting);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// The language allows the enum to have a non-enumerator
|
|
|
|
|
// value. Check that this doesn't happen.
|
|
|
|
|
RTC_NOTREACHED();
|
2018-04-16 12:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::RuntimeSettingEnqueuer::RuntimeSettingEnqueuer(
|
|
|
|
|
SwapQueue<RuntimeSetting>* runtime_settings)
|
2018-04-20 13:16:55 +02:00
|
|
|
: runtime_settings_(*runtime_settings) {
|
|
|
|
|
RTC_DCHECK(runtime_settings);
|
2018-04-16 12:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::RuntimeSettingEnqueuer::~RuntimeSettingEnqueuer() =
|
|
|
|
|
default;
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RuntimeSettingEnqueuer::Enqueue(
|
|
|
|
|
RuntimeSetting setting) {
|
|
|
|
|
size_t remaining_attempts = 10;
|
2018-04-20 13:16:55 +02:00
|
|
|
while (!runtime_settings_.Insert(&setting) && remaining_attempts-- > 0) {
|
2018-04-16 12:10:09 +02:00
|
|
|
RuntimeSetting setting_to_discard;
|
2018-04-20 13:16:55 +02:00
|
|
|
if (runtime_settings_.Remove(&setting_to_discard))
|
2018-04-16 12:10:09 +02:00
|
|
|
RTC_LOG(LS_ERROR)
|
|
|
|
|
<< "The runtime settings queue is full. Oldest setting discarded.";
|
|
|
|
|
}
|
|
|
|
|
if (remaining_attempts == 0)
|
|
|
|
|
RTC_LOG(LS_ERROR) << "Cannot enqueue a new runtime setting.";
|
|
|
|
|
}
|
2014-02-12 22:28:31 +00:00
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
int AudioProcessingImpl::ProcessStream(const float* const* src,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t samples_per_channel,
|
2014-04-22 21:00:04 +00:00
|
|
|
int input_sample_rate_hz,
|
2014-03-04 20:58:13 +00:00
|
|
|
ChannelLayout input_layout,
|
2014-04-22 21:00:04 +00:00
|
|
|
int output_sample_rate_hz,
|
|
|
|
|
ChannelLayout output_layout,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout");
|
2015-11-28 12:35:15 -08:00
|
|
|
StreamConfig input_stream;
|
|
|
|
|
StreamConfig output_stream;
|
|
|
|
|
{
|
|
|
|
|
// Access the formats_.api_format.input_stream beneath the capture lock.
|
|
|
|
|
// The lock must be released as it is later required in the call
|
|
|
|
|
// to ProcessStream(,,,);
|
|
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
input_stream = formats_.api_format.input_stream();
|
|
|
|
|
output_stream = formats_.api_format.output_stream();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
input_stream.set_sample_rate_hz(input_sample_rate_hz);
|
|
|
|
|
input_stream.set_num_channels(ChannelsFromLayout(input_layout));
|
|
|
|
|
input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout));
|
|
|
|
|
output_stream.set_sample_rate_hz(output_sample_rate_hz);
|
|
|
|
|
output_stream.set_num_channels(ChannelsFromLayout(output_layout));
|
|
|
|
|
output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout));
|
|
|
|
|
|
|
|
|
|
if (samples_per_channel != input_stream.num_frames()) {
|
|
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
|
|
|
|
return ProcessStream(src, input_stream, output_stream, dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessStream(const float* const* src,
|
|
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig");
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool reinitialization_required = false;
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Acquire the capture lock in order to safely call the function
|
|
|
|
|
// that retrieves the render side data. This function accesses apm
|
|
|
|
|
// getters that need the capture lock held when being called.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2016-10-22 05:04:30 -07:00
|
|
|
EmptyQueuedRenderAudio();
|
2015-11-28 12:35:15 -08:00
|
|
|
|
|
|
|
|
if (!src || !dest) {
|
|
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-01-07 17:45:09 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
processing_config = formats_.api_format;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
reinitialization_required = UpdateActiveSubmoduleStates();
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2015-11-16 16:27:42 -08:00
|
|
|
|
2019-05-23 14:28:00 +02:00
|
|
|
if (processing_config.input_stream() != input_config) {
|
|
|
|
|
processing_config.input_stream() = input_config;
|
|
|
|
|
reinitialization_required = true;
|
|
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2019-05-23 14:28:00 +02:00
|
|
|
if (processing_config.output_stream() != output_config) {
|
|
|
|
|
processing_config.output_stream() = output_config;
|
|
|
|
|
reinitialization_required = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reinitialization_required) {
|
|
|
|
|
// Reinitialize.
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
2019-05-23 14:28:00 +02:00
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
RETURN_ON_ERR(InitializeLocked(processing_config));
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2019-05-23 14:28:00 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2016-09-14 05:23:22 -07:00
|
|
|
RTC_DCHECK_EQ(processing_config.input_stream().num_frames(),
|
|
|
|
|
formats_.api_format.input_stream().num_frames());
|
2014-03-04 20:58:13 +00:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
RecordUnprocessedCaptureStream(src);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 12:15:46 +02:00
|
|
|
capture_.keyboard_info.Extract(src, formats_.api_format.input_stream());
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream());
|
2016-09-16 15:02:15 -07:00
|
|
|
RETURN_ON_ERR(ProcessCaptureStreamLocked());
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest);
|
2014-03-04 20:58:13 +00:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
RecordProcessedCaptureStream(dest);
|
|
|
|
|
}
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 10:52:28 +02:00
|
|
|
void AudioProcessingImpl::HandleCaptureRuntimeSettings() {
|
2018-04-16 12:10:09 +02:00
|
|
|
RuntimeSetting setting;
|
2018-05-15 10:52:28 +02:00
|
|
|
while (capture_runtime_settings_.Remove(&setting)) {
|
2018-09-10 10:18:07 +02:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
aec_dump_->WriteRuntimeSetting(setting);
|
|
|
|
|
}
|
2018-04-16 12:10:09 +02:00
|
|
|
switch (setting.type()) {
|
|
|
|
|
case RuntimeSetting::Type::kCapturePreGain:
|
2018-04-16 16:31:22 +02:00
|
|
|
if (config_.pre_amplifier.enabled) {
|
|
|
|
|
float value;
|
|
|
|
|
setting.GetFloat(&value);
|
|
|
|
|
private_submodules_->pre_amplifier->SetGainFactor(value);
|
|
|
|
|
}
|
|
|
|
|
// TODO(bugs.chromium.org/9138): Log setting handling by Aec Dump.
|
2018-04-16 12:10:09 +02:00
|
|
|
break;
|
2019-03-27 13:28:08 +01:00
|
|
|
case RuntimeSetting::Type::kCaptureCompressionGain: {
|
|
|
|
|
float value;
|
|
|
|
|
setting.GetFloat(&value);
|
|
|
|
|
int int_value = static_cast<int>(value + .5f);
|
|
|
|
|
config_.gain_controller1.compression_gain_db = int_value;
|
|
|
|
|
int error = agc1()->set_compression_gain_db(int_value);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-26 11:33:37 +02:00
|
|
|
case RuntimeSetting::Type::kCaptureFixedPostGain: {
|
|
|
|
|
if (config_.gain_controller2.enabled) {
|
|
|
|
|
float value;
|
|
|
|
|
setting.GetFloat(&value);
|
|
|
|
|
config_.gain_controller2.fixed_digital.gain_db = value;
|
|
|
|
|
private_submodules_->gain_controller2->ApplyConfig(
|
|
|
|
|
config_.gain_controller2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-10 15:50:02 +02:00
|
|
|
case RuntimeSetting::Type::kPlayoutVolumeChange: {
|
|
|
|
|
int value;
|
|
|
|
|
setting.GetInt(&value);
|
|
|
|
|
capture_.playout_volume = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-05-15 10:52:28 +02:00
|
|
|
case RuntimeSetting::Type::kCustomRenderProcessingRuntimeSetting:
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
break;
|
|
|
|
|
case RuntimeSetting::Type::kNotSpecified:
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::HandleRenderRuntimeSettings() {
|
|
|
|
|
RuntimeSetting setting;
|
|
|
|
|
while (render_runtime_settings_.Remove(&setting)) {
|
2018-09-10 10:18:07 +02:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
aec_dump_->WriteRuntimeSetting(setting);
|
|
|
|
|
}
|
2018-05-15 10:52:28 +02:00
|
|
|
switch (setting.type()) {
|
|
|
|
|
case RuntimeSetting::Type::kCustomRenderProcessingRuntimeSetting:
|
|
|
|
|
if (private_submodules_->render_pre_processor) {
|
|
|
|
|
private_submodules_->render_pre_processor->SetRuntimeSetting(setting);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-03-27 13:28:08 +01:00
|
|
|
case RuntimeSetting::Type::kCapturePreGain: // fall-through
|
|
|
|
|
case RuntimeSetting::Type::kCaptureCompressionGain: // fall-through
|
2019-04-26 11:33:37 +02:00
|
|
|
case RuntimeSetting::Type::kCaptureFixedPostGain: // fall-through
|
2019-05-10 15:50:02 +02:00
|
|
|
case RuntimeSetting::Type::kPlayoutVolumeChange: // fall-through
|
2018-04-20 13:16:55 +02:00
|
|
|
case RuntimeSetting::Type::kNotSpecified:
|
2018-04-16 12:10:09 +02:00
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 07:19:21 -07:00
|
|
|
void AudioProcessingImpl::QueueBandedRenderAudio(AudioBuffer* audio) {
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_DCHECK_GE(160, audio->num_frames_per_band());
|
2016-10-22 05:04:30 -07:00
|
|
|
|
|
|
|
|
// Insert the samples into the queue.
|
2019-04-25 15:18:06 +02:00
|
|
|
if (private_submodules_->echo_cancellation) {
|
|
|
|
|
RTC_DCHECK(aec_render_signal_queue_);
|
2019-04-29 12:14:50 +02:00
|
|
|
EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(),
|
|
|
|
|
num_reverse_channels(),
|
|
|
|
|
&aec_render_queue_buffer_);
|
|
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
if (!aec_render_signal_queue_->Insert(&aec_render_queue_buffer_)) {
|
|
|
|
|
// The data queue is full and needs to be emptied.
|
|
|
|
|
EmptyQueuedRenderAudio();
|
2016-10-22 05:04:30 -07:00
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
// Retry the insert (should always work).
|
|
|
|
|
bool result = aec_render_signal_queue_->Insert(&aec_render_queue_buffer_);
|
|
|
|
|
RTC_DCHECK(result);
|
|
|
|
|
}
|
2016-10-25 04:45:24 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
if (private_submodules_->echo_control_mobile) {
|
|
|
|
|
EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(),
|
|
|
|
|
num_reverse_channels(),
|
|
|
|
|
&aecm_render_queue_buffer_);
|
|
|
|
|
RTC_DCHECK(aecm_render_signal_queue_);
|
|
|
|
|
// Insert the samples into the queue.
|
|
|
|
|
if (!aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_)) {
|
|
|
|
|
// The data queue is full and needs to be emptied.
|
|
|
|
|
EmptyQueuedRenderAudio();
|
2016-10-25 04:45:24 -07:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
// Retry the insert (should always work).
|
|
|
|
|
bool result =
|
|
|
|
|
aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_);
|
|
|
|
|
RTC_DCHECK(result);
|
|
|
|
|
}
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
2016-10-25 05:42:20 -07:00
|
|
|
|
|
|
|
|
if (!constants_.use_experimental_agc) {
|
|
|
|
|
GainControlImpl::PackRenderAudioBuffer(audio, &agc_render_queue_buffer_);
|
|
|
|
|
// Insert the samples into the queue.
|
|
|
|
|
if (!agc_render_signal_queue_->Insert(&agc_render_queue_buffer_)) {
|
|
|
|
|
// The data queue is full and needs to be emptied.
|
|
|
|
|
EmptyQueuedRenderAudio();
|
|
|
|
|
|
|
|
|
|
// Retry the insert (should always work).
|
|
|
|
|
bool result = agc_render_signal_queue_->Insert(&agc_render_queue_buffer_);
|
|
|
|
|
RTC_DCHECK(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-15 07:19:21 -07:00
|
|
|
}
|
2016-10-28 05:39:16 -07:00
|
|
|
|
2017-05-15 07:19:21 -07:00
|
|
|
void AudioProcessingImpl::QueueNonbandedRenderAudio(AudioBuffer* audio) {
|
2016-10-28 05:39:16 -07:00
|
|
|
ResidualEchoDetector::PackRenderAudioBuffer(audio, &red_render_queue_buffer_);
|
|
|
|
|
|
|
|
|
|
// Insert the samples into the queue.
|
|
|
|
|
if (!red_render_signal_queue_->Insert(&red_render_queue_buffer_)) {
|
|
|
|
|
// The data queue is full and needs to be emptied.
|
|
|
|
|
EmptyQueuedRenderAudio();
|
|
|
|
|
|
|
|
|
|
// Retry the insert (should always work).
|
|
|
|
|
bool result = red_render_signal_queue_->Insert(&red_render_queue_buffer_);
|
|
|
|
|
RTC_DCHECK(result);
|
|
|
|
|
}
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::AllocateRenderQueue() {
|
2016-10-25 05:42:20 -07:00
|
|
|
const size_t new_agc_render_queue_element_max_size =
|
2017-05-15 07:19:21 -07:00
|
|
|
std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerBand);
|
2016-10-25 05:42:20 -07:00
|
|
|
|
2016-10-28 05:39:16 -07:00
|
|
|
const size_t new_red_render_queue_element_max_size =
|
|
|
|
|
std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerFrame);
|
|
|
|
|
|
2016-10-25 04:45:24 -07:00
|
|
|
// Reallocate the queues if the queue item sizes are too small to fit the
|
|
|
|
|
// data to put in the queues.
|
|
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
if (agc_render_queue_element_max_size_ <
|
|
|
|
|
new_agc_render_queue_element_max_size) {
|
|
|
|
|
agc_render_queue_element_max_size_ = new_agc_render_queue_element_max_size;
|
2016-10-25 04:45:24 -07:00
|
|
|
|
|
|
|
|
std::vector<int16_t> template_queue_element(
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_queue_element_max_size_);
|
2016-10-25 04:45:24 -07:00
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_signal_queue_.reset(
|
2016-10-25 04:45:24 -07:00
|
|
|
new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
|
|
|
|
|
kMaxNumFramesToBuffer, template_queue_element,
|
|
|
|
|
RenderQueueItemVerifier<int16_t>(
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_queue_element_max_size_)));
|
2016-10-25 04:45:24 -07:00
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_queue_buffer_.resize(agc_render_queue_element_max_size_);
|
|
|
|
|
agc_capture_queue_buffer_.resize(agc_render_queue_element_max_size_);
|
2016-10-25 04:45:24 -07:00
|
|
|
} else {
|
2016-10-25 05:42:20 -07:00
|
|
|
agc_render_signal_queue_->Clear();
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
2016-10-28 05:39:16 -07:00
|
|
|
|
|
|
|
|
if (red_render_queue_element_max_size_ <
|
|
|
|
|
new_red_render_queue_element_max_size) {
|
|
|
|
|
red_render_queue_element_max_size_ = new_red_render_queue_element_max_size;
|
|
|
|
|
|
|
|
|
|
std::vector<float> template_queue_element(
|
|
|
|
|
red_render_queue_element_max_size_);
|
|
|
|
|
|
|
|
|
|
red_render_signal_queue_.reset(
|
|
|
|
|
new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
|
|
|
|
|
kMaxNumFramesToBuffer, template_queue_element,
|
|
|
|
|
RenderQueueItemVerifier<float>(
|
|
|
|
|
red_render_queue_element_max_size_)));
|
|
|
|
|
|
|
|
|
|
red_render_queue_buffer_.resize(red_render_queue_element_max_size_);
|
|
|
|
|
red_capture_queue_buffer_.resize(red_render_queue_element_max_size_);
|
|
|
|
|
} else {
|
|
|
|
|
red_render_signal_queue_->Clear();
|
|
|
|
|
}
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::EmptyQueuedRenderAudio() {
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2019-04-25 15:18:06 +02:00
|
|
|
if (private_submodules_->echo_cancellation) {
|
|
|
|
|
RTC_DCHECK(aec_render_signal_queue_);
|
|
|
|
|
while (aec_render_signal_queue_->Remove(&aec_capture_queue_buffer_)) {
|
|
|
|
|
private_submodules_->echo_cancellation->ProcessRenderAudio(
|
|
|
|
|
aec_capture_queue_buffer_);
|
|
|
|
|
}
|
2016-10-25 04:45:24 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
if (private_submodules_->echo_control_mobile) {
|
|
|
|
|
RTC_DCHECK(aecm_render_signal_queue_);
|
|
|
|
|
while (aecm_render_signal_queue_->Remove(&aecm_capture_queue_buffer_)) {
|
|
|
|
|
private_submodules_->echo_control_mobile->ProcessRenderAudio(
|
|
|
|
|
aecm_capture_queue_buffer_);
|
|
|
|
|
}
|
2016-10-25 05:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (agc_render_signal_queue_->Remove(&agc_capture_queue_buffer_)) {
|
|
|
|
|
public_submodules_->gain_control->ProcessRenderAudio(
|
|
|
|
|
agc_capture_queue_buffer_);
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
2016-10-28 05:39:16 -07:00
|
|
|
|
|
|
|
|
while (red_render_signal_queue_->Remove(&red_capture_queue_buffer_)) {
|
2018-01-11 16:08:54 +01:00
|
|
|
RTC_DCHECK(private_submodules_->echo_detector);
|
|
|
|
|
private_submodules_->echo_detector->AnalyzeRenderAudio(
|
2016-10-28 05:39:16 -07:00
|
|
|
red_capture_queue_buffer_);
|
|
|
|
|
}
|
2016-10-22 05:04:30 -07:00
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Acquire the capture lock in order to safely call the function
|
2018-08-09 14:23:11 +02:00
|
|
|
// that retrieves the render side data. This function accesses APM
|
2015-11-28 12:35:15 -08:00
|
|
|
// getters that need the capture lock held when being called.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2016-10-22 05:04:30 -07:00
|
|
|
EmptyQueuedRenderAudio();
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2015-11-16 16:27:42 -08:00
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
if (!frame) {
|
2014-01-07 17:45:09 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
// Must be a native rate.
|
|
|
|
|
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
2014-11-17 23:01:23 +00:00
|
|
|
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
2014-04-22 21:00:04 +00:00
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
2015-11-17 02:16:45 -08:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool reinitialization_required = false;
|
2015-11-28 12:35:15 -08:00
|
|
|
{
|
|
|
|
|
// Aquire lock for the access of api_format.
|
|
|
|
|
// The lock is released immediately due to the conditional
|
|
|
|
|
// reinitialization.
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
// TODO(ajm): The input and output rates and channels are currently
|
|
|
|
|
// constrained to be identical in the int16 interface.
|
|
|
|
|
processing_config = formats_.api_format;
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
|
|
|
|
|
reinitialization_required = UpdateActiveSubmoduleStates();
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2019-05-23 14:28:00 +02:00
|
|
|
reinitialization_required =
|
|
|
|
|
reinitialization_required ||
|
|
|
|
|
processing_config.input_stream().sample_rate_hz() !=
|
|
|
|
|
frame->sample_rate_hz_ ||
|
|
|
|
|
processing_config.input_stream().num_channels() != frame->num_channels_ ||
|
|
|
|
|
processing_config.output_stream().sample_rate_hz() !=
|
|
|
|
|
frame->sample_rate_hz_ ||
|
|
|
|
|
processing_config.output_stream().num_channels() != frame->num_channels_;
|
|
|
|
|
|
|
|
|
|
if (reinitialization_required) {
|
|
|
|
|
processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
|
|
|
|
processing_config.input_stream().set_num_channels(frame->num_channels_);
|
|
|
|
|
processing_config.output_stream().set_sample_rate_hz(
|
|
|
|
|
frame->sample_rate_hz_);
|
|
|
|
|
processing_config.output_stream().set_num_channels(frame->num_channels_);
|
|
|
|
|
|
|
|
|
|
// Reinitialize.
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
2019-05-23 14:28:00 +02:00
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
RETURN_ON_ERR(InitializeLocked(processing_config));
|
2015-11-28 12:35:15 -08:00
|
|
|
}
|
2019-05-23 14:28:00 +02:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
2015-11-17 02:16:45 -08:00
|
|
|
if (frame->samples_per_channel_ !=
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.input_stream().num_frames()) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
|
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
RecordUnprocessedCaptureStream(*frame);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 12:15:46 +02:00
|
|
|
capture_.vad_activity = frame->vad_activity_;
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_.capture_audio->CopyFrom(frame);
|
2016-09-16 15:02:15 -07:00
|
|
|
RETURN_ON_ERR(ProcessCaptureStreamLocked());
|
2019-08-15 12:15:46 +02:00
|
|
|
if (submodule_states_.CaptureMultiBandProcessingActive() ||
|
|
|
|
|
submodule_states_.CaptureFullBandProcessingActive()) {
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_.capture_audio->CopyTo(frame);
|
2019-08-15 12:15:46 +02:00
|
|
|
}
|
|
|
|
|
frame->vad_activity_ = capture_.vad_activity;
|
2014-03-04 20:58:13 +00:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
RecordProcessedCaptureStream(*frame);
|
|
|
|
|
}
|
2014-03-04 20:58:13 +00:00
|
|
|
|
|
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
2018-05-15 10:52:28 +02:00
|
|
|
HandleCaptureRuntimeSettings();
|
2018-04-16 12:10:09 +02:00
|
|
|
|
2016-03-15 09:34:24 -07:00
|
|
|
// Ensure that not both the AEC and AECM are active at the same time.
|
2018-07-23 14:48:07 +00:00
|
|
|
// TODO(peah): Simplify once the public API Enable functions for these
|
|
|
|
|
// are moved to APM.
|
2019-04-29 12:14:50 +02:00
|
|
|
RTC_DCHECK_LE(!!private_submodules_->echo_controller +
|
|
|
|
|
!!private_submodules_->echo_cancellation +
|
|
|
|
|
!!private_submodules_->echo_control_mobile,
|
|
|
|
|
1);
|
2016-03-15 09:34:24 -07:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
AudioBuffer* capture_buffer = capture_.capture_audio.get(); // For brevity.
|
2015-08-14 10:35:55 -07:00
|
|
|
|
2018-04-16 16:31:22 +02:00
|
|
|
if (private_submodules_->pre_amplifier) {
|
|
|
|
|
private_submodules_->pre_amplifier->ApplyGain(AudioFrameView<float>(
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->channels(), capture_buffer->num_channels(),
|
2018-04-16 16:31:22 +02:00
|
|
|
capture_buffer->num_frames()));
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 09:19:21 +02:00
|
|
|
capture_input_rms_.Analyze(rtc::ArrayView<const float>(
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->channels_const()[0],
|
2016-11-29 08:09:09 -08:00
|
|
|
capture_nonlocked_.capture_processing_format.num_frames()));
|
2016-12-20 13:45:58 -08:00
|
|
|
const bool log_rms = ++capture_rms_interval_counter_ >= 1000;
|
|
|
|
|
if (log_rms) {
|
|
|
|
|
capture_rms_interval_counter_ = 0;
|
|
|
|
|
RmsLevel::Levels levels = capture_input_rms_.AverageAndPeak();
|
2016-12-06 04:28:04 -08:00
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelAverageRms",
|
|
|
|
|
levels.average, 1, RmsLevel::kMinLevelDb, 64);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureInputLevelPeakRms",
|
|
|
|
|
levels.peak, 1, RmsLevel::kMinLevelDb, 64);
|
2016-11-29 08:09:09 -08:00
|
|
|
}
|
|
|
|
|
|
2018-07-23 14:48:07 +00:00
|
|
|
if (private_submodules_->echo_controller) {
|
2018-07-16 17:08:41 +02:00
|
|
|
// Detect and flag any change in the analog gain.
|
2019-03-27 13:28:08 +01:00
|
|
|
int analog_mic_level = agc1()->stream_analog_level();
|
2018-07-16 17:08:41 +02:00
|
|
|
capture_.echo_path_gain_change =
|
|
|
|
|
capture_.prev_analog_mic_level != analog_mic_level &&
|
|
|
|
|
capture_.prev_analog_mic_level != -1;
|
|
|
|
|
capture_.prev_analog_mic_level = analog_mic_level;
|
|
|
|
|
|
2018-10-02 17:00:59 +02:00
|
|
|
// Detect and flag any change in the pre-amplifier gain.
|
|
|
|
|
if (private_submodules_->pre_amplifier) {
|
|
|
|
|
float pre_amp_gain = private_submodules_->pre_amplifier->GetGainFactor();
|
|
|
|
|
capture_.echo_path_gain_change =
|
|
|
|
|
capture_.echo_path_gain_change ||
|
|
|
|
|
(capture_.prev_pre_amp_gain != pre_amp_gain &&
|
2018-10-02 23:10:38 +02:00
|
|
|
capture_.prev_pre_amp_gain >= 0.f);
|
2018-10-02 17:00:59 +02:00
|
|
|
capture_.prev_pre_amp_gain = pre_amp_gain;
|
|
|
|
|
}
|
2019-05-10 15:50:02 +02:00
|
|
|
|
|
|
|
|
// Detect volume change.
|
|
|
|
|
capture_.echo_path_gain_change =
|
|
|
|
|
capture_.echo_path_gain_change ||
|
|
|
|
|
(capture_.prev_playout_volume != capture_.playout_volume &&
|
|
|
|
|
capture_.prev_playout_volume >= 0);
|
|
|
|
|
capture_.prev_playout_volume = capture_.playout_volume;
|
|
|
|
|
|
2017-10-09 10:20:34 +02:00
|
|
|
private_submodules_->echo_controller->AnalyzeCapture(capture_buffer);
|
2016-12-14 01:16:23 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc &&
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->gain_control->is_enabled()) {
|
|
|
|
|
private_submodules_->agc_manager->AnalyzePreProcess(
|
2019-08-20 09:19:21 +02:00
|
|
|
capture_buffer->channels_f()[0], capture_buffer->num_channels(),
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format.num_frames());
|
2018-09-10 13:59:41 +02:00
|
|
|
|
|
|
|
|
if (constants_.use_experimental_agc_process_before_aec) {
|
|
|
|
|
private_submodules_->agc_manager->Process(
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->channels_const()[0],
|
2018-09-10 13:59:41 +02:00
|
|
|
capture_nonlocked_.capture_processing_format.num_frames(),
|
|
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz());
|
|
|
|
|
}
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (submodule_states_.CaptureMultiBandSubModulesActive() &&
|
|
|
|
|
SampleRateSupportsMultiBand(
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz())) {
|
|
|
|
|
capture_buffer->SplitIntoFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-23 14:48:07 +00:00
|
|
|
if (private_submodules_->echo_controller) {
|
2017-02-23 05:16:26 -08:00
|
|
|
// Force down-mixing of the number of channels after the detection of
|
|
|
|
|
// capture signal saturation.
|
|
|
|
|
// TODO(peah): Look into ensuring that this kind of tampering with the
|
|
|
|
|
// AudioBuffer functionality should not be needed.
|
|
|
|
|
capture_buffer->set_num_channels(1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 01:16:23 -08:00
|
|
|
// TODO(peah): Move the AEC3 low-cut filter to this place.
|
|
|
|
|
if (private_submodules_->low_cut_filter &&
|
2018-07-23 14:48:07 +00:00
|
|
|
!private_submodules_->echo_controller) {
|
2016-11-22 07:24:52 -08:00
|
|
|
private_submodules_->low_cut_filter->Process(capture_buffer);
|
|
|
|
|
}
|
2016-09-16 15:02:15 -07:00
|
|
|
RETURN_ON_ERR(
|
|
|
|
|
public_submodules_->gain_control->AnalyzeCaptureAudio(capture_buffer));
|
|
|
|
|
public_submodules_->noise_suppression->AnalyzeCaptureAudio(capture_buffer);
|
2016-03-15 09:34:24 -07:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
if (private_submodules_->echo_control_mobile) {
|
|
|
|
|
// Ensure that the stream delay was set before the call to the
|
|
|
|
|
// AECM ProcessCaptureAudio function.
|
|
|
|
|
if (!was_stream_delay_set()) {
|
|
|
|
|
return AudioProcessing::kStreamParameterNotSetError;
|
|
|
|
|
}
|
2018-02-12 21:42:56 +01:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
if (public_submodules_->noise_suppression->is_enabled()) {
|
2019-08-15 12:15:46 +02:00
|
|
|
private_submodules_->echo_control_mobile->CopyLowPassReference(
|
|
|
|
|
capture_buffer);
|
2018-04-18 09:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer);
|
|
|
|
|
|
|
|
|
|
RETURN_ON_ERR(private_submodules_->echo_control_mobile->ProcessCaptureAudio(
|
2017-02-06 03:39:42 -08:00
|
|
|
capture_buffer, stream_delay_ms()));
|
2019-04-29 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
|
if (private_submodules_->echo_controller) {
|
|
|
|
|
data_dumper_->DumpRaw("stream_delay", stream_delay_ms());
|
2016-12-14 01:16:23 -08:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
if (was_stream_delay_set()) {
|
|
|
|
|
private_submodules_->echo_controller->SetAudioBufferDelay(
|
|
|
|
|
stream_delay_ms());
|
|
|
|
|
}
|
2016-03-15 04:32:28 -07:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
private_submodules_->echo_controller->ProcessCapture(
|
|
|
|
|
capture_buffer, capture_.echo_path_gain_change);
|
|
|
|
|
} else if (private_submodules_->echo_cancellation) {
|
|
|
|
|
// Ensure that the stream delay was set before the call to the
|
|
|
|
|
// AEC ProcessCaptureAudio function.
|
|
|
|
|
if (!was_stream_delay_set()) {
|
|
|
|
|
return AudioProcessing::kStreamParameterNotSetError;
|
|
|
|
|
}
|
2016-03-15 04:32:28 -07:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
RETURN_ON_ERR(private_submodules_->echo_cancellation->ProcessCaptureAudio(
|
|
|
|
|
capture_buffer, stream_delay_ms()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public_submodules_->noise_suppression->ProcessCaptureAudio(capture_buffer);
|
2017-06-07 10:08:10 +02:00
|
|
|
}
|
2016-10-28 05:39:16 -07:00
|
|
|
|
2019-08-15 12:15:46 +02:00
|
|
|
if (public_submodules_->voice_detection->is_enabled() &&
|
|
|
|
|
!public_submodules_->voice_detection->using_external_vad()) {
|
|
|
|
|
bool voice_active =
|
|
|
|
|
public_submodules_->voice_detection->ProcessCaptureAudio(
|
|
|
|
|
capture_buffer);
|
|
|
|
|
capture_.vad_activity =
|
|
|
|
|
voice_active ? AudioFrame::kVadActive : AudioFrame::kVadPassive;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-21 16:29:27 +01:00
|
|
|
if (config_.voice_detection.enabled) {
|
|
|
|
|
private_submodules_->voice_detector->ProcessCaptureAudio(capture_buffer);
|
|
|
|
|
capture_.stats.voice_detected =
|
|
|
|
|
private_submodules_->voice_detector->stream_has_voice();
|
|
|
|
|
} else {
|
|
|
|
|
capture_.stats.voice_detected = absl::nullopt;
|
|
|
|
|
}
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2016-02-13 16:40:47 -08:00
|
|
|
if (constants_.use_experimental_agc &&
|
2018-09-10 13:59:41 +02:00
|
|
|
public_submodules_->gain_control->is_enabled() &&
|
|
|
|
|
!constants_.use_experimental_agc_process_before_aec) {
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager->Process(
|
2019-08-20 09:19:21 +02:00
|
|
|
capture_buffer->split_bands_const_f(0)[kBand0To8kHz],
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2019-03-06 04:16:46 +01:00
|
|
|
// TODO(peah): Add reporting from AEC3 whether there is echo.
|
2016-03-15 02:28:08 -07:00
|
|
|
RETURN_ON_ERR(public_submodules_->gain_control->ProcessCaptureAudio(
|
2018-09-17 11:05:17 +02:00
|
|
|
capture_buffer,
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation &&
|
|
|
|
|
private_submodules_->echo_cancellation->stream_has_echo()));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (submodule_states_.CaptureMultiBandProcessingActive() &&
|
|
|
|
|
SampleRateSupportsMultiBand(
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz())) {
|
|
|
|
|
capture_buffer->MergeFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-15 07:19:21 -07:00
|
|
|
if (config_.residual_echo_detector.enabled) {
|
2018-01-11 16:08:54 +01:00
|
|
|
RTC_DCHECK(private_submodules_->echo_detector);
|
|
|
|
|
private_submodules_->echo_detector->AnalyzeCaptureAudio(
|
2019-08-21 15:02:37 +02:00
|
|
|
rtc::ArrayView<const float>(capture_buffer->channels()[0],
|
2017-05-15 07:19:21 -07:00
|
|
|
capture_buffer->num_frames()));
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-15 09:41:24 +00:00
|
|
|
// TODO(aluebs): Investigate if the transient suppression placement should be
|
|
|
|
|
// before or after the AGC.
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled) {
|
2014-12-15 09:41:24 +00:00
|
|
|
float voice_probability =
|
2015-11-28 12:35:15 -08:00
|
|
|
private_submodules_->agc_manager.get()
|
|
|
|
|
? private_submodules_->agc_manager->voice_probability()
|
|
|
|
|
: 1.f;
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->transient_suppressor->Suppress(
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->channels()[0], capture_buffer->num_frames(),
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_buffer->num_channels(),
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->split_bands_const(0)[kBand0To8kHz],
|
2019-08-15 12:15:46 +02:00
|
|
|
capture_buffer->num_frames_per_band(),
|
|
|
|
|
capture_.keyboard_info.keyboard_data,
|
|
|
|
|
capture_.keyboard_info.num_keyboard_frames, voice_probability,
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.key_pressed);
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:37:09 +02:00
|
|
|
// Experimental APM sub-module that analyzes |capture_buffer|.
|
|
|
|
|
if (private_submodules_->capture_analyzer) {
|
|
|
|
|
private_submodules_->capture_analyzer->Analyze(capture_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 11:05:17 +02:00
|
|
|
if (config_.gain_controller2.enabled) {
|
2018-08-06 16:32:12 +02:00
|
|
|
private_submodules_->gain_controller2->NotifyAnalogLevel(
|
2019-03-27 13:28:08 +01:00
|
|
|
agc1()->stream_analog_level());
|
2017-05-22 06:57:06 -07:00
|
|
|
private_submodules_->gain_controller2->Process(capture_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 12:04:02 +02:00
|
|
|
if (private_submodules_->capture_post_processor) {
|
|
|
|
|
private_submodules_->capture_post_processor->Process(capture_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
// The level estimator operates on the recombined data.
|
2019-08-21 15:02:37 +02:00
|
|
|
public_submodules_->level_estimator->ProcessStream(*capture_buffer);
|
2018-11-26 16:18:25 +01:00
|
|
|
if (config_.level_estimation.enabled) {
|
2019-08-21 15:02:37 +02:00
|
|
|
private_submodules_->output_level_estimator->ProcessStream(*capture_buffer);
|
2018-11-26 16:18:25 +01:00
|
|
|
capture_.stats.output_rms_dbfs =
|
|
|
|
|
private_submodules_->output_level_estimator->RMS();
|
|
|
|
|
} else {
|
|
|
|
|
capture_.stats.output_rms_dbfs = absl::nullopt;
|
|
|
|
|
}
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2019-08-20 09:19:21 +02:00
|
|
|
capture_output_rms_.Analyze(rtc::ArrayView<const float>(
|
2019-08-21 15:02:37 +02:00
|
|
|
capture_buffer->channels_const()[0],
|
2016-12-20 13:45:58 -08:00
|
|
|
capture_nonlocked_.capture_processing_format.num_frames()));
|
|
|
|
|
if (log_rms) {
|
|
|
|
|
RmsLevel::Levels levels = capture_output_rms_.AverageAndPeak();
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelAverageRms",
|
|
|
|
|
levels.average, 1, RmsLevel::kMinLevelDb, 64);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.ApmCaptureOutputLevelPeakRms",
|
|
|
|
|
levels.peak, 1, RmsLevel::kMinLevelDb, 64);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.was_stream_delay_set = false;
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t samples_per_channel,
|
2016-09-16 15:02:15 -07:00
|
|
|
int sample_rate_hz,
|
2014-03-04 20:58:13 +00:00
|
|
|
ChannelLayout layout) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
2015-07-23 11:41:39 -07:00
|
|
|
const StreamConfig reverse_config = {
|
2016-09-16 15:02:15 -07:00
|
|
|
sample_rate_hz,
|
|
|
|
|
ChannelsFromLayout(layout),
|
|
|
|
|
LayoutHasKeyboard(layout),
|
2015-07-23 11:41:39 -07:00
|
|
|
};
|
|
|
|
|
if (samples_per_channel != reverse_config.num_frames()) {
|
|
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
int AudioProcessingImpl::ProcessReverseStream(const float* const* src,
|
|
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config,
|
|
|
|
|
float* const* dest) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
2016-09-16 15:02:15 -07:00
|
|
|
RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, input_config, output_config));
|
2017-12-18 16:02:40 +01:00
|
|
|
if (submodule_states_.RenderMultiBandProcessingActive() ||
|
|
|
|
|
submodule_states_.RenderFullBandProcessingActive()) {
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(),
|
|
|
|
|
dest);
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
} else if (formats_.api_format.reverse_input_stream() !=
|
|
|
|
|
formats_.api_format.reverse_output_stream()) {
|
2016-09-16 15:02:15 -07:00
|
|
|
render_.render_converter->Convert(src, input_config.num_samples(), dest,
|
|
|
|
|
output_config.num_samples());
|
2015-08-14 10:35:55 -07:00
|
|
|
} else {
|
2016-09-16 15:02:15 -07:00
|
|
|
CopyAudioIfNeeded(src, input_config.num_frames(),
|
|
|
|
|
input_config.num_channels(), dest);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return kNoError;
|
2015-07-23 11:41:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
int AudioProcessingImpl::AnalyzeReverseStreamLocked(
|
2015-08-14 10:35:55 -07:00
|
|
|
const float* const* src,
|
2016-09-16 15:02:15 -07:00
|
|
|
const StreamConfig& input_config,
|
|
|
|
|
const StreamConfig& output_config) {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (src == nullptr) {
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2011-11-15 16:57:56 +00:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
if (input_config.num_channels() == 0) {
|
2015-07-23 11:41:39 -07:00
|
|
|
return kBadNumberChannelsError;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config = formats_.api_format;
|
2016-09-16 15:02:15 -07:00
|
|
|
processing_config.reverse_input_stream() = input_config;
|
|
|
|
|
processing_config.reverse_output_stream() = output_config;
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(MaybeInitializeRender(processing_config));
|
2018-04-12 22:44:09 +02:00
|
|
|
RTC_DCHECK_EQ(input_config.num_frames(),
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_frames());
|
2015-07-23 11:41:39 -07:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
const size_t channel_size =
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_frames();
|
|
|
|
|
const size_t num_channels =
|
|
|
|
|
formats_.api_format.reverse_input_stream().num_channels();
|
|
|
|
|
aec_dump_->WriteRenderStreamMessage(
|
2018-02-16 11:54:07 +01:00
|
|
|
AudioFrameView<const float>(src, num_channels, channel_size));
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
render_.render_audio->CopyFrom(src,
|
|
|
|
|
formats_.api_format.reverse_input_stream());
|
2016-09-16 15:02:15 -07:00
|
|
|
return ProcessRenderStreamLocked();
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) {
|
2015-12-17 06:42:29 -08:00
|
|
|
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame");
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_render_);
|
|
|
|
|
if (frame == nullptr) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kNullPointerError;
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
// Must be a native rate.
|
|
|
|
|
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
2014-11-17 23:01:23 +00:00
|
|
|
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
|
|
|
|
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
2014-04-22 21:00:04 +00:00
|
|
|
return kBadSampleRateError;
|
|
|
|
|
}
|
2014-03-10 22:26:12 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
if (frame->num_channels_ <= 0) {
|
|
|
|
|
return kBadNumberChannelsError;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
ProcessingConfig processing_config = formats_.api_format;
|
2015-08-14 10:35:55 -07:00
|
|
|
processing_config.reverse_input_stream().set_sample_rate_hz(
|
|
|
|
|
frame->sample_rate_hz_);
|
|
|
|
|
processing_config.reverse_input_stream().set_num_channels(
|
|
|
|
|
frame->num_channels_);
|
|
|
|
|
processing_config.reverse_output_stream().set_sample_rate_hz(
|
|
|
|
|
frame->sample_rate_hz_);
|
|
|
|
|
processing_config.reverse_output_stream().set_num_channels(
|
|
|
|
|
frame->num_channels_);
|
2015-07-23 11:41:39 -07:00
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
RETURN_ON_ERR(MaybeInitializeRender(processing_config));
|
2015-07-23 11:41:39 -07:00
|
|
|
if (frame->samples_per_channel_ !=
|
2015-11-28 12:35:15 -08:00
|
|
|
formats_.api_format.reverse_input_stream().num_frames()) {
|
2014-03-04 20:58:13 +00:00
|
|
|
return kBadDataLengthError;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
if (aec_dump_) {
|
|
|
|
|
aec_dump_->WriteRenderStreamMessage(*frame);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 15:02:37 +02:00
|
|
|
render_.render_audio->CopyFrom(frame);
|
2016-09-16 15:02:15 -07:00
|
|
|
RETURN_ON_ERR(ProcessRenderStreamLocked());
|
2019-08-15 12:15:46 +02:00
|
|
|
if (submodule_states_.RenderMultiBandProcessingActive() ||
|
|
|
|
|
submodule_states_.RenderFullBandProcessingActive()) {
|
2019-08-21 15:02:37 +02:00
|
|
|
render_.render_audio->CopyTo(frame);
|
2019-08-15 12:15:46 +02:00
|
|
|
}
|
2016-03-17 20:39:53 -07:00
|
|
|
return kNoError;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-16 15:02:15 -07:00
|
|
|
int AudioProcessingImpl::ProcessRenderStreamLocked() {
|
|
|
|
|
AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity.
|
2017-05-15 07:19:21 -07:00
|
|
|
|
2018-05-15 10:52:28 +02:00
|
|
|
HandleRenderRuntimeSettings();
|
|
|
|
|
|
2017-12-18 16:02:40 +01:00
|
|
|
if (private_submodules_->render_pre_processor) {
|
|
|
|
|
private_submodules_->render_pre_processor->Process(render_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 14:23:11 +02:00
|
|
|
QueueNonbandedRenderAudio(render_buffer);
|
|
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (submodule_states_.RenderMultiBandSubModulesActive() &&
|
2016-09-16 15:02:15 -07:00
|
|
|
SampleRateSupportsMultiBand(
|
|
|
|
|
formats_.render_processing_format.sample_rate_hz())) {
|
|
|
|
|
render_buffer->SplitIntoFrequencyBands();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-19 01:28:05 -07:00
|
|
|
if (submodule_states_.RenderMultiBandSubModulesActive()) {
|
|
|
|
|
QueueBandedRenderAudio(render_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 14:23:11 +02:00
|
|
|
// TODO(peah): Perform the queuing inside QueueRenderAudiuo().
|
2018-07-23 14:48:07 +00:00
|
|
|
if (private_submodules_->echo_controller) {
|
2017-10-09 10:20:34 +02:00
|
|
|
private_submodules_->echo_controller->AnalyzeRender(render_buffer);
|
2016-12-14 01:16:23 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
if (submodule_states_.RenderMultiBandProcessingActive() &&
|
2016-09-16 15:02:15 -07:00
|
|
|
SampleRateSupportsMultiBand(
|
|
|
|
|
formats_.render_processing_format.sample_rate_hz())) {
|
|
|
|
|
render_buffer->MergeFrequencyBands();
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
return kNoError;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::set_stream_delay_ms(int delay) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
2012-05-29 21:14:06 +00:00
|
|
|
Error retval = kNoError;
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_.was_stream_delay_set = true;
|
|
|
|
|
delay += capture_.delay_offset_ms;
|
2012-03-06 19:03:39 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
if (delay < 0) {
|
2012-05-29 21:14:06 +00:00
|
|
|
delay = 0;
|
|
|
|
|
retval = kBadStreamParameterWarning;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(ajm): the max is rather arbitrarily chosen; investigate.
|
|
|
|
|
if (delay > 500) {
|
2012-05-29 21:14:06 +00:00
|
|
|
delay = 500;
|
|
|
|
|
retval = kBadStreamParameterWarning;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 12:35:15 -08:00
|
|
|
capture_nonlocked_.stream_delay_ms = delay;
|
2012-05-29 21:14:06 +00:00
|
|
|
return retval;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::stream_delay_ms() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_nonlocked_.stream_delay_ms;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioProcessingImpl::was_stream_delay_set() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
// Used as callback from submodules, hence locking is not allowed.
|
|
|
|
|
return capture_.was_stream_delay_set;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.key_pressed = key_pressed;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-06 19:03:39 +00:00
|
|
|
void AudioProcessingImpl::set_delay_offset_ms(int offset) {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
capture_.delay_offset_ms = offset;
|
2012-03-06 19:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::delay_offset_ms() const {
|
2015-11-28 12:35:15 -08:00
|
|
|
rtc::CritScope cs(&crit_capture_);
|
|
|
|
|
return capture_.delay_offset_ms;
|
2012-03-06 19:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
void AudioProcessingImpl::set_stream_analog_level(int level) {
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
int error = agc1()->set_stream_analog_level(level);
|
|
|
|
|
RTC_DCHECK_EQ(kNoError, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioProcessingImpl::recommended_stream_analog_level() const {
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
return agc1()->stream_analog_level();
|
|
|
|
|
}
|
|
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
void AudioProcessingImpl::AttachAecDump(std::unique_ptr<AecDump> aec_dump) {
|
|
|
|
|
RTC_DCHECK(aec_dump);
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
|
|
|
|
|
// The previously attached AecDump will be destroyed with the
|
|
|
|
|
// 'aec_dump' parameter, which is after locks are released.
|
|
|
|
|
aec_dump_.swap(aec_dump);
|
|
|
|
|
WriteAecDumpConfigMessage(true);
|
2018-08-10 15:38:52 +02:00
|
|
|
aec_dump_->WriteInitMessage(formats_.api_format, rtc::TimeUTCMillis());
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::DetachAecDump() {
|
|
|
|
|
// The d-tor of a task-queue based AecDump blocks until all pending
|
|
|
|
|
// tasks are done. This construction avoids blocking while holding
|
|
|
|
|
// the render and capture locks.
|
|
|
|
|
std::unique_ptr<AecDump> aec_dump = nullptr;
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
aec_dump = std::move(aec_dump_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-02 16:03:21 +01:00
|
|
|
void AudioProcessingImpl::AttachPlayoutAudioGenerator(
|
|
|
|
|
std::unique_ptr<AudioGenerator> audio_generator) {
|
|
|
|
|
// TODO(bugs.webrtc.org/8882) Stub.
|
|
|
|
|
// Reset internal audio generator with audio_generator.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::DetachPlayoutAudioGenerator() {
|
|
|
|
|
// TODO(bugs.webrtc.org/8882) Stub.
|
|
|
|
|
// Delete audio generator, if one is attached.
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 17:29:59 +01:00
|
|
|
AudioProcessingStats AudioProcessingImpl::GetStatistics(
|
2017-11-20 13:07:16 +01:00
|
|
|
bool has_remote_tracks) const {
|
2018-11-26 16:18:25 +01:00
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
if (!has_remote_tracks) {
|
|
|
|
|
return capture_.stats;
|
|
|
|
|
}
|
|
|
|
|
AudioProcessingStats stats = capture_.stats;
|
|
|
|
|
EchoCancellationImpl::Metrics metrics;
|
|
|
|
|
if (private_submodules_->echo_controller) {
|
|
|
|
|
auto ec_metrics = private_submodules_->echo_controller->GetMetrics();
|
|
|
|
|
stats.echo_return_loss = ec_metrics.echo_return_loss;
|
|
|
|
|
stats.echo_return_loss_enhancement =
|
|
|
|
|
ec_metrics.echo_return_loss_enhancement;
|
|
|
|
|
stats.delay_ms = ec_metrics.delay_ms;
|
|
|
|
|
}
|
|
|
|
|
if (config_.residual_echo_detector.enabled) {
|
|
|
|
|
RTC_DCHECK(private_submodules_->echo_detector);
|
|
|
|
|
auto ed_metrics = private_submodules_->echo_detector->GetMetrics();
|
|
|
|
|
stats.residual_echo_likelihood = ed_metrics.echo_likelihood;
|
|
|
|
|
stats.residual_echo_likelihood_recent_max =
|
|
|
|
|
ed_metrics.echo_likelihood_recent_max;
|
|
|
|
|
}
|
2017-11-20 13:07:16 +01:00
|
|
|
return stats;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
GainControl* AudioProcessingImpl::gain_control() const {
|
2019-03-27 13:28:08 +01:00
|
|
|
return public_submodules_->gain_control_config_proxy.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LevelEstimator* AudioProcessingImpl::level_estimator() const {
|
2015-12-15 11:39:38 -08:00
|
|
|
return public_submodules_->level_estimator.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NoiseSuppression* AudioProcessingImpl::noise_suppression() const {
|
2019-01-11 15:10:32 +01:00
|
|
|
return public_submodules_->noise_suppression_proxy.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoiceDetection* AudioProcessingImpl::voice_detection() const {
|
2015-12-16 03:31:12 -08:00
|
|
|
return public_submodules_->voice_detection.get();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 07:24:52 -08:00
|
|
|
void AudioProcessingImpl::MutateConfig(
|
|
|
|
|
rtc::FunctionView<void(AudioProcessing::Config*)> mutator) {
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
mutator(&config_);
|
|
|
|
|
ApplyConfig(config_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioProcessing::Config AudioProcessingImpl::GetConfig() const {
|
|
|
|
|
rtc::CritScope cs_render(&crit_render_);
|
|
|
|
|
rtc::CritScope cs_capture(&crit_capture_);
|
|
|
|
|
return config_;
|
|
|
|
|
}
|
|
|
|
|
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
bool AudioProcessingImpl::UpdateActiveSubmoduleStates() {
|
|
|
|
|
return submodule_states_.Update(
|
2016-11-22 07:24:52 -08:00
|
|
|
config_.high_pass_filter.enabled,
|
2019-05-03 15:48:47 +02:00
|
|
|
!!private_submodules_->echo_cancellation,
|
|
|
|
|
!!private_submodules_->echo_control_mobile,
|
2016-10-28 05:39:16 -07:00
|
|
|
config_.residual_echo_detector.enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
public_submodules_->noise_suppression->is_enabled(),
|
|
|
|
|
public_submodules_->gain_control->is_enabled(),
|
2018-04-16 16:31:22 +02:00
|
|
|
config_.gain_controller2.enabled, config_.pre_amplifier.enabled,
|
2017-10-16 13:49:04 +02:00
|
|
|
capture_nonlocked_.echo_controller_enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
public_submodules_->voice_detection->is_enabled(),
|
2018-12-21 16:29:27 +01:00
|
|
|
config_.voice_detection.enabled,
|
The audio processing module (APM) relies on two for
functionalities doing sample-rate conversions:
-The implicit resampling done in the AudioBuffer CopyTo,
CopyFrom, InterleaveTo and DeinterleaveFrom methods.
-The multi-band splitting scheme.
The selection of rates in these have been difficult and
complicated, partly due to that the APM API which allows
for activating the APM submodules without notifying
the APM.
This CL adds functionality that for each capture frame
polls all submodules for whether they are active or not
and compares this against a cached result.
Furthermore, new functionality is added that based on the
results of the comparison do a reinitialization of the APM.
This has several advantages
-The code deciding on whether to analysis and synthesis is
needed for the bandsplitting can be much simplified and
centralized.
-The selection of the processing rate can be done such as
to avoid the implicit resampling that was in some cases
unnecessarily done.
-The optimization for whether an output copy is needed
that was done to improve performance due to the implicit
resampling is no longer needed, which simplifies the
code and makes it less error-prone in the sense that
is no longer neccessary to keep track of whether any
module has changed the signal.
Finally, it should be noted that the polling of the state
for all the submodules was done previously as well, but in
a less obvious and distributed manner.
BUG=webrtc:6181, webrtc:6220, webrtc:5298, webrtc:6296, webrtc:6298, webrtc:6297
Review-Url: https://codereview.webrtc.org/2304123002
Cr-Commit-Position: refs/heads/master@{#14175}
2016-09-10 04:42:27 -07:00
|
|
|
public_submodules_->level_estimator->is_enabled(),
|
|
|
|
|
capture_.transient_suppressor_enabled);
|
2015-08-14 10:35:55 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:42:40 +02:00
|
|
|
void AudioProcessingImpl::InitializeTransient() {
|
2015-11-28 12:35:15 -08:00
|
|
|
if (capture_.transient_suppressor_enabled) {
|
|
|
|
|
if (!public_submodules_->transient_suppressor.get()) {
|
|
|
|
|
public_submodules_->transient_suppressor.reset(new TransientSuppressor());
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
2015-11-28 12:35:15 -08:00
|
|
|
public_submodules_->transient_suppressor->Initialize(
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_nonlocked_.capture_processing_format.sample_rate_hz(),
|
|
|
|
|
capture_nonlocked_.split_rate, num_proc_channels());
|
2014-12-15 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 07:24:52 -08:00
|
|
|
void AudioProcessingImpl::InitializeLowCutFilter() {
|
2018-09-28 14:15:09 +02:00
|
|
|
if (submodule_states_.LowCutFilteringRequired()) {
|
2016-11-22 07:24:52 -08:00
|
|
|
private_submodules_->low_cut_filter.reset(
|
|
|
|
|
new LowCutFilter(num_proc_channels(), proc_sample_rate_hz()));
|
|
|
|
|
} else {
|
|
|
|
|
private_submodules_->low_cut_filter.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-22 06:57:06 -07:00
|
|
|
|
2017-10-14 08:28:46 +02:00
|
|
|
void AudioProcessingImpl::InitializeEchoController() {
|
2019-04-29 12:14:50 +02:00
|
|
|
bool use_echo_controller =
|
|
|
|
|
echo_control_factory_ ||
|
2019-03-06 04:16:46 +01:00
|
|
|
(config_.echo_canceller.enabled && !config_.echo_canceller.mobile_mode &&
|
2019-04-29 12:14:50 +02:00
|
|
|
!config_.echo_canceller.use_legacy_aec);
|
|
|
|
|
|
|
|
|
|
if (use_echo_controller) {
|
|
|
|
|
// Create and activate the echo controller.
|
2019-03-06 04:16:46 +01:00
|
|
|
if (echo_control_factory_) {
|
|
|
|
|
private_submodules_->echo_controller =
|
|
|
|
|
echo_control_factory_->Create(proc_sample_rate_hz());
|
|
|
|
|
} else {
|
|
|
|
|
private_submodules_->echo_controller = absl::make_unique<EchoCanceller3>(
|
|
|
|
|
EchoCanceller3Config(), proc_sample_rate_hz(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
capture_nonlocked_.echo_controller_enabled = true;
|
|
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation.reset();
|
|
|
|
|
aec_render_signal_queue_.reset();
|
2019-04-29 12:14:50 +02:00
|
|
|
private_submodules_->echo_control_mobile.reset();
|
|
|
|
|
aecm_render_signal_queue_.reset();
|
2019-04-25 15:18:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private_submodules_->echo_controller.reset();
|
|
|
|
|
capture_nonlocked_.echo_controller_enabled = false;
|
|
|
|
|
|
|
|
|
|
if (!config_.echo_canceller.enabled) {
|
|
|
|
|
private_submodules_->echo_cancellation.reset();
|
|
|
|
|
aec_render_signal_queue_.reset();
|
2019-04-29 12:14:50 +02:00
|
|
|
private_submodules_->echo_control_mobile.reset();
|
|
|
|
|
aecm_render_signal_queue_.reset();
|
2019-04-25 15:18:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-03-06 04:16:46 +01:00
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
if (config_.echo_canceller.mobile_mode) {
|
|
|
|
|
// Create and activate AECM.
|
2019-04-29 12:14:50 +02:00
|
|
|
size_t max_element_size =
|
|
|
|
|
std::max(static_cast<size_t>(1),
|
|
|
|
|
kMaxAllowedValuesOfSamplesPerBand *
|
|
|
|
|
EchoControlMobileImpl::NumCancellersRequired(
|
|
|
|
|
num_output_channels(), num_reverse_channels()));
|
|
|
|
|
|
|
|
|
|
std::vector<int16_t> template_queue_element(max_element_size);
|
|
|
|
|
|
|
|
|
|
aecm_render_signal_queue_.reset(
|
|
|
|
|
new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
|
|
|
|
|
kMaxNumFramesToBuffer, template_queue_element,
|
|
|
|
|
RenderQueueItemVerifier<int16_t>(max_element_size)));
|
|
|
|
|
|
|
|
|
|
aecm_render_queue_buffer_.resize(max_element_size);
|
|
|
|
|
aecm_capture_queue_buffer_.resize(max_element_size);
|
|
|
|
|
|
|
|
|
|
private_submodules_->echo_control_mobile.reset(new EchoControlMobileImpl());
|
|
|
|
|
|
|
|
|
|
private_submodules_->echo_control_mobile->Initialize(
|
|
|
|
|
proc_split_sample_rate_hz(), num_reverse_channels(),
|
|
|
|
|
num_output_channels());
|
|
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation.reset();
|
|
|
|
|
aec_render_signal_queue_.reset();
|
|
|
|
|
return;
|
2016-12-14 01:16:23 -08:00
|
|
|
}
|
2019-04-25 15:18:06 +02:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
private_submodules_->echo_control_mobile.reset();
|
|
|
|
|
aecm_render_signal_queue_.reset();
|
|
|
|
|
|
2019-04-25 15:18:06 +02:00
|
|
|
// Create and activate AEC2.
|
|
|
|
|
private_submodules_->echo_cancellation.reset(new EchoCancellationImpl());
|
|
|
|
|
private_submodules_->echo_cancellation->SetExtraOptions(
|
|
|
|
|
capture_nonlocked_.use_aec2_extended_filter,
|
|
|
|
|
capture_nonlocked_.use_aec2_delay_agnostic,
|
|
|
|
|
capture_nonlocked_.use_aec2_refined_adaptive_filter);
|
|
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
size_t element_max_size =
|
2019-04-25 15:18:06 +02:00
|
|
|
std::max(static_cast<size_t>(1),
|
|
|
|
|
kMaxAllowedValuesOfSamplesPerBand *
|
|
|
|
|
EchoCancellationImpl::NumCancellersRequired(
|
|
|
|
|
num_output_channels(), num_reverse_channels()));
|
|
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
std::vector<float> template_queue_element(element_max_size);
|
2019-04-25 15:18:06 +02:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
aec_render_signal_queue_.reset(
|
|
|
|
|
new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
|
|
|
|
|
kMaxNumFramesToBuffer, template_queue_element,
|
|
|
|
|
RenderQueueItemVerifier<float>(element_max_size)));
|
2019-04-25 15:18:06 +02:00
|
|
|
|
2019-04-29 12:14:50 +02:00
|
|
|
aec_render_queue_buffer_.resize(element_max_size);
|
|
|
|
|
aec_capture_queue_buffer_.resize(element_max_size);
|
2019-04-25 15:18:06 +02:00
|
|
|
|
|
|
|
|
private_submodules_->echo_cancellation->Initialize(
|
|
|
|
|
proc_sample_rate_hz(), num_reverse_channels(), num_output_channels(),
|
|
|
|
|
num_proc_channels());
|
|
|
|
|
|
|
|
|
|
private_submodules_->echo_cancellation->set_suppression_level(
|
|
|
|
|
config_.echo_canceller.legacy_moderate_suppression_level
|
|
|
|
|
? EchoCancellationImpl::SuppressionLevel::kModerateSuppression
|
|
|
|
|
: EchoCancellationImpl::SuppressionLevel::kHighSuppression);
|
2016-12-14 01:16:23 -08:00
|
|
|
}
|
2016-11-22 07:24:52 -08:00
|
|
|
|
2017-05-22 06:57:06 -07:00
|
|
|
void AudioProcessingImpl::InitializeGainController2() {
|
2017-10-13 11:05:17 +02:00
|
|
|
if (config_.gain_controller2.enabled) {
|
|
|
|
|
private_submodules_->gain_controller2->Initialize(proc_sample_rate_hz());
|
2017-05-22 06:57:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-16 16:31:22 +02:00
|
|
|
void AudioProcessingImpl::InitializePreAmplifier() {
|
|
|
|
|
if (config_.pre_amplifier.enabled) {
|
|
|
|
|
private_submodules_->pre_amplifier.reset(
|
|
|
|
|
new GainApplier(true, config_.pre_amplifier.fixed_gain_factor));
|
|
|
|
|
} else {
|
|
|
|
|
private_submodules_->pre_amplifier.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 05:39:16 -07:00
|
|
|
void AudioProcessingImpl::InitializeResidualEchoDetector() {
|
2018-01-11 16:08:54 +01:00
|
|
|
RTC_DCHECK(private_submodules_->echo_detector);
|
2018-03-14 17:13:48 +01:00
|
|
|
private_submodules_->echo_detector->Initialize(
|
2018-04-12 16:15:58 +02:00
|
|
|
proc_sample_rate_hz(), 1,
|
|
|
|
|
formats_.render_processing_format.sample_rate_hz(), 1);
|
2016-10-28 05:39:16 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:37:09 +02:00
|
|
|
void AudioProcessingImpl::InitializeAnalyzer() {
|
|
|
|
|
if (private_submodules_->capture_analyzer) {
|
|
|
|
|
private_submodules_->capture_analyzer->Initialize(proc_sample_rate_hz(),
|
|
|
|
|
num_proc_channels());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 12:04:02 +02:00
|
|
|
void AudioProcessingImpl::InitializePostProcessor() {
|
|
|
|
|
if (private_submodules_->capture_post_processor) {
|
|
|
|
|
private_submodules_->capture_post_processor->Initialize(
|
|
|
|
|
proc_sample_rate_hz(), num_proc_channels());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-18 16:02:40 +01:00
|
|
|
void AudioProcessingImpl::InitializePreProcessor() {
|
|
|
|
|
if (private_submodules_->render_pre_processor) {
|
|
|
|
|
private_submodules_->render_pre_processor->Initialize(
|
|
|
|
|
formats_.render_processing_format.sample_rate_hz(),
|
|
|
|
|
formats_.render_processing_format.num_channels());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 09:00:08 +02:00
|
|
|
void AudioProcessingImpl::UpdateHistogramsOnCallEnd() {}
|
2015-07-07 11:50:05 +02:00
|
|
|
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
void AudioProcessingImpl::WriteAecDumpConfigMessage(bool forced) {
|
|
|
|
|
if (!aec_dump_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-25 15:18:06 +02:00
|
|
|
|
|
|
|
|
std::string experiments_description = "";
|
|
|
|
|
if (private_submodules_->echo_cancellation) {
|
|
|
|
|
experiments_description +=
|
|
|
|
|
private_submodules_->echo_cancellation->GetExperimentsDescription();
|
|
|
|
|
}
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
// TODO(peah): Add semicolon-separated concatenations of experiment
|
|
|
|
|
// descriptions for other submodules.
|
|
|
|
|
if (constants_.agc_clipped_level_min != kClippedLevelMin) {
|
|
|
|
|
experiments_description += "AgcClippingLevelExperiment;";
|
|
|
|
|
}
|
2017-10-16 13:49:04 +02:00
|
|
|
if (capture_nonlocked_.echo_controller_enabled) {
|
|
|
|
|
experiments_description += "EchoController;";
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
}
|
2017-10-13 11:05:17 +02:00
|
|
|
if (config_.gain_controller2.enabled) {
|
|
|
|
|
experiments_description += "GainController2;";
|
|
|
|
|
}
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
InternalAPMConfig apm_config;
|
|
|
|
|
|
2019-03-06 04:16:46 +01:00
|
|
|
apm_config.aec_enabled = config_.echo_canceller.enabled;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
apm_config.aec_delay_agnostic_enabled =
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation &&
|
2018-11-01 08:59:29 +01:00
|
|
|
private_submodules_->echo_cancellation->is_delay_agnostic_enabled();
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
apm_config.aec_drift_compensation_enabled =
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation &&
|
2018-11-01 08:59:29 +01:00
|
|
|
private_submodules_->echo_cancellation->is_drift_compensation_enabled();
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
apm_config.aec_extended_filter_enabled =
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation &&
|
2018-11-01 08:59:29 +01:00
|
|
|
private_submodules_->echo_cancellation->is_extended_filter_enabled();
|
2019-04-25 15:18:06 +02:00
|
|
|
apm_config.aec_suppression_level =
|
|
|
|
|
private_submodules_->echo_cancellation
|
|
|
|
|
? static_cast<int>(
|
|
|
|
|
private_submodules_->echo_cancellation->suppression_level())
|
|
|
|
|
: 0;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
2019-05-03 15:48:47 +02:00
|
|
|
apm_config.aecm_enabled = !!private_submodules_->echo_control_mobile;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
apm_config.aecm_comfort_noise_enabled =
|
2019-04-29 12:14:50 +02:00
|
|
|
private_submodules_->echo_control_mobile &&
|
2018-11-05 16:10:00 +01:00
|
|
|
private_submodules_->echo_control_mobile->is_comfort_noise_enabled();
|
2019-04-29 12:14:50 +02:00
|
|
|
apm_config.aecm_routing_mode =
|
|
|
|
|
private_submodules_->echo_control_mobile
|
|
|
|
|
? static_cast<int>(
|
|
|
|
|
private_submodules_->echo_control_mobile->routing_mode())
|
|
|
|
|
: 0;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
apm_config.agc_enabled = public_submodules_->gain_control->is_enabled();
|
|
|
|
|
apm_config.agc_mode =
|
|
|
|
|
static_cast<int>(public_submodules_->gain_control->mode());
|
|
|
|
|
apm_config.agc_limiter_enabled =
|
|
|
|
|
public_submodules_->gain_control->is_limiter_enabled();
|
|
|
|
|
apm_config.noise_robust_agc_enabled = constants_.use_experimental_agc;
|
|
|
|
|
|
|
|
|
|
apm_config.hpf_enabled = config_.high_pass_filter.enabled;
|
|
|
|
|
|
|
|
|
|
apm_config.ns_enabled = public_submodules_->noise_suppression->is_enabled();
|
|
|
|
|
apm_config.ns_level =
|
|
|
|
|
static_cast<int>(public_submodules_->noise_suppression->level());
|
|
|
|
|
|
|
|
|
|
apm_config.transient_suppression_enabled =
|
|
|
|
|
capture_.transient_suppressor_enabled;
|
|
|
|
|
apm_config.experiments_description = experiments_description;
|
2018-04-16 13:52:32 +02:00
|
|
|
apm_config.pre_amplifier_enabled = config_.pre_amplifier.enabled;
|
|
|
|
|
apm_config.pre_amplifier_fixed_gain_factor =
|
|
|
|
|
config_.pre_amplifier.fixed_gain_factor;
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
|
|
|
|
|
if (!forced && apm_config == apm_config_for_aec_dump_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
aec_dump_->WriteConfig(apm_config);
|
|
|
|
|
apm_config_for_aec_dump_ = apm_config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RecordUnprocessedCaptureStream(
|
|
|
|
|
const float* const* src) {
|
|
|
|
|
RTC_DCHECK(aec_dump_);
|
|
|
|
|
WriteAecDumpConfigMessage(false);
|
|
|
|
|
|
|
|
|
|
const size_t channel_size = formats_.api_format.input_stream().num_frames();
|
|
|
|
|
const size_t num_channels = formats_.api_format.input_stream().num_channels();
|
|
|
|
|
aec_dump_->AddCaptureStreamInput(
|
2018-02-16 11:54:07 +01:00
|
|
|
AudioFrameView<const float>(src, num_channels, channel_size));
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
RecordAudioProcessingState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RecordUnprocessedCaptureStream(
|
|
|
|
|
const AudioFrame& capture_frame) {
|
|
|
|
|
RTC_DCHECK(aec_dump_);
|
|
|
|
|
WriteAecDumpConfigMessage(false);
|
|
|
|
|
|
|
|
|
|
aec_dump_->AddCaptureStreamInput(capture_frame);
|
|
|
|
|
RecordAudioProcessingState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RecordProcessedCaptureStream(
|
|
|
|
|
const float* const* processed_capture_stream) {
|
|
|
|
|
RTC_DCHECK(aec_dump_);
|
|
|
|
|
|
|
|
|
|
const size_t channel_size = formats_.api_format.output_stream().num_frames();
|
|
|
|
|
const size_t num_channels =
|
|
|
|
|
formats_.api_format.output_stream().num_channels();
|
2018-02-16 11:54:07 +01:00
|
|
|
aec_dump_->AddCaptureStreamOutput(AudioFrameView<const float>(
|
|
|
|
|
processed_capture_stream, num_channels, channel_size));
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
aec_dump_->WriteCaptureStreamMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RecordProcessedCaptureStream(
|
|
|
|
|
const AudioFrame& processed_capture_frame) {
|
|
|
|
|
RTC_DCHECK(aec_dump_);
|
|
|
|
|
|
|
|
|
|
aec_dump_->AddCaptureStreamOutput(processed_capture_frame);
|
|
|
|
|
aec_dump_->WriteCaptureStreamMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioProcessingImpl::RecordAudioProcessingState() {
|
|
|
|
|
RTC_DCHECK(aec_dump_);
|
|
|
|
|
AecDump::AudioProcessingState audio_proc_state;
|
|
|
|
|
audio_proc_state.delay = capture_nonlocked_.stream_delay_ms;
|
|
|
|
|
audio_proc_state.drift =
|
2019-04-25 15:18:06 +02:00
|
|
|
private_submodules_->echo_cancellation
|
|
|
|
|
? private_submodules_->echo_cancellation->stream_drift_samples()
|
|
|
|
|
: 0;
|
2019-03-27 13:28:08 +01:00
|
|
|
audio_proc_state.level = agc1()->stream_analog_level();
|
AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.
This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.
The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.
The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.
BUG=webrtc:7404
Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
2017-05-23 07:20:05 -07:00
|
|
|
audio_proc_state.keypress = capture_.key_pressed;
|
|
|
|
|
aec_dump_->AddAudioProcessingState(audio_proc_state);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 14:46:07 -07:00
|
|
|
AudioProcessingImpl::ApmCaptureState::ApmCaptureState(
|
2018-06-14 10:11:35 +02:00
|
|
|
bool transient_suppressor_enabled)
|
2019-05-03 09:00:08 +02:00
|
|
|
: delay_offset_ms(0),
|
2016-08-29 14:46:07 -07:00
|
|
|
was_stream_delay_set(false),
|
|
|
|
|
output_will_be_muted(false),
|
|
|
|
|
key_pressed(false),
|
|
|
|
|
transient_suppressor_enabled(transient_suppressor_enabled),
|
2016-09-16 15:02:15 -07:00
|
|
|
capture_processing_format(kSampleRate16kHz),
|
2017-04-10 14:12:41 -07:00
|
|
|
split_rate(kSampleRate16kHz),
|
2018-07-16 17:08:41 +02:00
|
|
|
echo_path_gain_change(false),
|
2018-10-02 17:00:59 +02:00
|
|
|
prev_analog_mic_level(-1),
|
2019-05-10 15:50:02 +02:00
|
|
|
prev_pre_amp_gain(-1.f),
|
|
|
|
|
playout_volume(-1),
|
|
|
|
|
prev_playout_volume(-1) {}
|
2016-08-29 14:46:07 -07:00
|
|
|
|
|
|
|
|
AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
|
|
|
|
|
|
2019-08-15 12:15:46 +02:00
|
|
|
void AudioProcessingImpl::ApmCaptureState::KeyboardInfo::Extract(
|
|
|
|
|
const float* const* data,
|
|
|
|
|
const StreamConfig& stream_config) {
|
|
|
|
|
if (stream_config.has_keyboard()) {
|
|
|
|
|
keyboard_data = data[stream_config.num_channels()];
|
|
|
|
|
} else {
|
|
|
|
|
keyboard_data = NULL;
|
|
|
|
|
}
|
|
|
|
|
num_keyboard_frames = stream_config.num_frames();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 14:46:07 -07:00
|
|
|
AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
|
|
|
|
|
|
|
|
|
|
AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|