'What determines the permitted period sizes for ALSA (libasound2)?
I am attempting to write low-latency ALSA code (on a Raspberry Pi, if that makes a difference). Based on my current understanding:
- The maximum latency has a lower-bound equal to the interrupt frequency
- The interrupt frequency is inversely proportional to the sampling rate and directly proportional to the buffer size.
- The maximum sampling rate is determined by the ADC hardware.
- The buffer size is factored into period_size * n_periods.
I do not know what determines what period and buffer sizes exist in the configuration space (nor how to output the extent of the configuration space).
Having set the sampling rate to the maximum allowed, I am attempting to lower latency by setting a small period size as follows:
// error-checking removed for brevity
int rate = 68880, n_periods = 2, period_size = 4096;
snd_pcm_hw_params_set_format(pcm, params, SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(pcm, params, &rate, NULL);
snd_pcm_hw_params_set_channels(pcm, params, 2);
snd_pcm_hw_params_set_periods(pcm, params, n_periods, 0);
snd_pcm_hw_params_set_buffer_size(pcm, params, (period_size * n_periods) / 4);
snd_pcm_hw_params_set_buffer_size fails with code -22 (Invalid argument) if period_size < 4096. (Decreasing period_size and increasing n_periods proportionally to keep buffer size constant doesn't help, so presumably period size is the issue.) Running the program with realtime priority via chrt -r 99 ./foo doesn't seem to change anything.
What determines the which period sizes exist within ALSA's configuration space?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
