Skip to content

Commit 59af769

Browse files
committed
Tweaks
1 parent 5be1468 commit 59af769

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

source/TS.NET.Engine/Threads/ProcessingThread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ private static unsafe void Loop(
724724
eventTrigger.EnqueueEvent(eventSampleIndex);
725725
}
726726

727-
eventTrigger.Process(sampleLengthPerChannel, sampleStartIndex, ref eventTriggerResults);
727+
eventTrigger.Process(sampleLengthPerChannel, sampleStartIndex, acquisitionBuffer.SamplesInBuffer, ref eventTriggerResults);
728728

729729
if (eventTriggerResults.CaptureEndCount > 0)
730730
{

source/TS.NET/Processing/Triggers/EventTrigger.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class EventTrigger : IEventTrigger
55
enum TriggerState { Unarmed, InCapture, InHoldoff }
66
private TriggerState triggerState = TriggerState.Unarmed;
77

8+
private long windowWidth;
9+
810
private long captureSamples;
911
private long captureRemaining;
1012

@@ -25,6 +27,8 @@ public void SetHorizontal(long windowWidth, long windowTriggerPosition, long add
2527
if (windowTriggerPosition > windowWidth - 1)
2628
windowTriggerPosition = windowWidth - 1;
2729

30+
this.windowWidth = windowWidth;
31+
2832
captureSamples = windowWidth - windowTriggerPosition;
2933
captureRemaining = 0;
3034

@@ -42,7 +46,7 @@ public void EnqueueEvent(ulong sampleIndex)
4246
eventQueue.Enqueue(sampleIndex);
4347
}
4448

45-
public void Process(int inputLength, ulong sampleStartIndex, ref EventTriggerResults results)
49+
public void Process(int inputLength, ulong sampleStartIndex, int acquisitionSamplesInBuffer, ref EventTriggerResults results)
4650
{
4751
ulong chunkStart = sampleStartIndex;
4852
ulong chunkEnd = sampleStartIndex + (ulong)inputLength;
@@ -56,6 +60,7 @@ public void Process(int inputLength, ulong sampleStartIndex, ref EventTriggerRes
5660
{
5761
case TriggerState.Unarmed:
5862
{
63+
5964
// Empty stale events out of queue.
6065
// This does limit the scope of triggers to current & future chunks,
6166
// when in reality there's a whole acquisition buffer available.
@@ -66,6 +71,13 @@ public void Process(int inputLength, ulong sampleStartIndex, ref EventTriggerRes
6671
eventQueue.Dequeue();
6772
}
6873

74+
// Only allow capture events once at least windowWidth samples have passed
75+
if (acquisitionSamplesInBuffer < windowWidth)
76+
{
77+
i = inputLength;
78+
break;
79+
}
80+
6981
if (eventQueue.TryPeek(out var eventIndex) && eventIndex >= chunkStart && eventIndex < chunkEnd)
7082
{
7183
eventQueue.Dequeue();

source/TS.NET/Processing/Triggers/IEventTrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ public interface IEventTrigger
44
{
55
void SetHorizontal(long windowWidth, long windowTriggerPosition, long additionalHoldoff);
66
void EnqueueEvent(ulong sampleIndex);
7-
void Process(int inputLength, ulong sampleStartIndex, ref EventTriggerResults results);
7+
void Process(int inputLength, ulong sampleStartIndex, int acquisitionSamplesInBuffer, ref EventTriggerResults results);
88
}

0 commit comments

Comments
 (0)