From d05905f871a7442d27299ee467dde09c9a428c21 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 4 Jun 2026 16:54:37 +0200 Subject: [PATCH] alsa: avoid rounding down period_size Only try to round down the period_size to the lowest power of 2 when we are resampling and scaling the period_size to match. In all other cases, we should honour the requested quantum duration. Fixes #5302 --- spa/plugins/alsa/alsa-pcm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 3b4feaf5e..d2c10ac74 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -2441,9 +2441,15 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ /* no period size specified. If we are batch or forcing our quantum, * use the graph requested quantum scaled by our rate */ if (period_size == 0 && (state->is_batch || state->force_quantum) && state->position) { - period_size = SPA_SCALE32_UP(state->position->clock.target_duration, - state->rate, state->position->clock.target_rate.denom); - period_size = flp2(period_size); + period_size = state->position->clock.target_duration; + /* only if we are rate adjusting, scale the period size and round down + * to a power of two. */ + if (state->position->clock.target_rate.denom != 0 && + state->rate != (int)state->position->clock.target_rate.denom) { + period_size = SPA_SCALE32_UP(period_size, + state->rate, state->position->clock.target_rate.denom); + period_size = flp2(period_size); + } } if (period_size == 0) period_size = default_period;