+ if (bit == 0 && last_bit == 1) {
+ // Check if we ever go up above HYSTERESIS_LIMIT before we dip down again.
+ bool true_pulse = false;
+ unsigned j;
+ int min_level_after = 32767;
+ for (j = i; j < pcm.size(); ++j) {
+ min_level_after = std::min<int>(min_level_after, pcm[j]);
+ if (pcm[j] > 0) break;
+ if (pcm[j] < -HYSTERESIS_LIMIT) {
+ true_pulse = true;
+ break;
+ }
+ }
+
+ if (!true_pulse) {
+#if 0
+ fprintf(stderr, "Ignored down-flank at %.6f seconds due to hysteresis (%d < %d).\n",
+ double(i) / SAMPLE_RATE, -min_level_after, HYSTERESIS_LIMIT);
+#endif
+ i = j;
+ continue;
+ }
+
+ // down-flank!