| 
									
										
										
										
											2019-10-17 00:03:52 +02: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_SAMPLEMOFIFO_H
 | 
					
						
							|  |  |  | #define INCLUDE_SAMPLEMOFIFO_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QObject>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							|  |  |  | #include "export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SDRBASE_API SampleMOFifo : public QObject { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     SampleMOFifo(QObject *parent = nullptr); | 
					
						
							|  |  |  |     SampleMOFifo(unsigned int nbStreams, unsigned int size, QObject *parent = nullptr); | 
					
						
							|  |  |  |     ~SampleMOFifo(); | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     void init(unsigned int nbStreams, unsigned int size); | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:21 +01:00
										 |  |  |     void resize(unsigned int size); | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     void reset(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void readSync( | 
					
						
							|  |  |  |         unsigned int amount, | 
					
						
							| 
									
										
										
										
											2019-10-23 18:35:47 +02:00
										 |  |  | 		unsigned int& ipart1Begin, unsigned int& ipart1End, // first part offsets where to read
 | 
					
						
							|  |  |  | 		unsigned int& ipart2Begin, unsigned int& ipart2End  // second part offsets
 | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 14:03:36 +01:00
										 |  |  |     void writeSync( //!< in place write with given amount
 | 
					
						
							| 
									
										
										
										
											2019-10-23 18:35:47 +02:00
										 |  |  |         unsigned int amount, | 
					
						
							|  |  |  | 		unsigned int& ipart1Begin, unsigned int& ipart1End, // first part offsets where to write
 | 
					
						
							|  |  |  | 		unsigned int& ipart2Begin, unsigned int& ipart2End  // second part offsets
 | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void readAsync( | 
					
						
							|  |  |  |         unsigned int amount, | 
					
						
							|  |  |  | 		unsigned int& ipart1Begin, unsigned int& ipart1End, | 
					
						
							|  |  |  | 		unsigned int& ipart2Begin, unsigned int& ipart2End, | 
					
						
							|  |  |  |         unsigned int stream | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 14:03:36 +01:00
										 |  |  |     void writeAsync( //!< in place write with given amount
 | 
					
						
							| 
									
										
										
										
											2019-10-23 18:35:47 +02:00
										 |  |  |         unsigned int amount, | 
					
						
							|  |  |  | 		unsigned int& ipart1Begin, unsigned int& ipart1End, | 
					
						
							|  |  |  | 		unsigned int& ipart2Begin, unsigned int& ipart2End, | 
					
						
							|  |  |  |         unsigned int stream | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 18:41:38 +02:00
										 |  |  |     std::vector<SampleVector>& getData() { return m_data; } | 
					
						
							|  |  |  |     SampleVector& getData(unsigned int stream) { return m_data[stream]; } | 
					
						
							| 
									
										
										
										
											2019-10-17 00:58:36 +02:00
										 |  |  |     unsigned int getNbStreams() const { return m_data.size(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     unsigned int remainderSync() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  |         return m_readCount; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     unsigned int remainderAsync(unsigned int stream) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (stream >= m_nbStreams) { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  |         return m_vReadCount[stream]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     static unsigned int getSizePolicy(unsigned int sampleRate); | 
					
						
							|  |  |  |     static const unsigned int m_rwDivisor; | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  |     static const unsigned int m_guardDivisor; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  | signals: | 
					
						
							| 
									
										
										
										
											2019-11-17 01:57:31 +01:00
										 |  |  | 	void dataReadSync(); | 
					
						
							|  |  |  |     void dataReadAsync(int streamIndex); | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     std::vector<SampleVector> m_data; | 
					
						
							|  |  |  |     unsigned int m_nbStreams; | 
					
						
							|  |  |  |     unsigned int m_size; | 
					
						
							| 
									
										
										
										
											2019-11-15 18:59:05 +01:00
										 |  |  |     unsigned int m_lowGuard; | 
					
						
							|  |  |  |     unsigned int m_highGuard; | 
					
						
							|  |  |  |     unsigned int m_midPoint; | 
					
						
							| 
									
										
										
										
											2019-10-17 00:03:52 +02:00
										 |  |  |     unsigned int m_readCount; | 
					
						
							|  |  |  |     unsigned int m_readHead; | 
					
						
							|  |  |  |     unsigned int m_writeHead; | 
					
						
							|  |  |  |     std::vector<unsigned int> m_vReadCount; | 
					
						
							|  |  |  |     std::vector<unsigned int> m_vReadHead; | 
					
						
							|  |  |  |     std::vector<unsigned int> m_vWriteHead; | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_SAMPLEMOFIFO_H
 |