Cog Audio converter: Fix end of track flush and extrapolation

This commit is contained in:
Christopher Snowhill 2022-01-11 19:37:17 -08:00
parent 8a91bc1d09
commit f44e4e793b

View file

@ -400,9 +400,10 @@ static void extrapolate(float *buffer, size_t channels, size_t frameSize, size_t
{ {
char writeBuf[CHUNK_SIZE]; char writeBuf[CHUNK_SIZE];
while ([self shouldContinue] == YES && [self endOfStream] == NO) //Need to watch EOS somehow.... while ([self shouldContinue] == YES) //Need to watch EOS somehow....
{ {
int amountConverted = [self convert:writeBuf amount:CHUNK_SIZE]; int amountConverted = [self convert:writeBuf amount:CHUNK_SIZE];
if (!amountConverted) break;
[self writeData:writeBuf amount:amountConverted]; [self writeData:writeBuf amount:amountConverted];
} }
} }
@ -457,17 +458,20 @@ tryagain:
{ {
ioNumberPackets = (int)resampler->latency(resampler_data); ioNumberPackets = (int)resampler->latency(resampler_data);
newSize = ioNumberPackets * floatFormat.mBytesPerPacket; newSize = ioNumberPackets * floatFormat.mBytesPerPacket;
newSize += inpSize;
if (!inputBuffer || inputBufferSize < newSize) if (!inputBuffer || inputBufferSize < newSize)
inputBuffer = realloc( inputBuffer, inputBufferSize = newSize * 64); inputBuffer = realloc( inputBuffer, inputBufferSize = newSize * 3);
extrapolateEnd = ioNumberPackets; extrapolateEnd = ioNumberPackets;
// Extrapolate end samples // Extrapolate end samples
if (inpSize) if (inpSize)
{
extrapolate( inputBuffer, floatFormat.mChannelsPerFrame, inpSize / floatFormat.mBytesPerPacket, extrapolateEnd, NO); extrapolate( inputBuffer, floatFormat.mChannelsPerFrame, inpSize / floatFormat.mBytesPerPacket, extrapolateEnd, NO);
inpSize = newSize; inpOffset = inpSize;
inpOffset = 0; inpSize += extrapolateEnd * floatFormat.mBytesPerPacket;
}
latencyPostfill = YES; latencyPostfill = YES;
break; break;
} }