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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/* Copyright (c) 2012-2015 Stanislaw Halik
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*/
#include "ftnoir_filter_accela.h"
#include <algorithm>
#include <cmath>
#include <QDebug>
#include <QMutexLocker>
#include "api/plugin-api.hpp"
constexpr double settings_accela::rot_gains[16][2];
constexpr double settings_accela::trans_gains[16][2];
FTNoIR_Filter::FTNoIR_Filter() : first_run(true)
{
s.make_splines(rot, trans);
}
void FTNoIR_Filter::filter(const double* input, double *output)
{
if (first_run)
{
for (int i = 0; i < 6; i++)
{
const double f = input[i];
output[i] = f;
last_output[i] = f;
smoothed_input[i] = f;
}
first_run = false;
t.start();
return;
}
const double rot_t = s.rot_sensitivity->cur();
const double trans_t = s.trans_sensitivity->cur();
const double dt = t.elapsed_seconds();
t.start();
const double RC = s.ewma->cur() / 1000.; // seconds
const double alpha = dt/(dt+RC);
const double rot_dz = s.rot_deadzone->cur();
const double trans_dz = s.trans_deadzone->cur();
const slider_value rot_nl_ = s.rot_nonlinearity;
const double rot_nl = rot_nl_.cur();
for (int i = 0; i < 6; i++)
{
spline& m = i >= 3 ? rot : trans;
smoothed_input[i] = smoothed_input[i] * (1.-alpha) + input[i] * alpha;
const double in = smoothed_input[i];
const double vec = in - last_output[i];
const double dz = i >= 3 ? rot_dz : trans_dz;
const double vec_ = std::max(0., fabs(vec) - dz);
const double thres = i >= 3 ? rot_t : trans_t;
const double out_ = vec_ / thres;
const double out = i >= 3 && std::fabs(rot_nl - 1) > 5e-3 && vec_ < rot_nl_.max()
? (std::pow(out_/rot_nl_.max(), rot_nl))
: out_;
const double val = double(m.getValue(out));
last_output[i] = output[i] = last_output[i] + signum(vec) * dt * val;
}
}
void settings_accela::make_splines(spline& rot, spline& trans)
{
rot = spline();
trans = spline();
rot.setMaxInput(rot_gains[0][0]);
trans.setMaxInput(trans_gains[0][0]);
rot.setMaxOutput(rot_gains[0][1]);
trans.setMaxOutput(trans_gains[0][1]);
for (int i = 0; rot_gains[i][0] >= 0; i++)
rot.addPoint(QPointF(rot_gains[i][0], rot_gains[i][1]));
for (int i = 0; trans_gains[i][0] >= 0; i++)
trans.addPoint(QPointF(trans_gains[i][0], trans_gains[i][1]));
}
OPENTRACK_DECLARE_FILTER(FTNoIR_Filter, FilterControls, FTNoIR_FilterDll)
|