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.
This commit is contained in:
Arun Raghavan 2024-07-03 11:15:59 -04:00
parent 0c5b2f1154
commit 9cd2bbc585

View file

@ -2352,8 +2352,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);