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
public class Program
{
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)
{
......@@ -20,7 +20,7 @@ namespace GazeWebSocketServer
if (args.Length > 0 && args[0] == "-d")
{
Task.Run(() => SimulateGazeDataHz(10));
Task.Run(() => SimulateGazeDataHz(600));
}
else
{
......
......@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace TrackerBridge.DSP
{
public class GazeDecimator : IGazeFilter
public class GazeDecimatorFixedLength : IGazeFilter
{
private GazeData[] buffer;
private Int32 currentValueIndex;
......@@ -17,6 +17,8 @@ namespace TrackerBridge.DSP
private Object outputLock = new Object();
private Object inputLock = new Object();
public event EventHandler<GazeData> OutputAvailable;
public Single InputFrequency {
get { return inputFrequency; }
set {
......@@ -39,6 +41,7 @@ namespace TrackerBridge.DSP
}
}
}
public Single OutputFrequency {
get { return outputFrequency; }
set {
......@@ -47,7 +50,7 @@ namespace TrackerBridge.DSP
}
}
public GazeDecimator(Single outputFrequency, Single inputFrequency)
public GazeDecimatorFixedLength(Single outputFrequency, Single inputFrequency)
{
this.outputFrequency = outputFrequency;
this.inputFrequency = inputFrequency;
......@@ -58,29 +61,32 @@ namespace TrackerBridge.DSP
{
lock (inputLock)
{
buffer[currentValueIndex] = input;
currentValueIndex = (currentValueIndex + 1) % buffer.Length;
}
buffer[currentValueIndex] = input;
if (currentValueIndex == 0)
if (currentValueIndex == buffer.Length-1)
{
GazeData sum = buffer[0];
for (Int32 index = 1; index < buffer.Length; index++)
{
GazeData sum = buffer[0];
for (Int32 index = 1; index < buffer.Length; index++)
{
sum += buffer[index];
}
lock (outputLock)
{
output = sum / buffer.Length;
}
sum += buffer[index];
}
sum /= buffer.Length;
lock (outputLock)
{
output = sum;
}
}
}
public void Reset()
{
Int32 bufferLength = Convert.ToInt32(InputFrequency / OutputFrequency);
buffer = new GazeData[bufferLength];
currentValueIndex = 0;
currentValueIndex = -1;
output = null;
}
}
......
......@@ -8,6 +8,7 @@ namespace TrackerBridge.DSP
{
interface IGazeFilter
{
event EventHandler<GazeData> OutputAvailable;
GazeData? Output { get; }
void Input(GazeData input);
void Reset();
......
......@@ -26,13 +26,14 @@ namespace TrackerBridge
}
}
public GazeDataProcessor(IBridgeTracker tracker)
{
tracker.TrackingFrequencyChanged += OnTrackingFrequencyChanged;
screenHeight = Convert.ToSingle(SystemParameters.PrimaryScreenHeight);
screenWidth = Convert.ToSingle(SystemParameters.PrimaryScreenWidth);
gazeFilters = new IGazeFilter[1];
gazeFilters[0] = new GazeDecimator(outputFrequency, tracker.GetTrackingFrequency());
gazeFilters[0] = new GazeDecimatorFixedLength(outputFrequency, tracker.GetTrackingFrequency());
}
public void Initialize()
{
......@@ -66,9 +67,9 @@ namespace TrackerBridge
{
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;
}
}
......
......@@ -48,7 +48,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DSP\GazeDecimator.cs" />
<Compile Include="DSP\GazeDecimatorFixedLength.cs" />
<Compile Include="GazeData.cs" />
<Compile Include="GazeDataProcessor.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