From 6fb53fc9f1b25d2924f8f3e01ef14a2b8e489212 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 31 Aug 2023 17:22:38 +0200 Subject: [PATCH] alsa: round to next power of 2 for max period_size Prefer to make the period_size bigger rather than smaller because of rate conversion. --- spa/plugins/alsa/alsa-pcm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 2a0ac8281..d8dee9d2d 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1663,7 +1663,8 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ period_size = state->default_period_size; is_batch = snd_pcm_hw_params_is_batch(params) && !state->disable_batch; - default_period = flp2(SPA_SCALE32_UP(DEFAULT_PERIOD, state->rate, DEFAULT_RATE)); + default_period = SPA_SCALE32_UP(DEFAULT_PERIOD, state->rate, DEFAULT_RATE); + default_period = flp2(2 * default_period - 1); /* no period size specified. If we are batch or not using timers, * use the graph duration as the period */