1
0
mirror of https://github.com/nu774/fdkaac.git synced 2024-12-28 08:10:43 +01:00

extrapolater: don't return more samples than required

fixes https://github.com/nu774/fdkaac/issues/54
This commit is contained in:
nu774 2022-08-04 21:06:48 +09:00
parent ecddb7d633
commit 0ce71d066a

View File

@ -144,17 +144,22 @@ static int process1(extrapolater_t *self, void *buffer, unsigned nframes)
assert(bp->count <= nframes); assert(bp->count <= nframes);
memcpy(buffer, bp->data, bp->count * sfmt->bytes_per_frame); memcpy(buffer, bp->data, bp->count * sfmt->bytes_per_frame);
if (!fetch(self, nframes)) { if (!fetch(self, nframes)) {
// got EOF
buffer_t *bbp = &self->buffer[self->nbuffer]; buffer_t *bbp = &self->buffer[self->nbuffer];
if (bp->count < 2 * LPC_ORDER) { 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; size_t total = bp->count + bbp->count;
if (bbp->count && if (bbp->count &&
realloc_buffer(bbp, total * sfmt->bytes_per_frame) == 0 && realloc_buffer(bbp, total * sfmt->bytes_per_frame) == 0 &&
realloc_buffer(bp, total * sfmt->bytes_per_frame) == 0) realloc_buffer(bp, total * sfmt->bytes_per_frame) == 0)
{ {
memcpy(bbp->data + bbp->count * sfmt->channels_per_frame, memcpy(bbp->data + bbp->count * sfmt->channels_per_frame,
bp->data, bp->count * sfmt->bytes_per_frame); bp->data,
memcpy(bp->data, bbp->data, total * sfmt->bytes_per_frame); bp->count * sfmt->bytes_per_frame);
bp->count = total; 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) if (bp->count >= 2 * LPC_ORDER)