| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							| 
									
										
										
										
											2023-11-19 06:43:20 +01:00
										 |  |  | // Copyright (C) 2015-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2023 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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 INCLUDE_AUDIOFIFO_H
 | 
					
						
							|  |  |  | #define INCLUDE_AUDIOFIFO_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | #include <QObject>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QWaitCondition>
 | 
					
						
							| 
									
										
										
										
											2017-08-25 01:17:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API AudioFifo : public QObject { | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | public: | 
					
						
							|  |  |  | 	AudioFifo(); | 
					
						
							| 
									
										
										
										
											2017-08-25 00:02:49 +02:00
										 |  |  | 	AudioFifo(uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	~AudioFifo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:02:49 +02:00
										 |  |  | 	bool setSize(uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2022-06-04 12:27:57 +02:00
										 |  |  |     bool setSampleSize(uint32_t sampleSize, uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 15:30:53 +02:00
										 |  |  | 	uint32_t write(const quint8* data, uint32_t numSamples); | 
					
						
							|  |  |  | 	uint32_t read(quint8* data, uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2022-06-17 02:25:34 +02:00
										 |  |  |     bool readOne(quint8* data); | 
					
						
							| 
									
										
										
										
											2024-03-13 01:30:10 +01:00
										 |  |  |     uint32_t writeOne(const quint8* data); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 11:49:47 +02:00
										 |  |  | 	uint32_t drain(uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 11:49:47 +02:00
										 |  |  | 	inline uint32_t flush() { return drain(m_fill); } | 
					
						
							|  |  |  | 	inline uint32_t fill() const { return m_fill; } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	inline bool isEmpty() const { return m_fill == 0; } | 
					
						
							|  |  |  | 	inline bool isFull() const { return m_fill == m_size; } | 
					
						
							| 
									
										
										
										
											2017-08-24 11:49:47 +02:00
										 |  |  | 	inline uint32_t size() const { return m_size; } | 
					
						
							| 
									
										
										
										
											2022-03-18 17:08:04 +01:00
										 |  |  | 	void setLabel(const QString& label) { m_label = label; } | 
					
						
							| 
									
										
										
										
											2017-08-24 11:49:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | private: | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qint8* m_fifo; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-04 12:27:57 +02:00
										 |  |  | 	uint32_t m_sampleSize; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 11:49:47 +02:00
										 |  |  | 	uint32_t m_size; | 
					
						
							|  |  |  | 	uint32_t m_fill; | 
					
						
							|  |  |  | 	uint32_t m_head; | 
					
						
							|  |  |  | 	uint32_t m_tail; | 
					
						
							| 
									
										
										
										
											2022-03-18 17:08:04 +01:00
										 |  |  | 	QString m_label; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:02:49 +02:00
										 |  |  | 	bool create(uint32_t numSamples); | 
					
						
							| 
									
										
										
										
											2020-11-13 15:53:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  | 	void dataReady(); | 
					
						
							| 
									
										
										
										
											2022-03-18 17:08:04 +01:00
										 |  |  | 	void overflow(int nsamples); | 
					
						
							| 
									
										
										
										
											2023-11-13 12:15:56 +00:00
										 |  |  |     void underflow(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_AUDIOFIFO_H
 |