diff --git a/pasada-lib/iir_filter.cpp b/pasada-lib/iir_filter.cpp index 9b19cfd..6dcaf74 100644 --- a/pasada-lib/iir_filter.cpp +++ b/pasada-lib/iir_filter.cpp @@ -5,7 +5,9 @@ #include "iir_filter.h" #include +#ifndef DEBUG_IIR #define DEBUG_IIR 0 +#endif #if (DEBUG_IIR == 1) #define DEBUG_PRINT(expr) do { expr; } while (0) diff --git a/pasada-lib/ssf_filter.cpp b/pasada-lib/ssf_filter.cpp index 1ad5cec..7fa724b 100644 --- a/pasada-lib/ssf_filter.cpp +++ b/pasada-lib/ssf_filter.cpp @@ -9,6 +9,17 @@ #include #include +#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 make_ones(size_t sw) { std::vector ones; ones.resize(sw); @@ -66,15 +77,15 @@ double SsfStepDetector::filter(double ssf) { if (num_samples == LEN_INIT) { // initial threshold setting 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); } 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 // +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 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; // 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; @@ -138,19 +149,19 @@ void RunningQuality::append(std::vector &rawBeat, std::vector &r if (beatTemplates.size() == 0) { // 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); justLocked = false; } else if (beatTemplates.size() <= 2) { // restart if there is no clear correlation between beats if (goodBeat) { - std::cerr << "(2) good initial beat -> addTemplate()" << std::endl; + DEBUG_PRINT(std::cerr << "(2) good initial beat -> addTemplate()" << std::endl); addTemplate(ssf); if (beatTemplates.size() > 2) - justLocked = true; // TODO why not set? wrong compiler optimization? (is it unaware of member change?) - //std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl; + justLocked = true; + //DEBUG_PRINT(std::cerr << " (2) beatTemplates.size()=" << beatTemplates.size() << " justLocked=" << ((int) justLocked) << std::endl); } 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); //badBeatRanges.clear(); justLocked = false; @@ -158,7 +169,7 @@ void RunningQuality::append(std::vector &rawBeat, std::vector &r } else { // 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) { addTemplate(ssf); } else {