- int bit = (pcm[i] > 0) ? 1 : 0;
- 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 (pcm[i] > hysteresis_upper_limit) {
+ state = ABOVE;
+ } else if (pcm[i] < hysteresis_lower_limit) {
+ if (state == ABOVE) {
+ // down-flank!
+ double t = find_crossing(pcm, i - 1, hysteresis_lower_limit) * (1.0 / sample_rate) + crop_start;
+ if (last_downflank > 0) {
+ pulse p;
+ p.time = t;
+ p.len = t - last_downflank;
+ pulses.push_back(p);