X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=estimate-skew.c;h=e8ba75ea41c5b2bc68415751940738270dafee6d;hb=e9e02908106107a3265fabc92acd06eb9ee683c1;hp=1c44f864ca9fed96a26f8c195edf7e70573741eb;hpb=f0d94272ccbb005ef20ddf9140fa3b4fa4fcf7c9;p=audiosync diff --git a/estimate-skew.c b/estimate-skew.c index 1c44f86..e8ba75e 100644 --- a/estimate-skew.c +++ b/estimate-skew.c @@ -54,12 +54,14 @@ int main(int argc, char **argv) short prev_sample, sample = 0; int in_pos = -1; - double p = -1.0; - double speed = 1.0; + double p = 0.0; + double speed = 1.001; 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 += 1e-8 * offset; fwrite(&speed, sizeof(double), 1, skew); - printf("%f (offset=%f)\n", speed, offset); + printf("%f (offset=%f / filt=%f)\n", speed, intp_sample - refs, offset); } }