From 072d3f3c9e20ca8bd9b53b1bc856645270dc56bc Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sun, 6 Apr 2025 22:17:28 -0400
Subject: [PATCH] dr_mp3: Fix seek table generation with memory buffers instead
of i/o callbacks.
drmp3_calculate_seek_points() builds the table with file positions like this:
```c
mp3FrameInfo[iMP3Frame].bytePos = pMP3->streamCursor - pMP3->dataSize;
drmp3_decode_next_frame_ex__callbacks() updates both streamCursor and dataSize,
but drmp3_decode_next_frame_ex__memory() does not, so all entries in the seek
table end up pointing at the start of the audio file.
This patch updates streamCursor as we read more bytes, but leaves dataSize at
zero, since the latter appears to be how much is left to consume of the
existing read buffer before more is read from disk, so subtracting zero in
drmp3_calculate_seek_points() is the correct thing to do when reading entirely
from memory.
Fixes dr_mp3: Binding a seek table causing incorrect seeks. · Issue #278 · mackron/dr_libs · GitHub
[ Mainstraem P/R: dr_mp3: Fix seek table generation with memory buffers instead of i/o callbacks. by icculus · Pull Request #279 · mackron/dr_libs · GitHub. ]
src/codecs/dr_libs/dr_mp3.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/codecs/dr_libs/dr_mp3.h b/src/codecs/dr_libs/dr_mp3.h
index d764ea6d..af594ab2 100644
— a/src/codecs/dr_libs/dr_mp3.h
+++ b/src/codecs/dr_libs/dr_mp3.h
@@ -2883,6 +2883,7 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__memory(drmp3* pMP3, drmp3d_sampl
/* Consume the data. */
pMP3->memory.currentReadPos += (size_t)info.frame_bytes;
-
pMP3->streamCursor += (size_t)info.frame_bytes;
return pcmFramesRead;
}