1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-20 00:25:53 -05:00

Added a double buffered sample sink FIFO class

This commit is contained in:
f4exb 2016-10-06 15:39:18 +02:00
parent f90be69221
commit 12ac603741
5 changed files with 1512 additions and 0 deletions

View File

@ -115,6 +115,7 @@ set(sdrbase_SOURCES
sdrbase/dsp/pidcontroller.cpp sdrbase/dsp/pidcontroller.cpp
sdrbase/dsp/phaselock.cpp sdrbase/dsp/phaselock.cpp
sdrbase/dsp/samplefifo.cpp sdrbase/dsp/samplefifo.cpp
sdrbase/dsp/samplesinkfifodoublebuffered.cpp
sdrbase/dsp/basebandsamplesink.cpp sdrbase/dsp/basebandsamplesink.cpp
sdrbase/dsp/nullsink.cpp sdrbase/dsp/nullsink.cpp
sdrbase/dsp/spectrumscopecombovis.cpp sdrbase/dsp/spectrumscopecombovis.cpp
@ -205,6 +206,8 @@ set(sdrbase_HEADERS
sdrbase/dsp/phaselock.h sdrbase/dsp/phaselock.h
sdrbase/dsp/pidcontroller.h sdrbase/dsp/pidcontroller.h
sdrbase/dsp/samplefifo.h sdrbase/dsp/samplefifo.h
sdrbase/dsp/samplesinkfifodoublebuffered.h
sdrbase/dsp/samplesinkfifodecimator.h
sdrbase/dsp/basebandsamplesink.h sdrbase/dsp/basebandsamplesink.h
sdrbase/dsp/nullsink.h sdrbase/dsp/nullsink.h
sdrbase/dsp/scopevis.h sdrbase/dsp/scopevis.h

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "samplesinkfifodoublebuffered.h"
SampleSinkFifoDoubleBuffered::SampleSinkFifoDoubleBuffered(uint32_t size, uint32_t signalThreshold) :
m_size(size),
m_signalThreshold(signalThreshold),
m_i(0),
m_count(0),
m_readIndex(0),
m_readCount(0)
{
assert(m_signalThreshold < m_size/2);
m_data.resize(2*m_size);
}
SampleSinkFifoDoubleBuffered::~SampleSinkFifoDoubleBuffered()
{
}
void SampleSinkFifoDoubleBuffered::getWriteIterator(SampleVector::iterator& it1)
{
it1 = m_data.begin() + m_i;
}
void SampleSinkFifoDoubleBuffered::bumpIndex(SampleVector::iterator& it1)
{
m_data[m_i+m_size] = m_data[m_i];
m_i = (m_i+1) % m_size;
it1 = m_data.begin() + m_i;
if (m_count < m_signalThreshold)
{
m_count++;
}
else
{
QMutexLocker mutexLocker(&m_mutex);
m_readIndex = m_i + m_size - m_count;
m_readCount = m_count;
m_count = 0;
emit dataReady();
}
}
void SampleSinkFifoDoubleBuffered::read(SampleVector::iterator& begin, SampleVector::iterator& end)
{
QMutexLocker mutexLocker(&m_mutex);
begin = m_data.begin() + m_readIndex;
end = begin + m_readCount;
}

View File

@ -0,0 +1,52 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_DSP_SAMPLESINKFIFODOUBLEBUFFERED_H_
#define SDRBASE_DSP_SAMPLESINKFIFODOUBLEBUFFERED_H_
#include <QObject>
#include <QMutex>
#include <stdint.h>
#include <assert.h>
#include "util/export.h"
#include "dsp/dsptypes.h"
class SDRANGEL_API SampleSinkFifoDoubleBuffered : public QObject {
Q_OBJECT
public:
SampleSinkFifoDoubleBuffered(uint32_t size, uint32_t signalThreshold);
~SampleSinkFifoDoubleBuffered();
void getWriteIterator(SampleVector::iterator& it1);
void bumpIndex(SampleVector::iterator& it1);
void read(SampleVector::iterator& begin, SampleVector::iterator& end);
private:
uint32_t m_size;
uint32_t m_signalThreshold;
SampleVector m_data;
uint32_t m_i;
uint32_t m_count;
uint32_t m_readIndex;
uint32_t m_readCount;
QMutex m_mutex;
signals:
void dataReady();
};
#endif /* SDRBASE_DSP_SAMPLESINKFIFODOUBLEBUFFERED_H_ */

View File

@ -56,6 +56,7 @@ SOURCES += mainwindow.cpp\
dsp/pidcontroller.cpp\ dsp/pidcontroller.cpp\
dsp/phaselock.cpp\ dsp/phaselock.cpp\
dsp/samplefifo.cpp\ dsp/samplefifo.cpp\
dsp/samplesinkfifodoublebuffered.cpp\
dsp/basebandsamplesink.cpp\ dsp/basebandsamplesink.cpp\
dsp/nullsink.cpp\ dsp/nullsink.cpp\
dsp/spectrumscopecombovis.cpp\ dsp/spectrumscopecombovis.cpp\
@ -136,6 +137,8 @@ HEADERS += mainwindow.h\
dsp/phaselock.h\ dsp/phaselock.h\
dsp/pidcontroller.h\ dsp/pidcontroller.h\
dsp/samplefifo.h\ dsp/samplefifo.h\
dsp/samplesinkfifodoublebuffered.h\
dsp/samplesinkfifodecimator.h\
dsp/basebandsamplesink.h\ dsp/basebandsamplesink.h\
dsp/nullsink.h\ dsp/nullsink.h\
dsp/scopevis.h\ dsp/scopevis.h\