From bb55c5e2ec209a9b70f6739fa8f9d49f781ac72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Fri, 15 Nov 2019 14:22:30 +0100 Subject: [PATCH] Correct the upmixing of mono to stereo in ACM2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL is a correction to the former CL that changed the remixing for surround. A bug in that CL caused the upmixing from mono to stereo to place zeros in the right channel. The unittest CL is present in https://webrtc-review.googlesource.com/c/src/+/155740 Bug: b/144458371 Change-Id: I192e587a1b083a7bb55dcac2343f8b6d3942b9ed Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159864 Reviewed-by: Sam Zackrisson Reviewed-by: Henrik Lundin Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#29805} --- .../audio_coding/acm2/audio_coding_module.cc | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/audio_coding/acm2/audio_coding_module.cc b/modules/audio_coding/acm2/audio_coding_module.cc index 0232f2722d..efef3c090d 100644 --- a/modules/audio_coding/acm2/audio_coding_module.cc +++ b/modules/audio_coding/acm2/audio_coding_module.cc @@ -243,11 +243,27 @@ void ReMix(const AudioFrame& input, } const int16_t* input_data = input.data(); - size_t in_index = 0; size_t out_index = 0; - // When upmixing is needed, copy the available channels directly, and set the - // remaining channels to zero. + // When upmixing is needed and the input is mono copy the left channel + // into the left and right channels, and set any remaining channels to zero. + if (input.num_channels_ == 1 && input.num_channels_ < num_output_channels) { + for (size_t k = 0; k < input.samples_per_channel_; ++k) { + (*output)[out_index++] = input_data[k]; + (*output)[out_index++] = input_data[k]; + for (size_t j = 2; j < num_output_channels; ++j) { + (*output)[out_index++] = 0; + } + RTC_DCHECK_EQ(out_index, (k + 1) * num_output_channels); + } + RTC_DCHECK_EQ(out_index, input.samples_per_channel_ * num_output_channels); + return; + } + + size_t in_index = 0; + + // When upmixing is needed and the output is surround, copy the available + // channels directly, and set the remaining channels to zero. if (input.num_channels_ < num_output_channels) { for (size_t k = 0; k < input.samples_per_channel_; ++k) { for (size_t j = 0; j < input.num_channels_; ++j) {