From ebdc40838523de2bedeab644d613420f3ac44a29 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 24 May 2024 15:11:18 +0100 Subject: [PATCH] Update sfxSndStream.cpp streaming file fixes, also only wrap back around when we have read the whole file. --- Engine/source/sfx/media/sfxSndStream.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Engine/source/sfx/media/sfxSndStream.cpp b/Engine/source/sfx/media/sfxSndStream.cpp index 2ccad264f..a2a508804 100644 --- a/Engine/source/sfx/media/sfxSndStream.cpp +++ b/Engine/source/sfx/media/sfxSndStream.cpp @@ -139,13 +139,22 @@ U32 SFXSndStream::read(U8* buffer, U32 length) return 0; } - if (framesRead != sfinfo.frames) + if (framesRead != framesToRead) { Con::errorf("SFXSndStream - read: %s", sf_strerror(sndFile)); } - // reset stream - setPosition(0); + // make sure we are more than 0 position. + if (getPosition() > 0) + { + // (convert to frames) == number of frames available? + if ((getPosition() / mFormat.getBytesPerSample()) == sfinfo.frames) + { + // reset stream + setPosition(0); + } + } + return framesRead * mFormat.getBytesPerSample(); }