From 0ce71d066a93ac8a789a416f507e7ce99da97e8c Mon Sep 17 00:00:00 2001 From: nu774 Date: Thu, 4 Aug 2022 21:06:48 +0900 Subject: [PATCH] extrapolater: don't return more samples than required fixes https://github.com/nu774/fdkaac/issues/54 --- src/extrapolater.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/extrapolater.c b/src/extrapolater.c index b093478..97e06fe 100644 --- a/src/extrapolater.c +++ b/src/extrapolater.c @@ -144,17 +144,22 @@ static int process1(extrapolater_t *self, void *buffer, unsigned nframes) assert(bp->count <= nframes); memcpy(buffer, bp->data, bp->count * sfmt->bytes_per_frame); if (!fetch(self, nframes)) { + // got EOF buffer_t *bbp = &self->buffer[self->nbuffer]; if (bp->count < 2 * LPC_ORDER) { + // final frame is too short, so we join with the pre-final frame size_t total = bp->count + bbp->count; if (bbp->count && realloc_buffer(bbp, total * sfmt->bytes_per_frame) == 0 && realloc_buffer(bp, total * sfmt->bytes_per_frame) == 0) { memcpy(bbp->data + bbp->count * sfmt->channels_per_frame, - bp->data, bp->count * sfmt->bytes_per_frame); - memcpy(bp->data, bbp->data, total * sfmt->bytes_per_frame); - bp->count = total; + bp->data, + bp->count * sfmt->bytes_per_frame); + memcpy(bp->data, + bbp->data + bp->count * sfmt->channels_per_frame, + bbp->count * sfmt->bytes_per_frame); + bp->count = bbp->count; } } if (bp->count >= 2 * LPC_ORDER)