tags:

views:

29

answers:

1

I would like to call snd_pcm_readi() and get AUDIO DATA every 20 ms or every 40 ms. I want to know how to get my data synchronously ... that is every X ms ...

Thanks for any responses.

+1  A: 

for realtime audio read or playback, you'll typically create a dedicated high priority worker thread to call from, and then utilize a few ring buffers. your thread should avoid locking.

alsa examples:

http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2latency_8c-example.html#a36

http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html

if you're simply reading from disk, you'll want ample buffer, then just wake up and see if you need to read more before the next time you wake up (considering total latency).

Justin
Is snd_pcm_wait() the function I need to call? I am still not so clear?
Xofo
@Xofo sorry, the question is waaay to broad for me to answer in a reasonable amount of time (or succinctly) -- i don't even know what you're doing with the audio (filling/copying, generating, processing, reading from disk, reading from a number of other sources). it would help to add a lot of detail to your post. the docs may answer some of your high level questions (with notes on notifications, and how alsa handles data exchanges - snd_pcm_wait may be what you want, if you need only a poll routine in a simple program): http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html
Justin