]> git.sesse.net Git - audiosync/blobdiff - estimate-skew.c
Fix more bugs in estimate-skew.
[audiosync] / estimate-skew.c
index 1c44f864ca9fed96a26f8c195edf7e70573741eb..e8ba75ea41c5b2bc68415751940738270dafee6d 100644 (file)
@@ -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);
        }
 }