Skip to content

Commit 781b4da

Browse files
perexgtiwai
authored andcommitted
ALSA: pcm: fix playback silence - correct incremental silencing
Commit 9a826dd ("[ALSA] pcm core: fix silence_start calculations") came with exactly the right commit message, but the patch just made things broken in a different way: We'd fill at a too low address if the area was already partially zeroed, so we'd under-fill. This affected both thresholded mode (where it was somewhat less likely) and top-up mode (where it would be the case consistently). Co-developed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz> Link: https://lore.kernel.org/r/20230505155244.2312199-3-oswald.buddenhagen@gmx.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 2fbaa44 commit 781b4da

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

sound/core/pcm_lib.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
8787
if (avail > runtime->buffer_size)
8888
avail = runtime->buffer_size;
8989
runtime->silence_filled = avail > 0 ? avail : 0;
90-
runtime->silence_start = (runtime->status->hw_ptr +
91-
runtime->silence_filled) %
92-
runtime->boundary;
90+
runtime->silence_start = runtime->status->hw_ptr;
9391
} else {
9492
ofs = runtime->status->hw_ptr;
9593
frames = new_hw_ptr - ofs;
@@ -98,18 +96,16 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
9896
runtime->silence_filled -= frames;
9997
if ((snd_pcm_sframes_t)runtime->silence_filled < 0) {
10098
runtime->silence_filled = 0;
101-
runtime->silence_start = new_hw_ptr;
102-
} else {
103-
runtime->silence_start = ofs;
10499
}
100+
runtime->silence_start = new_hw_ptr;
105101
}
106102
frames = runtime->buffer_size - runtime->silence_filled;
107103
}
108104
if (snd_BUG_ON(frames > runtime->buffer_size))
109105
return;
110106
if (frames == 0)
111107
return;
112-
ofs = runtime->silence_start % runtime->buffer_size;
108+
ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
113109
while (frames > 0) {
114110
transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
115111
err = fill_silence_frames(substream, ofs, transfer);

0 commit comments

Comments
 (0)