Skip to content

Commit

Permalink
Compensate incorrect slope on start
Browse files Browse the repository at this point in the history
The first frames are typically received and decoded with more delay than
the others, causing a wrong slope estimation on start.

To compensate, assume an initial slope of 1, then progressively use the
estimated slope.
  • Loading branch information
rom1v committed Jul 13, 2021
1 parent 563d459 commit 285963f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,25 @@ sc_clock_estimate(struct sc_clock *clock,
.system = clock->right_sum.system / ((clock->count + 1) / 2),
.stream = clock->right_sum.stream / ((clock->count + 1) / 2),
};
double slope = (double) (right_avg.system - left_avg.system)
/ (right_avg.stream - left_avg.stream);

if (clock->count < SC_CLOCK_RANGE) {
/* The first frames are typically received and decoded with more delay
* than the others, causing a wrong slope estimation on start. To
* compensate, assume an initial slope of 1, then progressively use the
* estimated slope. */
slope = (clock->count * slope + (SC_CLOCK_RANGE - clock->count))
/ SC_CLOCK_RANGE;
}

struct sc_clock_point global_avg = {
.system = (clock->left_sum.system + clock->right_sum.system)
/ clock->count,
.stream = (clock->left_sum.stream + clock->right_sum.stream)
/ clock->count,
};

double slope = (double) (right_avg.system - left_avg.system)
/ (right_avg.stream - left_avg.stream);
sc_tick offset = global_avg.system - (sc_tick) (global_avg.stream * slope);

*out_slope = slope;
Expand Down

0 comments on commit 285963f

Please sign in to comment.