From 6603fab4055e219cd958f6ec1dacd70faf5c6e3c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Feb 2020 09:50:49 +0100 Subject: [PATCH] spa-resample: flush last samples Use 0 samples to flush out the last samples from the resampler. --- spa/plugins/audioconvert/spa-resample.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spa/plugins/audioconvert/spa-resample.c b/spa/plugins/audioconvert/spa-resample.c index 9a8c6589d..0fcfaff4c 100644 --- a/spa/plugins/audioconvert/spa-resample.c +++ b/spa/plugins/audioconvert/spa-resample.c @@ -158,6 +158,7 @@ static int do_conversion(struct data *d) void *dst[channels]; uint32_t i; int j, k, queued; + bool flushing = false; spa_zero(r); r.log = &logger.log; @@ -178,8 +179,18 @@ static int do_conversion(struct data *d) in_len = SPA_MIN(MAX_SAMPLES, (int)resample_in_len(&r, out_len)) - queued; pin_len = in_len = sf_readf_float(d->ifile, &ibuf[queued * channels], in_len); - if (pin_len == 0) - break; + if (pin_len == 0) { + if (flushing) + break; + + flushing = true; + pin_len = in_len = resample_delay(&r); + + for (k = 0, i = 0; i < pin_len; i++) { + for (j = 0; j < channels; j++) + ibuf[k++] = 0.0; + } + } in_len += queued; pin_len = in_len;