summaryrefslogtreecommitdiffhomepage
path: root/filter-ewma2/ftnoir_filter_ewma2.h
blob: 328279acfada0229b1d5daf67c0ec2ec0717d708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include "opentrack/plugin-api.hpp"
#include "ui_ftnoir_ewma_filtercontrols.h"
#include <QWidget>
#include <QMutex>
#include "opentrack-compat/options.hpp"
#include "opentrack-compat/timer.hpp"
using namespace options;

struct settings : opts {
    // these are sadly sliders for now due to int/double mismatch -sh
    value<slider_value> kMinSmoothing, kMaxSmoothing, kSmoothingScaleCurve;
    settings() :
        opts("ewma-filter"),
        kMinSmoothing(b, "min-smoothing", slider_value(.02, .01, 1)),
        kMaxSmoothing(b, "max-smoothing", slider_value(.7, .01, 1)),
        kSmoothingScaleCurve(b, "smoothing-scale-curve", slider_value(.7, .01, 1))
    {}
};


class FTNoIR_Filter : public IFilter
{
public:
    FTNoIR_Filter();
    void filter(const double *input, double *output);
private:
    // Deltas are smoothed over the last 1/20sec.
    const double delta_RC = 1./20;
    // Noise is smoothed over the last 60sec.
    const double noise_RC = 60.0;
    double last_delta[6];
    double last_noise[6];
    double last_output[6];
    Timer timer;
    settings s;
    bool first_run;
};

class FilterControls: public IFilterDialog
{
    Q_OBJECT
public:
    FilterControls();
    void register_filter(IFilter*) override {}
    void unregister_filter() override {}

private:
    Ui::UICFilterControls ui;
    settings s;

private slots:
    void doOK();
    void doCancel();
    void update_labels(int);
};

class FTNoIR_FilterDll : public Metadata
{
public:
    QString name() { return QString("EWMA"); }
    QIcon icon() { return QIcon(":/images/filter-16.png"); }
};