From 80937d0d06fb0908ed8504c30e6f3557acf45167 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 31 Jul 2014 03:39:36 +0200 Subject: [PATCH] ALStream: Fix sometimes not unqueuing all buffers before play Very rarely rogue buffers would remain and play on loop on song switch because we only ever cleared processed, not queued, buffers from the source. The correct way to completely clear a source's queue is to simply attach a null buffer to it. --- src/al-util.h | 5 +++++ src/alstream.cpp | 14 ++------------ src/alstream.h | 1 - 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/al-util.h b/src/al-util.h index 9735277..08c126e 100644 --- a/src/al-util.h +++ b/src/al-util.h @@ -133,6 +133,11 @@ namespace Source return buffer; } + inline void clearQueue(Source::ID id) + { + attachBuffer(id, Buffer::ID(0)); + } + inline ALint getInteger(Source::ID id, ALenum prop) { ALint value; diff --git a/src/alstream.cpp b/src/alstream.cpp index 8819579..2b68c0b 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -57,8 +57,7 @@ ALStream::~ALStream() { close(); - clearALQueue(); - + AL::Source::clearQueue(alSrc); AL::Source::del(alSrc); for (int i = 0; i < STREAM_BUFS; ++i) @@ -228,7 +227,7 @@ void ALStream::stopStream() void ALStream::startStream(float offset) { - clearALQueue(); + AL::Source::clearQueue(alSrc); preemptPause = false; streamInited = false; @@ -292,15 +291,6 @@ void ALStream::checkStopped() state = Stopped; } -void ALStream::clearALQueue() -{ - /* Unqueue all buffers */ - ALint queuedBufs = AL::Source::getProcBufferCount(alSrc); - - while (queuedBufs--) - AL::Source::unqueueBuffer(alSrc); -} - /* thread func */ void ALStream::streamData() { diff --git a/src/alstream.h b/src/alstream.h index 537733b..a20e350 100644 --- a/src/alstream.h +++ b/src/alstream.h @@ -112,7 +112,6 @@ private: void resumeStream(); void checkStopped(); - void clearALQueue(); /* thread func */ void streamData();