1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 18:15:45 -05:00

Tx support: added a sample source FIFO class

This commit is contained in:
f4exb 2016-10-10 01:13:12 +02:00
parent 2f3bb94bbc
commit 6e82cb37b8
4 changed files with 128 additions and 0 deletions

View File

@ -115,6 +115,7 @@ set(sdrbase_SOURCES
sdrbase/dsp/pidcontroller.cpp
sdrbase/dsp/phaselock.cpp
sdrbase/dsp/samplesinkfifo.cpp
sdrbase/dsp/samplesourcefifo.cpp
sdrbase/dsp/samplesinkfifodoublebuffered.cpp
sdrbase/dsp/basebandsamplesink.cpp
sdrbase/dsp/nullsink.cpp
@ -206,6 +207,7 @@ set(sdrbase_HEADERS
sdrbase/dsp/phaselock.h
sdrbase/dsp/pidcontroller.h
sdrbase/dsp/samplesinkfifo.h
sdrbase/dsp/samplesourcefifo.h
sdrbase/dsp/samplesinkfifodoublebuffered.h
sdrbase/dsp/samplesinkfifodecimator.h
sdrbase/dsp/basebandsamplesink.h

View 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;
}
}

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_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_ */

View File

@ -56,6 +56,7 @@ SOURCES += mainwindow.cpp\
dsp/pidcontroller.cpp\
dsp/phaselock.cpp\
dsp/samplesinkfifo.cpp\
dsp/samplesourcefifo.cpp\
dsp/samplesinkfifodoublebuffered.cpp\
dsp/basebandsamplesink.cpp\
dsp/nullsink.cpp\
@ -137,6 +138,7 @@ HEADERS += mainwindow.h\
dsp/phaselock.h\
dsp/pidcontroller.h\
dsp/samplesinkfifo.h\
dsp/samplesourcefifo.h\
dsp/samplesinkfifodoublebuffered.h\
dsp/samplesinkfifodecimator.h\
dsp/basebandsamplesink.h\