Browse Source

Reduce source:tell drift after a streaming Source loops.

Fixes #1810
Sasha Szpakowski 2 years ago
parent
commit
a51d45b1a3
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/modules/audio/openal/Source.cpp

+ 13 - 8
src/modules/audio/openal/Source.cpp

@@ -1160,6 +1160,19 @@ int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
 			decoded = 0;
 	}
 
+	// This shouldn't run after toLoop is calculated in this streamAtomic call,
+	// otherwise it'll decrease too quickly.
+	// TODO: this code is hard to understand, can it be made more clear?
+	// It's meant to reset offsetSamples once OpenAL starts processing the first
+	// queued buffer after a loop.
+	if (toLoop > 0)
+	{
+		if (--toLoop == 0)
+		{
+			offsetSamples = 0;
+		}
+	}
+
 	if (decoder->isFinished() && isLooping())
 	{
 		int queued, processed;
@@ -1172,14 +1185,6 @@ int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
 		d->rewind();
 	}
 
-	if (toLoop > 0)
-	{
-		if (--toLoop == 0)
-		{
-			offsetSamples = 0;
-		}
-	}
-
 	return decoded;
 }