Playing with the ALSA sound library.
I have a mutlithreaded application with its own audio I/O thread.
I’d like to be able to quickly reset an audio clip to start playing from
its beginning.
Attempt 1) Single write thread doing the playing. Use
‘snd_pcm_playback_drain’ (on another thread) to immediately cutoff the
sound. Works great, except the write thread takes way too much time
to pop back out, so I can submit a new write.
Attempt 2) Multiple write threads. Every time I want to reset the
audio, I ‘snd_pcm_playback_drain’ and then start up a new write thread
(using the same handle). Audio gets garbled.
Attempt 3) Multiple write threads, multiple handle. Every time I want
to reset the audio, I ‘snd_pcm_playback_drain’ then start up a new
thread, doing another ‘snd_pcm_open’ for each thread. Works great,
… however seems to have a handle limit, as the ‘snd_pcm_open’
blocks after something like 4-6 opens, waiting for one of the other
handles to free up. Not good as I’m back to waiting for the write
thread to pop out, so I can close the handle its using.
Any other ideas? Is there a way to interrupt the write? I’d like to
stay with a single thread, if possible, but I don’t like the delay that
it takes to finally pop out of the write. Will it help if I boost the
priority of the write thread? I’m quickly running out of other things
to try, so thought I’d ask here.
Regards,
Jon Grimm