1 /******************************************************************************\
2  * Technische Universitaet Darmstadt, Institut fuer Nachrichtentechnik
3  * Copyright (c) 2001-2006
4  *
5  * Author(s):
6  *	Volker Fischer
7  *
8  * Adapted for ham sstv use Ties Bos - PA0MBo
9  *
10  * Description:
11  *	Global definitions
12  *
13  ******************************************************************************
14  *
15  * This program is free software; you can redistribute it and/or modify it under
16  * the terms of the GNU General Public License as published by the Free Software
17  * Foundation; either version 2 of the License, or (at your option) any later
18  * version.
19  *
20  * This program is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU General Public License along with
26  * this program; if not, write to the Free Software Foundation, Inc.,
27  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29 \******************************************************************************/
30 
31 #if !defined(DEF_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_)
32 #define DEF_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_
33 #include "appglobal.h"
34 #include "appdefs.h"
35 
36 #include <string>
37 #include <stdio.h>
38 #include <math.h>
39 #include "../config.h"
40 
41 
42 #include "tables/TableDRMGlobal.h"
43 
44 
45 /* Definitions ****************************************************************/
46 /* When you define the following flag, a directory called
47    "test" MUST EXIST in the windows directory (or linux directory if you use
48    Linux)! */
49 #define _DEBUG_
50 #undef _DEBUG_
51 
52 
53 /* Choose algorithms -------------------------------------------------------- */
54 /* There are two algorithms available for frequency offset estimation for
55    tracking mode: Using frequency pilots or the guard-interval correlation. In
56    case of guard-interval correlation (which will be chosen if this macro is
57    defined), the Hilbert filter in TimeSync must be used all the time -> more
58    CPU usage. Also, the frequency tracking range is smaller */
59 #undef USE_FRQOFFS_TRACK_GUARDCORR
60 
61 /* The sample rate offset estimation can be done using the frequency pilots or
62    the movement of the estimated impulse response. Defining this macro will
63    enable the frequency pilot based estimation. Simulations showed that this
64    method is more vulnerable to bad channel situations */
65 #undef USE_SAMOFFS_TRACK_FRE_PIL
66 
67 /* Using max-log MAP decoder. A lot more memory and CPU is needed for this
68    method. This is just for showing the potential of an improved decoding
69    method and should not be activated for the "regular" version of Dream */
70 #undef USE_MAX_LOG_MAP
71 
72 /* This method tries to speed up the audio output after a re-synchronization
73    when long symbol interleaver is used. We work with erasure symbols to mark
74    data which is not yet received. We hope that the channel decoder can still
75    decode audio even if not all data is yet received to fill the interleaver
76    history */
77 #define USE_ERASURE_FOR_FASTER_ACQ
78 
79 /* If the following macro is defined, the Wiener filter for channel estimation
80    in time direction will be a Decision-Directed channel estimation ->
81    additional to the actual pilot cells, hard decisions about the data cells
82    are used as new pilots, too */
83 #undef USE_DD_WIENER_FILT_TIME
84 
85 
86 
87 
88 #if HAVE_STDINT_H
89 # include <stdint.h>
90 #elif HAVE_INTTYPES_H
91 # include <inttypes.h>
92 #elif defined(_WIN32)
93 # ifndef HAVE_INT8_T
94 #  define HAVE_INT8_T 1
95    typedef signed char int8_t;
96 # endif
97 # ifndef HAVE_INT16_T
98 #  define HAVE_INT16_T 1
99    typedef signed __int16 int16_t;
100 # endif
101 # ifndef HAVE_INT32_T
102 #  define HAVE_INT32_T 1
103    typedef signed __int32 int32_t;
104 # endif
105    typedef unsigned char uint8_t;
106 # ifndef HAVE_U_INT16_T
107 #  define HAVE_U_INT16_T 1
108    typedef unsigned __int16 uint16_t;
109 # endif
110 # ifndef HAVE_U_INT32_T
111 #  define HAVE_U_INT32_T 1
112    typedef unsigned __int32 uint32_t;
113 # endif
114 typedef signed __int64 int64_t;
115 typedef unsigned __int64 uint64_t;
116 #else
117 typedef signed char int8_t;
118 typedef unsigned char uint8_t;
119 typedef signed int int16_t;
120 typedef unsigned int uint16_t;
121 typedef signed long int32_t;
122 typedef unsigned long uint32_t;
123 typedef signed long long int64_t;
124 typedef unsigned long long uint64_t;
125 #endif
126 
127 /* Define type-specific information */
128 #define SIZEOF__BYTE					8
129 #define _MAXSHORT						32767
130 #define _MAXREAL						((_REAL) 3.4e38) /* Max for float */
131 
132 #ifdef USE_ERASURE_FOR_FASTER_ACQ
133 /* Use max-value for showing that this is an erasure */
134 # define ERASURE_TAG_VALUE				_MAXREAL
135 #endif
136 
137 
138 /* MAP ---------------------------------------------------------------------- */
139 #ifdef USE_MAX_LOG_MAP
140 typedef _REAL							_DECISION;
141 # define ML_SOFT_INF_MAX_VALUE			((_DECISION) 1e10)
ExtractBit(_DECISION dD)142 inline _BINARY ExtractBit(_DECISION dD) {return dD > 0 ? 1 : 0;}
BitToSoft(_BINARY biB)143 inline _DECISION BitToSoft(_BINARY biB) {return biB == 0 ? -1.0 : 1.0;}
144 #else
145 typedef _BINARY							_DECISION;
146 #define ExtractBit(a)					(a)
147 #define BitToSoft(a)					(a)
148 #endif
149 
150 
151 /* Definitions for window message system ------------------------------------ */
152 typedef unsigned int					_MESSAGE_IDENT;
153 #define MS_FAC_CRC						1	/* MS: Message */
154 #define MS_SDC_CRC						2
155 #define MS_MSC_CRC						3
156 #define MS_FRAME_SYNC					4
157 #define MS_TIME_SYNC					5
158 #define MS_IOINTERFACE					6
159 #define MS_RESET_ALL					7
160 #define MS_MOT_OBJ_STAT					8
161 
162 #define GUI_CONTROL_UPDATE_TIME			500	/* Milliseconds */
163 #define GUI_CONTROL_UPDATE_TIME_FAST	250	/* Milliseconds */
164 
165 
166 /* Global enumerations ------------------------------------------------------ */
167 enum ESpecOcc {SO_0, SO_1, SO_2, SO_3, SO_4, SO_5}; /* SO: Spectrum Occupancy */
168 enum ERobMode {RM_ROBUSTNESS_MODE_A, RM_ROBUSTNESS_MODE_B,
169 		RM_ROBUSTNESS_MODE_E, RM_ROBUSTNESS_MODE_D,    // pa0mbo was MODE_D
170 		RM_NO_MODE_DETECTED}; /* RM: Robustness Mode */
171 
172 
173 /* Constants ---------------------------------------------------------------- */
174 const _REAL crPi = ((_REAL) 3.14159265358979323846);
175 
176 
177 #define S9_DBUV 34.0 /* S9 in dBuV for converting HamLib S-meter readings to RSCI format */
178 
179 /* Define a number for the case: log10(0), which would lead to #inf */
180 #define RET_VAL_LOG_0					((_REAL) -200.0)
181 
182 
183 ///* Standard definitions */
184 //#define	true							1
185 //#define false							0
186 
187 
188 /* Classes ********************************************************************/
189 /* For metric */
190 class CDistance
191 {
192 public:
193 	/* Distance towards 0 or towards 1 */
194 	_REAL rTow0;
195 	_REAL rTow1;
196 };
197 
198 /* Viterbi needs information of equalized received signal and channel */
199 class CEquSig
200 {
201 public:
CEquSig()202 	CEquSig() : cSig(_COMPLEX((_REAL) 0.0, (_REAL) 0.0)), rChan((_REAL) 0.0) {}
CEquSig(const _COMPLEX cNS,const _REAL rNC)203 	CEquSig(const _COMPLEX cNS, const _REAL rNC) : cSig(cNS), rChan(rNC) {}
204 
205 	_COMPLEX	cSig; /* Actual signal */
206 	_REAL		rChan; /* Channel power at this cell */
207 };
208 
209 /* Mutex object to access data safely from different threads */
210 /* QT mutex */
211 #ifdef USE_QT_GUI
212 # if #if (QT_VERSION >= QT_VERSION_CHECK(3, 0, 0))
213 #  include <qthread.h>
214 # else
215 #  include <qmutex.h>
216 # endif
217 class CMutex
218 {
219 public:
Lock()220 	void Lock() {Mutex.lock();}
Unlock()221 	void Unlock() {Mutex.unlock();}
222 
223 protected:
224 	QMutex Mutex;
225 };
226 #else
227 /* No GUI and no threads, we do not need mutex in this case */
228 class CMutex
229 {
230 public:
Lock()231 	void Lock() {}
Unlock()232 	void Unlock() {}
233 };
234 #endif
235 
236 class CGenErr
237 {
238 public:
CGenErr(string strNE)239 	CGenErr(string strNE) : strError(strNE) {}
240 	string strError;
241 };
242 
243 // FIXME something nicer than using "MAX_NUM_TAPS_DRM_CHAN"
244 /* For simulation, data from channel simulation */
245 #define MAX_NUM_TAPS_DRM_CHAN			4
246 template<class T> class CChanSimData
247 {
248 public:
249 	T					tIn; /* Channel input data */
250 	T					tOut; /* Output of the channel (with noise) */
251 	T					tRef; /* Channel reference signal (without noise) */
252 	_COMPLEX			veccTap[MAX_NUM_TAPS_DRM_CHAN]; /* Tap gains */
253 	_COMPLEX			veccTapBackw[MAX_NUM_TAPS_DRM_CHAN];
254 };
255 typedef CChanSimData<_REAL>		CChanSimDataMod; /* OFDM modulated signals */
256 typedef CChanSimData<_COMPLEX>	CChanSimDataDemod; /* Demodulated signals */
257 
258 /* Path for simulation output and status files */
259 #define SIM_OUT_FILES_PATH				"test/"
260 
261 
262 /* Prototypes for global functions ********************************************/
263 /* Posting a window message */
264 //void PostWinMessage(const _MESSAGE_IDENT MessID, const int iMessageParam = 0);
265 
266 /* Debug error handling */
267 void DebugError(const char* pchErDescr, const char* pchPar1Descr,
268 				const double dPar1, const char* pchPar2Descr,
269 				const double dPar2);
270 
271 void ErrorMessage(string strErrorString);
272 
273 
274 /* Global functions ***********************************************************/
275 /* Converting _REAL to _SAMPLE */
Real2Sample(const _REAL rInput)276 inline _SAMPLE Real2Sample(const _REAL rInput)
277 {
278 	/* Lower bound */
279 	if (rInput < -_MAXSHORT)
280 		return -_MAXSHORT;
281 
282 	/* Upper bound */
283 	if (rInput > _MAXSHORT)
284 		return _MAXSHORT;
285 
286 	return (_SAMPLE) rInput;
287 }
288 
289 
290 #endif // !defined(DEF_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_)
291