I have a program that does the following:
The program will periodically play any sound requests it receives, but occasionally the open will fail and return a "Device or resource busy" error. This typically happens when there are a lot of sound files. However, the close call is always successful. I would assume that if the close was successful that the PCM would be immediately available for anyone else to use. I should also add that there is nothing else on the system using sound.
Could it be possible that ALSA still needs to clean up some resources after the close? Is the PCM interface not designed to be opened and closed that often? Most examples on the Internet open the PCM stream at start up and close it at shut down.
Do not close and open this often. You could use
snd_pcm_open() and snd_pcm_close() only once (start and end of your application) and use this when you want to reset your streams:
snd_pcm_drop()
and
snd_pcm_prepare()
Normally this shouldn't be a problem at all, since dmix can handle several streams. However, if you're using direct hw:0 access, the close() step might be asynchronous in some way, that an immediate open() might not work too well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With