ScopeNG: use dynamic storage for TraceControl objects

This commit is contained in:
f4exb 2018-04-03 22:29:09 +02:00
parent b8b2ceb47d
commit 26b4b50d23
2 changed files with 53 additions and 38 deletions

View File

@ -439,7 +439,7 @@ int ScopeVisNG::processTraces(const SampleVector::const_iterator& cbegin, const
while ((begin < end) && (m_nbSamples > 0))
{
std::vector<TraceControl>::iterator itCtl = m_traces.m_tracesControl.begin();
std::vector<TraceControl*>::iterator itCtl = m_traces.m_tracesControl.begin();
std::vector<TraceData>::iterator itData = m_traces.m_tracesData.begin();
std::vector<float *>::iterator itTrace = m_traces.m_traces[m_traces.currentBufferIndex()].begin();
@ -451,21 +451,21 @@ int ScopeVisNG::processTraces(const SampleVector::const_iterator& cbegin, const
Projector::ProjectionType projectionType = itData->m_projectionType;
if (itCtl->m_traceCount[m_traces.currentBufferIndex()] < m_traceSize)
if ((*itCtl)->m_traceCount[m_traces.currentBufferIndex()] < m_traceSize)
{
uint32_t& traceCount = itCtl->m_traceCount[m_traces.currentBufferIndex()]; // reference for code clarity
uint32_t& traceCount = (*itCtl)->m_traceCount[m_traces.currentBufferIndex()]; // reference for code clarity
float v;
if (projectionType == Projector::ProjectionMagLin)
{
v = (itCtl->m_projector.run(*begin) - itData->m_ofs)*itData->m_amp - 1.0f;
v = ((*itCtl)->m_projector.run(*begin) - itData->m_ofs)*itData->m_amp - 1.0f;
}
else if (projectionType == Projector::ProjectionMagDB)
{
// there is no processing advantage in direct calculation without projector
// uint32_t magsq = begin->m_real*begin->m_real + begin->m_imag*begin->m_imag;
// v = ((log10f(magsq/1073741824.0f)*0.2f - 2.0f*itData->m_ofs) + 2.0f)*itData->m_amp - 1.0f;
float pdB = itCtl->m_projector.run(*begin);
float pdB = (*itCtl)->m_projector.run(*begin);
float p = pdB - (100.0f * itData->m_ofs);
v = ((p/50.0f) + 2.0f)*itData->m_amp - 1.0f;
@ -473,34 +473,34 @@ int ScopeVisNG::processTraces(const SampleVector::const_iterator& cbegin, const
{
if (traceCount == shift)
{
itCtl->m_maxPow = -200.0f;
itCtl->m_sumPow = 0.0f;
itCtl->m_nbPow = 1;
(*itCtl)->m_maxPow = -200.0f;
(*itCtl)->m_sumPow = 0.0f;
(*itCtl)->m_nbPow = 1;
}
if (pdB > -200.0f)
{
if (pdB > itCtl->m_maxPow)
if (pdB > (*itCtl)->m_maxPow)
{
itCtl->m_maxPow = pdB;
(*itCtl)->m_maxPow = pdB;
}
itCtl->m_sumPow += pdB;
itCtl->m_nbPow++;
(*itCtl)->m_sumPow += pdB;
(*itCtl)->m_nbPow++;
}
}
if ((m_nbSamples == 1) && (itCtl->m_nbPow > 0)) // on last sample create power display overlay
if ((m_nbSamples == 1) && ((*itCtl)->m_nbPow > 0)) // on last sample create power display overlay
{
double avgPow = itCtl->m_sumPow / itCtl->m_nbPow;
double peakToAvgPow = itCtl->m_maxPow - avgPow;
itData->m_textOverlay = QString("%1 %2 %3").arg(itCtl->m_maxPow, 0, 'f', 1).arg(avgPow, 0, 'f', 1).arg(peakToAvgPow, 4, 'f', 1, ' ');
itCtl->m_nbPow = 0;
double avgPow = (*itCtl)->m_sumPow / (*itCtl)->m_nbPow;
double peakToAvgPow = (*itCtl)->m_maxPow - avgPow;
itData->m_textOverlay = QString("%1 %2 %3").arg((*itCtl)->m_maxPow, 0, 'f', 1).arg(avgPow, 0, 'f', 1).arg(peakToAvgPow, 4, 'f', 1, ' ');
(*itCtl)->m_nbPow = 0;
}
}
else
{
v = (itCtl->m_projector.run(*begin) - itData->m_ofs) * itData->m_amp;
v = ((*itCtl)->m_projector.run(*begin) - itData->m_ofs) * itData->m_amp;
}
if(v > 1.0f) {
@ -789,7 +789,7 @@ void ScopeVisNG::updateMaxTraceDelay()
uint32_t projectorCounts[(int) Projector::nbProjectionTypes];
memset(projectorCounts, 0, ((int) Projector::nbProjectionTypes)*sizeof(uint32_t));
std::vector<TraceData>::iterator itData = m_traces.m_tracesData.begin();
std::vector<TraceControl>::iterator itCtrl = m_traces.m_tracesControl.begin();
std::vector<TraceControl*>::iterator itCtrl = m_traces.m_tracesControl.begin();
for (; itData != m_traces.m_tracesData.end(); ++itData, ++itCtrl)
{
@ -805,11 +805,11 @@ void ScopeVisNG::updateMaxTraceDelay()
if (projectorCounts[(int) itData->m_projectionType] > 0)
{
allocateCache = true;
itCtrl->m_projector.setCacheMaster(false);
(*itCtrl)->m_projector.setCacheMaster(false);
}
else
{
itCtrl->m_projector.setCacheMaster(true);
(*itCtrl)->m_projector.setCacheMaster(true);
}
projectorCounts[(int) itData->m_projectionType]++;
@ -820,9 +820,9 @@ void ScopeVisNG::updateMaxTraceDelay()
for (; itCtrl != m_traces.m_tracesControl.end(); ++itCtrl)
{
if (allocateCache) {
itCtrl->m_projector.setCache(m_projectorCache);
(*itCtrl)->m_projector.setCache(m_projectorCache);
} else {
itCtrl->m_projector.setCache(0);
(*itCtrl)->m_projector.setCache(0);
}
}

View File

@ -529,10 +529,12 @@ private:
m_triggerDelayCount(0),
m_triggerCounter(0)
{
qDebug("TriggerCondition");
}
~TriggerCondition()
{
qDebug("~TriggerCondition");
}
void initProjector()
@ -687,11 +689,13 @@ private:
TraceControl() : m_projector(Projector::ProjectionReal)
{
qDebug("TraceControl::TraceControl");
reset();
}
~TraceControl()
{
qDebug("TraceControl::~TraceControl");
}
void initProjector(Projector::ProjectionType projectionType)
@ -715,7 +719,7 @@ private:
struct Traces
{
std::vector<TraceControl> m_tracesControl; //!< Corresponding traces control data
std::vector<TraceControl*> m_tracesControl; //!< Corresponding traces control data
std::vector<TraceData> m_tracesData; //!< Corresponding traces data
std::vector<float *> m_traces[2]; //!< Double buffer of traces processed by glScope
int m_traceSize; //!< Current size of a trace in buffer
@ -750,11 +754,13 @@ private:
{
if (m_traces[0].size() < m_maxNbTraces)
{
qDebug("ScopeVisNG::addTrace");
m_traces[0].push_back(0);
m_traces[1].push_back(0);
m_tracesData.push_back(traceData);
m_tracesControl.push_back(TraceControl());
m_tracesControl.back().initProjector(traceData.m_projectionType);
m_tracesControl.push_back(new TraceControl());
TraceControl *traceControl = m_tracesControl.back();
traceControl->initProjector(traceData.m_projectionType);
resize(traceSize);
}
@ -763,8 +769,9 @@ private:
void changeTrace(const TraceData& traceData, uint32_t traceIndex)
{
if (traceIndex < m_tracesControl.size()) {
m_tracesControl[traceIndex].releaseProjector();
m_tracesControl[traceIndex].initProjector(traceData.m_projectionType);
TraceControl *traceControl = m_tracesControl[traceIndex];
traceControl->releaseProjector();
traceControl->initProjector(traceData.m_projectionType);
m_tracesData[traceIndex] = traceData;
}
}
@ -773,11 +780,14 @@ private:
{
if (traceIndex < m_tracesControl.size())
{
qDebug("ScopeVisNG::removeTrace");
m_traces[0].erase(m_traces[0].begin() + traceIndex);
m_traces[1].erase(m_traces[1].begin() + traceIndex);
m_tracesControl[traceIndex].releaseProjector();
TraceControl *traceControl = m_tracesControl[traceIndex];
traceControl->releaseProjector();
m_tracesControl.erase(m_tracesControl.begin() + traceIndex);
m_tracesData.erase(m_tracesData.begin() + traceIndex);
delete traceControl;
resize(m_traceSize); // reallocate pointers
}
@ -792,19 +802,24 @@ private:
int nextControlIndex = (traceIndex + (upElseDown ? 1 : -1)) % (m_tracesControl.size());
int nextDataIndex = (traceIndex + (upElseDown ? 1 : -1)) % (m_tracesData.size()); // should be the same
m_tracesControl[traceIndex].releaseProjector();
m_tracesControl[nextControlIndex].releaseProjector();
TraceControl *traceControl = m_tracesControl[traceIndex];
TraceControl *nextTraceControl = m_tracesControl[nextControlIndex];
TraceControl nextControl = m_tracesControl[nextControlIndex];
m_tracesControl[nextControlIndex] = m_tracesControl[traceIndex];
m_tracesControl[traceIndex] = nextControl;
traceControl->releaseProjector();
nextTraceControl->releaseProjector();
m_tracesControl[nextControlIndex] = traceControl;
m_tracesControl[traceIndex] = nextTraceControl;
TraceData nextData = m_tracesData[nextDataIndex];
m_tracesData[nextDataIndex] = m_tracesData[traceIndex];
m_tracesData[traceIndex] = nextData;
m_tracesControl[traceIndex].initProjector(m_tracesData[traceIndex].m_projectionType);
m_tracesControl[nextControlIndex].initProjector(m_tracesData[nextDataIndex].m_projectionType);
traceControl = m_tracesControl[traceIndex];
nextTraceControl = m_tracesControl[nextControlIndex];
traceControl->initProjector(m_tracesData[traceIndex].m_projectionType);
nextTraceControl->initProjector(m_tracesData[nextDataIndex].m_projectionType);
}
void resize(int traceSize)
@ -838,9 +853,9 @@ private:
{
evenOddIndex = !evenOddIndex;
for (std::vector<TraceControl>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it)
for (std::vector<TraceControl*>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it)
{
it->m_traceCount[currentBufferIndex()] = 0;
(*it)->m_traceCount[currentBufferIndex()] = 0;
}
}