1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

GLScope redesign: TraceBackDiscreteMemory refactoring

This commit is contained in:
f4exb 2021-06-06 11:12:27 +02:00
parent 046c066c11
commit 9642eac44d
2 changed files with 91 additions and 50 deletions

View File

@ -304,7 +304,7 @@ void ScopeVis::processMemoryTrace()
}
SampleVector::const_iterator mend;
m_traceDiscreteMemory.at(traceMemoryIndex).getEndPoint(mend);
m_traceDiscreteMemory.getEndPointAt(traceMemoryIndex, mend);
SampleVector::const_iterator mbegin = mend - m_traceSize;
SampleVector::const_iterator mbegin_tb = mbegin - m_maxTraceDelay;
m_nbSamples = m_traceSize + m_maxTraceDelay;
@ -314,14 +314,14 @@ void ScopeVis::processMemoryTrace()
}
}
void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbegin, int length, int& triggerPointToEnd)
void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vcbegin, int length, int& triggerPointToEnd)
{
SampleVector::const_iterator begin(vbegin[0]);
std::vector<SampleVector::const_iterator> vbegin(vcbegin);
int firstRemainder = length;
// memory storage
m_traceDiscreteMemory.current().write(begin, length);
m_traceDiscreteMemory.writeCurrent(vbegin[0], length);
// Removed in 4.2.4 may cause trigger bug
// if (m_traceDiscreteMemory.current().absoluteFill() < m_traceSize)
@ -351,7 +351,9 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
{
if (triggerCondition->m_triggerDelayCount > 0) // skip samples during delay period
{
begin += triggerCondition->m_triggerDelayCount;
for (auto begin : vbegin) {
begin += triggerCondition->m_triggerDelayCount;
}
processed += triggerCondition->m_triggerDelayCount;
firstRemainder -= triggerCondition->m_triggerDelayCount;
triggerCondition->m_triggerDelayCount = 0;
@ -363,7 +365,9 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
{
m_triggerComparator.reset();
m_triggerState = TriggerUntriggered;
++begin;
for (auto begin : vbegin) {
++begin;
}
++processed;
--firstRemainder;
continue;
@ -380,13 +384,18 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
}
}
if (m_triggerComparator.triggered(*begin, *triggerCondition)) // matched the current trigger
uint32_t triggerStreamIndex = triggerCondition->m_triggerData.m_streamIndex;
const Sample& s = *vbegin[triggerStreamIndex];
if (m_triggerComparator.triggered(s, *triggerCondition)) // matched the current trigger
{
if (triggerCondition->m_triggerData.m_triggerDelay > 0)
{
triggerCondition->m_triggerDelayCount = triggerCondition->m_triggerData.m_triggerDelay; // initialize delayed samples counter
m_triggerState = TriggerDelay;
++begin;
for (auto begin : vbegin) {
++begin;
}
++processed;
--firstRemainder;
continue;
@ -408,7 +417,9 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
}
}
++begin;
for (auto begin : vbegin) {
++begin;
}
++processed;
--firstRemainder;
} // look for trigger
@ -421,8 +432,9 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
int remainder;
int count = firstRemainder; // number of samples in traceback buffer past the current point
SampleVector::iterator mend;
m_traceDiscreteMemory.current().current(mend);
SampleVector::iterator mbegin = mend - count;
m_traceDiscreteMemory.getCurrent(mend);
SampleVector::iterator mbegin;
TraceBackDiscreteMemory::moveIt(mend, mbegin, -count);
if (m_traceStart) // start of trace processing
{
@ -436,12 +448,18 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
// process until begin point
if (m_maxTraceDelay > 0) { // trace back
processTraces(mbegin - m_preTriggerDelay - m_maxTraceDelay, m_maxTraceDelay, true);
if (m_maxTraceDelay > 0)
{ // trace back
SampleVector::iterator tbegin;
TraceBackDiscreteMemory::moveIt(mbegin, tbegin, - m_preTriggerDelay - m_maxTraceDelay);
processTraces(tbegin , m_maxTraceDelay, true);
}
if (m_preTriggerDelay > 0) { // pre-trigger
processTraces(mbegin - m_preTriggerDelay, m_preTriggerDelay);
if (m_preTriggerDelay > 0)
{ // pre-trigger
SampleVector::iterator tbegin;
TraceBackDiscreteMemory::moveIt(mbegin, tbegin, -m_preTriggerDelay);
processTraces(tbegin, m_preTriggerDelay);
}
// process the rest of the trace
@ -456,8 +474,8 @@ void ScopeVis::processTrace(const std::vector<SampleVector::const_iterator>& vbe
if (remainder >= 0) // finished
{
mbegin = mend - remainder;
m_traceDiscreteMemory.current().setEndPoint(mbegin);
TraceBackDiscreteMemory::moveIt(mend, mbegin, -remainder);
m_traceDiscreteMemory.setCurrentEndPoint(mbegin);
m_traceDiscreteMemory.store(m_preTriggerDelay+remainder); // next memory trace.
m_triggerState = TriggerUntriggered;
m_triggerWaitForReset = m_triggerOneShot;

View File

@ -610,17 +610,17 @@ private:
SampleVector::iterator m_endPoint;
};
typedef std::vector<TraceBackBuffer> TraceBackBufferStream;
struct TraceBackDiscreteMemory
{
std::vector<TraceBackBuffer> m_traceBackBuffers;
uint32_t m_memSize;
uint32_t m_currentMemIndex;
uint32_t m_traceSize;
/**
* Give memory size in number of traces
*/
TraceBackDiscreteMemory(uint32_t size) : m_memSize(size), m_currentMemIndex(0), m_traceSize(0)
TraceBackDiscreteMemory(uint32_t size) :
m_memSize(size),
m_currentMemIndex(0),
m_traceSize(0)
{
m_traceBackBuffers.resize(m_memSize);
}
@ -643,7 +643,7 @@ private:
* Copy a trace length of samples into the new memory slot
* samplesToReport are the number of samples to report on the next trace
*/
TraceBackBuffer &store(int samplesToReport)
void store(int samplesToReport)
{
uint32_t nextMemIndex = m_currentMemIndex < (m_memSize-1) ? m_currentMemIndex+1 : 0;
m_traceBackBuffers[nextMemIndex].reset();
@ -652,34 +652,8 @@ private:
samplesToReport
);
m_currentMemIndex = nextMemIndex;
return m_traceBackBuffers[m_currentMemIndex]; // new trace
}
/**
* Recalls trace at shift positions back. Therefore 0 is current. Wraps around memory size.
*/
TraceBackBuffer& recall(uint32_t shift)
{
int index = (m_currentMemIndex + (m_memSize - (shift % m_memSize))) % m_memSize;
return m_traceBackBuffers[index];
}
/**
* Return trace at current memory position
*/
TraceBackBuffer& current()
{
return m_traceBackBuffers[m_currentMemIndex];
}
/**
* Return trace at given memory position
*/
TraceBackBuffer& at(int index)
{
return m_traceBackBuffers[index];
}
/**
* Return current memory index
*/
@ -742,6 +716,55 @@ private:
return false;
}
}
/**
* Get current point at current memory position
*/
void getCurrent(SampleVector::iterator& it) {
current().current(it);
}
/**
* Set end point at current memory position
*/
void setCurrentEndPoint(const SampleVector::iterator& it) {
current().setEndPoint(it);
}
/**
* Get end point at given memory position
*/
void getEndPointAt(int index, SampleVector::const_iterator& mend) {
at(index).getEndPoint(mend);
}
/**
* Write trace at current memory position
*/
void writeCurrent(const SampleVector::const_iterator& begin, int length) {
current().write(begin, length);
}
/**
* Move buffer iterator by a certain amount
*/
static void moveIt(const SampleVector::iterator& x, SampleVector::iterator& y, int amount) {
y = x + amount;
}
private:
std::vector<TraceBackBuffer> m_traceBackBuffers;
uint32_t m_memSize;
uint32_t m_currentMemIndex;
uint32_t m_traceSize;
TraceBackBuffer& current() { //!< Return trace at current memory position
return m_traceBackBuffers[m_currentMemIndex];
}
TraceBackBuffer& at(int index) { //!< Return trace at given memory position
return m_traceBackBuffers[index];
}
};
/**