From 985ac6ceaa2a34554d27dc39116559ddae808522 Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Mon, 13 Aug 2007 15:18:44 +0000 Subject: Made calcTrueSampleSize seek back to stream's start when ending the function. svn-id: r28595 --- engines/agi/sound.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'engines/agi/sound.cpp') diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp index f376ca2ff7..d5db02f732 100644 --- a/engines/agi/sound.cpp +++ b/engines/agi/sound.cpp @@ -49,13 +49,18 @@ namespace Agi { * Needed because a zero byte in the sample data ends the sample prematurely. */ uint calcTrueSampleSize(Common::SeekableReadStream &sample, uint size) { + uint32 startPos = sample.pos(); // Save stream's starting position // Search for a zero byte in the sample data, // as that would end the sample prematurely. - for (uint i = 0; i < size; i++) - if (sample.readByte() == 0) - return i; - // If no zero was found in the sample, then return its whole size. - return size; + uint result = size; // Set a default value for the result + for (uint i = 0; i < size; i++) { + if (sample.readByte() == 0) { + result = i; + break; + } + } + sample.seek(startPos); // Seek back to the stream's starting position + return result; } struct IIgsEnvelopeSegment { -- cgit v1.2.3