2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/scopevis.h"
|
|
|
|
#include "gui/glscope.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "util/messagequeue.h"
|
|
|
|
|
2015-07-06 07:17:51 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
ScopeVis::ScopeVis(GLScope* glScope) :
|
|
|
|
m_glScope(glScope),
|
2015-07-06 23:17:16 +00:00
|
|
|
m_trace(96000),
|
2014-05-18 15:52:39 +00:00
|
|
|
m_fill(0),
|
|
|
|
m_triggerState(Untriggered),
|
|
|
|
m_triggerChannel(TriggerFreeRun),
|
|
|
|
m_triggerLevelHigh(0.01 * 32768),
|
|
|
|
m_triggerLevelLow(0.01 * 32768 - 1024),
|
|
|
|
m_sampleRate(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVis::configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevelHigh, Real triggerLevelLow)
|
|
|
|
{
|
|
|
|
Message* cmd = DSPConfigureScopeVis::create(triggerChannel, triggerLevelHigh, triggerLevelLow);
|
|
|
|
cmd->submit(msgQueue, this);
|
|
|
|
}
|
|
|
|
|
2014-06-15 08:32:25 +00:00
|
|
|
void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
|
|
|
while(begin < end) {
|
|
|
|
if(m_triggerChannel == TriggerChannelI) {
|
|
|
|
if(m_triggerState == Untriggered) {
|
|
|
|
while(begin < end) {
|
|
|
|
if(begin->real() >= m_triggerLevelHigh) {
|
|
|
|
m_triggerState = Triggered;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_triggerState == Triggered) {
|
|
|
|
int count = end - begin;
|
|
|
|
if(count > (int)(m_trace.size() - m_fill))
|
|
|
|
count = m_trace.size() - m_fill;
|
|
|
|
std::vector<Complex>::iterator it = m_trace.begin() + m_fill;
|
|
|
|
for(int i = 0; i < count; ++i) {
|
|
|
|
*it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0);
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
m_fill += count;
|
|
|
|
if(m_fill >= m_trace.size()) {
|
|
|
|
m_glScope->newTrace(m_trace, m_sampleRate);
|
|
|
|
m_fill = 0;
|
|
|
|
m_triggerState = WaitForReset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_triggerState == WaitForReset) {
|
|
|
|
while(begin < end) {
|
|
|
|
if(begin->real() < m_triggerLevelLow) {
|
|
|
|
m_triggerState = Untriggered;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(m_triggerChannel == TriggerChannelQ) {
|
|
|
|
if(m_triggerState == Untriggered) {
|
|
|
|
while(begin < end) {
|
|
|
|
if(begin->imag() >= m_triggerLevelHigh) {
|
|
|
|
m_triggerState = Triggered;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_triggerState == Triggered) {
|
|
|
|
int count = end - begin;
|
|
|
|
if(count > (int)(m_trace.size() - m_fill))
|
|
|
|
count = m_trace.size() - m_fill;
|
|
|
|
std::vector<Complex>::iterator it = m_trace.begin() + m_fill;
|
|
|
|
for(int i = 0; i < count; ++i) {
|
|
|
|
*it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0);
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
m_fill += count;
|
|
|
|
if(m_fill >= m_trace.size()) {
|
|
|
|
m_glScope->newTrace(m_trace, m_sampleRate);
|
|
|
|
m_fill = 0;
|
|
|
|
m_triggerState = WaitForReset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_triggerState == WaitForReset) {
|
|
|
|
while(begin < end) {
|
|
|
|
if(begin->imag() < m_triggerLevelLow) {
|
|
|
|
m_triggerState = Untriggered;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int count = end - begin;
|
|
|
|
if(count > (int)(m_trace.size() - m_fill))
|
|
|
|
count = m_trace.size() - m_fill;
|
|
|
|
std::vector<Complex>::iterator it = m_trace.begin() + m_fill;
|
|
|
|
for(int i = 0; i < count; ++i) {
|
|
|
|
*it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0);
|
|
|
|
++begin;
|
|
|
|
}
|
|
|
|
m_fill += count;
|
|
|
|
if(m_fill >= m_trace.size()) {
|
|
|
|
m_glScope->newTrace(m_trace, m_sampleRate);
|
|
|
|
m_fill = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVis::start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeVis::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-23 18:05:28 +00:00
|
|
|
bool ScopeVis::handleMessageKeep(Message* message)
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
|
|
|
if(DSPSignalNotification::match(message)) {
|
|
|
|
DSPSignalNotification* signal = (DSPSignalNotification*)message;
|
2015-07-06 07:17:51 +00:00
|
|
|
//fprintf(stderr, "ScopeVis::handleMessage @%x : %d samples/sec, %lld Hz offset\n", this, signal->getSampleRate(), signal->getFrequencyOffset());
|
2014-05-18 15:52:39 +00:00
|
|
|
m_sampleRate = signal->getSampleRate();
|
|
|
|
return true;
|
|
|
|
} else if(DSPConfigureScopeVis::match(message)) {
|
|
|
|
DSPConfigureScopeVis* conf = (DSPConfigureScopeVis*)message;
|
|
|
|
m_triggerState = Untriggered;
|
|
|
|
m_triggerChannel = (TriggerChannel)conf->getTriggerChannel();
|
|
|
|
m_triggerLevelHigh = conf->getTriggerLevelHigh() * 32767;
|
|
|
|
m_triggerLevelLow = conf->getTriggerLevelLow() * 32767;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 18:05:28 +00:00
|
|
|
|
|
|
|
bool ScopeVis::handleMessage(Message* message)
|
|
|
|
{
|
|
|
|
bool done = handleMessageKeep(message);
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
{
|
|
|
|
message->completed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return done;
|
|
|
|
}
|
2015-07-06 23:17:16 +00:00
|
|
|
|
|
|
|
void ScopeVis::setSampleRate(int sampleRate)
|
|
|
|
{
|
|
|
|
m_sampleRate = sampleRate;
|
|
|
|
}
|