OpenAL Source Stays AL_INITIALIZED After alSourcePlay With No Queued Buffer
0 reputation · 20 Oct 2020, 00:34 UTC
0 reputation · 20 Oct 2020, 00:34 UTC
Under the OpenAL 1.1 API as implemented by OpenAL Soft, a source normally moves to AL_PLAYING when alSourcePlay is called. With no buffer queued, it can remain AL_INITIALIZED, readable through alGetSourcei(source, AL_SOURCE_STATE). For a low-traffic workload playing short sounds infrequently, it is unclear whether repeated alSourcePlay calls on an idle source add measurable per-call overhead or whether the cost sits elsewhere.
Two design details complicate the choice. alSourceQueueBuffers copies buffer data on each call, so a queue-and-play pattern in a sparse loop may shift CPU cost toward copying rather than playback. Separately, OpenAL Soft selects the output device through AL_DEVICE_SPECIFIER, and device initialization can add startup latency that matters when sounds are rare.
The state and per-call cost are observable with alGetSourcei and timing, but the intended baseline for an unqueued source is not fully specified.
33275 reputation · 20 Oct 2020, 10:56 UTC
When alSourcePlay is invoked on a source that has no buffers queued, the source remains in the AL_INITIALIZED state and the call behaves as a no‑op. The only work done is a lightweight state check, so there is no recurring CPU cost tied to playback.
Because no buffer is queued, the mixer never receives data to process. The driver therefore returns immediately after verifying the source state, incurring only the cost of the state‑check path. No mixing, no device wake‑up, and no buffer copy occurs.
For low‑traffic workloads, keeping the source idle (no queued buffer) avoids the copy cost of alSourceQueueBuffers. The per‑play overhead is tiny and usually negligible compared to other work. If you prefer to keep the mixer active, queue a single‑sample silence buffer; the copy cost of that buffer is typically far smaller than the play‑call overhead.
Which OpenAL implementation (OpenAL Soft, Creative Labs, Apple OpenAL, etc.) are you targeting, as error handling for alSourcePlay with no buffers can differ between libraries?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.