DEADSOFTWARE

Sound: OpenAL: Reclaim stream buffers on stream change
authorfgsfds <pvt.fgsfds@gmail.com>
Mon, 2 Sep 2019 17:41:31 +0000 (20:41 +0300)
committerfgsfds <pvt.fgsfds@gmail.com>
Mon, 2 Sep 2019 17:41:31 +0000 (20:41 +0300)
src/engine/e_sound_al.inc

index a5c83646ff18937ecf004e228250272b3af25b05..b73b37f760bdc00f7ea75883425a92b4360ee711 100644 (file)
@@ -451,6 +451,8 @@ begin
 end;
 
 procedure AssignSound(ID: DWORD; Src: ALuint); inline;
+var
+  S: ALint;
 begin
   alGetError(); // reset error state
 
@@ -459,8 +461,17 @@ begin
     // this is a stream
     // reset position
     e_SoundsArray[ID].Loader.SetPosition(0);
-    if CurStream <> ID then // changing streams, stop the thing just in case
-      alSourceStop(Src);
+    if CurStream <> ID then // changing streams
+    begin
+      alSourceStop(Src); // this should mark all buffers as processed
+      alGetSourcei(Src, AL_BUFFERS_PROCESSED, S);
+      // unqueue all buffers
+      if S > 0 then
+      begin
+        alSourceUnqueueBuffers(Src, S, @alStreamBufs[alStreamAvail]);
+        alStreamAvail := NUM_STREAM_BUFFERS;
+      end;
+    end;
     // this shit is playing now
     CurStream := ID;
   end