Commit 54d4ce37 by Stefan Schreistetter

Tried to fix performance issue with fixed length decimator. Decimator still does…

Tried to fix performance issue with fixed length decimator. Decimator still does not work properly, likely because processing is still slower than 1,7 ms (1/600).
parent 7f1eeecc
...@@ -11,7 +11,7 @@ namespace GazeWebSocketServer ...@@ -11,7 +11,7 @@ namespace GazeWebSocketServer
public class Program public class Program
{ {
private static GazeServer gazeServer; private static GazeServer gazeServer;
private static GazeDecimator decimator = new GazeDecimator(1, 600); private static GazeDecimatorFixedLength decimator = new GazeDecimatorFixedLength(1, 600);
public static void Main(string[] args) public static void Main(string[] args)
{ {
...@@ -20,7 +20,7 @@ namespace GazeWebSocketServer ...@@ -20,7 +20,7 @@ namespace GazeWebSocketServer
if (args.Length > 0 && args[0] == "-d") if (args.Length > 0 && args[0] == "-d")
{ {
Task.Run(() => SimulateGazeDataHz(10)); Task.Run(() => SimulateGazeDataHz(600));
} }
else else
{ {
......
...@@ -6,7 +6,7 @@ using System.Threading.Tasks; ...@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace TrackerBridge.DSP namespace TrackerBridge.DSP
{ {
public class GazeDecimator : IGazeFilter public class GazeDecimatorFixedLength : IGazeFilter
{ {
private GazeData[] buffer; private GazeData[] buffer;
private Int32 currentValueIndex; private Int32 currentValueIndex;
...@@ -17,6 +17,8 @@ namespace TrackerBridge.DSP ...@@ -17,6 +17,8 @@ namespace TrackerBridge.DSP
private Object outputLock = new Object(); private Object outputLock = new Object();
private Object inputLock = new Object(); private Object inputLock = new Object();
public event EventHandler<GazeData> OutputAvailable;
public Single InputFrequency { public Single InputFrequency {
get { return inputFrequency; } get { return inputFrequency; }
set { set {
...@@ -39,6 +41,7 @@ namespace TrackerBridge.DSP ...@@ -39,6 +41,7 @@ namespace TrackerBridge.DSP
} }
} }
} }
public Single OutputFrequency { public Single OutputFrequency {
get { return outputFrequency; } get { return outputFrequency; }
set { set {
...@@ -47,7 +50,7 @@ namespace TrackerBridge.DSP ...@@ -47,7 +50,7 @@ namespace TrackerBridge.DSP
} }
} }
public GazeDecimator(Single outputFrequency, Single inputFrequency) public GazeDecimatorFixedLength(Single outputFrequency, Single inputFrequency)
{ {
this.outputFrequency = outputFrequency; this.outputFrequency = outputFrequency;
this.inputFrequency = inputFrequency; this.inputFrequency = inputFrequency;
...@@ -58,29 +61,32 @@ namespace TrackerBridge.DSP ...@@ -58,29 +61,32 @@ namespace TrackerBridge.DSP
{ {
lock (inputLock) lock (inputLock)
{ {
buffer[currentValueIndex] = input;
currentValueIndex = (currentValueIndex + 1) % buffer.Length; currentValueIndex = (currentValueIndex + 1) % buffer.Length;
}
buffer[currentValueIndex] = input;
if (currentValueIndex == 0) if (currentValueIndex == buffer.Length-1)
{ {
GazeData sum = buffer[0]; GazeData sum = buffer[0];
for (Int32 index = 1; index < buffer.Length; index++) for (Int32 index = 1; index < buffer.Length; index++)
{ {
sum += buffer[index]; sum += buffer[index];
} }
sum /= buffer.Length;
lock (outputLock) lock (outputLock)
{ {
output = sum / buffer.Length; output = sum;
}
} }
} }
} }
public void Reset() public void Reset()
{ {
Int32 bufferLength = Convert.ToInt32(InputFrequency / OutputFrequency); Int32 bufferLength = Convert.ToInt32(InputFrequency / OutputFrequency);
buffer = new GazeData[bufferLength]; buffer = new GazeData[bufferLength];
currentValueIndex = 0; currentValueIndex = -1;
output = null; output = null;
} }
} }
......
...@@ -8,6 +8,7 @@ namespace TrackerBridge.DSP ...@@ -8,6 +8,7 @@ namespace TrackerBridge.DSP
{ {
interface IGazeFilter interface IGazeFilter
{ {
event EventHandler<GazeData> OutputAvailable;
GazeData? Output { get; } GazeData? Output { get; }
void Input(GazeData input); void Input(GazeData input);
void Reset(); void Reset();
......
...@@ -26,13 +26,14 @@ namespace TrackerBridge ...@@ -26,13 +26,14 @@ namespace TrackerBridge
} }
} }
public GazeDataProcessor(IBridgeTracker tracker) public GazeDataProcessor(IBridgeTracker tracker)
{ {
tracker.TrackingFrequencyChanged += OnTrackingFrequencyChanged; tracker.TrackingFrequencyChanged += OnTrackingFrequencyChanged;
screenHeight = Convert.ToSingle(SystemParameters.PrimaryScreenHeight); screenHeight = Convert.ToSingle(SystemParameters.PrimaryScreenHeight);
screenWidth = Convert.ToSingle(SystemParameters.PrimaryScreenWidth); screenWidth = Convert.ToSingle(SystemParameters.PrimaryScreenWidth);
gazeFilters = new IGazeFilter[1]; gazeFilters = new IGazeFilter[1];
gazeFilters[0] = new GazeDecimator(outputFrequency, tracker.GetTrackingFrequency()); gazeFilters[0] = new GazeDecimatorFixedLength(outputFrequency, tracker.GetTrackingFrequency());
} }
public void Initialize() public void Initialize()
{ {
...@@ -66,9 +67,9 @@ namespace TrackerBridge ...@@ -66,9 +67,9 @@ namespace TrackerBridge
{ {
foreach(IGazeFilter filter in gazeFilters) foreach(IGazeFilter filter in gazeFilters)
{ {
if(filter.GetType() == typeof(GazeDecimator)) if(filter.GetType() == typeof(GazeDecimatorFixedLength))
{ {
GazeDecimator decimator = (GazeDecimator)filter; GazeDecimatorFixedLength decimator = (GazeDecimatorFixedLength)filter;
decimator.InputFrequency = frequency; decimator.InputFrequency = frequency;
} }
} }
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DSP\GazeDecimator.cs" /> <Compile Include="DSP\GazeDecimatorFixedLength.cs" />
<Compile Include="GazeData.cs" /> <Compile Include="GazeData.cs" />
<Compile Include="GazeDataProcessor.cs" /> <Compile Include="GazeDataProcessor.cs" />
<Compile Include="DSP\IGazeFilter.cs" /> <Compile Include="DSP\IGazeFilter.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment