Cog Audio: Enhance track end extrapolator so it will always have a reasonable amount of buffered data for extrapolation
parent
e6124335d1
commit
7cc89c9f92
|
@ -46,6 +46,9 @@
|
||||||
size_t floatBufferSize;
|
size_t floatBufferSize;
|
||||||
size_t floatSize, floatOffset;
|
size_t floatSize, floatOffset;
|
||||||
|
|
||||||
|
size_t floatConvertedSize;
|
||||||
|
float floatConvertedLast[CHUNK_SIZE];
|
||||||
|
|
||||||
AudioStreamBasicDescription inputFormat;
|
AudioStreamBasicDescription inputFormat;
|
||||||
AudioStreamBasicDescription floatFormat;
|
AudioStreamBasicDescription floatFormat;
|
||||||
AudioStreamBasicDescription dmFloatFormat; // downmixed/upmixed float format
|
AudioStreamBasicDescription dmFloatFormat; // downmixed/upmixed float format
|
||||||
|
|
|
@ -485,12 +485,35 @@ tryagain:
|
||||||
extrapolateEnd = ioNumberPackets;
|
extrapolateEnd = ioNumberPackets;
|
||||||
|
|
||||||
// Extrapolate end samples
|
// Extrapolate end samples
|
||||||
if (inpSize)
|
if ( inpSize < sizeof(floatConvertedLast))
|
||||||
{
|
{
|
||||||
extrapolate( inputBuffer, floatFormat.mChannelsPerFrame, inpSize / floatFormat.mBytesPerPacket, extrapolateEnd, NO);
|
size_t inpTotal = newSize + floatConvertedSize;
|
||||||
|
if (inpTotal > sizeof(floatConvertedLast))
|
||||||
|
inpTotal = sizeof(floatConvertedLast);
|
||||||
|
|
||||||
|
if (inpTotal - newSize < floatConvertedSize)
|
||||||
|
{
|
||||||
|
memmove(floatConvertedLast, ((uint8_t*)floatConvertedLast) + newSize, inpTotal - newSize);
|
||||||
|
floatConvertedSize = inpTotal - newSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(((uint8_t*)floatConvertedLast) + floatConvertedSize, inputBuffer, inpSize);
|
||||||
|
|
||||||
|
extrapolate( floatConvertedLast, floatFormat.mChannelsPerFrame, inpTotal / floatFormat.mBytesPerPacket, extrapolateEnd, NO );
|
||||||
|
|
||||||
|
newSize = ioNumberPackets * floatFormat.mBytesPerPacket;
|
||||||
|
|
||||||
|
memcpy( inputBuffer, ((uint8_t*)floatConvertedLast) + inpTotal - newSize, newSize );
|
||||||
|
|
||||||
|
inpSize = newSize;
|
||||||
|
inpOffset = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extrapolate( inputBuffer, floatFormat.mChannelsPerFrame, newSize / floatFormat.mBytesPerPacket, extrapolateEnd, NO );
|
||||||
|
|
||||||
inpOffset = inpSize;
|
inpOffset = inpSize;
|
||||||
inpSize += extrapolateEnd * floatFormat.mBytesPerPacket;
|
inpSize = newSize;
|
||||||
}
|
}
|
||||||
latencyPostfill = YES;
|
latencyPostfill = YES;
|
||||||
break;
|
break;
|
||||||
|
@ -628,6 +651,13 @@ tryagain:
|
||||||
// Input now contains bytesReadFromInput worth of floats, in the input sample rate
|
// Input now contains bytesReadFromInput worth of floats, in the input sample rate
|
||||||
inpSize = bytesReadFromInput;
|
inpSize = bytesReadFromInput;
|
||||||
inpOffset = 0;
|
inpOffset = 0;
|
||||||
|
|
||||||
|
// Preserve last samples, for end extrapolator, if needed
|
||||||
|
size_t preserved = inpSize;
|
||||||
|
if (preserved > sizeof(floatConvertedLast))
|
||||||
|
preserved = sizeof(floatConvertedLast);
|
||||||
|
memcpy(floatConvertedLast, inputBuffer + inpSize - preserved, preserved);
|
||||||
|
floatConvertedSize = preserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inpOffset != inpSize && floatOffset == floatSize)
|
if (inpOffset != inpSize && floatOffset == floatSize)
|
||||||
|
@ -823,6 +853,8 @@ static float db_to_scale(float db)
|
||||||
floatOffset = 0;
|
floatOffset = 0;
|
||||||
floatSize = 0;
|
floatSize = 0;
|
||||||
|
|
||||||
|
floatConvertedSize = 0;
|
||||||
|
|
||||||
// This is a post resampler, post-down/upmix format
|
// This is a post resampler, post-down/upmix format
|
||||||
|
|
||||||
dmFloatFormat = floatFormat;
|
dmFloatFormat = floatFormat;
|
||||||
|
|
Loading…
Reference in New Issue