Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: John McKay <adenosine3p@gmail.com>
To: <alsa-devel@alsa-project.org>
Subject: [alsa-devel] [PATCH] Fix JACK plugin buffer sizes
Date: Sun, 27 Oct 2019 05:30:12 +0000	[thread overview]
Message-ID: <5db53218.1c69fb81.4bca1.5d88@mx.google.com> (raw)

I was having a conversation on the Archlinux forums[1] about using the
alsa-plugins JACK plugin. While one of the bugs that we found has
already been fixed in the git alsa-lib, there is another bug relating
to buffer sizes.

Currently snd_pcm_hw_params_set_buffer_size_near() doesn't really work
when you are using this plugin unless you happen to request a buffer
size that almost exactly matches a whole multiple of periods that the
JACK is asking for. After some debugging, I discovered the reason is
that some plugins, notably the 'plug' plugin that most everybody is
going to use to change frequency/format directly attempt to manipulate
the buffer size. This causes the code in pcm_ioplug.c to fail because it
cannot find a number of periods/period time that can fit the buffer.

The included patch stops this by specifying the list of acceptable
buffer sizes as well, so that when other plugins try to change the
buffer it always picks one that will work. It does have some problems
in the JACK plugin now offers a number of periods/sizes that don't
exist but in practice asking for huge buffers just seems to give you a
more sane value.

[1] https://bbs.archlinux.org/viewtopic.php?id=250116

--- jack/pcm_jack.c	2019-05-10 06:57:24.000000000 +0000
+++ jack/pcm_jack.c	2019-10-27 03:43:36.053734268 +0000
@@ -428,6 +428,7 @@
 	unsigned int format = SND_PCM_FORMAT_FLOAT;
 	unsigned int rate = jack_get_sample_rate(jack->client);
 	unsigned int psize_list[MAX_PERIODS_MULTIPLE];
+	unsigned int bsize_list[MAX_PERIODS_MULTIPLE];
 	unsigned int nframes = jack_get_buffer_size(jack->client);
 	unsigned int jack_buffer_bytes = (snd_pcm_format_size(format, nframes) *
 					  jack->num_ports);
@@ -441,6 +442,9 @@
 	for (i = 1; i <= ARRAY_SIZE(psize_list); i++)
 		psize_list[i-1] = jack_buffer_bytes * i;
 
+	for (i = 1; i <= ARRAY_SIZE(bsize_list); i++)
+		bsize_list[i-1] = jack_buffer_bytes * (i + 1);
+
 	jack->sample_bits = snd_pcm_format_physical_width(format);
 	if ((err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_ACCESS,
 						 ARRAY_SIZE(access_list), access_list)) < 0 ||
@@ -452,6 +456,8 @@
 						   rate, rate)) < 0 ||
 	    (err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_PERIOD_BYTES,
 						 ARRAY_SIZE(psize_list), psize_list)) < 0 ||
+	    (err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_BUFFER_BYTES,
+						 ARRAY_SIZE(bsize_list), bsize_list)) < 0 ||
 	    (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_PERIODS,
 						   2, 64)) < 0)
 		return err;


_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

                 reply	other threads:[~2019-10-27  5:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5db53218.1c69fb81.4bca1.5d88@mx.google.com \
    --to=adenosine3p@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox