I'm trying to capture audio for a sip like application.
I want to get 20 milliseconds of audio at 8khz mono.
I need the application to get audio exactly every 20 milliseconds to avoid jitter.
I have set parameters as follows
I want the periods to be 2 and the buffer to be 320 (period_size*periods). However if I try to set either of these using:
Then I get -22 returned, which is -EINVAL
The period size specifies how often the hardware notifies your application that a complete period has been captured. It is a hardware parameter, which means that the hardware might not support the value that you want.
To get the period size that is nearest to your desired value, use snd_pcm_hw_params_set_period_size_near()
.
If you want to read 160 samples, just tell snd_pcm_read*()
to read 160 frames. However, if this does not match the period size, you will get jitter. If reducing jitter is important, you have to put the samples in your own queue and take them with
out with an appropriate timer.
Please note that capture latency depends only on the period size, not on the buffer size, so you should make the buffer as large as possible to reduce the risk of overruns.