Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Audio
MovingCoilBallistics.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
Settings/SettingsWrapper.hpp
>
4
5
BEGIN_CS_NAMESPACE
6
7
class
MovingCoilBallistics
{
8
public
:
9
MovingCoilBallistics
(
float
springConstant
,
float
friction
,
float
mass,
10
float
Ts
= 1.0 /
MAX_FPS
)
11
:
springConstant
(
springConstant
/ mass *
Ts
),
12
friction
(
friction
/ mass *
Ts
),
Ts
(
Ts
) {}
13
16
float
operator()
(
float
input) {
17
// float x_dot_new = (1 - friction / mass * Ts) * x_dot -
18
// springConstant / mass * Ts * (x + input);
19
float
x_dot_new = (1 -
friction
) *
x_dot
+
springConstant
* (input -
x
);
20
x
=
Ts
*
x_dot
+
x
;
21
x_dot
= x_dot_new;
22
23
DEBUGVAL
(
x
,
x_dot
);
24
DEBUGVAL
(
friction
,
springConstant
,
Ts
);
25
26
if
(
x
>= 1) {
27
x
= 1;
28
x_dot
=
x_dot
> 0 ? -1 *
x_dot
:
x_dot
;
29
}
else
if
(
x
< 0) {
30
x
= 0;
31
x_dot
=
x_dot
< 0 ? -1 *
x_dot
:
x_dot
;
32
}
33
return
x
;
34
}
35
36
static
MovingCoilBallistics
officialVU
() {
37
return
MovingCoilBallistics
(0.16025, 0.0215, 0.001);
38
}
39
40
static
MovingCoilBallistics
responsiveVU
(
float
Tsfactor = 2.0) {
41
return
MovingCoilBallistics
(0.16025, 0.0215, 0.001, Tsfactor /
MAX_FPS
);
42
}
43
44
static
MovingCoilBallistics
noOvershoot
(
float
Tsfactor = 1.0) {
45
return
MovingCoilBallistics
(1.05, 0.1, 0.002, Tsfactor /
MAX_FPS
);
46
}
47
48
private
:
49
const
float
springConstant
;
50
const
float
friction
;
51
const
float
Ts
;
52
53
float
x
= 0;
54
float
x_dot
= 0;
55
};
56
57
END_CS_NAMESPACE
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
SettingsWrapper.hpp
MAX_FPS
constexpr uint8_t MAX_FPS
The maximum frame rate of the displays.
Definition
Settings/Settings.hpp:57
MovingCoilBallistics::operator()
float operator()(float input)
Definition
MovingCoilBallistics.hpp:16
MovingCoilBallistics::noOvershoot
static MovingCoilBallistics noOvershoot(float Tsfactor=1.0)
Definition
MovingCoilBallistics.hpp:44
MovingCoilBallistics::x_dot
float x_dot
Definition
MovingCoilBallistics.hpp:54
MovingCoilBallistics::responsiveVU
static MovingCoilBallistics responsiveVU(float Tsfactor=2.0)
Definition
MovingCoilBallistics.hpp:40
MovingCoilBallistics::Ts
const float Ts
Definition
MovingCoilBallistics.hpp:51
MovingCoilBallistics::MovingCoilBallistics
MovingCoilBallistics(float springConstant, float friction, float mass, float Ts=1.0/MAX_FPS)
Definition
MovingCoilBallistics.hpp:9
MovingCoilBallistics::friction
const float friction
Definition
MovingCoilBallistics.hpp:50
MovingCoilBallistics::officialVU
static MovingCoilBallistics officialVU()
Definition
MovingCoilBallistics.hpp:36
MovingCoilBallistics::x
float x
Definition
MovingCoilBallistics.hpp:53
MovingCoilBallistics::springConstant
const float springConstant
Definition
MovingCoilBallistics.hpp:49
DEBUGVAL
#define DEBUGVAL(...)
Print multiple expressions and their values to the debug output if debugging is enabled.
Definition
Debug.hpp:175
Generated by
1.17.0