From 48876eaffb8944a53bf1fd5320a4c00493a468e5 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 2 Sep 2019 20:41:31 +0300 Subject: [PATCH] Sound: OpenAL: Reclaim stream buffers on stream change --- src/engine/e_sound_al.inc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/engine/e_sound_al.inc b/src/engine/e_sound_al.inc index a5c8364..b73b37f 100644 --- a/src/engine/e_sound_al.inc +++ b/src/engine/e_sound_al.inc @@ -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 -- 2.29.2