From 8bc9738ccb98ab4c86daf9b45c530ebbc777766a Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 10 Jul 2022 15:08:56 -0700 Subject: [PATCH] [Downmixer] Only downmix to stereo if not stereo When downmixing to mono, only downmix to stereo first if the source is not already stereo. Signed-off-by: Christopher Snowhill --- Audio/Chain/Downmix.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Audio/Chain/Downmix.m b/Audio/Chain/Downmix.m index 1bb981a48..a8291640e 100644 --- a/Audio/Chain/Downmix.m +++ b/Audio/Chain/Downmix.m @@ -149,10 +149,12 @@ static void downmix_to_stereo(const float *inBuffer, int channels, uint32_t conf static void downmix_to_mono(const float *inBuffer, int channels, uint32_t config, float *outBuffer, size_t count) { float tempBuffer[count * 2]; - downmix_to_stereo(inBuffer, channels, config, tempBuffer, count); - inBuffer = tempBuffer; - channels = 2; - config = AudioConfigStereo; + if(channels > 2 || config != AudioConfigStereo) { + downmix_to_stereo(inBuffer, channels, config, tempBuffer, count); + inBuffer = tempBuffer; + channels = 2; + config = AudioConfigStereo; + } cblas_scopy((int)count, inBuffer, 2, outBuffer, 1); vDSP_vadd(outBuffer, 1, inBuffer + 1, 2, outBuffer, 1, count); }