diff --git a/sourcestats.c b/sourcestats.c index 7dfc9db..900dc60 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -779,6 +779,22 @@ SST_SlewSamples(SST_Stats inst, struct timespec *when, double dfreq, double doff /* ================================================== */ +void +SST_CorrectOffset(SST_Stats inst, double doffset) +{ + int i; + + if (!inst->n_samples) + return; + + for (i = -inst->runs_samples; i < inst->n_samples; i++) + inst->offsets[get_runsbuf_index(inst, i)] += doffset; + + inst->estimated_offset += doffset; +} + +/* ================================================== */ + void SST_AddDispersion(SST_Stats inst, double dispersion) { diff --git a/sourcestats.h b/sourcestats.h index bb5fb71..7a551e6 100644 --- a/sourcestats.h +++ b/sourcestats.h @@ -102,6 +102,10 @@ SST_GetTrackingData(SST_Stats inst, struct timespec *ref_time, extern void SST_SlewSamples(SST_Stats inst, struct timespec *when, double dfreq, double doffset); +/* This routine corrects already accumulated samples to improve the + frequency estimate when a new sample is accumulated */ +extern void SST_CorrectOffset(SST_Stats inst, double doffset); + /* This routine is called when an indeterminate offset is introduced into the local time. */ extern void SST_AddDispersion(SST_Stats inst, double dispersion);