From 074e4115dd034317bc084574b0c01c2bc4025c67 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 1 Feb 2022 22:47:11 -0800 Subject: [PATCH] sox resampler: Perform post file flush Flush the resampler when the source file terminates, so that it outputs delayed samples properly. This fixes gapless decoding of resampled files. Signed-off-by: Christopher Snowhill --- Audio/Chain/ConverterNode.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Audio/Chain/ConverterNode.m b/Audio/Chain/ConverterNode.m index 4198d44e5..3dc65017e 100644 --- a/Audio/Chain/ConverterNode.m +++ b/Audio/Chain/ConverterNode.m @@ -954,7 +954,22 @@ tryagain: if (!skipResampler) { + ioNumberPackets += soxr_delay(soxr); + soxr_process(soxr, (float *)(((uint8_t*)inputBuffer) + inpOffset), inputSamples, &inputDone, floatBuffer, ioNumberPackets, &outputDone); + + if (latencyEatenPost) + { + // Post file flush + size_t idone = 0, odone = 0; + + do + { + soxr_process(soxr, NULL, 0, &idone, floatBuffer + outputDone * floatFormat.mBytesPerPacket, ioNumberPackets - outputDone, &odone); + outputDone += odone; + } + while (odone > 0); + } } else {