From 92c541ea0365e72eec17c81e0c50539da8e83ea6 Mon Sep 17 00:00:00 2001 From: Oschowa Date: Sun, 1 Nov 2020 18:44:14 +0100 Subject: [PATCH] pipewire-alsa: Make sure to always fill the pipewire buffers with silence on process if there is not enough data. This fixes noise with the retroarch alsa backend on pause, which doesn't actually pause the device. --- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index e0d91698a..009241f37 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -199,7 +199,6 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b, snd_pcm_uf } else { nframes = d[0].chunk->size / pw->stride; } - nframes = SPA_MIN(nframes, *hw_avail); if (pw->blocks == 1) { ptr = SPA_MEMBER(d[0].data, d[0].chunk->offset, void); @@ -224,14 +223,11 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b, snd_pcm_uf if (io->state == SND_PCM_STATE_RUNNING || io->state == SND_PCM_STATE_DRAINING) { snd_pcm_uframes_t hw_ptr = pw->hw_ptr; - if (*hw_avail > 0) { + xfer = SPA_MIN(nframes, *hw_avail); + if (xfer > 0) { const snd_pcm_channel_area_t *areas = snd_pcm_ioplug_mmap_areas(io); const snd_pcm_uframes_t offset = hw_ptr % io->buffer_size; - xfer = nframes; - if (xfer > *hw_avail) - xfer = *hw_avail; - if (io->stream == SND_PCM_STREAM_PLAYBACK) snd_pcm_areas_copy_wrap(pwareas, 0, nframes, areas, offset, @@ -249,6 +245,7 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b, snd_pcm_uf if (hw_ptr > pw->boundary) hw_ptr -= pw->boundary; pw->hw_ptr = hw_ptr; + *hw_avail -= xfer; } } /* check if requested frames were copied */ @@ -259,7 +256,6 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b, snd_pcm_uf snd_pcm_areas_silence(pwareas, xfer, io->channels, frames, io->format); - xfer += frames; } if (io->state == SND_PCM_STATE_RUNNING || io->state == SND_PCM_STATE_DRAINING) { @@ -267,7 +263,7 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b, snd_pcm_uf pw->xrun_detected = true; } } - *hw_avail -= xfer; + return 0; }