Skip to content

Commit 2fbaa44

Browse files
perexgtiwai
authored andcommitted
ALSA: pcm: fix playback silence - use the actual new_hw_ptr for the threshold mode
The snd_pcm_playback_hw_avail() function uses runtime->status->hw_ptr. Unfortunately, in case when we call this function from snd_pcm_update_hw_ptr0(), this variable contains the previous hardware pointer. Use the new_hw_ptr argument to calculate hw_avail (filled samples by the user space) to correct the threshold comparison. The new_hw_ptr argument may also be set to ULONG_MAX which means the initialization phase. In this case, use runtime->status->hw_ptr. Suggested-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Link: https://lore.kernel.org/r/20230505155244.2312199-2-oswald.buddenhagen@gmx.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent d7f5dd9 commit 2fbaa44

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sound/core/pcm_lib.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
6363
}
6464
if (runtime->silence_filled >= runtime->buffer_size)
6565
return;
66-
noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
66+
/* initialization outside pointer updates */
67+
if (new_hw_ptr == ULONG_MAX)
68+
new_hw_ptr = runtime->status->hw_ptr;
69+
/* get hw_avail with the boundary crossing */
70+
noise_dist = appl_ptr - new_hw_ptr;
71+
if (noise_dist < 0)
72+
noise_dist += runtime->boundary;
73+
/* total noise distance */
74+
noise_dist += runtime->silence_filled;
6775
if (noise_dist >= (snd_pcm_sframes_t) runtime->silence_threshold)
6876
return;
6977
frames = runtime->silence_threshold - noise_dist;

0 commit comments

Comments
 (0)