All,
When I play regular PCM audio through the HDMI that's connected to my amplifier I noticed buggy behaviour when using the snd_pcm_drain() call.
From my understanding of ALSA, during playback snd_pcm_drain() normally
blocks until the playback buffer is empty.
Here's what I'm experiencing:
a. If the PCM handle is in BLOCKING mode, the snd_pcm_drain() function will block indefinitely (I've waited 30 seconds, before I gave up).
b. In NON-BLOCKING mode, the first call to snd_pcm_drain results in a " Resource temporarily unavailable", subsequent call works but the pcm state has changed to DRAINING and takes about 1 sec to change to SETUP. Even though the audio has less than 0.5 seconds of actual playback left.
So to make it work, I changed my single snd_pcm_drain() call into the following pseudo code: while(state==RUNNING && snd_pcm_drain()<0) { state=snd_pcm_state() }
while(state==DRAINING && sleep(100)){ state=snd_pcm_state() }
Even though this seem to "sort of work", another problem with this approach I've noticed, is that part of the beginning of the playback buffer may be replayed at the end of the drain:
1. start playback at beginning of file 2. seek to close to the end of the file (snd_pcm_drop() gets called) 3. end of file reached, drain gets called, hear the end of the song + part of the beginning again?
So I'm wondering whether this may be related to the drain issue I've noticed. I've attached the alsa-info.
Thanks,
Sander