aboutsummaryrefslogtreecommitdiffstats
path: root/al/source.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-03-05 18:45:17 -0800
committerChris Robinson <[email protected]>2023-03-05 18:45:17 -0800
commit1e5af1eb2f8334045e71a831f98424f1eb19854a (patch)
tree05c06865a9b19467f72622e5cbb01dc5c0372e67 /al/source.cpp
parent28ec3afb7949be155aaa477c6e8c7358ac309459 (diff)
Report the current buffer ID of a streaming source
The AL_BUFFER query should only return the buffer that was set on a static source, but some apps used it to detect when a current buffer of a streaming source changed instead of AL_BUFFERS_PROCESSED.
Diffstat (limited to 'al/source.cpp')
-rw-r--r--al/source.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/al/source.cpp b/al/source.cpp
index 7a739d3d..d39c1edc 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -2172,8 +2172,19 @@ try {
case AL_BUFFER:
CheckSize(1);
{
- ALbufferQueueItem *BufferList{(Source->SourceType == AL_STATIC)
- ? &Source->mQueue.front() : nullptr};
+ ALbufferQueueItem *BufferList{};
+ /* HACK: This query should technically only return the buffer set
+ * on a static source. However, some apps had used it to detect
+ * when a streaming source changed buffers, so report the current
+ * buffer's ID when playing.
+ */
+ if(Source->SourceType == AL_STATIC || Source->state == AL_INITIAL)
+ BufferList = &Source->mQueue.front();
+ else if(Voice *voice{GetSourceVoice(Source, Context)})
+ {
+ VoiceBufferItem *Current{voice->mCurrentBuffer.load(std::memory_order_relaxed)};
+ BufferList = static_cast<ALbufferQueueItem*>(Current);
+ }
ALbuffer *buffer{BufferList ? BufferList->mBuffer : nullptr};
values[0] = buffer ? static_cast<int>(buffer->id) : 0;
}