+/**
+ * Set the samplerate of the ALSA device.
+ *
+ * Changes the samplerate of the given ALSA device if the specified samplerate
+ * is supported by the hardware.
+ *
+ * The new samplerate is recorded, but it is not applied to the hardware. The
+ * samplerate is applied to the hardware only when acquisition is started via
+ * dev_acquisition_start(), and cannot be changed during acquisition. To change
+ * the samplerate, several steps are needed:
+ *
+ * 1) If acquisition is running, it must first be stopped.
+ * 2) dev_config_set() must be called with the new samplerate.
+ * 3) When starting a new acquisition, the new samplerate is applied.
+ *
+ */
+SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi,
+ uint64_t newrate)
+{
+ struct dev_context *devc;
+ size_t i;
+ uint64_t rate = 0;
+
+ if (!(devc = sdi->priv))
+ return SR_ERR_ARG;
+
+ i = 0;
+ do {
+ if (newrate == devc->samplerates[i]) {
+ rate = newrate;
+ break;
+ }
+ } while (devc->samplerates[i++] != 0);
+
+ if (!rate) {
+ sr_err("Sample rate %" PRIu64 " not supported.", newrate);
+ return SR_ERR_ARG;
+ }
+
+ devc->cur_samplerate = rate;
+ return SR_OK;
+}
+