Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting audio data every 20 milliseconds in ALSA?

Tags:

audio

alsa

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.

like image 737
Xofo Avatar asked Oct 26 '22 05:10

Xofo


1 Answers

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).

like image 81
justin Avatar answered Oct 31 '22 13:10

justin