From f2bafe84fe778728b81f236890946a51183098a1 Mon Sep 17 00:00:00 2001 From: borine <32966433+borine@users.noreply.github.com> Date: Fri, 11 Jun 2021 12:25:57 +0100 Subject: [PATCH] fix alsa hw params constraints Current pcm plugin code results in very strange buffer and period size selections if the application sets period size before buffer size. This simple fix corrects that issue. There does not appear to be any clue in the ALSA docs as to why the period size max needs to be so high, but looking at other io plugin examples they all appear to set the max period to at least 1MB and in testing this change always gives sensible values for both period and bufffer sizes. --- src/asound/bluealsa-pcm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/asound/bluealsa-pcm.c b/src/asound/bluealsa-pcm.c index 6221b2f9c..c165cf8e9 100644 --- a/src/asound/bluealsa-pcm.c +++ b/src/asound/bluealsa-pcm.c @@ -942,7 +942,11 @@ static int bluealsa_set_hw_constraint(struct bluealsa_pcm *pcm) { snd_pcm_format_physical_width(get_snd_pcm_format(pcm->ba_pcm.format)) / 8; if ((err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, - min_p, 1024 * 16)) < 0) + min_p, 1024 * 1024)) < 0) + return err; + + if ((err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, + 2 * min_p, 2 * 1024 * 1024)) < 0) return err; if ((err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS,