On 04.08.2017 15:37, Tanu Kaskinen wrote: > On Mon, 2017-04-17 at 21:37 +0200, Georg Chini wrote: >> @@ -327,11 +335,20 @@ static void adjust_rates(struct userdata *u) { >> } >> >> /* Allow one underrun per hour */ >> - if (u->iteration_counter * u->adjust_time / PA_USEC_PER_SEC / 3600 > run_hours) { >> + if (u->iteration_counter * u->real_adjust_time / PA_USEC_PER_SEC / 3600 > run_hours) { >> u->underrun_counter = PA_CLIP_SUB(u->underrun_counter, 1u); >> pa_log_info("Underrun counter: %u", u->underrun_counter); >> } >> >> + /* Calculate real adjust time */ >> + now = pa_rtclock_now(); >> + if (!u->source_sink_changed) { >> + u->adjust_counter++; >> + u->real_adjust_time_sum += now - u->adjust_time_stamp; >> + u->real_adjust_time = u->real_adjust_time_sum / u->adjust_counter; >> + } >> + u->adjust_time_stamp = now; >> + >> /* Rates and latencies*/ >> old_rate = u->sink_input->sample_spec.rate; >> base_rate = u->source_output->sample_spec.rate; >> @@ -364,7 +381,9 @@ static void adjust_rates(struct userdata *u) { >> pa_log_debug("Loopback latency at base rate is %0.2f ms", (double)latency_at_optimum_rate / PA_USEC_PER_MSEC); >> >> /* Calculate new rate */ >> - new_rate = rate_controller(base_rate, u->adjust_time, latency_difference); >> + new_rate = rate_controller(base_rate, u->real_adjust_time, latency_difference); >> + >> + u->source_sink_changed = false; > This "source_sink_changed = false" assignment would be better right > after the code that checks its value, at least based on this patch > alone. But maybe later patches use this variable too in a way that > makes this suggestion less good? > > Otherwise looks fine. > Yes, the variable is later user within rate_controller(). Also there will be other variables that indicate state changes between two calls of adjust_rate() (for example if the latency offset changed). I'll push the patch to next as is if you have no objection.