]> git.sesse.net Git - c64tapwav/commitdiff
Add some hysteresis to get rid of the worst noise.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 2 May 2013 18:13:52 +0000 (20:13 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 2 May 2013 18:13:52 +0000 (20:13 +0200)
decode.c

index 7e4c84b182bcea56530cda7bedcb9c3e334e3dd0..993f103a597e5286989c40a3fc5ba648328bc95a 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -6,6 +6,7 @@
 
 #define LANCZOS_RADIUS 30
 #define LEN 813440
+#define HYSTERESIS_LIMIT 1000
 
 double sinc(double x)
 {
@@ -92,9 +93,10 @@ int main(int argc, char **argv)
 #endif
        int last_bit = -1;
        double last_upflank = -1;
+       int last_max_level = 0;
        for (int i = 0; i < LEN; ++i) {
                int bit = (in[i] > 0) ? 1 : 0;
-               if (bit == 1 && last_bit == 0) {
+               if (bit == 1 && last_bit == 0 && last_max_level > HYSTERESIS_LIMIT) {
                        // up-flank!
                        double t = find_zerocrossing(i - 1) * (123156.0/44100.0);
                        if (last_upflank > 0) {
@@ -103,7 +105,9 @@ int main(int argc, char **argv)
                                printf("0x%x\n", len);
                        }
                        last_upflank = t;
+                       last_max_level = 0;
                }
+               last_max_level = std::max(last_max_level, abs(in[i]));
                last_bit = bit;
        }
 }