On Wed, 2015-02-25 at 19:43 +0100, Georg Chini wrote: > Move the timer restart to the beginning of the callback function. Please try to remember to always answer the question "why" in commit messages. > --- > Â src/modules/module-loopback.c | 14 ++++++++------ > Â 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c > index f9255ee..79bd106 100644 > --- a/src/modules/module-loopback.c > +++ b/src/modules/module-loopback.c > @@ -196,9 +196,6 @@ static void adjust_rates(struct userdata *u) { > Â Â Â Â Â pa_assert(u); > Â Â Â Â Â pa_assert_ctl_context(); > Â > -Â Â Â Â pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL); > -Â Â Â Â pa_asyncmsgq_send(u->source_output->source->asyncmsgq, PA_MSGOBJECT(u->source_output), SOURCE_OUTPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL); > - > Â Â Â Â Â /* Rates and latencies*/ > Â Â Â Â Â old_rate = u->sink_input->sample_spec.rate; > Â Â Â Â Â base_rate = u->source_output->sample_spec.rate; > @@ -236,8 +233,6 @@ static void adjust_rates(struct userdata *u) { > Â Â Â Â Â /* Set rate */ > Â Â Â Â Â pa_sink_input_set_rate(u->sink_input, new_rate); > Â Â Â Â Â pa_log_debug("[%s] Updated sampling rate to %lu Hz.", u->sink_input->sink->name, (unsigned long) new_rate); > - > -Â Â Â Â pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time); > Â } > Â > Â /* Called from main context */ > @@ -248,6 +243,13 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim > Â Â Â Â Â pa_assert(a); > Â Â Â Â Â pa_assert(u->time_event == e); > Â > +Â Â Â Â /* Restart timer right away */ > +Â Â Â Â pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time); If the goal of this change is to make the wakeups happen exactly with adjust_time intervals instead of adjust_time + time taken in servicing the timer interrupt, wouldn't it be better to have a counter of the timer events and use start_time + counter * adjust_time as the time value here? That way the average interval should become exactly adjust_time. > + > +Â Â Â Â /* Get sink and source latency snapshot */ > +Â Â Â Â pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL); > +Â Â Â Â pa_asyncmsgq_send(u->source_output->source->asyncmsgq, PA_MSGOBJECT(u->source_output), SOURCE_OUTPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL); > + > Â Â Â Â Â adjust_rates(u); > Â } > Â > @@ -257,7 +259,7 @@ static void enable_adjust_timer(struct userdata *u, bool enable) { > Â Â Â Â Â Â Â Â Â if (u->time_event || u->adjust_time <= 0) > Â Â Â Â Â Â Â Â Â Â Â Â Â return; > Â > -Â Â Â Â Â Â Â Â u->time_event = pa_core_rttime_new(u->module->core, pa_rtclock_now() + u->adjust_time, time_callback, u); > +Â Â Â Â Â Â Â Â u->time_event = pa_core_rttime_new(u->module->core, pa_rtclock_now() + 333 * PA_USEC_PER_MSEC, time_callback, u); What is this about? -- Tanu