alsa-pcm: scale max_error with quantum size

Adjust the max-error between the hardware delay and the quantum. Limit
this between 256 and quantum/2 to make sure we are not too sensitive.
This commit is contained in:
Wim Taymans 2022-05-11 10:34:27 +02:00
parent e6c2ac3450
commit 9d186cf622
2 changed files with 12 additions and 14 deletions

View file

@ -1873,6 +1873,7 @@ static inline void check_position_config(struct state *state)
state->duration = state->position->clock.duration;
state->rate_denom = state->position->clock.rate.denom;
state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom;
state->max_error = SPA_MAX(256.0f, state->threshold / 2.0f);
state->resample = ((uint32_t)state->rate != state->rate_denom) || state->matching;
state->alsa_sync = true;
}
@ -2412,11 +2413,10 @@ int spa_alsa_start(struct state *state)
state->following = is_following(state);
setup_matching(state);
spa_dll_init(&state->dll);
state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom;
state->last_threshold = state->threshold;
spa_dll_init(&state->dll);
state->max_error = (256.0 * state->rate) / state->rate_denom;
state->max_error = SPA_MAX(256.0f, state->threshold / 2.0f);
spa_log_debug(state->log, "%p: start %d duration:%d rate:%d follower:%d match:%d resample:%d",
state, state->threshold, state->duration, state->rate_denom,