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.
sdrbase
util
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>
23
class
DoubleBufferFIFO
24
{
25
public
:
26
DoubleBufferFIFO
(
int
size) :
m_size
(size),
m_writeIndex
(0),
m_currentIndex
(0)
27
{
28
m_data
=
new
T[2*
m_size
];
29
}
30
31
~DoubleBufferFIFO
()
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;
49
m_currentIndex
=
m_writeIndex
;
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
;
81
int
m_writeIndex
;
82
int
m_currentIndex
;
83
};
84
85
#endif
/* SDRBASE_UTIL_DOUBLEBUFFERFIFO_H_ */
DoubleBufferFIFO::resize
void resize(int size)
Definition:
doublebufferfifo.h:36
DoubleBufferFIFO::~DoubleBufferFIFO
~DoubleBufferFIFO()
Definition:
doublebufferfifo.h:31
DoubleBufferFIFO::zeroBack
void zeroBack(int delay)
Definition:
doublebufferfifo.h:67
DoubleBufferFIFO::write
void write(const T &element)
Definition:
doublebufferfifo.h:45
DoubleBufferFIFO::m_size
int m_size
Definition:
doublebufferfifo.h:79
DoubleBufferFIFO
Definition:
doublebufferfifo.h:23
DoubleBufferFIFO::m_writeIndex
int m_writeIndex
Definition:
doublebufferfifo.h:81
i
int32_t i
Definition:
decimators.h:244
DoubleBufferFIFO::m_currentIndex
int m_currentIndex
Definition:
doublebufferfifo.h:82
DoubleBufferFIFO::readBack
T & readBack(int delay)
Definition:
doublebufferfifo.h:58
DoubleBufferFIFO::DoubleBufferFIFO
DoubleBufferFIFO(int size)
Definition:
doublebufferfifo.h:26
DoubleBufferFIFO::m_data
T * m_data
Definition:
doublebufferfifo.h:80
Generated on Fri Aug 2 2019 17:56:33 for SDRAngel by
1.8.13