Skip to content

Commit 17757aa

Browse files
committed
BufferedStream: correction
1 parent 1211a4d commit 17757aa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/AudioTools/CoreAudio/AudioStreams.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,17 @@ class BufferedStream : public ModifyingStream {
608608

609609
/// refills the buffer with data from the source
610610
void refill() {
611+
// Preserve any existing unread data then append new bytes
611612
buffer.trim();
612-
size_t result = readExt(buffer.address(), buffer.availableForWrite());
613-
buffer.setAvailable(result);
613+
size_t already_available = buffer.available();
614+
size_t free_space = buffer.availableForWrite();
615+
if (free_space == 0) {
616+
// Buffer full – nothing we can append
617+
return;
618+
}
619+
// Read new data directly behind existing bytes
620+
size_t added = readExt(buffer.address() + already_available, free_space);
621+
buffer.setAvailable(already_available + added);
614622
}
615623

616624
/// refill only if not enough data

0 commit comments

Comments
 (0)