From 7057cca05e246567f6927914cd027a8daa5cf8db Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 7 Sep 2022 21:58:32 +0200 Subject: [PATCH] alsa: adjust min and max rates Use the DSD scaler and interleave factors to calculate the min and max rates. --- spa/plugins/alsa/alsa-pcm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 829db8f75..fb68bbf27 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -782,7 +782,7 @@ static bool uint32_array_contains(uint32_t *vals, uint32_t n_vals, uint32_t val) return false; } -static int add_rate(struct state *state, uint32_t scale, uint32_t rate, bool all, uint32_t index, uint32_t *next, +static int add_rate(struct state *state, uint32_t scale, uint32_t interleave, bool all, uint32_t index, uint32_t *next, uint32_t min_allowed_rate, snd_pcm_hw_params_t *params, struct spa_pod_builder *b) { struct spa_pod_frame f[1]; @@ -794,10 +794,11 @@ static int add_rate(struct state *state, uint32_t scale, uint32_t rate, bool all CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min"); CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max"); - spa_log_debug(state->log, "min:%u max:%u min-allowed:%u all:%d", - min, max, min_allowed_rate, all); + spa_log_debug(state->log, "min:%u max:%u min-allowed:%u scale:%u interleave:%u all:%d", + min, max, min_allowed_rate, scale, interleave, all); - min = SPA_MAX(min_allowed_rate, min); + min = SPA_MAX(min_allowed_rate * scale / interleave, min); + max = max * interleave / scale; if (max < min) return 0; @@ -1069,7 +1070,7 @@ static int enum_pcm_formats(struct state *state, uint32_t index, uint32_t *next, choice->body.type = SPA_CHOICE_Enum; spa_pod_builder_pop(b, &f[1]); - if ((res = add_rate(state, 1, false, index & 0xffff, next, 0, params, b)) != 1) + if ((res = add_rate(state, 1, 1, false, index & 0xffff, next, 0, params, b)) != 1) return res; if ((res = add_channels(state, false, index & 0xffff, next, params, b)) != 1) @@ -1164,7 +1165,7 @@ static int enum_iec958_formats(struct state *state, uint32_t index, uint32_t *ne } spa_pod_builder_pop(b, &f[1]); - if ((res = add_rate(state, 1, true, index & 0xffff, next, 0, params, b)) != 1) + if ((res = add_rate(state, 1, 1, true, index & 0xffff, next, 0, params, b)) != 1) return res; (*next)++; @@ -1228,7 +1229,8 @@ static int enum_dsd_formats(struct state *state, uint32_t index, uint32_t *next, * 176400. This would correspond to "DSD32" (which does not exist). Trying * to use such a rate with DSD hardware does not work and may cause undefined * behavior in said hardware. */ - if ((res = add_rate(state, 8, true, index & 0xffff, next, 44100, params, b)) != 1) + if ((res = add_rate(state, 8, SPA_ABS(interleave), true, index & 0xffff, + next, 44100, params, b)) != 1) return res; if ((res = add_channels(state, true, index & 0xffff, next, params, b)) != 1)