The code has been running in Chrome since 2020 and ChromeOS since 2022 (https://crrev.com/c/3452884) without issues.
Bug: webrtc:11803
Change-Id: I0c572d362b1f52b4591c7790e11a87c1a1ad1a79
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/293342
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39316}
- Lowering the energy threshold for updating the accumulated error.
- Not using the pre-echo estimate in the initial frames when the matched filters have been recently initialized.
- Slight speed up for the increases in the accumulated error.
- Not periodically resetting the accumulated error.
Bug: webrtc:14205
Change-Id: Ic337332e263b27d7a3aba0ab4b371517780f9c90
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291320
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39175}
Based on offline testing; needed to allow input volume adaptations
more frequently. Note that if the estimated speech level falls in
the target range, the recommended input volume won't change and
hence the new lower threshold won't necessarily increase the
number of adjustments.
Bug: webrtc:7494
Change-Id: Iabb501c188da238ea7b7137175bcfe09239c90a2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291110
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39161}
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}
- Test behavior with no input volume controller
- Test behavior with startup volume higher than the minimum
input volume
Bug: webrtc:7494
Change-Id: I36d48e2bd277b8a71eb6fbb0272c26c7176b3d5e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286380
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38932}
Make sure that the input volume controller implementations exhibit
the adaptive behavior regardless of the sample rate and the number
of channels. The newly added tests check that:
- a downward adjustment takes place with clipping input
- an upward adjustment takes place with a too low speech level
- a downward adjustment takes place with a too high speech level
Bug: webrtc:14761
Change-Id: I1795e74c5f219e15107e928ebaca2bfa75214526
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287301
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38930}
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}
Only allow the application of min input volume if the applied input
volume is above zero. To implement this, add a member variable to
store the applied input volume. Rename the related setter to reflect
its new functionality.
Bug: webrtc:7494
Change-Id: Ia70d5cb4dfd972aad9ef2663a81884f3e5cb0758
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287680
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38878}
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}
Rename MonoInputVolumeController member input_volume_ to reflect its
use to store the most recent input volume recommendation.
Rename the remaining variables named as manager in the unit tests.
Bug: webrtc:7494
Change-Id: I31ffdc131c98061ef2b36f98b685c5182b3c6861
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287123
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38854}
The `WebRTC.Audio.AgcSetLevel` name is misleading and the histogram
is logged for each channel - but the input volume is one for all the
channels.
Changes:
- `WebRTC.Audio.Apm.RecommendedInputVolume.OnChangeToMatchTarget`
is the new name
- Now available not only in `AgcManagerDirect` (AGC1), but also in
`InputVolumeController` (AGC2)
- Logged once and not for each channel
- Also add the following AGC implementation agnostic histograms
- `WebRTC.Audio.Apm.AppliedInputVolume.OnChange`
- `WebRTC.Audio.Apm.RecommendedInputVolume.OnChange`
- Fix `SpeechSamplesReader::Feed()` in the unit tests, which did
not set the applied input volume and apply the recommended one
The histogram definitions are updated in crrev.com/c/4087426.
Bug: webrtc:7494
Change-Id: I03c5dfb08165805215ca2c4bb6509b16de8d68da
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287081
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38852}
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}
Remove deprecated unit test helper functions CallPreProcessAudioBuffer()
and CallPreProcForChangingAudio(). Replace the use of these functions
with CallAgcSequence(). Remove a duplicate unit test using one of these
functions. The new calls follow the API contract.
Bug: webrtc:7494
Change-Id: Idc033cb48f4fab1814c4c6e0f23edc4a6a9faa64
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285960
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38826}
Currently the fixed digital gain is applied after the input volume
controller and before the adaptive digital one. This CL moves its
application after the adaptive digital controller and before the
limiter.
Reasons:
- This change is safe: no production config where both adaptive and
fixed digital controllers are jointly used
- More predictable behavior: when the fixed digital controller is
used after the adaptive digital controller it is easier to describe
the overall behavior - i.e., the fixed digital combined with the
limiter can be used for digital compression
- Allow to remove an unwanted temporal dependency: in a follow-up CL
the input volume controller will use the latest speech level
estimation instead of that from the previously analyzed frame; this
CL makes that change easier.
Bug: webrtc:7494
Change-Id: I2e9869081e0eba1e4f30f11ea93a973ca7fea28c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286340
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38813}
Isolates the build targets for the `AdaptiveDigitalGainController`
dependencies that will be moved into `GainController2`.
`AdaptiveDigitalGainController` will be removed because the wrapper
itself adds little - that's the reason why it has no unit tests.
Bug: webrtc:7494
Change-Id: I2ca41f9255c8faefe4b2cb4ec1f8db536e582f39
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280482
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38799}
- use the new naming convention 'input volume'
- fix Yoda-style expressions in the unit tests
- clarify how the gain map values are generated
Bug: webrtc:7494
Change-Id: I4d6ee897a93cdefa6735733b053c57326d01a528
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285467
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38795}
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}
Always enforce the minimum input volume, not only if overridden.
The only exception is when the applied input volume is zero: in that
case zero is still recommended.
This CL also adapts the unit tests and replaces "mic level" with
the "input volume".
Bug: webrtc:7494
Change-Id: I20c14624fbd357ab91ea05521c3723ec1045a8db
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285462
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38769}
Make the argument speech_probability non-optional in
InputVolumeController::Process() and
MonoInputVolumeController::Process().
Additional clean-up: Remove the flag enabled in the
config. Add unit tests for MonoInputVolumeController.
Bug: webrtc:7494
Change-Id: Ie28af77dc628bf71d09ce1ff033d39031f77a21e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/283700
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38710}
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}
Make speech probability threshold configurable by replacing
kSpeechProbabilitySilenceThreshold with speech_probability_threshold in
InputVolumeController::Config.
Make the processing more robust against outliers in speech probability
estimaton by computing an aggregate speech activity over a speech
segment. In MonoInputVolumeController::Process(), use the passed
non-empty speech probabilities to compute the speech activity over the
speech segment and only allow updates for segments with a high enough
ratio of speech frames. Pass RMS error and speech probability for every
frame in Process(): If rms_error_dbfs is empty, volume updates are not
allowed; if speech_probability is empty, the frame counts as a non-
speech frame.
Remove startup_min_volume from the config since it's no longer used
after https://webrtc-review.googlesource.com/c/src/+/282821.
Bug: webrtc:7494
Change-Id: I0ab81b03371496315348f552133aa9909bd36f26
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/283523
Commit-Queue: Hanna Silen <silen@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38685}
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}
Replace kUpdateInputVolumeWaitFrames with
update_input_volume_wait_frames in InputVolumeController::Config.
Also, fix an off-by-one error in the frame count to give a better
readability for non-zero wait frames. Now
update_input_volume_wait_frames_ = 100 allows updates every 100 frames
instead of every 101 frames. Effectively, this makes
update_input_volume_wait_frames = 0 and 1 to behave similarly (i.e.,
they now both allow updates after every frame).
Bug: webrtc:7494
Change-Id: I597f7e88895a4dcd365dc6dee526acb9d971b2fc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282863
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38648}
Replace the use of MonoInputController::min_mic_level() with
MonoInputVolumeController::clipped_level_min() when estimating input
volume adjustment from clipping prediction. The adjustment is later
capped in MonoInputVolumeController::HandleClipping() using
clipped_level_min_ so no audio changes are expected from this change.
Bug: webrtc:7494
Change-Id: Ie26d0aa5cce3eeef06f70a281504889519bb5aca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282840
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38593}