alsa: reset dll in prepare

When we do_prepare, always reset the dll. We already set the alsa_sync
field but that is only used by followers to resync in some cases.

When reseting the dll, we also reset the next_time and base_time values,
we however need to do this before calculating the error in update_time
when we are the driver in IRQ mode or else we get some crazy error
that distorts the rate estimation.
This commit is contained in:
Wim Taymans 2025-06-11 13:03:18 +02:00
parent b0462cb5de
commit 524da5962d

View file

@ -2571,6 +2571,7 @@ static int do_prepare(struct state *state)
state->alsa_sync = true;
state->alsa_sync_warning = false;
state->alsa_started = false;
spa_dll_init(&state->dll);
return 0;
}
@ -2797,6 +2798,12 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram
double err, corr, avg;
int32_t diff;
if (SPA_UNLIKELY(state->dll.bw == 0.0)) {
spa_dll_set_bw(&state->dll, SPA_DLL_BW_MAX, state->threshold, state->rate);
state->next_time = current_time;
state->base_time = current_time;
}
if (state->disable_tsched && !follower) {
err = (int64_t)(current_time - state->next_time);
err = err / 1e9 * state->rate;
@ -2807,11 +2814,6 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram
err = target - delay;
}
if (SPA_UNLIKELY(state->dll.bw == 0.0)) {
spa_dll_set_bw(&state->dll, SPA_DLL_BW_MAX, state->threshold, state->rate);
state->next_time = current_time;
state->base_time = current_time;
}
diff = (int32_t) (state->last_threshold - state->threshold);
if (SPA_UNLIKELY(diff != 0)) {
@ -2888,9 +2890,9 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram
state->clock->next_nsec = state->next_time;
}
spa_log_trace_fp(state->log, "%p: follower:%d %"PRIu64" %f %ld %ld %f %f %u",
state, follower, current_time, corr, delay, target, err, state->threshold * corr,
state->threshold);
spa_log_trace_fp(state->log, "%p: follower:%d %"PRIu64" %"PRIu64" %f %ld %ld %f %f %u",
state, follower, current_time, state->next_time, corr, delay, target,
err, state->threshold * corr, state->threshold);
return 0;
}