summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2023-05-05 17:52:42 +0200
committerTakashi Iwai <tiwai@suse.de>2023-05-05 18:23:52 +0200
commit6d8d56db0cd14c415c26e27d949c615750c40d70 (patch)
tree1ecb903a9fcccc10a10d1af329dafe0b318045fc /sound
parent190cb66a4ee0ac4419e1f8a9de46074a8c8e4c23 (diff)
ALSA: pcm: playback silence - move silence variable updates to separate function
The code tracking the added samples in thresholded mode and the code tracking the just played samples in top-up mode are semantically identical, so factor it out to a common function to enhance readability. 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-5-oswald.buddenhagen@gmx.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/core/pcm_lib.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index a1838130c830..670572c9a8cc 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -33,6 +33,25 @@
static int fill_silence_frames(struct snd_pcm_substream *substream,
snd_pcm_uframes_t off, snd_pcm_uframes_t frames);
+
+static inline void update_silence_vars(struct snd_pcm_runtime *runtime,
+ snd_pcm_uframes_t ptr,
+ snd_pcm_uframes_t new_ptr)
+{
+ snd_pcm_sframes_t delta;
+
+ delta = new_ptr - ptr;
+ if (delta == 0)
+ return;
+ if (delta < 0)
+ delta += runtime->boundary;
+ if ((snd_pcm_uframes_t)delta < runtime->silence_filled)
+ runtime->silence_filled -= delta;
+ else
+ runtime->silence_filled = 0;
+ runtime->silence_start = new_ptr;
+}
+
/*
* fill ring buffer with silence
* runtime->silence_start: starting pointer to silence area
@@ -49,18 +68,9 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
int err;
if (runtime->silence_size < runtime->boundary) {
- snd_pcm_sframes_t noise_dist, n;
+ snd_pcm_sframes_t noise_dist;
snd_pcm_uframes_t appl_ptr = READ_ONCE(runtime->control->appl_ptr);
- if (runtime->silence_start != appl_ptr) {
- n = appl_ptr - runtime->silence_start;
- if (n < 0)
- n += runtime->boundary;
- if ((snd_pcm_uframes_t)n < runtime->silence_filled)
- runtime->silence_filled -= n;
- else
- runtime->silence_filled = 0;
- runtime->silence_start = appl_ptr;
- }
+ update_silence_vars(runtime, runtime->silence_start, appl_ptr);
/* initialization outside pointer updates */
if (new_hw_ptr == ULONG_MAX)
new_hw_ptr = runtime->status->hw_ptr;
@@ -87,15 +97,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
runtime->silence_filled = avail > 0 ? avail : 0;
runtime->silence_start = runtime->status->hw_ptr;
} else {
- ofs = runtime->status->hw_ptr;
- frames = new_hw_ptr - ofs;
- if ((snd_pcm_sframes_t)frames < 0)
- frames += runtime->boundary;
- runtime->silence_filled -= frames;
- if ((snd_pcm_sframes_t)runtime->silence_filled < 0) {
- runtime->silence_filled = 0;
- }
- runtime->silence_start = new_hw_ptr;
+ update_silence_vars(runtime, runtime->status->hw_ptr, new_hw_ptr);
}
frames = runtime->buffer_size - runtime->silence_filled;
}