mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-31 06:12:26 -04:00
Tx support: added a sample source FIFO class
This commit is contained in:
parent
2f3bb94bbc
commit
6e82cb37b8
@ -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/samplesinkfifo.cpp
|
sdrbase/dsp/samplesinkfifo.cpp
|
||||||
|
sdrbase/dsp/samplesourcefifo.cpp
|
||||||
sdrbase/dsp/samplesinkfifodoublebuffered.cpp
|
sdrbase/dsp/samplesinkfifodoublebuffered.cpp
|
||||||
sdrbase/dsp/basebandsamplesink.cpp
|
sdrbase/dsp/basebandsamplesink.cpp
|
||||||
sdrbase/dsp/nullsink.cpp
|
sdrbase/dsp/nullsink.cpp
|
||||||
@ -206,6 +207,7 @@ set(sdrbase_HEADERS
|
|||||||
sdrbase/dsp/phaselock.h
|
sdrbase/dsp/phaselock.h
|
||||||
sdrbase/dsp/pidcontroller.h
|
sdrbase/dsp/pidcontroller.h
|
||||||
sdrbase/dsp/samplesinkfifo.h
|
sdrbase/dsp/samplesinkfifo.h
|
||||||
|
sdrbase/dsp/samplesourcefifo.h
|
||||||
sdrbase/dsp/samplesinkfifodoublebuffered.h
|
sdrbase/dsp/samplesinkfifodoublebuffered.h
|
||||||
sdrbase/dsp/samplesinkfifodecimator.h
|
sdrbase/dsp/samplesinkfifodecimator.h
|
||||||
sdrbase/dsp/basebandsamplesink.h
|
sdrbase/dsp/basebandsamplesink.h
|
||||||
|
72
sdrbase/dsp/samplesourcefifo.cpp
Normal file
72
sdrbase/dsp/samplesourcefifo.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 "samplesourcefifo.h"
|
||||||
|
|
||||||
|
SampleSourceFifo::SampleSourceFifo(uint32_t size, uint32_t samplesChunkSize) :
|
||||||
|
m_size(size),
|
||||||
|
m_samplesChunkSize(samplesChunkSize),
|
||||||
|
m_i(0)
|
||||||
|
{
|
||||||
|
assert(samplesChunkSize < m_size/4);
|
||||||
|
m_data.resize(2*m_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SampleSourceFifo::~SampleSourceFifo()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void SampleSourceFifo::read(SampleVector::iterator& begin, SampleVector::iterator& end)
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
end = m_data.begin() + m_size + m_i;
|
||||||
|
begin = end - m_samplesChunkSize;
|
||||||
|
emit dataRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SampleSourceFifo::getReadIterator(SampleVector::iterator& beginRead)
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
beginRead = m_data.begin() + m_size + m_i - m_samplesChunkSize;
|
||||||
|
emit dataRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SampleSourceFifo::write(const Sample& sample)
|
||||||
|
{
|
||||||
|
m_data[m_i] = sample;
|
||||||
|
m_data[m_i+m_size] = sample;
|
||||||
|
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
m_i = (m_i+1) % m_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SampleSourceFifo::getWriteIterator(SampleVector::iterator& writeAt)
|
||||||
|
{
|
||||||
|
writeAt = m_data.begin() + m_i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SampleSourceFifo::bumpIndex()
|
||||||
|
{
|
||||||
|
m_data[m_i+m_size] = m_data[m_i];
|
||||||
|
m_i = (m_i+1) % m_size;
|
||||||
|
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
m_i = (m_i+1) % m_size;
|
||||||
|
}
|
||||||
|
}
|
52
sdrbase/dsp/samplesourcefifo.h
Normal file
52
sdrbase/dsp/samplesourcefifo.h
Normal 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_SAMPLESOURCEFIFO_H_
|
||||||
|
#define SDRBASE_DSP_SAMPLESOURCEFIFO_H_
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "util/export.h"
|
||||||
|
#include "dsp/dsptypes.h"
|
||||||
|
|
||||||
|
class SDRANGEL_API SampleSourceFifo : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SampleSourceFifo(uint32_t size, uint32_t samplesChunkSize);
|
||||||
|
~SampleSourceFifo();
|
||||||
|
|
||||||
|
unsigned int getChunkSize() const { return m_samplesChunkSize; }
|
||||||
|
void read(SampleVector::iterator& begin, SampleVector::iterator& end);
|
||||||
|
void getReadIterator(SampleVector::iterator& beginRead); //!< begin read at this point for the chunksize length
|
||||||
|
void write(const Sample& sample); //!< write directly
|
||||||
|
void getWriteIterator(SampleVector::iterator& writeAt); //!< get iterator to current item for update - write phase 1
|
||||||
|
void bumpIndex(); //!< copy current item to second buffer and bump write index - write phase 2
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_size;
|
||||||
|
uint32_t m_samplesChunkSize;
|
||||||
|
SampleVector m_data;
|
||||||
|
uint32_t m_i;
|
||||||
|
QMutex m_mutex;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataRead(); // signal data has been read past a read chunk of samples
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SDRBASE_DSP_SAMPLESOURCEFIFO_H_ */
|
@ -56,6 +56,7 @@ SOURCES += mainwindow.cpp\
|
|||||||
dsp/pidcontroller.cpp\
|
dsp/pidcontroller.cpp\
|
||||||
dsp/phaselock.cpp\
|
dsp/phaselock.cpp\
|
||||||
dsp/samplesinkfifo.cpp\
|
dsp/samplesinkfifo.cpp\
|
||||||
|
dsp/samplesourcefifo.cpp\
|
||||||
dsp/samplesinkfifodoublebuffered.cpp\
|
dsp/samplesinkfifodoublebuffered.cpp\
|
||||||
dsp/basebandsamplesink.cpp\
|
dsp/basebandsamplesink.cpp\
|
||||||
dsp/nullsink.cpp\
|
dsp/nullsink.cpp\
|
||||||
@ -137,6 +138,7 @@ HEADERS += mainwindow.h\
|
|||||||
dsp/phaselock.h\
|
dsp/phaselock.h\
|
||||||
dsp/pidcontroller.h\
|
dsp/pidcontroller.h\
|
||||||
dsp/samplesinkfifo.h\
|
dsp/samplesinkfifo.h\
|
||||||
|
dsp/samplesourcefifo.h\
|
||||||
dsp/samplesinkfifodoublebuffered.h\
|
dsp/samplesinkfifodoublebuffered.h\
|
||||||
dsp/samplesinkfifodecimator.h\
|
dsp/samplesinkfifodecimator.h\
|
||||||
dsp/basebandsamplesink.h\
|
dsp/basebandsamplesink.h\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user