Skip to content

Commit 659701b

Browse files
committed
Merge remote-tracking branch 'origin/master' into noisereductionfilter
2 parents 6ff6a3f + 3003200 commit 659701b

6 files changed

Lines changed: 156 additions & 3 deletions

File tree

.modules/OpenTabletDriver

Submodule OpenTabletDriver updated 177 files

DevocubFilters/AntiChatter.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using System;
2+
using System.Numerics;
3+
using OpenTabletDriver.Plugin.Attributes;
4+
using OpenTabletDriver.Plugin.Tablet;
5+
6+
namespace TabletDriverFilters.Devocub
7+
{
8+
using static MathF;
9+
10+
[PluginName("TabletDriver AntiChatter Filter")]
11+
public class AntiChatter : IFilter
12+
{
13+
private Vector2 _lastPos;
14+
private float _timerInterval;
15+
private const float _threshold = 0.9f;
16+
private float _latency = 2.0f;
17+
18+
public Vector2 Filter(Vector2 point)
19+
{
20+
Vector2 calcTarget = new Vector2();
21+
float deltaX, deltaY, distance, weightModifier, predictionModifier;
22+
23+
if (_lastPos == null)
24+
{
25+
_lastPos = point;
26+
return point;
27+
}
28+
29+
if (PredictionEnabled)
30+
{
31+
// Calculate predicted position onNewPacket
32+
if (_lastPos.X != point.X || _lastPos.Y != point.Y)
33+
{
34+
// Calculate distance between last 2 packets and prediction
35+
deltaX = point.X - _lastPos.X;
36+
deltaY = point.Y - _lastPos.Y;
37+
distance = Sqrt(deltaX * deltaX + deltaY * deltaY);
38+
predictionModifier = 1 / Cosh((distance - PredictionOffsetX) * PredictionSharpness) * PredictionStrength + PredictionOffsetY;
39+
40+
// Apply prediction
41+
deltaX *= predictionModifier;
42+
deltaY *= predictionModifier;
43+
44+
// Update predicted position
45+
calcTarget.X = (float)(point.X + deltaX);
46+
calcTarget.Y = (float)(point.Y + deltaY);
47+
48+
// Update old position for further prediction
49+
_lastPos.X = point.X;
50+
_lastPos.Y = point.Y;
51+
}
52+
}
53+
else
54+
{
55+
calcTarget.X = point.X;
56+
calcTarget.Y = point.Y;
57+
}
58+
59+
deltaX = calcTarget.X - _lastPos.X;
60+
deltaY = calcTarget.Y - _lastPos.Y;
61+
distance = Sqrt(deltaX * deltaX + deltaY * deltaY);
62+
63+
float stepCount = Latency / TimerInterval;
64+
float target = 1 - _threshold;
65+
float weight = (float)(1.0 - (1.0 / Pow((float)(1.0 / target), (float)(1.0 / stepCount))));
66+
67+
// Devocub smoothing
68+
// Increase weight of filter in {formula} times
69+
weightModifier = (float)(Pow(distance + AntichatterOffsetX, AntichatterStrength * -1) * AntichatterMultiplier);
70+
71+
// Limit minimum
72+
if (weightModifier + AntichatterOffsetY < 0)
73+
weightModifier = 0;
74+
else
75+
weightModifier += AntichatterOffsetY;
76+
77+
weightModifier = weight / weightModifier;
78+
weightModifier = Math.Clamp(weightModifier, 0, 1);
79+
_lastPos.X += (float)(deltaX * weightModifier);
80+
_lastPos.Y += (float)(deltaY * weightModifier);
81+
82+
return _lastPos;
83+
}
84+
85+
public FilterStage FilterStage => FilterStage.PostTranspose;
86+
87+
[SliderProperty("Latency", 0f, 5f, 2f)]
88+
public float Latency
89+
{
90+
set => _latency = Math.Clamp(value, 0, 1000);
91+
get => _latency;
92+
}
93+
94+
[Property("Timer Interval"), Unit("hz")]
95+
public float TimerInterval
96+
{
97+
set => _timerInterval = 1000f / value;
98+
get => _timerInterval;
99+
}
100+
101+
[Property("Antichatter Strength")]
102+
public float AntichatterStrength { set; get; } = 3;
103+
104+
[Property("Antichatter Multiplier")]
105+
public float AntichatterMultiplier { set; get; } = 1;
106+
107+
[Property("Antichatter Offset X")]
108+
public float AntichatterOffsetX { set; get; }
109+
110+
[Property("Antichatter Offset Y")]
111+
public float AntichatterOffsetY { set; get; } = 1;
112+
113+
[BooleanProperty("Prediction", "")]
114+
public bool PredictionEnabled { set; get; }
115+
116+
[Property("Prediction Strength")]
117+
public float PredictionStrength { set; get; } = 1.1f;
118+
119+
[Property("Prediction Sharpness")]
120+
public float PredictionSharpness { set; get; } = 1;
121+
122+
[Property("Prediction Offset X")]
123+
public float PredictionOffsetX { set; get; } = 3;
124+
125+
[Property("Prediction Offset Y")]
126+
public float PredictionOffsetY { set; get; } = 0.3f;
127+
}
128+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9+
</ItemGroup>
10+
11+
</Project>

HawkuFilters/HawkuFilters.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

HawkuFilters/Smoothing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void SetPreviousState(Vector2 lastPosition)
5252
[SliderProperty("Latency", 0f, 5f, 2f)]
5353
public float Latency { set; get; }
5454

55-
[UnitProperty("Timer Interval", "hz")]
55+
[Property("Timer Interval"), Unit("hz")]
5656
public float TimerInterval
5757
{
5858
set => _timerInterval = 1000f / value;

TabletDriverFilters.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26124.0
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HawkuFilters", "HawkuFilters\HawkuFilters.csproj", "{EBD5C9CA-5B65-40B9-8923-696819BEF243}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevocubFilters", "DevocubFilters\DevocubFilters.csproj", "{7FE69139-B75B-44D8-8771-76FA8A8B5193}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -30,5 +32,17 @@ Global
3032
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x64.Build.0 = Release|Any CPU
3133
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x86.ActiveCfg = Release|Any CPU
3234
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x86.Build.0 = Release|Any CPU
35+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x64.ActiveCfg = Debug|Any CPU
38+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x64.Build.0 = Debug|Any CPU
39+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x86.ActiveCfg = Debug|Any CPU
40+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x86.Build.0 = Debug|Any CPU
41+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x64.ActiveCfg = Release|Any CPU
44+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x64.Build.0 = Release|Any CPU
45+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x86.ActiveCfg = Release|Any CPU
46+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x86.Build.0 = Release|Any CPU
3347
EndGlobalSection
3448
EndGlobal

0 commit comments

Comments
 (0)