feat: StepDetector update FPS, more FPS fixes
This commit is contained in:
@@ -33,8 +33,8 @@ public:
|
||||
*/
|
||||
class SsfStepDetector {
|
||||
protected:
|
||||
const size_t LEN_INIT;
|
||||
const size_t LEN_TH_WIN;
|
||||
size_t LEN_INIT;
|
||||
size_t LEN_TH_WIN;
|
||||
size_t num_samples;
|
||||
double ssf_threshold;
|
||||
double ssf_threshold_nm1;
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
* @param len_refr duration of refractory period, in samples
|
||||
*/
|
||||
SsfStepDetector(double fps);
|
||||
~SsfStepDetector();
|
||||
double filter(double val);
|
||||
double peek_threshold();
|
||||
|
||||
@@ -62,18 +63,19 @@ public:
|
||||
class RunningQuality {
|
||||
protected:
|
||||
// TODO: make it a filter (output proper samples)
|
||||
// TODO: use fps info
|
||||
|
||||
/** template beat is resampled to this #samples */
|
||||
const int BEAT_LEN = 120 /* 2*FPS for 30 bpm lower end */;
|
||||
int BEAT_LEN;
|
||||
|
||||
/** threshold for accepting initial beats */
|
||||
const double BEAT_CORR_THR_1 = 0.9;
|
||||
double BEAT_CORR_THR_1 = 0.9;
|
||||
/** threshold for accepting subsequent beats */
|
||||
const double BEAT_CORR_THR_2 = 0.8;
|
||||
double BEAT_CORR_THR_2 = 0.8;
|
||||
/** absolute SSF threshold for accepting any beat */
|
||||
const double SSF_THRESHOLD = 5.0;
|
||||
double SSF_THRESHOLD = 5.0;
|
||||
/** number of recent beats to use for beat template. must be even (alternating feet have different patterns; make it symmetric) */
|
||||
const int NUM_BEATS = 4;
|
||||
int NUM_BEATS = 4;
|
||||
|
||||
std::deque<std::vector<double> > beatTemplates;
|
||||
std::vector<double> beatTemplate;
|
||||
@@ -93,8 +95,8 @@ protected:
|
||||
virtual void dispatchBeat(int idx, bool good, double posCorr);
|
||||
|
||||
public:
|
||||
RunningQuality();
|
||||
explicit RunningQuality(bool disableSsf);
|
||||
RunningQuality(double fps);
|
||||
explicit RunningQuality(double fps, bool disableSsf);
|
||||
virtual ~RunningQuality();
|
||||
|
||||
// note: arg should be an iterator really, but can do later
|
||||
@@ -116,6 +118,7 @@ protected:
|
||||
double sqi;
|
||||
public:
|
||||
RunningQualityFilter(double fps);
|
||||
~RunningQualityFilter();
|
||||
double filter(double y, double ssf, double step);
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ protected:
|
||||
Resampler res_x;
|
||||
Resampler res_y;
|
||||
Resampler res_z;
|
||||
double fps;
|
||||
|
||||
public:
|
||||
StepDetector(double fps, StepListener *listener, bool debug = false);
|
||||
|
||||
@@ -86,6 +86,7 @@ SsfStepDetector::SsfStepDetector(double fps) :
|
||||
{
|
||||
assert (LEN_INIT >= LEN_TH_WIN && "LEN_INIT < LEN_TH_WIN, check normalization of initial ssf_threshold");
|
||||
}
|
||||
SsfStepDetector::~SsfStepDetector() {}
|
||||
double SsfStepDetector::filter(double ssf) {
|
||||
double ssf_mean = f_ssf_mean.filter(ssf) / ((double) LEN_TH_WIN);
|
||||
double rv = 0.0;
|
||||
@@ -154,8 +155,13 @@ void RunningQuality::replaceTemplate(std::vector<double>& x) {
|
||||
void RunningQuality::dispatchLocked() { /* implement me, add Listener etc. */ }
|
||||
void RunningQuality::dispatchBeat(int idx, bool good, double posCorr) { /* implement me, add Listener etc. */ }
|
||||
|
||||
RunningQuality::RunningQuality(): beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(false) {}
|
||||
RunningQuality::RunningQuality(bool disableSsf): beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(disableSsf) {}
|
||||
static int get_beat_len(double fps) {
|
||||
/* 2*FPS for 30 bpm lower end */
|
||||
return 2.0 * fps;
|
||||
}
|
||||
|
||||
RunningQuality::RunningQuality(double fps): BEAT_LEN(get_beat_len(fps)), beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(false) {}
|
||||
RunningQuality::RunningQuality(double fps, bool disableSsf): BEAT_LEN(get_beat_len(fps)), beatCorrThr2(BEAT_CORR_THR_2), justLocked(false), idx(0), disableSsf(disableSsf) {}
|
||||
RunningQuality::~RunningQuality() {}
|
||||
|
||||
// note: arg should be an iterator really, but can do later
|
||||
@@ -221,7 +227,8 @@ bool RunningQuality::append(std::vector<double> &rawBeat, std::vector<double> &r
|
||||
}
|
||||
|
||||
|
||||
RunningQualityFilter::RunningQualityFilter(double fps) : sqi(0.0) {}
|
||||
RunningQualityFilter::RunningQualityFilter(double fps) : f_sqi(fps), sqi(0.0) {}
|
||||
RunningQualityFilter::~RunningQualityFilter() {}
|
||||
|
||||
double RunningQualityFilter::filter(double y, double ssf, double step) {
|
||||
if (step == 1.0) {
|
||||
|
||||
@@ -12,7 +12,8 @@ StepDetector::StepDetector(double fps, StepListener *listener, bool debug) :
|
||||
f_ssf(fps),
|
||||
f_ssd(fps),
|
||||
f_sqi(fps),
|
||||
debug(debug)
|
||||
debug(debug),
|
||||
fps(0.0)
|
||||
{}
|
||||
|
||||
static int gravity_num_taps(double fps) {
|
||||
@@ -50,6 +51,14 @@ void StepDetector::filter(double ts, std::vector<float> values) {
|
||||
res_x.push(ts, values[0]);
|
||||
res_y.push(ts, values[1]);
|
||||
res_z.push(ts, values[2]);
|
||||
// as soon as there is 'fps' information, re-init the classes requiring fps info
|
||||
if (fps == 0.0 && res_x.peek()) {
|
||||
fps = res_x.get_fs();
|
||||
f_grav = GravityFilter(fps);
|
||||
f_ssf = SsfFilter(fps);
|
||||
f_ssd = SsfStepDetector(fps);
|
||||
f_sqi = RunningQualityFilter(fps);
|
||||
}
|
||||
while (res_x.peek()) {
|
||||
double x = res_x.get(), y = res_y.get(), z = res_z.get();
|
||||
std::vector<double> samp { x, y, z };
|
||||
@@ -85,7 +94,7 @@ double StepDetector::primeFilters(double fps, std::vector<double> sig) {
|
||||
double ts = 0;
|
||||
for (size_t i = 0; i < N_INIT; i++) {
|
||||
const auto a_i = static_cast<float>(sig[i]);
|
||||
filter(ts, std::vector<float> {0.0f, a_i, 0.0f});
|
||||
filter(ts * 1e9, std::vector<float> {0.0f, a_i, 0.0f});
|
||||
ts += 1.0 / fps;
|
||||
}
|
||||
// clear debug buffers
|
||||
|
||||
Reference in New Issue
Block a user