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.
dsptypes.h
Go to the documentation of this file.
1 // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
3 // written by Christian Daniel //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef INCLUDE_DSPTYPES_H
20 #define INCLUDE_DSPTYPES_H
21 
22 #include <complex>
23 #include <vector>
24 #include <QtGlobal>
25 
26 #ifdef SDR_RX_SAMPLE_24BIT
27 #define SDR_RX_SAMP_SZ 24 // internal fixed arithmetic sample size
28 #define SDR_RX_SCALEF 8388608.0f
29 #define SDR_RX_SCALED 8388608.0
30 typedef qint32 FixReal;
31 #else
32 #define SDR_RX_SAMP_SZ 16 // internal fixed arithmetic sample size
33 #define SDR_RX_SCALEF 32768.0f
34 #define SDR_RX_SCALED 32768.0
35 typedef qint16 FixReal;
36 #endif
37 
38 #define SDR_TX_SAMP_SZ 16
39 #define SDR_TX_SCALEF 32768.0f
40 #define SDR_TX_SCALED 32768.0
41 
42 typedef float Real;
43 typedef std::complex<Real> Complex;
44 
45 #pragma pack(push, 1)
46 struct Sample
47 {
48  Sample() : m_real(0), m_imag(0) {}
49  Sample(FixReal real) : m_real(real), m_imag(0) {}
50  Sample(FixReal real, FixReal imag) : m_real(real), m_imag(imag) {}
51  Sample(const Sample& other) : m_real(other.m_real), m_imag(other.m_imag) {}
52  inline Sample& operator=(const Sample& other) { m_real = other.m_real; m_imag = other.m_imag; return *this; }
53 
54  inline Sample& operator+=(const Sample& other) { m_real += other.m_real; m_imag += other.m_imag; return *this; }
55  inline Sample& operator-=(const Sample& other) { m_real -= other.m_real; m_imag -= other.m_imag; return *this; }
56  inline Sample& operator/=(const unsigned int& divisor) { m_real /= divisor; m_imag /= divisor; return *this; }
57 
58  inline void setReal(FixReal v) { m_real = v; }
59  inline void setImag(FixReal v) { m_imag = v; }
60 
61  inline FixReal real() const { return m_real; }
62  inline FixReal imag() const { return m_imag; }
63 
66 };
67 
68 struct FSample
69 {
70  FSample() : m_real(0), m_imag(0) {}
71  FSample(Real real) : m_real(real), m_imag(0) {}
72  FSample(Real real, Real imag) : m_real(real), m_imag(imag) {}
73  FSample(const FSample& other) : m_real(other.m_real), m_imag(other.m_imag) {}
74  inline FSample& operator=(const FSample& other) { m_real = other.m_real; m_imag = other.m_imag; return *this; }
75 
76  inline FSample& operator+=(const FSample& other) { m_real += other.m_real; m_imag += other.m_imag; return *this; }
77  inline FSample& operator-=(const FSample& other) { m_real -= other.m_real; m_imag -= other.m_imag; return *this; }
78  inline FSample& operator/=(const Real& divisor) { m_real /= divisor; m_imag /= divisor; return *this; }
79 
80  inline void setReal(Real v) { m_real = v; }
81  inline void setImag(Real v) { m_imag = v; }
82 
83  inline Real real() const { return m_real; }
84  inline Real imag() const { return m_imag; }
85 
88 };
89 
90 struct AudioSample {
91  qint16 l;
92  qint16 r;
93 };
94 #pragma pack(pop)
95 
96 typedef std::vector<Sample> SampleVector;
97 typedef std::vector<FSample> FSampleVector;
98 typedef std::vector<AudioSample> AudioVector;
99 
100 #endif // INCLUDE_DSPTYPES_H
void setImag(Real v)
Definition: dsptypes.h:81
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
Sample & operator+=(const Sample &other)
Definition: dsptypes.h:54
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
Real real() const
Definition: dsptypes.h:83
Sample & operator/=(const unsigned int &divisor)
Definition: dsptypes.h:56
FSample(Real real, Real imag)
Definition: dsptypes.h:72
FSample(const FSample &other)
Definition: dsptypes.h:73
Sample()
Definition: dsptypes.h:48
void setReal(Real v)
Definition: dsptypes.h:80
FSample & operator/=(const Real &divisor)
Definition: dsptypes.h:78
FSample & operator+=(const FSample &other)
Definition: dsptypes.h:76
qint16 r
Definition: dsptypes.h:92
Sample & operator-=(const Sample &other)
Definition: dsptypes.h:55
FixReal m_real
Definition: dsptypes.h:64
void setImag(FixReal v)
Definition: dsptypes.h:59
std::vector< FSample > FSampleVector
Definition: dsptypes.h:97
Real imag() const
Definition: dsptypes.h:84
Sample(FixReal real)
Definition: dsptypes.h:49
FSample & operator=(const FSample &other)
Definition: dsptypes.h:74
Sample(const Sample &other)
Definition: dsptypes.h:51
Sample & operator=(const Sample &other)
Definition: dsptypes.h:52
qint16 l
Definition: dsptypes.h:91
void setReal(FixReal v)
Definition: dsptypes.h:58
FSample & operator-=(const FSample &other)
Definition: dsptypes.h:77
FixReal real() const
Definition: dsptypes.h:61
FixReal imag() const
Definition: dsptypes.h:62
Real m_real
Definition: dsptypes.h:86
FixReal m_imag
Definition: dsptypes.h:65
FSample(Real real)
Definition: dsptypes.h:71
Real m_imag
Definition: dsptypes.h:87
std::complex< Real > Complex
Definition: dsptypes.h:43
float Real
Definition: dsptypes.h:42
FSample()
Definition: dsptypes.h:70
qint16 FixReal
Definition: dsptypes.h:35
Sample(FixReal real, FixReal imag)
Definition: dsptypes.h:50