Add one frame (10 ms) of silence in APM output after unmuting
This CL adds one frame (10 ms) of silence in APM output after unmuting to mask
audio resulting from the turning on the processing that was deactivated
during the muting.
Bug: b/177830919
Change-Id: If44cfb0ef270dde839dcd3f0b98d1c91e81668dd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211343
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33454}
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 79a3151..ec426f6 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -1325,6 +1325,20 @@
// Pass stats for reporting.
stats_reporter_.UpdateStatistics(capture_.stats);
+ // Temporarily set the output to zero after the stream has been unmuted
+ // (capture output is again used). The purpose of this is to avoid clicks and
+ // artefacts in the audio that results when the processing again is
+ // reactivated after unmuting.
+ if (!capture_.capture_output_used_last_frame &&
+ capture_.capture_output_used) {
+ for (size_t ch = 0; ch < capture_buffer->num_channels(); ++ch) {
+ rtc::ArrayView<float> channel_view(capture_buffer->channels()[ch],
+ capture_buffer->num_frames());
+ std::fill(channel_view.begin(), channel_view.end(), 0.f);
+ }
+ }
+ capture_.capture_output_used_last_frame = capture_.capture_output_used;
+
capture_.was_stream_delay_set = false;
return kNoError;
}
@@ -2025,6 +2039,7 @@
AudioProcessingImpl::ApmCaptureState::ApmCaptureState()
: was_stream_delay_set(false),
capture_output_used(true),
+ capture_output_used_last_frame(true),
key_pressed(false),
capture_processing_format(kSampleRate16kHz),
split_rate(kSampleRate16kHz),