libvgm: Fix track ending without glitches

Track rendering returns the number of bytes rendered, which also cuts
short when the track ends. So properly react to this count when running
the player, so we don't keep trying to render, or pick up uninitialized
data from the buffer.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-07-15 06:32:27 -07:00
parent a14254bd2e
commit e8a7eaf954

View file

@ -242,11 +242,16 @@ const int masterVol = 0x10000; // Fixed point 16.16
int numSamples = framesToDo * numChannels * (numBitsPerSample / 8);
mainPlr->Render(numSamples, buf);
UINT32 numRendered = mainPlr->Render(numSamples, buf);
buf = (void*)(((uint8_t*)buf) + numSamples);
buf = (void*)(((uint8_t*)buf) + numRendered);
framesDone += framesToDo;
UINT32 framesRendered = numRendered / (numChannels * (numBitsPerSample / 8));
framesDone += framesRendered;
if(framesRendered < framesToDo)
break;
}
[chunk setStreamTimestamp:streamTimestamp];