SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AudioFifo Class Reference

#include <audiofifo.h>

Inherits QObject.

Public Member Functions

 AudioFifo ()
 
 AudioFifo (uint32_t numSamples)
 
 ~AudioFifo ()
 
bool setSize (uint32_t numSamples)
 
uint32_t write (const quint8 *data, uint32_t numSamples)
 
uint32_t read (quint8 *data, uint32_t numSamples)
 
uint32_t drain (uint32_t numSamples)
 
void clear ()
 
uint32_t flush ()
 
uint32_t fill () const
 
bool isEmpty () const
 
bool isFull () const
 
uint32_t size () const
 

Private Member Functions

bool create (uint32_t numSamples)
 

Private Attributes

QMutex m_mutex
 
qint8 * m_fifo
 
const uint32_t m_sampleSize
 
uint32_t m_size
 
uint32_t m_fill
 
uint32_t m_head
 
uint32_t m_tail
 

Detailed Description

Definition at line 29 of file audiofifo.h.

Constructor & Destructor Documentation

◆ AudioFifo() [1/2]

AudioFifo::AudioFifo ( )

Definition at line 27 of file audiofifo.cpp.

References m_fill, m_head, m_size, and m_tail.

27  :
28  m_fifo(0),
29  m_sampleSize(sizeof(AudioSample))
30 {
31  m_size = 0;
32  m_fill = 0;
33  m_head = 0;
34  m_tail = 0;
35 }
uint32_t m_tail
Definition: audiofifo.h:60
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
qint8 * m_fifo
Definition: audiofifo.h:53
uint32_t m_head
Definition: audiofifo.h:59
const uint32_t m_sampleSize
Definition: audiofifo.h:55

◆ AudioFifo() [2/2]

AudioFifo::AudioFifo ( uint32_t  numSamples)

Definition at line 37 of file audiofifo.cpp.

References create(), and m_mutex.

37  :
38  m_fifo(0),
39  m_sampleSize(sizeof(AudioSample))
40 {
41  QMutexLocker mutexLocker(&m_mutex);
42 
43  create(numSamples);
44 }
QMutex m_mutex
Definition: audiofifo.h:51
bool create(uint32_t numSamples)
Definition: audiofifo.cpp:165
qint8 * m_fifo
Definition: audiofifo.h:53
const uint32_t m_sampleSize
Definition: audiofifo.h:55
+ Here is the call graph for this function:

◆ ~AudioFifo()

AudioFifo::~AudioFifo ( )

Definition at line 46 of file audiofifo.cpp.

References m_fifo, m_mutex, and m_size.

47 {
48  QMutexLocker mutexLocker(&m_mutex);
49 
50  if (m_fifo != 0)
51  {
52  delete[] m_fifo;
53  m_fifo = 0;
54  }
55 
56  m_size = 0;
57 }
QMutex m_mutex
Definition: audiofifo.h:51
uint32_t m_size
Definition: audiofifo.h:57
qint8 * m_fifo
Definition: audiofifo.h:53

Member Function Documentation

◆ clear()

void AudioFifo::clear ( )

Definition at line 156 of file audiofifo.cpp.

References m_fill, m_head, m_mutex, and m_tail.

Referenced by AMDemod::processOneSample(), AMMod::processOneSample(), NFMMod::processOneSample(), SSBMod::processOneSample(), AMDemod::start(), WFMDemod::start(), DSDDemod::start(), NFMDemod::start(), BFMDemod::start(), DATVDemod::start(), AMMod::start(), WFMMod::start(), NFMMod::start(), SSBMod::start(), and FreeDVMod::start().

157 {
158  QMutexLocker mutexLocker(&m_mutex);
159 
160  m_fill = 0;
161  m_head = 0;
162  m_tail = 0;
163 }
QMutex m_mutex
Definition: audiofifo.h:51
uint32_t m_tail
Definition: audiofifo.h:60
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_head
Definition: audiofifo.h:59
+ Here is the caller graph for this function:

◆ create()

bool AudioFifo::create ( uint32_t  numSamples)
private

Definition at line 165 of file audiofifo.cpp.

References m_fifo, m_fill, m_head, m_sampleSize, m_size, and m_tail.

Referenced by AudioFifo(), and setSize().

166 {
167  if(m_fifo != 0)
168  {
169  delete[] m_fifo;
170  m_fifo = 0;
171  }
172 
173  m_fill = 0;
174  m_head = 0;
175  m_tail = 0;
176 
177  m_fifo = new qint8[numSamples * m_sampleSize];
178  m_size = numSamples;
179 
180  return true;
181 }
uint32_t m_tail
Definition: audiofifo.h:60
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
qint8 * m_fifo
Definition: audiofifo.h:53
uint32_t m_head
Definition: audiofifo.h:59
const uint32_t m_sampleSize
Definition: audiofifo.h:55
+ Here is the caller graph for this function:

◆ drain()

uint AudioFifo::drain ( uint32_t  numSamples)

Definition at line 141 of file audiofifo.cpp.

References m_fill, m_head, m_mutex, and m_size.

142 {
143  QMutexLocker mutexLocker(&m_mutex);
144 
145  if(numSamples > m_fill)
146  {
147  numSamples = m_fill;
148  }
149 
150  m_head = (m_head + numSamples) % m_size;
151  m_fill -= numSamples;
152 
153  return numSamples;
154 }
QMutex m_mutex
Definition: audiofifo.h:51
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
uint32_t m_head
Definition: audiofifo.h:59

◆ fill()

uint32_t AudioFifo::fill ( ) const
inline

Definition at line 45 of file audiofifo.h.

45 { return m_fill; }
uint32_t m_fill
Definition: audiofifo.h:58

◆ flush()

uint32_t AudioFifo::flush ( )
inline

Definition at line 44 of file audiofifo.h.

44 { return drain(m_fill); }
uint32_t drain(uint32_t numSamples)
Definition: audiofifo.cpp:141
uint32_t m_fill
Definition: audiofifo.h:58

◆ isEmpty()

bool AudioFifo::isEmpty ( ) const
inline

Definition at line 46 of file audiofifo.h.

Referenced by read().

46 { return m_fill == 0; }
uint32_t m_fill
Definition: audiofifo.h:58
+ Here is the caller graph for this function:

◆ isFull()

bool AudioFifo::isFull ( ) const
inline

Definition at line 47 of file audiofifo.h.

Referenced by write().

47 { return m_fill == m_size; }
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
+ Here is the caller graph for this function:

◆ read()

uint AudioFifo::read ( quint8 *  data,
uint32_t  numSamples 
)

Definition at line 103 of file audiofifo.cpp.

References isEmpty(), m_fifo, m_fill, m_head, m_mutex, m_sampleSize, m_size, and MIN.

Referenced by AMMod::pullAudio(), WFMMod::pullAudio(), NFMMod::pullAudio(), SSBMod::pullAudio(), FreeDVMod::pullAudio(), FCDProThread::work(), and FCDProPlusThread::work().

104 {
105  uint32_t total;
106  uint32_t remaining;
107  uint32_t copyLen;
108 
109  if (m_fifo == 0) {
110  return 0;
111  }
112 
113  m_mutex.lock();
114 
115  total = MIN(numSamples, m_fill);
116  remaining = total;
117 
118  while (remaining != 0)
119  {
120  if (isEmpty())
121  {
122  m_mutex.unlock();
123  return total - remaining; // read so far
124  }
125 
126  copyLen = MIN(remaining, m_fill);
127  copyLen = MIN(copyLen, m_size - m_head);
128  memcpy(data, m_fifo + (m_head * m_sampleSize), copyLen * m_sampleSize);
129 
130  m_head += copyLen;
131  m_head %= m_size;
132  m_fill -= copyLen;
133  data += copyLen * m_sampleSize;
134  remaining -= copyLen;
135  }
136 
137  m_mutex.unlock();
138  return total;
139 }
QMutex m_mutex
Definition: audiofifo.h:51
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
unsigned int uint32_t
Definition: rtptypes_win.h:46
qint8 * m_fifo
Definition: audiofifo.h:53
uint32_t m_head
Definition: audiofifo.h:59
const uint32_t m_sampleSize
Definition: audiofifo.h:55
bool isEmpty() const
Definition: audiofifo.h:46
#define MIN(x, y)
Definition: audiofifo.cpp:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSize()

bool AudioFifo::setSize ( uint32_t  numSamples)

Definition at line 59 of file audiofifo.cpp.

References create(), and m_mutex.

Referenced by AMDemod::applyAudioSampleRate(), SSBDemod::applyAudioSampleRate(), and FreeDVDemod::applyAudioSampleRate().

60 {
61  QMutexLocker mutexLocker(&m_mutex);
62 
63  return create(numSamples);
64 }
QMutex m_mutex
Definition: audiofifo.h:51
bool create(uint32_t numSamples)
Definition: audiofifo.cpp:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

uint32_t AudioFifo::size ( ) const
inline

Definition at line 48 of file audiofifo.h.

48 { return m_size; }
uint32_t m_size
Definition: audiofifo.h:57

◆ write()

uint AudioFifo::write ( const quint8 *  data,
uint32_t  numSamples 
)

Definition at line 66 of file audiofifo.cpp.

References isFull(), m_fifo, m_fill, m_mutex, m_sampleSize, m_size, m_tail, and MIN.

Referenced by UDPSink::audioReadyRead(), AMDemod::feed(), WFMDemod::feed(), DSDDemod::feed(), BFMDemod::feed(), FreeDVDemod::feed(), AMBEWorker::handleInputMessages(), AMDemod::processOneSample(), NFMDemod::processOneSample(), AMMod::processOneSample(), NFMMod::processOneSample(), SSBDemod::processOneSample(), SSBMod::processOneSample(), FreeDVDemod::pushSampleToAudio(), and DATVideoRender::RenderStream().

67 {
68  uint32_t total;
69  uint32_t remaining;
70  uint32_t copyLen;
71 
72  if (m_fifo == 0) {
73  return 0;
74  }
75 
76  m_mutex.lock();
77 
78  total = MIN(numSamples, m_size - m_fill);
79  remaining = total;
80 
81  while (remaining != 0)
82  {
83  if (isFull())
84  {
85  m_mutex.unlock();
86  return total - remaining; // written so far
87  }
88 
89  copyLen = MIN(remaining, m_size - m_fill);
90  copyLen = MIN(copyLen, m_size - m_tail);
91  memcpy(m_fifo + (m_tail * m_sampleSize), data, copyLen * m_sampleSize);
92  m_tail += copyLen;
93  m_tail %= m_size;
94  m_fill += copyLen;
95  data += copyLen * m_sampleSize;
96  remaining -= copyLen;
97  }
98 
99  m_mutex.unlock();
100  return total;
101 }
QMutex m_mutex
Definition: audiofifo.h:51
uint32_t m_tail
Definition: audiofifo.h:60
uint32_t m_fill
Definition: audiofifo.h:58
uint32_t m_size
Definition: audiofifo.h:57
unsigned int uint32_t
Definition: rtptypes_win.h:46
qint8 * m_fifo
Definition: audiofifo.h:53
const uint32_t m_sampleSize
Definition: audiofifo.h:55
bool isFull() const
Definition: audiofifo.h:47
#define MIN(x, y)
Definition: audiofifo.cpp:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_fifo

qint8* AudioFifo::m_fifo
private

Definition at line 53 of file audiofifo.h.

Referenced by create(), read(), write(), and ~AudioFifo().

◆ m_fill

uint32_t AudioFifo::m_fill
private

Definition at line 58 of file audiofifo.h.

Referenced by AudioFifo(), clear(), create(), drain(), read(), and write().

◆ m_head

uint32_t AudioFifo::m_head
private

Definition at line 59 of file audiofifo.h.

Referenced by AudioFifo(), clear(), create(), drain(), and read().

◆ m_mutex

QMutex AudioFifo::m_mutex
private

Definition at line 51 of file audiofifo.h.

Referenced by AudioFifo(), clear(), drain(), read(), setSize(), write(), and ~AudioFifo().

◆ m_sampleSize

const uint32_t AudioFifo::m_sampleSize
private

Definition at line 55 of file audiofifo.h.

Referenced by create(), read(), and write().

◆ m_size

uint32_t AudioFifo::m_size
private

Definition at line 57 of file audiofifo.h.

Referenced by AudioFifo(), create(), drain(), read(), write(), and ~AudioFifo().

◆ m_tail

uint32_t AudioFifo::m_tail
private

Definition at line 60 of file audiofifo.h.

Referenced by AudioFifo(), clear(), create(), and write().


The documentation for this class was generated from the following files: