| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 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>
 | 
					
						
							|  |  |  | #include "util/export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 01:26:51 +02:00
										 |  |  | class SDRANGEL_API AudioFifo : public QObject { | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | public: | 
					
						
							|  |  |  | 	AudioFifo(); | 
					
						
							|  |  |  | 	AudioFifo(uint sampleSize, uint numSamples); | 
					
						
							|  |  |  | 	~AudioFifo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool setSize(uint sampleSize, uint numSamples); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	uint write(const quint8* data, uint numSamples, int timeout_ms = INT_MAX); | 
					
						
							|  |  |  | 	uint read(quint8* data, uint numSamples, int timeout_ms = INT_MAX); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	uint drain(uint numSamples); | 
					
						
							|  |  |  | 	void clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	inline uint flush() { return drain(m_fill); } | 
					
						
							|  |  |  | 	inline uint fill() const { return m_fill; } | 
					
						
							|  |  |  | 	inline bool isEmpty() const { return m_fill == 0; } | 
					
						
							|  |  |  | 	inline bool isFull() const { return m_fill == m_size; } | 
					
						
							|  |  |  | 	inline uint size() const { return m_size; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qint8* m_fifo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	uint m_sampleSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	uint m_size; | 
					
						
							|  |  |  | 	uint m_fill; | 
					
						
							|  |  |  | 	uint m_head; | 
					
						
							|  |  |  | 	uint m_tail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QMutex m_writeWaitLock; | 
					
						
							|  |  |  | 	QMutex m_readWaitLock; | 
					
						
							|  |  |  | 	QWaitCondition m_writeWaitCondition; | 
					
						
							|  |  |  | 	QWaitCondition m_readWaitCondition; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool create(uint sampleSize, uint numSamples); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_AUDIOFIFO_H
 |