fix audiostream cutouts from openal buffer underrun#7456
Conversation
When a streaming OpenAL source plays through all queued buffers it transitions to AL_STOPPED. Per the spec, queueing more buffers after that does not auto-resume playback -- alSourcePlay must be called again. This is the likely cause of music and briefing voices cutting out. To fix this, check for underrun and call alSourcePlay if needed. Also double MAX_STREAM_BUFFERS from 4 to 8, bumping the margin to ~2s of queued audio. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
03f6b79 to
1245546
Compare
|
MAX_STREAM_BUFFERS should not be changed. Each buffer is intended to contain 1 second of audio, so you're bumping it from 4 seconds to 8 seconds, not 2 seconds. It is dependent on the audio format of course, with the current setup being for 1 second of 44.1kHz stereo per buffer (as defined by So increasing I should point out that the SDL3 audio changes (maybe for 26.0) should eliminate this problem as well as it doesn't have the same shortcoming. But that doesn't change the need for this PR in the meantime. |
Sorry, that made no sense. Basically you want |
|
Claude is pushing back:
So the |
|
Ahh, I looked for it to divide by MAX_STREAM_BUFFERS before I said anything and assumed it used the full size when I didn't find it. Honestly that seems like something I would do and not comment on it. :( But Claude is correct and if it gets capped at all then there's a chance for it to underrun. I'd still recommend bumping BIGBUF_SIZE over adding MAX_STREAM_BUFFERS though. Having more stream buffers of a smaller size tends to result in audio issues (crackling, static, etc.) when it transitions between buffers due to alignment and what not. |
|
Oh, is the Claude would like to politely disagree with the max buffers vs size claim:
But this is separate from the actual fix, so I can take that out of the PR if you want. |
|
Hmm, my brain is mush I think. Far too many versions of that code in too many code bases for me to keep it straight any longer. It all makes sense that it's right, and all makes sense that it's wrong. 🤷 So I think this is fine based on Claude + the few brain cells I can muster to look at audiostr. |
When a streaming OpenAL source plays through all queued buffers it transitions to AL_STOPPED. Per the spec, queueing more buffers after that does not auto-resume playback -- alSourcePlay must be called again. This is the likely cause of music and briefing voices cutting out.
To fix this, check for underrun and call alSourcePlay if needed. Also double MAX_STREAM_BUFFERS from 4 to 8, bumping the margin to ~2s of queued audio.
Tested with menu and mission audio; also tested with a forced underrun to prove that underrun recovery works successfully.