From ccd68990ad16ecd1950f15ef99832803ad876ef5 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 3 Jul 2024 11:15:59 -0400 Subject: [PATCH] alsa-pcm: Lower the frequency of USB gadget rate updates While the spec allows for 1ppm changes, our rate matching logic applies these changes quite often, which can be spammy on USB. I haven't seen hosts mind this, but it seems like it might be a problem at some point. Additionally, if we also have bind ctls enabled, every pitch update is also a wakeup for ourselves (whether or not we're listening for the pitch ctls, since the mixer fd does not distinguish between ctls, those are filtered after we wake up). The 10ppm threshold is empirically tested as being not "too noisy" (i.e. when updates happen, I can see them scroll by with `amixer events`). If necessary, we can make this configurable in the future. --- spa/plugins/alsa/alsa-pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 2c4a19a7b..f07372f23 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -2292,8 +2292,10 @@ int spa_alsa_update_rate_match(struct state *state) last_pitch = (uint64_t)(1000000 / state->last_rate); } - /* The pitch adjustment is limited to 1 ppm */ - if (pitch == last_pitch) + /* The pitch adjustment is limited to 1 ppm according to the spec, but + * let's avoid very granular changes so that we don't spam the host + * (and ourselves, if bind-ctls are enabled). */ + if (SPA_ABS((int)pitch - (int)last_pitch) < 10) return 0; snd_ctl_elem_value_set_integer(state->pitch_elem, 0, pitch);