From 657d2d5996b80455124d7adac79f439fa2dc1f38 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 31 May 2021 18:36:04 +0200 Subject: [PATCH] GLScope redesign: DoubleBufferSimple: replaced current iterator by current position --- sdrbase/dsp/scopevis.cpp | 2 +- sdrbase/dsp/scopevis.h | 13 ++++---- sdrbase/util/doublebuffer.h | 61 ++++++++++++++++--------------------- 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 1be0be5f8..3d09ebba9 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -318,7 +318,7 @@ void ScopeVis::processTrace(const std::vector& vbe // memory storage - m_traceDiscreteMemory.current().write(begin, end); + m_traceDiscreteMemory.current().write(begin, length); // Removed in 4.2.4 may cause trigger bug // if (m_traceDiscreteMemory.current().absoluteFill() < m_traceSize) diff --git a/sdrbase/dsp/scopevis.h b/sdrbase/dsp/scopevis.h index cbb13ed17..37c14706a 100644 --- a/sdrbase/dsp/scopevis.h +++ b/sdrbase/dsp/scopevis.h @@ -36,6 +36,7 @@ #include "util/message.h" #include "util/messagequeue.h" #include "util/doublebuffer.h" +#include "util/doublebuffermultiple.h" class GLScopeInterface; @@ -542,12 +543,8 @@ private: m_traceBuffer.reset(); } - void write(const SampleVector::const_iterator begin, const SampleVector::const_iterator end) { - m_traceBuffer.write(begin, end); - } - void write(const SampleVector::const_iterator begin, int nbSamples) { - m_traceBuffer.write(begin, begin + nbSamples); + m_traceBuffer.write(begin, nbSamples); } unsigned int absoluteFill() const { @@ -634,8 +631,10 @@ private: { uint32_t nextMemIndex = m_currentMemIndex < (m_memSize-1) ? m_currentMemIndex+1 : 0; m_traceBackBuffers[nextMemIndex].reset(); - m_traceBackBuffers[nextMemIndex].write(m_traceBackBuffers[m_currentMemIndex].m_endPoint - samplesToReport, - m_traceBackBuffers[m_currentMemIndex].m_endPoint); + m_traceBackBuffers[nextMemIndex].write( + m_traceBackBuffers[m_currentMemIndex].m_endPoint - samplesToReport, + samplesToReport + ); m_currentMemIndex = nextMemIndex; return m_traceBackBuffers[m_currentMemIndex]; // new trace } diff --git a/sdrbase/util/doublebuffer.h b/sdrbase/util/doublebuffer.h index 04b662aad..e3e023e46 100644 --- a/sdrbase/util/doublebuffer.h +++ b/sdrbase/util/doublebuffer.h @@ -32,7 +32,7 @@ public: DoubleBufferSimple() { m_size = 0; - m_current = m_data.end(); + m_currentPosition = 0; } ~DoubleBufferSimple() {} @@ -41,7 +41,7 @@ public: { m_size = other.m_size; m_data = other.m_data; - m_current = m_data.begin(); + m_currentPosition = 0; } DoubleBufferSimple& operator=(const DoubleBufferSimple& other) @@ -52,7 +52,7 @@ public: m_size = other.m_size; m_data = other.m_data; - m_current = m_data.begin(); + m_currentPosition = 0; return *this; } @@ -60,41 +60,34 @@ public: { m_size = size; m_data.resize(2*size); - m_current = m_data.begin(); + m_currentPosition = 0; } - void write(const typename std::vector::const_iterator& begin, const typename std::vector::const_iterator& cend) - { - typename std::vector::const_iterator end = cend; + void write(const typename std::vector::const_iterator& begin, int length) + { + int insize = length > m_size ? m_size : length; - if ((end - begin) > m_size) - { - end = begin + m_size; - } + std::copy(begin, begin + insize, m_data.begin() + m_currentPosition); - int insize = end - begin; + if ((m_currentPosition + insize) > m_size) + { + int sizeLeft = m_size - m_currentPosition; + std::copy(begin, begin + sizeLeft, m_data.begin() + m_currentPosition + m_size); + std::copy(begin + sizeLeft, begin + insize, m_data.begin()); + m_currentPosition = insize - sizeLeft; + } + else + { + std::copy(begin, begin + insize, m_data.begin() + m_currentPosition + m_size); + m_currentPosition += insize; + } + } - std::copy(begin, end, m_current); - - if (((m_current - m_data.begin()) + insize) > m_size) - { - int sizeLeft = m_size - (m_current - m_data.begin()); - std::copy(begin, begin + sizeLeft, m_current + m_size); - std::copy(begin + sizeLeft, end, m_data.begin()); - m_current = m_data.begin() + (insize - sizeLeft); - } - else - { - std::copy(begin, end, m_current + m_size); - m_current += insize; - } - } - - typename std::vector::iterator getCurrent() const { return m_current + m_size; } + typename std::vector::iterator getCurrent() { return m_data.begin() + m_currentPosition + m_size; } typename std::vector::const_iterator begin() const { return m_data.begin(); } typename std::vector::iterator begin() { return m_data.begin(); } - unsigned int absoluteFill() const { return m_current - m_data.begin(); } - void reset() { m_current = m_data.begin(); } + unsigned int absoluteFill() const { return m_currentPosition; } + void reset() { m_currentPosition = 0; } QByteArray serialize() const { @@ -102,7 +95,7 @@ public: QByteArray buf(reinterpret_cast(m_data.data()), m_data.size()*sizeof(T)); s.writeS32(1, m_size); - s.writeU32(2, m_current - m_data.begin()); + s.writeU32(2, m_currentPosition); s.writeBlob(3, buf); return s.final(); @@ -124,7 +117,7 @@ public: d.readS32(1, &m_size, m_data.size()/2); m_data.resize(2*m_size); d.readU32(2, &tmpUInt, 0); - m_current = m_data.begin() + tmpUInt; + m_currentPosition = tmpUInt; d.readBlob(3, &buf); //qDebug("DoubleBufferSimple::deserialize: m_data.size(): %u buf.size(): %d", m_data.size(), buf.size()); //std::copy(reinterpret_cast(m_data.data()), buf.data(), buf.data() + buf.size()); // bug @@ -141,7 +134,7 @@ public: private: int m_size; std::vector m_data; - typename std::vector::iterator m_current; + int m_currentPosition; }; #endif /* SDRBASE_UTIL_DOUBLEBUFFER_H_ */