X-Git-Url: https://git.sesse.net/?p=audiosync;a=blobdiff_plain;f=estimate-skew.c;h=d2991fc32cafe04f89a5d921951ee3afce2f8e7c;hp=1c44f864ca9fed96a26f8c195edf7e70573741eb;hb=eacd887c25d1ddde6f165513e9fd1f4a0c5b8afc;hpb=f0d94272ccbb005ef20ddf9140fa3b4fa4fcf7c9 diff --git a/estimate-skew.c b/estimate-skew.c index 1c44f86..d2991fc 100644 --- a/estimate-skew.c +++ b/estimate-skew.c @@ -11,7 +11,7 @@ double frac(double x) double filter(double x) { static double l = 0.0; - l = 0.001 * x + 0.999 * l; + l = 0.01 * x + 0.99 * l; return l; } @@ -58,8 +58,10 @@ int main(int argc, char **argv) double speed = 1.0; while (!feof(in1) && !feof(in2)) { + short refs; + // read sample from reference - if (fread(&sample, sizeof(short), 1, in1) != 1) { + if (fread(&refs, sizeof(short), 1, in1) != 1) { exit(0); } @@ -75,14 +77,14 @@ int main(int argc, char **argv) // linear interpolation (works well since delta_p varies so slowly) double t = frac(p); - short intp_sample = prev_sample * (1.0 - t) + sample * t; + double intp_sample = prev_sample * (1.0 - t) + sample * t; // subtract the two samples and pull it through a filter. we assume // the sines are normalized for now (and that there's no dc skew) - double offset = -0.001 * filter(intp_sample - sample); - speed += offset; + double offset = filter(intp_sample - refs); + speed -= 0.00000001 * offset; fwrite(&speed, sizeof(double), 1, skew); - printf("%f (offset=%f)\n", speed, offset); + printf("%f (offset=%f)\n", speed, intp_sample - sample); } }