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 //
// //
// 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 ; }
2016-10-15 07:53:06 +00:00
2016-10-23 12:14:32 +00:00
void init ( ) ;
2016-10-24 16:06:44 +00:00
/** begin read at current read point for the given length and activate R/W signals */
void readAndSignal ( SampleVector : : iterator & beginRead , unsigned int nbSamples ) ;
2016-10-15 07:53:06 +00:00
2016-10-24 16:06:44 +00:00
void getReadIterator ( SampleVector : : iterator & readUntil ) ; //!< get iterator past the last sample that was read by a read with signal (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
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
2016-10-09 23:13:12 +00:00
private :
uint32_t m_size ;
uint32_t m_samplesChunkSize ;
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-10-24 16:06:44 +00:00
void dataWrite ( ) ; // signal data is read past a read chunk of samples and write 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_ */