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.
doublebufferfifo.h
Go to the documentation of this file.
1 // Copyright (C) 2016 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef SDRBASE_UTIL_DOUBLEBUFFERFIFO_H_
19 #define SDRBASE_UTIL_DOUBLEBUFFERFIFO_H_
20 
21 
22 template<typename T>
24 {
25 public:
27  {
28  m_data = new T[2*m_size];
29  }
30 
32  {
33  delete[] m_data;
34  }
35 
36  void resize(int size)
37  {
38  delete[] m_data;
39  m_size = size;
40  m_data = new T[2*m_size];
41  m_writeIndex = 0;
42  m_currentIndex = 0;
43  }
44 
45  void write(const T& element)
46  {
47  m_data[m_writeIndex] = element;
48  m_data[m_writeIndex+m_size] = element;
50 
51  if (m_writeIndex < m_size - 1) {
52  m_writeIndex++;
53  } else {
54  m_writeIndex = 0;
55  }
56  }
57 
58  T& readBack(int delay)
59  {
60  if (delay > m_size) {
61  delay = m_size;
62  }
63 
64  return m_data[m_currentIndex + m_size - delay];
65  }
66 
67  void zeroBack(int delay)
68  {
69  if (delay > m_size) {
70  delay = m_size;
71  }
72 
73  for (int i = 0; i < delay; i++) {
74  m_data[m_currentIndex + m_size - i] = 0;
75  }
76  }
77 
78 private:
79  int m_size;
80  T *m_data;
83 };
84 
85 #endif /* SDRBASE_UTIL_DOUBLEBUFFERFIFO_H_ */
void resize(int size)
void zeroBack(int delay)
void write(const T &element)
int32_t i
Definition: decimators.h:244
T & readBack(int delay)
DoubleBufferFIFO(int size)