refactor: disable debug prints by a switch in RunningQuality

This commit is contained in:
2026-03-12 21:35:05 +01:00
parent bfb3c99184
commit 716a54e76e
2 changed files with 22 additions and 9 deletions

View File

@@ -5,7 +5,9 @@
#include "iir_filter.h" #include "iir_filter.h"
#include <iostream> #include <iostream>
#ifndef DEBUG_IIR
#define DEBUG_IIR 0 #define DEBUG_IIR 0
#endif
#if (DEBUG_IIR == 1) #if (DEBUG_IIR == 1)
#define DEBUG_PRINT(expr) do { expr; } while (0) #define DEBUG_PRINT(expr) do { expr; } while (0)

View File

@@ -9,6 +9,17 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#ifndef DEBUG_SSF
#define DEBUG_SSF 0
#endif
#if (DEBUG_SSF == 1)
#define DEBUG_PRINT(expr) do { expr; } while (0)
#else
#define DEBUG_PRINT(expr) while(0) { expr; }
#endif
static std::vector<double> make_ones(size_t sw) { static std::vector<double> make_ones(size_t sw) {
std::vector<double> ones; std::vector<double> ones;
ones.resize(sw); ones.resize(sw);
@@ -66,15 +77,15 @@ double SsfStepDetector::filter(double ssf) {
if (num_samples == LEN_INIT) { if (num_samples == LEN_INIT) {
// initial threshold setting // initial threshold setting
ssf_threshold = 3.0 * ssf_mean * 0.99; // see Zong 2003 for the magic numbers ssf_threshold = 3.0 * ssf_mean * 0.99; // see Zong 2003 for the magic numbers
//std::cerr << "before prime()" << std::endl; //DEBUG_PRINT(std::cerr << "before prime()" << std::endl);
f_ssf_threshold_smoothing.prime(ssf_threshold); f_ssf_threshold_smoothing.prime(ssf_threshold);
} else if (num_samples > LEN_TH_WIN) { } else if (num_samples > LEN_TH_WIN) {
//std::cerr << "adaptive threshold setting" << std::endl; //DEBUG_PRINT(std::cerr << "adaptive threshold setting" << std::endl);
// adaptive threshold setting // adaptive threshold setting
// +2 is half the window size // +2 is half the window size
// TODO: param upon SsfFilter.upslope_width/2 instead of hardcoding -- also f_ssf_threshold_smoothing(), nb. should be even number // TODO: param upon SsfFilter.upslope_width/2 instead of hardcoding -- also f_ssf_threshold_smoothing(), nb. should be even number
if (num_samples == n_refr + 2) { if (num_samples == n_refr + 2) {
//std::cerr << "setting adaptive threshold setting" << std::endl; //DEBUG_PRINT(std::cerr << "setting adaptive threshold setting" << std::endl);
ssf_threshold_nm1 = ssf_threshold; ssf_threshold_nm1 = ssf_threshold;
// the ssf peak comes 3 samples (half-window + 1 sample) after the crossing // the ssf peak comes 3 samples (half-window + 1 sample) after the crossing
ssf_threshold = f_ssf_threshold_smoothing.filter(ssf) / ((double) f_ssf_threshold_smoothing.size()) * 0.6; ssf_threshold = f_ssf_threshold_smoothing.filter(ssf) / ((double) f_ssf_threshold_smoothing.size()) * 0.6;
@@ -138,19 +149,19 @@ void RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
if (beatTemplates.size() == 0) { if (beatTemplates.size() == 0) {
// cannot correlate the first beat, no template yet // cannot correlate the first beat, no template yet
std::cerr << "(0) first beat -> addTemplate()" << std::endl; DEBUG_PRINT(std::cerr << "(0) first beat -> addTemplate()" << std::endl);
addTemplate(ssf); addTemplate(ssf);
justLocked = false; justLocked = false;
} else if (beatTemplates.size() <= 2) { } else if (beatTemplates.size() <= 2) {
// restart if there is no clear correlation between beats // restart if there is no clear correlation between beats
if (goodBeat) { if (goodBeat) {
std::cerr << "(2) good initial beat -> addTemplate()" << std::endl; DEBUG_PRINT(std::cerr << "(2) good initial beat -> addTemplate()" << std::endl);
addTemplate(ssf); addTemplate(ssf);
if (beatTemplates.size() > 2) if (beatTemplates.size() > 2)
justLocked = true; // TODO why not set? wrong compiler optimization? (is it unaware of member change?) justLocked = true;
//std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl; //DEBUG_PRINT(std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl);
} else { } else {
std::cerr << "(2) bad initial beat idx=" << idx << " -> replaceTemplate() corr=" << std::fixed << std::setw(7) << std::setprecision(4) << corr << " checkedSsf=" << checkedSsf << std::endl; DEBUG_PRINT(std::cerr << "(2) bad initial beat idx=" << idx << " -> replaceTemplate() corr=" << std::fixed << std::setw(7) << std::setprecision(4) << corr << " checkedSsf=" << checkedSsf << std::endl);
replaceTemplate(ssf); replaceTemplate(ssf);
//badBeatRanges.clear(); //badBeatRanges.clear();
justLocked = false; justLocked = false;
@@ -158,7 +169,7 @@ void RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
} else { } else {
// running mode: collect bad beats, but may be OK not to restart immediately // running mode: collect bad beats, but may be OK not to restart immediately
std::cerr << "(3) running mode, good=" << ((int) goodBeat) << " justLocked=" << ((int) justLocked) << std::endl; DEBUG_PRINT(std::cerr << "(3) running mode, good=" << ((int) goodBeat) << " justLocked=" << ((int) justLocked) << std::endl);
if (goodBeat) { if (goodBeat) {
addTemplate(ssf); addTemplate(ssf);
} else { } else {