* [PATCH] ALSA: sparc: cs4231: Require an integer number of periods
@ 2026-12-01 21:15 Stian Halseth
2026-12-02 8:32 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Stian Halseth @ 2026-12-01 21:15 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, linux-sound, sparclinux, linux-kernel,
Stian Halseth, stable
The DMA engine is fed one period at a time. snd_cs4231_advance_dma()
wraps after runtime->periods periods. Nothing requires the buffer to
be a whole number of periods. When it is not, the DMA ring ends before
the buffer does. The frames in the tail are never played. On capture,
the tail is never filled.
Any application that sets its own buffer and period sizes can hit
this. Buffer and period times can also round to such sizes. A minimal
case:
aplay -D hw:0 -t raw -f S16_BE -c 2 -r 48000 \
--buffer-size=8192 --period-size=2016 /dev/zero
The DMA wraps after 8064 frames, but ALSA counts each wrap as a full
pass of 8192 frames. On a Sun Ultra 5, hw_ptr in the substream's proc
status advances 48781 frames/s, against 48020 with 2048-frame periods.
With music the skipped frames are heard as distortion. This was found
with Audacious, which picks such sizes by default on this card.
Add the integer periods constraint, as other drivers that program DMA
per period do.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://github.com/sparclinux/issues/issues/134
Cc: stable@vger.kernel.org
Signed-off-by: Stian Halseth <stian@itx.no>
---
sound/sparc/cs4231.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 0489eac16..a2b414318 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -1094,6 +1094,10 @@ static int snd_cs4231_playback_open(struct snd_pcm_substream *substream)
runtime->hw = snd_cs4231_playback;
+ err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0)
+ return err;
+
err = snd_cs4231_open(chip, CS4231_MODE_PLAY);
if (err < 0)
return err;
@@ -1113,6 +1117,10 @@ static int snd_cs4231_capture_open(struct snd_pcm_substream *substream)
runtime->hw = snd_cs4231_capture;
+ err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0)
+ return err;
+
err = snd_cs4231_open(chip, CS4231_MODE_RECORD);
if (err < 0)
return err;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: sparc: cs4231: Require an integer number of periods
2026-12-01 21:15 [PATCH] ALSA: sparc: cs4231: Require an integer number of periods Stian Halseth
@ 2026-12-02 8:32 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-12-02 8:32 UTC (permalink / raw)
To: Stian Halseth
Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, sparclinux,
linux-kernel, stable
On Tue, 01 Dec 2026 22:15:14 +0100,
Stian Halseth wrote:
>
> The DMA engine is fed one period at a time. snd_cs4231_advance_dma()
> wraps after runtime->periods periods. Nothing requires the buffer to
> be a whole number of periods. When it is not, the DMA ring ends before
> the buffer does. The frames in the tail are never played. On capture,
> the tail is never filled.
>
> Any application that sets its own buffer and period sizes can hit
> this. Buffer and period times can also round to such sizes. A minimal
> case:
>
> aplay -D hw:0 -t raw -f S16_BE -c 2 -r 48000 \
> --buffer-size=8192 --period-size=2016 /dev/zero
>
> The DMA wraps after 8064 frames, but ALSA counts each wrap as a full
> pass of 8192 frames. On a Sun Ultra 5, hw_ptr in the substream's proc
> status advances 48781 frames/s, against 48020 with 2048-frame periods.
> With music the skipped frames are heard as distortion. This was found
> with Audacious, which picks such sizes by default on this card.
>
> Add the integer periods constraint, as other drivers that program DMA
> per period do.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Closes: https://github.com/sparclinux/issues/issues/134
> Cc: stable@vger.kernel.org
> Signed-off-by: Stian Halseth <stian@itx.no>
Applied to for-next branch. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 21:15 [PATCH] ALSA: sparc: cs4231: Require an integer number of periods Stian Halseth
2026-12-02 8:32 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox