Skip to content

Commit ffd78ac

Browse files
committed
Fix low sample rate LFP display lag for wide displays
1 parent b146d73 commit ffd78ac

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

Plugins/LfpViewer/LfpDisplayCanvas.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,10 +1262,11 @@ void LfpDisplaySplitter::updateScreenBuffer()
12621262
lastScreenBufferIndex.set (channel, sbi);
12631263
//std::cout << "Setting channel " << channel << " lastScreenBufferIndex to " << lastScreenBufferIndex[channel] << std::endl;
12641264

1265-
float subSampleOffset = leftOverSamples[channel];
1265+
float pixelOffset = leftOverSamples[channel];
1266+
float subSampleOffset = 0.0f;
12661267

12671268
//if (ratio > 1)
1268-
pixelsToFill += subSampleOffset; // keep track of fractional pixels left over from the last round
1269+
pixelsToFill += pixelOffset; // keep track of fractional pixels left over from the last round
12691270

12701271
if (triggerChannel >= 0)
12711272
{
@@ -1291,7 +1292,8 @@ void LfpDisplaySplitter::updateScreenBuffer()
12911292
newSamples += displayBufferSize;
12921293

12931294
pixelsToFill = newSamples * invRatio;
1294-
subSampleOffset = 0;
1295+
pixelOffset = 0.0f;
1296+
subSampleOffset = 0.0f;
12951297

12961298
// rewind screen buffer to the far left
12971299
screenBufferIndex.set (channel, 0);
@@ -1414,7 +1416,7 @@ void LfpDisplaySplitter::updateScreenBuffer()
14141416
// subSampleOffset, which accumulates rounding errors,
14151417
// causing the displayed sample positions to drift from
14161418
// the true timeline.
1417-
float samplePos = float (i) * ratio;
1419+
float samplePos = (float (i) - pixelOffset) * ratio;
14181420
int sampleStep = int (samplePos);
14191421
float alpha = samplePos - float (sampleStep);
14201422

@@ -1427,13 +1429,8 @@ void LfpDisplaySplitter::updateScreenBuffer()
14271429
}
14281430
else
14291431
{
1430-
// Skip the very first pixel if the display buffer has
1431-
// never been written (dbiStart == 0 means no previous
1432-
// sample exists to interpolate from).
1433-
if (dbiStart == 0 && sampleStep == 0)
1434-
continue;
1435-
1436-
const float val0 = displayData[lastIndex];
1432+
const bool hasPreviousSample = ! (dbiStart == 0 && sampleStep == 0);
1433+
const float val0 = hasPreviousSample ? displayData[lastIndex] : displayData[curDbi];
14371434
const float val1 = displayData[curDbi];
14381435
const float val = (1.0f - alpha) * val0 + alpha * val1;
14391436

0 commit comments

Comments
 (0)