]> git.sesse.net Git - c64tapwav/blobdiff - decode.cpp
Remove an unused #include.
[c64tapwav] / decode.cpp
index 1a5ee74856c5c635e37ea434213307114964be6c..0e88f9d85d73d55d5e5a55262c5f68f1b99acfcf 100644 (file)
@@ -1,8 +1,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
-#include <unistd.h>
 #include <assert.h>
+#include <limits.h>
 #include <vector>
 #include <algorithm>
 
@@ -41,7 +41,7 @@ double find_zerocrossing(const std::vector<short> &pcm, int x)
 
        double upper = x;
        double lower = x + 1;
-       while (upper - lower > 1e-6) {
+       while (lower - upper > 1e-3) {
                double mid = 0.5f * (upper + lower);
                if (lanczos_interpolate(pcm, mid) > 0) {
                        upper = mid;
@@ -60,6 +60,7 @@ struct pulse {
        
 int main(int argc, char **argv)
 {
+       make_lanczos_weight_table();
        std::vector<short> pcm;
 
        while (!feof(stdin)) {
@@ -189,4 +190,20 @@ int main(int argc, char **argv)
 
        fwrite(&hdr, sizeof(hdr), 1, stdout);
        fwrite(tap_data.data(), tap_data.size(), 1, stdout);
+
+       // Output a debug raw file with pulse detection points.
+       fp = fopen("debug.raw", "wb");
+       short one = 32767;
+       short zero = 0;
+       unsigned pulsenum = 0;
+       for (unsigned i = 0; i < pcm.size(); ++i) {
+               unsigned next_pulse = (pulsenum >= pulses.size()) ? INT_MAX : int(pulses[pulsenum].time * SAMPLE_RATE);
+               if (i >= next_pulse) {
+                       fwrite(&one, sizeof(one), 1, fp);
+                       ++pulsenum;
+               } else {
+                       fwrite(&zero, sizeof(zero), 1, fp);
+               }
+       }
+       fclose(fp);
 }