20 #include <QMutexLocker> 46 m_livePreTriggerDelay(0),
47 m_currentTriggerIndex(0),
48 m_focusedTriggerIndex(0),
49 m_triggerState(TriggerUntriggered),
50 m_focusedTraceIndex(0),
51 m_traceSize(m_traceChunkSize),
52 m_liveTraceSize(m_traceChunkSize),
61 m_traceDiscreteMemory(m_nbTraceMemories),
64 m_triggerOneShot(false),
65 m_triggerWaitForReset(false),
66 m_currentTraceMemoryIndex(0)
68 setObjectName(
"ScopeVis");
100 qDebug(
"ScopeVis::setSampleRate: %d S/s", sampleRate);
137 qDebug() <<
"ScopeVis::addTrace:" 138 <<
" m_amp: " << traceData.
m_amp 139 <<
" m_ofs: " << traceData.
m_ofs 147 qDebug() <<
"ScopeVis::changeTrace:" 148 <<
" trace: " << traceIndex
149 <<
" m_amp: " << traceData.
m_amp 150 <<
" m_ofs: " << traceData.
m_ofs 158 qDebug() <<
"ScopeVis::removeTrace:" 159 <<
" trace: " << traceIndex;
166 qDebug() <<
"ScopeVis::moveTrace:" 167 <<
" trace: " << traceIndex
168 <<
" up: " << upElseDown;
221 void ScopeVis::feed(
const SampleVector::const_iterator& cbegin,
const SampleVector::const_iterator& end,
bool positiveOnly)
249 SampleVector::const_iterator begin(cbegin);
250 int triggerPointToEnd;
256 triggerPointToEnd = -1;
265 triggerPointToEnd = -1;
285 if (traceMemoryIndex < 0) {
290 SampleVector::const_iterator mbegin = mend -
m_traceSize;
299 void ScopeVis::processTrace(
const SampleVector::const_iterator& cbegin,
const SampleVector::const_iterator& end,
int& triggerPointToEnd)
301 SampleVector::const_iterator begin(cbegin);
353 triggerPointToEnd = end - begin;
380 triggerPointToEnd = end - begin;
394 int count = end - begin;
396 SampleVector::iterator mbegin = mend - count;
404 if (traceTime >= 1.0f) {
430 mbegin = mend - remainder;
441 int mTriggerPointToEnd = -1;
445 if (mTriggerPointToEnd >= 0) {
446 triggerPointToEnd = mTriggerPointToEnd;
490 int ScopeVis::processTraces(
const SampleVector::const_iterator& cbegin,
const SampleVector::const_iterator& end,
bool traceBack)
492 SampleVector::const_iterator begin(cbegin);
504 if (traceBack && ((end - begin) > itData->m_traceDelay)) {
517 v = ((*itCtl)->m_projector.run(*begin) - itData->m_ofs)*itData->m_amp - 1.0f;
521 Real magsq = (*itCtl)->m_projector.run(*begin);
522 v = (magsq - itData->m_ofs)*itData->m_amp - 1.0f;
524 if ((traceCount >= shift) && (traceCount < shift+length))
526 if (traceCount == shift)
528 (*itCtl)->m_maxPow = 0.0f;
529 (*itCtl)->m_sumPow = 0.0f;
530 (*itCtl)->m_nbPow = 1;
535 if (magsq > (*itCtl)->m_maxPow)
537 (*itCtl)->m_maxPow = magsq;
540 (*itCtl)->m_sumPow += magsq;
547 double avgPow = (*itCtl)->m_sumPow / (*itCtl)->m_nbPow;
548 itData->m_textOverlay = QString(
"%1 %2").arg((*itCtl)->m_maxPow, 0,
'e', 2).arg(avgPow, 0,
'e', 2);
549 (*itCtl)->m_nbPow = 0;
556 double magsq = re*re + im*im;
557 float pdB = log10f(magsq) * 10.0f;
558 float p = pdB - (100.0f * itData->m_ofs);
559 v = ((p/50.0f) + 2.0f)*itData->m_amp - 1.0f;
561 if ((traceCount >= shift) && (traceCount < shift+length))
563 if (traceCount == shift)
565 (*itCtl)->m_maxPow = 0.0f;
566 (*itCtl)->m_sumPow = 0.0f;
567 (*itCtl)->m_nbPow = 1;
572 if (magsq > (*itCtl)->m_maxPow)
574 (*itCtl)->m_maxPow = magsq;
577 (*itCtl)->m_sumPow += magsq;
584 double avgPow = log10f((*itCtl)->m_sumPow / (*itCtl)->m_nbPow)*10.0;
585 double peakPow = log10f((*itCtl)->m_maxPow)*10.0;
586 double peakToAvgPow = peakPow - avgPow;
587 itData->m_textOverlay = QString(
"%1 %2 %3").arg(peakPow, 0,
'f', 1).arg(avgPow, 0,
'f', 1).arg(peakToAvgPow, 4,
'f', 1,
' ');
588 (*itCtl)->m_nbPow = 0;
593 v = ((*itCtl)->m_projector.run(*begin) - itData->m_ofs) * itData->m_amp;
598 }
else if (v < -1.0f) {
602 (*itTrace)[2*traceCount]
603 = traceCount - shift;
604 (*itTrace)[2*traceCount + 1] = v;
615 if (traceTime >= 1.0f) {
622 if (traceTime < 1.0f)
656 qDebug() <<
"ScopeVis::handleMessage: DSPSignalNotification: m_sampleRate: " <<
m_sampleRate;
661 QMutexLocker configLocker(&
m_mutex);
703 qDebug() <<
"ScopeVis::handleMessage: MsgConfigureScopeVisNG:" 717 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGAddTrigger";
718 QMutexLocker configLocker(&
m_mutex);
726 QMutexLocker configLocker(&
m_mutex);
729 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGChangeTrigger: " << triggerIndex;
747 QMutexLocker configLocker(&
m_mutex);
750 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGRemoveTrigger: " << triggerIndex;
756 delete triggerCondition;
763 QMutexLocker configLocker(&
m_mutex);
766 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGMoveTrigger: " << triggerIndex;
768 if (!conf.
getMoveUp() && (triggerIndex == 0)) {
788 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGFocusOnTrigger: " << triggerIndex;
802 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGAddTrace";
803 QMutexLocker configLocker(&
m_mutex);
814 QMutexLocker configLocker(&
m_mutex);
818 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGChangeTrace: " << traceIndex;
827 QMutexLocker configLocker(&
m_mutex);
830 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGRemoveTrace: " << traceIndex;
839 QMutexLocker configLocker(&
m_mutex);
842 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGMoveTrace: " << traceIndex;
853 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGFocusOnTrace: " << traceIndex;
867 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGOneShot";
878 qDebug() <<
"ScopeVis::handleMessage: MsgScopeVisNGMemoryTrace: " << memoryIndex;
907 qDebug() <<
"ScopeVis::handleMessage" << message.
getIdentifier() <<
" not handled";
914 int maxTraceDelay = 0;
915 bool allocateCache =
false;
923 if (itData->m_traceDelay > maxTraceDelay)
925 maxTraceDelay = itData->m_traceDelay;
928 if (itData->m_projectionType < 0) {
932 if (projectorCounts[(
int) itData->m_projectionType] > 0)
934 allocateCache =
true;
935 (*itCtrl)->m_projector.setCacheMaster(
false);
939 (*itCtrl)->m_projector.setCacheMaster(
true);
942 projectorCounts[(int) itData->m_projectionType]++;
952 (*itCtrl)->m_projector.setCache(0);
970 (*it0)[2*
i] = (
i - shift);
971 (*it0)[2*
i + 1] = 0.0f;
972 (*it1)[2*
i] = (
i - shift);
973 (*it1)[2*
i + 1] = 0.0f;
987 float levelPowerLin = level + 1.0f;
988 float levelPowerdB = (100.0f * (level - 1.0f));
993 v = (levelPowerLin - itData->m_ofs)*itData->m_amp - 1.0f;
997 float ofsdB = itData->m_ofs * 100.0f;
998 v = ((levelPowerdB + 100.0f - ofsdB)*itData->m_amp)/50.0f - 1.0f;
1002 v = (level - itData->m_ofs) * itData->m_amp;
1007 }
else if (v < -1.0f) {
1011 itData->m_triggerDisplayLevel = v;
1015 itData->m_triggerDisplayLevel = 2.0f;
uint32_t getTriggerIndex() const
void addTrigger(const TriggerData &triggerData)
void newTraces(std::vector< float *> *traces)
uint32_t m_triggerRepeat
Number of trigger conditions before the final decisive trigger.
void addTrace(const TraceData &traceData, int traceSize)
ScopeVis(GLScope *glScope=0)
const TraceData & getTraceData() const
uint32_t currentBufferIndex() const
static MsgScopeVisNGChangeTrigger * create(const TriggerData &triggerData, uint32_t triggerIndex)
void changeTrigger(const TriggerData &triggerData, uint32_t triggerIndex)
static MsgScopeVisNGRemoveTrigger * create(uint32_t triggerIndex)
void write(const SampleVector::const_iterator begin, const SampleVector::const_iterator end)
void changeTrace(const TraceData &traceData, uint32_t traceIndex)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
std::vector< TraceControl * > m_tracesControl
Corresponding traces control data.
uint32_t m_focusedTriggerIndex
Index of the trigger that has focus.
void processTrace(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, int &triggerPointToEnd)
void moveTrigger(uint32_t triggerIndex, bool upElseDown)
void setTraceSize(int trceSize, bool emitSignal=false)
uint32_t getTraceIndex() const
bool m_triggerWaitForReset
In one shot mode suspended until reset by UI.
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
void focusOnTrace(uint32_t traceIndex)
int m_liveSampleRate
Sample rate in live mode.
void updateGLScopeDisplay()
void setTraces(std::vector< ScopeVis::TraceData > *tracesData, std::vector< float *> *traces)
std::vector< TraceData > m_tracesData
Corresponding traces data.
Calculate logarithmic (dB) of squared magnitude.
void removeTrace(uint32_t traceIndex)
const TriggerData & getTriggerData() const
TraceBackBuffer & current()
uint32_t getTriggerIndex() const
SampleVector::iterator current()
void setTriggerPre(uint32_t triggerPre, bool emitSignal=false)
number of samples
uint32_t currentIndex() const
bool nextTrigger()
Returns true if not final.
int m_focusedTraceIndex
Index of the trace that has focus.
Trigger is not kicked off yet (or trigger list is empty)
Gives the number of projections in the enum.
void setLiveRate(int sampleRate)
uint32_t m_timeOfsProMill
Start trace shift in 1/1000 trace size.
Trigger conditions have been kicked off but it is waiting for delay before final kick off...
void setFocusedTriggerData(ScopeVis::TriggerData &triggerData)
int m_traceDelay
Trace delay in number of samples.
static MsgScopeVisNGFocusOnTrace * create(uint32_t traceIndex)
const TriggerData & getTriggerData() const
uint32_t getTriggerIndex() const
void setMemoryIndex(uint32_t memoryIndex)
Real m_projectorCache[(int) Projector::nbProjectionTypes]
static MsgScopeVisNGMoveTrigger * create(uint32_t triggerIndex, bool moveUpElseDown)
uint32_t m_triggerCounter
Counter of trigger occurrences.
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
static MsgScopeVisNGMoveTrace * create(uint32_t traceIndex, bool moveUpElseDown)
uint32_t m_traceSize
Size of traces in number of samples.
uint32_t m_livePreTriggerDelay
Pre-trigger delay in number of samples in live mode.
uint32_t m_liveTraceSize
Size of traces in number of samples in live mode.
static MsgScopeVisNGFocusOnTrigger * create(uint32_t triggerIndex)
int m_liveLog2Decim
Sample rate decimation log2 in live mode.
static MsgScopeVisNGMemoryTrace * create(uint32_t memoryIndex)
TraceBackBuffer & at(int index)
uint32_t m_triggerDelayCount
Counter of samples for delay.
void configure(uint32_t traceSize, uint32_t timeBase, uint32_t timeOfsProMill, uint32_t triggerPre, bool freeRun)
void focusOnTrigger(uint32_t triggerIndex)
TraceBackBuffer & store(int samplesToReport)
void moveTrace(uint32_t traceIndex, bool upElseDown)
uint32_t m_timeBase
Trace display time divisor.
int m_triggerLocation
Trigger location from end point.
int m_maxTraceDelay
Maximum trace delay.
uint32_t m_currentTriggerIndex
Index of current index in the chain.
static MsgScopeVisNGOneShot * create(bool oneShot)
void setFocusedTraceIndex(uint32_t traceIndex)
void setPreTriggerDelay(uint32_t preTriggerDelay, bool emitSignal=false)
static bool match(const Message *message)
Calculate linear magnitude or modulus.
TriggerData m_triggerData
Trigger data.
static MsgScopeVisNGChangeTrace * create(const TraceData &traceData, uint32_t traceIndex)
Calculate linear squared magnitude or power.
bool m_traceStart
Trace is at start point.
void setTimeBase(int timeBase)
void setOneShot(bool oneShot)
float m_amp
Amplification factor.
static const uint32_t m_traceChunkSize
void setSampleRate(int sampleRate)
void resize(uint32_t size)
bool triggered(const Sample &s, TriggerCondition &triggerCondition)
uint32_t m_preTriggerDelay
Pre-trigger delay in number of samples.
Traces m_traces
Displayable traces.
static const uint32_t m_nbTraceMemories
void computeDisplayTriggerLevels()
void changeTrace(const TraceData &traceData, uint32_t traceIndex)
uint32_t getMemoryIndex() const
uint32_t getTraceIndex() const
void processMemoryTrace()
uint32_t getTriggerIndex() const
SampleVector::iterator m_endPoint
const QAtomicInt & getProcessingTraceIndex() const
void setTraceSize(uint32_t traceSize, bool emitSignal=false)
void setTimeOfsProMill(int timeOfsProMill)
Trigger has been kicked off.
int getSampleRate() const
void addTrace(const TraceData &traceData)
const TraceData & getTraceData() const
virtual const char * getIdentifier() const
static MsgScopeVisNGRemoveTrace * create(uint32_t traceIndex)
uint32_t m_triggerDelay
Delay before the trigger is kicked off in number of samples (trigger delay)
int m_nbSamples
Number of samples yet to process in one complex trace.
void resize(int traceSize)
uint32_t m_currentTraceMemoryIndex
The current index of trace in memory (0: current)
int processTraces(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool traceBack=false)
static MsgScopeVisNGAddTrace * create(const TraceData &traceData)
std::vector< TriggerCondition * > m_triggerConditions
Chain of triggers.
void moveTrace(uint32_t traceIndex, bool upElseDown)
bool isVerticalDisplayChange(const TraceData &traceData, uint32_t traceIndex)
TriggerComparator m_triggerComparator
Compares sample level to trigger level.
void setLiveRateLog2Decim(int log2Decim)
TraceBackDiscreteMemory m_traceDiscreteMemory
Complex trace memory for triggered states TODO: vectorize when more than on input is allowed...
TriggerState m_triggerState
Current trigger state.
void removeTrigger(uint32_t triggerIndex)
uint32_t getTraceIndex() const
bool m_triggerOneShot
True when one shot mode is active.
uint32_t getTraceIndex() const
float m_ofs
Offset factor.
int m_sampleRate
Actual sample rate being used.
void setSampleRate(int sampleRate)
static MsgScopeVisNGAddTrigger * create(const TriggerData &triggerData)
void updateMaxTraceDelay()
std::vector< float * > m_traces[2]
Double buffer of traces processed by glScope.
void removeTrace(uint32_t traceIndex)
bool m_freeRun
True if free running (trigger globally disabled)
virtual bool handleMessage(const Message &message)
Processing of a message. Returns true if message has actually been processed.