2014-05-18 11:52:39 -04: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-23 18:51:27 -04:00
|
|
|
#include <QObject>
|
2014-05-18 11:52:39 -04:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QWaitCondition>
|
2017-08-24 19:17:21 -04:00
|
|
|
|
|
|
|
#include "dsp/dsptypes.h"
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2018-03-03 14:23:38 -05:00
|
|
|
class SDRBASE_API AudioFifo : public QObject {
|
2015-08-23 18:51:27 -04:00
|
|
|
Q_OBJECT
|
2014-05-18 11:52:39 -04:00
|
|
|
public:
|
|
|
|
AudioFifo();
|
2017-08-24 18:02:49 -04:00
|
|
|
AudioFifo(uint32_t numSamples);
|
2014-05-18 11:52:39 -04:00
|
|
|
~AudioFifo();
|
|
|
|
|
2017-08-24 18:02:49 -04:00
|
|
|
bool setSize(uint32_t numSamples);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2018-09-12 09:30:53 -04:00
|
|
|
uint32_t write(const quint8* data, uint32_t numSamples);
|
|
|
|
uint32_t read(quint8* data, uint32_t numSamples);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-08-24 05:49:47 -04:00
|
|
|
uint32_t drain(uint32_t numSamples);
|
2014-05-18 11:52:39 -04:00
|
|
|
void clear();
|
|
|
|
|
2017-08-24 05:49:47 -04:00
|
|
|
inline uint32_t flush() { return drain(m_fill); }
|
|
|
|
inline uint32_t fill() const { return m_fill; }
|
2014-05-18 11:52:39 -04:00
|
|
|
inline bool isEmpty() const { return m_fill == 0; }
|
|
|
|
inline bool isFull() const { return m_fill == m_size; }
|
2017-08-24 05:49:47 -04:00
|
|
|
inline uint32_t size() const { return m_size; }
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
private:
|
|
|
|
QMutex m_mutex;
|
|
|
|
|
|
|
|
qint8* m_fifo;
|
|
|
|
|
2017-08-24 17:54:51 -04:00
|
|
|
const uint32_t m_sampleSize;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-08-24 05:49:47 -04:00
|
|
|
uint32_t m_size;
|
|
|
|
uint32_t m_fill;
|
|
|
|
uint32_t m_head;
|
|
|
|
uint32_t m_tail;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-08-24 18:02:49 -04:00
|
|
|
bool create(uint32_t numSamples);
|
2014-05-18 11:52:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_AUDIOFIFO_H
|