When the `WebRTC-Audio-GainController2` field trial is used, the
initial APM configuration is adjusted depending on its original
values and the field trial parameters.
This CL fixes two cases when the code crashes:
1. when, in the initial APM config, AGC1 is enabled, AGC2 is
disabled and TS is enabled
2. when the initial APM sample rate is different from the
capture one and the VAD APM sub-module is not re-initialized
This CL also improves the unit tests coverage and it has been
tested offline to check that the VAD sub-module is created only
when expected and that AGC2 uses its internal VAD when expected.
The tests ran on a few Wav files with different sample rates and
one AEC dump and on 16 different APM and field trial
configurations.
Bug: chromium:1407341, b/265112132
Change-Id: I7cc267ea81cb02be92c1f37f273b7ae93b6e4634
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/290988
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Olga Sharonova <olka@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39118}
In order to experiment with AGC2 and TS at the same time, 3 field
trials are removed and merged into `WebRTC-Audio-GainController2`,
which is existing.
New parameters for the `WebRTC-Audio-GainController2` field trial:
- `switch_to_agc2`: true by default; when true, the gain control
switches to AGC2 (both for the input volume and for the adaptive
digital gain);
- `min_input_volume`: minimum input volume enforced by the input
volume controller when the applied input volume is not zero;
- `disallow_transient_suppressor_usage`: when true, TS is never
created.
Removed field trials:
- `WebRTC-Audio-Agc2-MinInputVolume`: now a parameter of
`WebRTC-Audio-GainController2`;
- `WebRTC-ApmTransientSuppressorKillSwitch`: now a parameter of
`WebRTC-Audio-GainController2`;
- `WebRTC-Audio-TransientSuppressorVadMode`: automatically inferred
from `WebRTC-Audio-GainController2`.
Bug: webrtc:7494
Change-Id: I452798c0862d71f9adae6d163fe841df05ca44d6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287861
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38890}
In InputVolumeController, rename AnalyzePreProcess() and Process() to
reflect their use and replace the use of the getter
recommended_input_volume() with an optional return value from the
latter one. The added return value carries the recommended input
volume if the call sequence follows the API contract. Make the member
applied_input_volume_ optional. Restrict the use of the getter
recommended_input_volume() for test use. Add a method
capture_output_used() for test use.
In GainController2, store the output of InputVolumeController::Process()
in a new member variable that's updated in Analyze() and Process(). Use
a trivial getter to read the value in APM.
Bug: webrtc:7494
Change-Id: Ifcfb466c4f558be560eb6d2f45410d04adb7e2ad
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287862
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38889}
Pass the correct number of channels needed by the AGC2 input volume
controller. This change doesn't affect the adaptive digital
controller which reads the number of channel from the passed audio
buffer instance for each processed frame.
Note that the `AdaptiveDigitalGainController::Initialize()` impl
was removed in [1], but that CL didn't remove the declaration (done
in this CL).
[1] https://webrtc-review.googlesource.com/c/src/+/287222/5/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc#105
Bug: webrtc:7494
Change-Id: I07369ab4025a251b25c716cf618e4222fdb60fc8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287320
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38863}
Add AGC2 digital adaptive config parameters in the field trial
"WebRTC-Audio-InputVolumeControllerExperiment". Rename it as
"WebRTC-Audio-GainController2" to reflect that the override now adjusts
the parameters for both input volume controller and adaptive digital
controller.
Bug: webrtc:7494
Change-Id: Ifbc1b8be76cf23b0b6b74b22b5167a45972cab38
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286880
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38855}
Now that `InputVolumeController` is finalized, it's time to
consolidate AGC2.
Main changes:
- Remove `AdaptiveDigitalGainController`: it's too simple to justify
a dedicated class and some components of it are also used by
`InputVolumeController`
- Remove unwanted temporal dependency: make `InputVolumeController`
adapt the volume based on the current speech level estimation and
not on the estimation from the previous frame
Tested: AGC2 adaptive digital bit-exactness verified
Bug: webrtc:7494
Change-Id: I175c2741cafc52be81794219c996a3824c3bbf5e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280560
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38841}
Regardless of the APM config, the transient suppressor (TS) submodule
won't be created if the `WebRTC-ApmTransientSuppressorKillSwitch`
field trial, disabled by default, is enabled.
Bug: webrtc:13663
Change-Id: Ic1ef9aa57c728296d671d4ef253630c581a86610
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286382
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38839}
Add a field trial WebRTC-Audio-InputVolumeControllerExperiment and
a mechanism to adjust the config accordingly. Pass the additional
input volume controller config to GainController2.
Bug: webrtc:7494
Change-Id: I3dd624df1f4774cb533417747627995e1f60aa68
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/284101
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38780}
The integration relies on GainController2 methods Process() and
GetRecommendedInputVolume() to internally take into account whether
the input volume controller is enabled in the ctor or not. These
methods are called for every frame processed if GainController2 is
enabled. Analyze() is called if the input volume controller is
enabled.
The functionality can be enabled from the APM config and is not
enabled by default. If multiple input volume controllers are enabled,
an error is logged.
Tested: Bitexact on a large number of aecdumps if not enabled
Bug: webrtc:7494
Change-Id: I9105483be34eb95fab3c46afbbd368802e956fad
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282720
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38776}
when volume emulation is used or when neither an input volume
controller nor volume emulation are used.
This CL adds 3 tests, 2 of which currently fail because APM
behaves in an undesired way. In [1] the behavior is fixed and
the tests are enabled.
A DCHECK in `AudioProcessingImpl::set_stream_analog_level` has
been removed since a more robust behavior can be obtained - namely,
that expected in the disabled unit tests added in this CL.
[1] https://webrtc-review.googlesource.com/c/src/+/281185
Bug: webrtc:14581
Change-Id: I29d2c000cd1baf90606487afd9a4042e6f487834
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/281184
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38696}
This CL adds more explicit tests for unsupported sample rates in the WebRTC audio processing module (APM). Rates are restricted to the range [8000, 384000] Hz. Rates outside this range are handled as best as possible, depending on the format.
Tested: bitexact on a large number of aecdumps
Bug: chromium:1332484, chromium:1334991
Change-Id: I9639d03dc837e1fdff64d1f9d1fff0edc0fb299f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276920
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38663}
This is a reland of commit 8d7273357d
Root cause:
audioproc_f doesn't call `metrics::Enable()` and therefore the stats
reporter crashed when `metrics::HistogramFactoryGetCountsLinear()`
returned a nullptr.
Bug fix:
Added `InputVolumeStatsReporter::cannot_log_stats_`, a const flag
that is set to true if any histogram factory returns a nullptr.
When true, the class does nothing.
This CL also includes other code readability improvements that were
not part of the original CL.
Original change's description:
> APM: log both applied and recommended input volume stats
>
> This CL replaces the existing `WebRTC.Audio.ApmAnalogGain.*` stats
> with `WebRTC.Audio.Apm.AppliedInputVolume.*` and adds the
> `WebRTC.Audio.Apm.RecommendedInputVolume.*` stats.
>
> Bug: webrtc:7494
> Change-Id: I70be710d20b1589fc814cbce3d3329ac1500686f
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280220
> Reviewed-by: Hanna Silen <silen@webrtc.org>
> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#38468}
Bug: webrtc:7494
Change-Id: I8373d16beb06b84f439d2c2274ededea7c5e95b0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280661
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38484}
This CL replaces the existing `WebRTC.Audio.ApmAnalogGain.*` stats
with `WebRTC.Audio.Apm.AppliedInputVolume.*` and adds the
`WebRTC.Audio.Apm.RecommendedInputVolume.*` stats.
Bug: webrtc:7494
Change-Id: I70be710d20b1589fc814cbce3d3329ac1500686f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280220
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38468}
Adopt the new naming convention, which replaces "analog gain" and
"mic level" with "input volume", in the input volume stats reporter.
Bug: webrtc:7494
Change-Id: Ia24876151f51dd1dcc4e4f9db56c64d11ae3b442
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279840
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38467}
MaybeInitializeCapture may overwrite the render configuration of a concurrent render reinitialization, leading to a second render reinitialization on the next render processing call.
See bug description for details.
Tested: Verified bitexactness offline (single-threaded) on a large number of aecdumps.
Bug: webrtc:14495
Change-Id: I9b70b454ce1c27859c3414c9c9ec89b7bbe35559
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/277380
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38241}
Main changes:
- `AgcManagerDirectTestHelper::FirstProcess()` replaced by
`CallAgcSequence()`, which is API contract compliant
- `ExpectCheckVolumeAndReset()`, `SetVolumeAndProcess()` and
`ExpectInitialize() `removed
- TODOs added for the next batch of improvements
- `AgcManagerDirectTestHelper::mock_agc` now using `NiceMock`
- `AgcManagerDirect::(AnalyzePre)Process()` now receives a
const ref
- `AnalyzePreProcess(const float* const*,size_t )` removed
Bug: webrtc:7494
Change-Id: Ie5bbaa590586dd806b30494fb00ca9c742c241e2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273490
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38056}
The current design of the modified getter is error-prone since the
returned value changes meaning based on when (which point in the code)
the getter is called - namely, before `ProcessStream()` is called the
getter returns the stream analog level, after it returns the
recommended level.
Plus, the new implementation, which essentially returns a local
member, removes the risks that the non-trivial implementation
is computationally expensive.
Bug: webrtc:7494, b/241923537
Change-Id: I6714444df27bcc055ae693974ecd1f77f79e6ec0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271580
Reviewed-by: Hanna Silen <silen@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38055}
The `recommended_stream_analog_level()` getter is used to retrieve
both the applied and the recommended input volume. This behavior is
error-prone since the caller must know what is returned based on
the point in the code (namely, before/after the AGC has changed
the last applied input volume into a recommended level).
This CL is a first step to make clarity on which input volume is
handled in different parts of APM. Next in the pipeline: make
`recommended_stream_analog_level()` a trivial getter that always
returns the recommended level.
Main changes:
- When `recommended_stream_analog_level()` is called but
`set_stream_analog_level()` is not called, APM logs an error
and returns a fall-back volume (which should not be applied
since, when `set_stream_analog_level()` is not called, no
external input volume is expected to be present
- When APM is used without calling the `*_stream_analog_level()`
methods (e.g., when the caller does not provide any input volume),
the recorded AEC dumps won't store `Stream::applied_input_level`
Other changes:
- Removed `AudioProcessingImpl::capture_::prev_analog_mic_level`
- Removed redundant code in `GainController2` around detecting
input volume changes (already done by APM)
- Adapted the `audioproc_f` and `unpack_aecdump` tools
- Data dumps clean-up: the applied and the recommended input
volumes are now recorded in an AGC implementation agnostic way
Bug: webrtc:7494, b/241923537
Change-Id: I3cb4a731fd9f3dc19bf6ac679b7ed8c969ea283b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271544
Reviewed-by: Per Åhgren <peah@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38054}
Switching to an AGC implementation agnostic solution for the input
volume emulation functionality offered by the
`capture_levels_adjuster` sub-module.
This CL also fixes a (silent) bug due to which, when the input
volume is emulated via the capture adjuster sub-module, AGC2
reads an incorrect value for the applied input volume.
Tested: audioproc_f with `--analog_mic_gain_emulation 1` used
to verify bit-exactness for one Wav file and one AEC dump for
which the input volume varies.
Bug: webrtc:7494, b/241923537
Change-Id: Ide3085f9a5dfd85888ad812ebd56faa175fb2ba7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273902
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38053}
Making it clear that the field is used to store the applied input
volume and not the recommended input volume.
Bug: webrtc:7494, b/241923537
Change-Id: Ib91bc1a12348f63e3a4ba6e068ed02e40786a87b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271342
Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38051}
Fixing a bug due to which the analog controller could not be disabled.
AudioProcessing::Config::GainController1::AnalogGainController::enabled
was ignored and therefore `recommended_stream_analog_level_locked()` in
APM was returning the level recommended by `AgcManagerDirect`.
When the analog controller is disabled, `stream_analog_level()` now
returns the last value set via `set_stream_analog_level()`.
However, the analog controller code is still running and, in particular,
the existing metrics are reported as if the controller were enabled.
This choice was made to reduce the risks of adding bugs in the digital
compression gain selection part, which is tied to the analog
controller. The metric drawback will be solved in a follow-up CL.
Additional changes:
- log `WebRTC.Audio.GainController.Analog.Enabled` when
AGC1 is created or when its config changes
- first step to replace "analog level" with "input volume"
Bug: webrtc:7909, b/180019868
Change-Id: I28ce9556dd98f3dd9ad546799406c55478730435
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/270663
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38044}
This is the first step of migrating
AudioProcessing::CreateAndAttachAecDump() from using std::string to
absl::string_view.
Bug: webrtc:13579
Change-Id: I8fc373e7ac55fd8e96bb0b01d1a30e28883ac9a2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269400
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37631}
When the `WebRTC-Audio-TransientSuppressorVadMode-RnnVad` field trial
is set, APM now uses (i) its RNN VAD sub-module to compute the voice
probability, (ii) that probability for TS and (iii) a temporally
delayed version of it for AGC2 (the delay introduced by TS is taken
into account).
Bug: webrtc:13663
Change-Id: Ic0f245c3f00d318c19bb01d3dbc2d5176c90f851
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266362
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37291}
Add a VoiceActivityDetectorWrapper submodule in AudioProcessingImpl
and enable injecting speech probability into GainController2.
Bug: webrtc:13663
Change-Id: I05e13b737d085b45ac8ce76660191867c56834c2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265166
Commit-Queue: Hanna Silen <silen@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37275}
More robust API option that allows to fully initialize TS when created.
Bug: webrtc:13663
Change-Id: I42c38612ef772eb6d0bbde49d04ea39332a0e3c7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/255821
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36490}
It is now required to specify which VAD is used to compute the speech
probability passed when `TransientSuppressor::Suppress()` is called.
In this way, it is possible to adapt parameters and/or logic of a
`TransientSuppressor` implementation to the behavior of the used
VAD. This CL also adds a "no VAD" mode option, which ignores the speech
probability argument passed when `Suppress()` and always applies mild
suppression to preserve transparency.
Finally, this CL adds a field trial to choose which VAD is used by
APM for transient suppression. Wiring the RNN VAD to TS will be done
in a follow-up CL.
Bug: webrtc:13663
Change-Id: I21ed49f91875a4ee0f04db97ea87c0dbc3db7f8a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250962
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36485}
The features have two safety fallbacks:
- multichannel config has a killswitch WebRTC-Aec3SetupSpecificDefaultConfigDefaultsKillSwitch
- stereo detection has a killswitch WebRTC-Aec3StereoContentDetectionKillSwitch
Both features are enabled by default in the AEC3 config.
Tested: Bitexact on a large number of aecdumps.
Bug: chromium:1295710
Change-Id: I340cdc9140dacd4ca22d0911eb9f732b6cf8b226
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258129
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36482}
This enum is no longer needed. Also moving the last piece of code from
common.h to audio_processing_impl.h, allowing to delete common.h.
Bug: chromium:1271981, b/217349489
Change-Id: If115336c36d6d7b5845a903e421c18aebfe434ee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251242
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35946}
- Switch from ptr+size to rtc::ArrayView
- Remove `AgcManagerDirect::sample_rate_hz_` since it's always 16 kHz
- Stop passing nullptr in agc_manager_direct_unittest.cc when
`AgcManagerDirect::Process()` is called
- Allow to correctly run the tests added in the child CL (see [1])
[1] https://webrtc-review.googlesource.com/c/src/+/250141
Bug: webrtc:7494
Change-Id: I0292d7038d6510ca7c58af32b6003a1e4b121b00
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250541
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35910}
The 6-parameter Initialize method is removed. The has_keyboard parameter
in the StreamConfig constructor is removed together with the underlying
member and helper functions.
Bug: chromium:1271981, b/217349489
Change-Id: I7259a114a395f74f735a9c06510c0fc0f0f008e3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250221
Reviewed-by: Sam Zackrisson <saza@google.com>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Auto-Submit: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35908}