the ALSA state machine
Hello,
I am trying to debug some ALSA playback code. I have two playback
devices,. The first is A USB sound bar and the second is A Bluetooth sound bar. The issue I am debugging is truncated output on the Bluetooth sound bar. The USB sound bar works fine. I've added assertions to understand how my code may be getting out of sync with the ALSA state machine.
For reference, I am using the documentation at
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
After opening the device, I check its state and it is always in theSND_PCM_STATE_OPEN state, as expected. After initializing the h/w and s/w params, however, the document says I should be in the SND_PCM_STATE_SETUP state. Instead, however, I am in the SND_PCM_STATE_PREPARED state. I then call snd_pcm_prepare() and remain in the SND_PCM_STATE_PREPARED state. I then call snd_pcm_start(). In the USB version I get an -EPIPE error. In the Bluetooth code I do not get an error. Finally, I check the state before I exit my initialization code and I am in the SND_PCM_STATE_PREPARED, not the SND_PCM_STATE_RUNNING state. Evidently, the documentation and the code do not agree. Which is correct? It would be trivial to check the state and omit the snd_pcm_prepare() call if it is already in the prepared state. But I am trying to follow the document as closely as possible.
Thoughts?
David
Quoted 4 lines · On 8/9/26 00:47, [email protected] wrote:
Hello,
I am trying to debug some ALSA playback code. I have two playback
devices,. The first is A USB sound bar and the second is A Bluetooth sound bar. The issue I am debugging is truncated output on the Bluetooth sound
Quoted 8 lines
bar. The USB sound bar works fine. I've added assertions to understand how my code may be getting out of sync with the ALSA state machine.
For reference, I am using the documentation at
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
After opening the device, I check its state and it is always in theSND_PCM_STATE_OPENstate, as expected. After initializing the h/w and s/w params, however, the document says I should be in theSND_PCM_STATE_SETUPstate. Instead, however, I am in theSND_PCM_STATE_PREPAREDstate. I then
It's correct per snd_pcm_hw_params() documentation:
"""
* After this call, #snd_pcm_prepare() is called automatically and
* the stream is brought to \c #SND_PCM_STATE_PREPARED state.
"""
Quoted 2 lines
call
snd_pcm_prepare()and remain in theSND_PCM_STATE_PREPAREDstate. I then callsnd_pcm_start(). In the USB version I get an-EPIPEerror. In the
EPIPE usually means that there are not enough data (samples) in the ring buffer.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat