Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b38d48da3eb6
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 89ece625d9d6
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Dec 7, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    89ece62 View commit details
Showing with 74 additions and 12 deletions.
  1. +71 −1 scopehal/Filter.cpp
  2. +2 −1 scopehal/Filter.h
  3. +1 −10 scopeprotocols/ThresholdFilter.cpp
72 changes: 71 additions & 1 deletion scopehal/Filter.cpp
Original file line number Diff line number Diff line change
@@ -996,7 +996,7 @@ void Filter::ClearAnalysisCache()
@return The ready-to-use output waveform
*/
AnalogWaveform* Filter::SetupOutputWaveform(AnalogWaveform* din, size_t stream, size_t skipstart, size_t skipend)
AnalogWaveform* Filter::SetupOutputWaveform(WaveformBase* din, size_t stream, size_t skipstart, size_t skipend)
{
//Create the waveform, but only if necessary
AnalogWaveform* cap = dynamic_cast<AnalogWaveform*>(GetData(stream));
@@ -1052,3 +1052,73 @@ AnalogWaveform* Filter::SetupOutputWaveform(AnalogWaveform* din, size_t stream,

return cap;
}

/**
@brief Sets up a digital output waveform and copies timebase configuration from the input.
A new output waveform is created if necessary, but when possible the existing one is reused.
Timestamps are copied from the input to the output.
@param din Input waveform
@param stream Stream index
@param skipstart Number of input samples to discard from the beginning of the waveform
@param skipend Number of input samples to discard from the end of the waveform
@return The ready-to-use output waveform
*/
DigitalWaveform* Filter::SetupDigitalOutputWaveform(WaveformBase* din, size_t stream, size_t skipstart, size_t skipend)
{
//Create the waveform, but only if necessary
DigitalWaveform* cap = dynamic_cast<DigitalWaveform*>(GetData(stream));
if(cap == NULL)
{
cap = new DigitalWaveform;
SetData(cap, stream);
}

//Copy configuration
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startFemtoseconds = din->m_startFemtoseconds;
cap->m_triggerPhase = din->m_triggerPhase;

size_t len = din->m_offsets.size() - (skipstart + skipend);
size_t curlen = cap->m_offsets.size();

cap->Resize(len);

//If the input waveform is NOT dense packed, no optimizations possible.
if(!din->m_densePacked)
{
memcpy(&cap->m_offsets[0], &din->m_offsets[skipstart], len*sizeof(int64_t));
memcpy(&cap->m_durations[0], &din->m_durations[skipstart], len*sizeof(int64_t));
cap->m_densePacked = false;
}

//Input waveform is dense packed, but output is not.
//Need to clear some old stuff but we can produce a dense packed output.
//Note that we copy from zero regardless of skipstart to produce a dense packed output.
//TODO: AVX2 optimizations here so we don't need to read data we already know the value of
else if(!cap->m_densePacked)
{
memcpy(&cap->m_offsets[0], &din->m_offsets[0], len*sizeof(int64_t));
memcpy(&cap->m_durations[0], &din->m_durations[0], len*sizeof(int64_t));
cap->m_densePacked = true;
}

//Both waveforms are dense packed, but new size is bigger. Need to copy the additional data.
else if(len > curlen)
{
size_t increase = len - curlen;
memcpy(&cap->m_offsets[curlen], &din->m_offsets[curlen], increase*sizeof(int64_t));
memcpy(&cap->m_durations[curlen], &din->m_durations[curlen], increase*sizeof(int64_t));
}

//Both waveforms are dense packed, new size is smaller or the same.
//This is what we want: no work needed at all!
else
{
}

return cap;
}
3 changes: 2 additions & 1 deletion scopehal/Filter.h
Original file line number Diff line number Diff line change
@@ -194,7 +194,8 @@ class Filter : public OscilloscopeChannel
i ++;
}

AnalogWaveform* SetupOutputWaveform(AnalogWaveform* din, size_t stream, size_t skipstart, size_t skipend);
AnalogWaveform* SetupOutputWaveform(WaveformBase* din, size_t stream, size_t skipstart, size_t skipend);
DigitalWaveform* SetupDigitalOutputWaveform(WaveformBase* din, size_t stream, size_t skipstart, size_t skipend);

public:
//Text formatting for CHANNEL_TYPE_COMPLEX decodes
11 changes: 1 addition & 10 deletions scopeprotocols/ThresholdFilter.cpp
Original file line number Diff line number Diff line change
@@ -103,9 +103,7 @@ void ThresholdFilter::Refresh()
//Setup
float midpoint = m_parameters[m_threshname].GetFloatVal();
float hys = m_parameters[m_hysname].GetFloatVal();
DigitalWaveform* cap = new DigitalWaveform;
cap->Resize(len);
cap->CopyTimestamps(din);
auto cap = SetupDigitalOutputWaveform(din, 0, 0, 0);

//Threshold all of our samples
//Optimized inner loop if no hysteresis
@@ -131,11 +129,4 @@ void ThresholdFilter::Refresh()
cap->m_samples[i] = cur;
}
}

SetData(cap, 0);

//Copy our time scales from the input
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startFemtoseconds = din->m_startFemtoseconds;
}