1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 12:22:00 -05:00
sdrangel/sdrbase/dsp/samplemififo.h

101 lines
4.5 KiB
C
Raw Normal View History

2019-09-24 18:35:02 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 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 //
// (at your option) any later version. //
// //
// 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 INCLUDE_SAMPLEMIFIFO_H
#define INCLUDE_SAMPLEMIFIFO_H
#include <QObject>
#include <QMutex>
2019-10-02 19:19:43 -04:00
#include <vector>
2019-09-24 18:35:02 -04:00
#include "dsp/dsptypes.h"
#include "export.h"
class SDRBASE_API SampleMIFifo : public QObject {
Q_OBJECT
public:
2019-10-02 19:19:43 -04:00
SampleMIFifo(QObject *parent = nullptr);
SampleMIFifo(unsigned int nbStreams, unsigned int size, QObject *parent = nullptr);
2019-10-06 03:53:32 -04:00
~SampleMIFifo();
2019-10-02 19:19:43 -04:00
void init(unsigned int nbStreams, unsigned int size);
void reset();
void writeSync(const quint8* data, unsigned int count); //!< de-interleaved data in input with count bytes for each stream
void writeSync(const std::vector<SampleVector::const_iterator>& vbegin, unsigned int size);
void readSync(
std::vector<SampleVector::const_iterator*> vpart1Begin, std::vector<SampleVector::const_iterator*> vpart1End,
std::vector<SampleVector::const_iterator*> vpart2Begin, std::vector<SampleVector::const_iterator*> vpart2End
);
void readSync(
std::vector<unsigned int>& vPart1Begin, std::vector<unsigned int>& vPart1End,
std::vector<unsigned int>& vPart2Begin, std::vector<unsigned int>& vPart2End
);
void readSync(
unsigned int& ipart1Begin, unsigned int& ipart1End,
unsigned int& ipart2Begin, unsigned int& ipart2End
);
void writeAsync(const quint8* data, unsigned int count, unsigned int stream);
2019-10-06 03:53:32 -04:00
void writeAsync(const SampleVector::const_iterator& begin, unsigned int inputSize, unsigned int stream);
2019-10-02 19:19:43 -04:00
void readAsync(
SampleVector::const_iterator* part1Begin, SampleVector::const_iterator* part1End,
SampleVector::const_iterator* part2Begin, SampleVector::const_iterator* part2End,
unsigned int stream);
void readAsync(
unsigned int& ipart1Begin, unsigned int& ipart1End,
unsigned int& ipart2Begin, unsigned int& ipart2End,
unsigned int stream);
2019-10-02 19:19:43 -04:00
const std::vector<SampleVector>& getData() { return m_data; }
const SampleVector& getData(unsigned int stream) { return m_data[stream]; }
unsigned int getNbStreams() const { return m_data.size(); }
inline unsigned int fillSync()
{
QMutexLocker mutexLocker(&m_mutex);
2019-10-02 19:19:43 -04:00
unsigned int fill = m_head <= m_fill ? m_fill - m_head : m_size - (m_head - m_fill);
return fill;
}
inline unsigned int fillAsync(unsigned int stream)
{
if (stream >= m_nbStreams) {
return 0;
}
QMutexLocker mutexLocker(&m_mutex);
2019-10-02 19:19:43 -04:00
unsigned int fill = m_vHead[stream] <= m_vFill[stream] ? m_vFill[stream] - m_vHead[stream] : m_size - (m_vHead[stream] - m_vFill[stream]);
return fill;
}
2019-09-24 18:35:02 -04:00
signals:
void dataSyncReady();
2019-10-02 19:19:43 -04:00
void dataAsyncReady(int streamIndex);
2019-09-24 18:35:02 -04:00
private:
2019-10-02 19:19:43 -04:00
std::vector<SampleVector> m_data;
unsigned int m_nbStreams;
2019-10-02 19:19:43 -04:00
unsigned int m_size;
unsigned int m_fill; //!< Number of samples written from beginning of samples vector (sync)
unsigned int m_head; //!< Number of samples read from beginning of samples vector (sync)
std::vector<unsigned int> m_vFill; //!< Number of samples written from beginning of samples vector (async)
std::vector<unsigned int> m_vHead; //!< Number of samples read from beginning of samples vector (async)
QMutex m_mutex;
2019-09-24 18:35:02 -04:00
};
2019-10-02 19:19:43 -04:00
#endif // INCLUDE_SAMPLEMIFIFO_H