Re: Flushing issue (was: So, where'd the volume controls get to?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Samuel Thibault, le dim. 11 oct. 2020 17:16:40 +0200, a ecrit:
> Samuel Thibault, le dim. 11 oct. 2020 16:35:16 +0200, a ecrit:
> > Gregory Nowak, le sam. 10 oct. 2020 20:55:32 -0700, a ecrit:
> > > 4. Open the sound card with another application.
> > 
> > Oh, in that case I do get the mixture on my system indeed.
> 
> It seems the buffering is happening inside alsa's dmix then. Could you
> try the attached patch on pcaudiolib? (which is the one that configures
> the buffering)

And this version should be also fixing it for pulseaudio.

Samuel
---
 src/alsa.c       |    3 +++
 src/audio_priv.h |    4 ++++
 src/pulseaudio.c |    7 +++++++
 3 files changed, 14 insertions(+)

--- a/src/alsa.c
+++ b/src/alsa.c
@@ -99,6 +99,7 @@ alsa_object_open(struct audio_object *ob
 
 	snd_pcm_hw_params_t *params = NULL;
 	snd_pcm_hw_params_malloc(&params);
+	snd_pcm_uframes_t bufsize = (rate * channels * LATENCY) / 1000;
 
 	int err = 0;
 	if ((err = snd_pcm_open(&self->handle, self->device ? self->device : "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0)
@@ -113,6 +114,8 @@ alsa_object_open(struct audio_object *ob
 		goto error;
 	if ((err = snd_pcm_hw_params_set_channels(self->handle, params, channels)) < 0)
 		goto error;
+	if ((err = snd_pcm_hw_params_set_buffer_size_near(self->handle, params, &bufsize)) < 0)
+		goto error;
 	if ((err = snd_pcm_hw_params(self->handle, params)) < 0)
 		goto error;
 	if ((err = snd_pcm_prepare(self->handle)) < 0)
--- a/src/pulseaudio.c
+++ b/src/pulseaudio.c
@@ -74,6 +74,13 @@ pulseaudio_object_open(struct audio_obje
 	}
 
 	int error = 0;
+	pa_buffer_attr battr;
+
+	battr.fragsize = (uint32_t) -1;
+	battr.maxlength = (uint32_t) -1;
+	battr.minreq = (uint32_t) -1;
+	battr.prebuf = (uint32_t) -1;
+	battr.tlength = pa_bytes_per_second(&self->ss) * LATENCY / 1000;
 	self->s = pa_simple_new(NULL,
 	                        self->application_name,
 	                        PA_STREAM_PLAYBACK,
--- a/src/audio_priv.h
+++ b/src/audio_priv.h
@@ -52,6 +52,10 @@ struct audio_object
 	                         int error);
 };
 
+/* We try to aim for 10ms cancelation latency, which will be perceived as
+ * "snappy" by users */
+#define LATENCY 10
+
 #if defined(_WIN32) || defined(_WIN64)
 
 #include <windows.h>
_______________________________________________
Speakup mailing list
Speakup@xxxxxxxxxxxxxxxxx
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup

[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]

  Powered by Linux