I have a C ++ object that accepts audio requests and plays them using ALSA. There is a thread that handles audio requests. Some sounds are periodic and carry over after the contents of the wav file has been recorded in the ALSA library. Is there any way to know when all the data has been reproduced? The snd_pcm_writei function is a blocking recording function, but this does not necessarily mean that the file was played.
One option I'm considering is to call snd_pcm_drain after playing each sound file, and then call snd_pcm_prepare when playing the next file. Would this be a good solution? Or is it ineffective?
Update: "Drain solution" seems to work, but is not very effective. The call takes some time (maybe it clears some resources) and adds latency to the program. The delay is best seen when I play many small files in sequence. Between each files you can hear a few seconds of silence; this is done by snd_pcm_drain.
c ++ alsa
waffleman
source share