summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-07-24 16:29:59 +0200
committerRobin Gareus <robin@gareus.org>2019-07-24 16:40:32 +0200
commit0fe3cba8b131ca1196ef30c0ccb5acb914817276 (patch)
tree5b826a8f881addf6a334306b955b315bd602100c
parent31ec8ce7d18e36d3c765beeb0445eb946373addf (diff)
Fix ALSA available buffersize detection:
buffer-size = periods * period-size Previously, buffersize was used for period-size. This fixes an issue with a dedicated .asoundrc configuring a specific period-size or buffer-size that has to be exact. Ardour's device configuration failed in this case. This has not been an issues since most hardware devices offer a wide range: 8 < period-size < 262144 ; 16 < buffer-size < 524288. Only a subset of which (32 .8192) is allowed by Ardour.
-rw-r--r--libs/ardouralsautil/deviceparams.cc58
1 files changed, 56 insertions, 2 deletions
diff --git a/libs/ardouralsautil/deviceparams.cc b/libs/ardouralsautil/deviceparams.cc
index 2e9f121a15..381f5b8f75 100644
--- a/libs/ardouralsautil/deviceparams.cc
+++ b/libs/ardouralsautil/deviceparams.cc
@@ -33,6 +33,10 @@ ARDOUR::get_alsa_device_parameters (const char* device_name, const bool play, AL
nfo->valid = false;
+ unsigned long min_psiz, max_psiz;
+ unsigned long min_bufz, max_bufz;
+ unsigned int min_nper, max_nper;
+
err = snd_pcm_open (&pcm, device_name,
play ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE,
SND_PCM_NONBLOCK);
@@ -66,17 +70,67 @@ ARDOUR::get_alsa_device_parameters (const char* device_name, const bool play, AL
goto error_out;
}
- err = snd_pcm_hw_params_get_buffer_size_min (hw_params, &nfo->min_size);
+ err = snd_pcm_hw_params_get_period_size_min (hw_params, &min_psiz, 0);
+ if (err < 0) {
+ errmsg = "Cannot get minimum period size";
+ goto error_out;
+ }
+ err = snd_pcm_hw_params_get_period_size_max (hw_params, &max_psiz, 0);
+ if (err < 0) {
+ errmsg = "Cannot get maximum period size";
+ goto error_out;
+ }
+
+ err = snd_pcm_hw_params_get_buffer_size_min (hw_params, &min_bufz);
if (err < 0) {
errmsg = "Cannot get minimum buffer size";
goto error_out;
}
- err = snd_pcm_hw_params_get_buffer_size_max (hw_params, &nfo->max_size);
+ err = snd_pcm_hw_params_get_buffer_size_max (hw_params, &max_bufz);
if (err < 0) {
errmsg = "Cannot get maximum buffer size";
goto error_out;
}
+
+ err = snd_pcm_hw_params_get_periods_min (hw_params, &min_nper, 0);
+ if (err < 0) {
+ errmsg = "Cannot get minimum period count";
+ goto error_out;
+ }
+ err = snd_pcm_hw_params_get_periods_max (hw_params, &max_nper, 0);
+ if (err < 0) {
+ errmsg = "Cannot get maximum period count";
+ goto error_out;
+ }
+
snd_pcm_close (pcm);
+
+ /* see also libs/backends/alsa/zita-alsa-pcmi.cc
+ * If any debug parameter is set, print device info.
+ */
+ if (getenv ("ZITA_ALSA_PCMI_DEBUG")) {
+ fprintf (stdout, "ALSA: *%s* device-info\n", play ? "playback" : "capture");
+ fprintf (stdout, " dev_name : %s\n", device_name);
+ fprintf (stdout, " channels : %u\n", nfo->max_channels);
+ fprintf (stdout, " min_rate : %u\n", nfo->min_rate);
+ fprintf (stdout, " max_rate : %u\n", nfo->max_rate);
+ fprintf (stdout, " min_psiz : %lu\n", nfo->min_size);
+ fprintf (stdout, " max_psiz : %lu\n", nfo->max_size);
+ fprintf (stdout, " min_bufz : %lu\n", min_bufz);
+ fprintf (stdout, " max_bufz : %lu\n", max_bufz);
+ fprintf (stdout, " min_nper : %d\n", min_nper);
+ fprintf (stdout, " max_nper : %d\n", max_nper);
+ fprintf (stdout, " possible : %lu .. %lu\n", nfo->min_size, nfo->max_size);
+ }
+
+ /* AlsaAudioBackend supports n-periods 2, 3 */
+ if (min_nper > 2 || max_nper < 3) {
+ errmsg = "Unsupported period count";
+ return 1;
+ }
+
+ nfo->min_size = std::max (min_psiz, min_bufz / 3);
+ nfo->max_size = std::min (max_psiz, max_bufz / 2);
nfo->valid = true;
return 0;