2016-10-09 23:13:12 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 //
|
2019-04-11 12:32:15 +00:00
|
|
|
// (at your option) any later version. //
|
2016-10-09 23:13:12 +00:00
|
|
|
// //
|
|
|
|
// 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>
|
2018-03-20 12:49:21 +00:00
|
|
|
#include "export.h"
|
2016-10-09 23:13:12 +00:00
|
|
|
#include "dsp/dsptypes.h"
|
|
|
|
|
2018-03-03 19:23:38 +00:00
|
|
|
class SDRBASE_API SampleSourceFifo : public QObject {
|
2016-10-09 23:13:12 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-05-18 04:30:37 +00:00
|
|
|
SampleSourceFifo(uint32_t size, QObject* parent = nullptr);
|
|
|
|
SampleSourceFifo(const SampleSourceFifo& other);
|
2016-10-09 23:13:12 +00:00
|
|
|
~SampleSourceFifo();
|
|
|
|
|
2016-12-23 13:29:42 +00:00
|
|
|
void resize(uint32_t size);
|
2016-12-26 11:11:51 +00:00
|
|
|
uint32_t size() const { return m_size; }
|
2016-10-23 12:14:32 +00:00
|
|
|
void init();
|
2016-10-25 01:31:36 +00:00
|
|
|
/** advance read pointer for the given length and activate R/W signals */
|
|
|
|
void readAdvance(SampleVector::iterator& readUntil, unsigned int nbSamples);
|
2019-10-19 03:07:24 +00:00
|
|
|
void readAdvance(SampleVector::const_iterator& readUntil, unsigned int nbSamples);
|
2016-10-15 07:53:06 +00:00
|
|
|
|
2016-10-25 01:31:36 +00:00
|
|
|
void getReadIterator(SampleVector::iterator& readUntil); //!< get iterator past the last sample of a read advance operation (i.e. current read iterator)
|
2016-10-09 23:13:12 +00:00
|
|
|
void getWriteIterator(SampleVector::iterator& writeAt); //!< get iterator to current item for update - write phase 1
|
2016-10-23 21:27:19 +00:00
|
|
|
void bumpIndex(SampleVector::iterator& writeAt); //!< copy current item to second buffer and bump write index - write phase 2
|
2019-05-10 11:20:30 +00:00
|
|
|
int getIteratorOffset(const SampleVector::iterator& iterator);
|
|
|
|
void setIteratorFromOffset(SampleVector::iterator& iterator, int offset);
|
2016-10-09 23:13:12 +00:00
|
|
|
|
2016-10-15 07:53:06 +00:00
|
|
|
void write(const Sample& sample); //!< write directly - phase 1 + phase 2
|
|
|
|
|
2018-09-29 19:40:22 +00:00
|
|
|
/** returns ratio of off center over buffer size with sign: negative read lags and positive read leads */
|
2018-05-27 22:40:33 +00:00
|
|
|
float getRWBalance() const
|
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
if (m_iw > m_ir) {
|
|
|
|
delta = (m_size/2) - (m_iw - m_ir);
|
|
|
|
} else {
|
|
|
|
delta = (m_ir - m_iw) - (m_size/2);
|
|
|
|
}
|
|
|
|
return delta / (float) m_size;
|
|
|
|
}
|
|
|
|
|
2016-10-09 23:13:12 +00:00
|
|
|
private:
|
|
|
|
uint32_t m_size;
|
|
|
|
SampleVector m_data;
|
2016-10-15 07:53:06 +00:00
|
|
|
uint32_t m_iw;
|
|
|
|
uint32_t m_ir;
|
2016-10-23 12:14:32 +00:00
|
|
|
bool m_init;
|
2016-10-09 23:13:12 +00:00
|
|
|
QMutex m_mutex;
|
|
|
|
|
|
|
|
signals:
|
2016-12-21 01:24:49 +00:00
|
|
|
void dataWrite(int nbSamples); // signal data is read past a threshold and writing new samples to fill in is needed
|
|
|
|
void dataRead(int nbSamples); // signal a read has been done for a number of samples
|
2016-10-09 23:13:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SDRBASE_DSP_SAMPLESOURCEFIFO_H_ */
|