snd_pcm_hw_params_set_rate_near() will try to use the samplerate closest to the
given value, potentially starting the acquisition with a different samplerate
than the one specified.
Instead, use snd_pcm_hw_params_set_rate(). It will return an error if the
samplerate is not supported by the hardware, which is arguably better than
collecting data with a different samplerate than the one specified.
Signed-off-by: Alexandru Gagniuc <redacted>
sr_dbg("Setting audio samplerate to %" PRIu64 "Hz.",
devc->cur_samplerate);
- ret = snd_pcm_hw_params_set_rate_near(devc->capture_handle,
- devc->hw_params, (unsigned int *)&devc->cur_samplerate, 0);
+ ret = snd_pcm_hw_params_set_rate(devc->capture_handle, devc->hw_params,
+ (unsigned int)devc->cur_samplerate, 0);
if (ret < 0) {
sr_err("Can't set audio sample rate: %s.", snd_strerror(ret));
return SR_ERR;