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.
atvdemodsettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 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 #include <QColor>
19 
20 #include "dsp/dspengine.h"
21 #include "util/simpleserializer.h"
22 #include "settings/serializable.h"
23 #include "atvdemodsettings.h"
24 
26  m_channelMarker(0)
27 {
29 }
30 
32 {
33  m_lineTimeFactor = 0;
34  m_topTimeFactor = 0;
35  m_fpsIndex = 1; // 25 FPS
36  m_halfImage = false; // m_fltRatioOfRowsToDisplay = 1.0
39  m_nbLinesIndex = 1; // 625 lines
40 
43  m_fltRFBandwidth = 0;
45  m_blnFFTFiltering = false;
46  m_blndecimatorEnable = false;
47  m_fltBFOFrequency = 0.0f;
48  m_fmDeviation = 0.5f;
49 
50  m_intSampleRate = 0;
52  m_intNumberOfLines = 625;
53  m_fltLineDuration = 0.0f;
54  m_fltTopDuration = 0.0f;
55  m_fltFramePerS = 25.0f;
59  m_blnHSync = false;
60  m_blnVSync = false;
61  m_blnInvertVideo = false;
66 
69 
70  m_rgbColor = QColor(255, 255, 255).rgb();
71  m_title = "ATV Demodulator";
72  m_udpAddress = "127.0.0.1";
73  m_udpPort = 9999;
74 }
75 
76 QByteArray ATVDemodSettings::serialize() const
77 {
78  SimpleSerializer s(1);
79 
81  s.writeU32(2, m_rgbColor);
82  s.writeS32(3, roundf(m_fltVoltLevelSynchroTop*1000.0)); // mV
83  s.writeS32(4, roundf(m_fltVoltLevelSynchroBlack*1000.0)); // mV
84  s.writeS32(5, m_lineTimeFactor); // added UI
85  s.writeS32(6, m_topTimeFactor); // added UI
87  s.writeS32(8, m_fpsIndex); // added UI
88  s.writeBool(9, m_blnHSync);
89  s.writeBool(10,m_blnVSync);
90  s.writeBool(11, m_halfImage); // added UI
91  s.writeS32(12, m_RFBandwidthFactor); // added UI
92  s.writeS32(13, m_OppBandwidthFactor); // added UI
93  s.writeS32(14, roundf(m_fltBFOFrequency));
95  s.writeS32(16, m_nbLinesIndex); // added UI
96  s.writeS32(17, roundf(m_fmDeviation * 500.0));
98 
99  if (m_channelMarker) {
101  }
102 
103  s.writeString(20, m_title);
104 
105  return s.final();
106 }
107 
108 bool ATVDemodSettings::deserialize(const QByteArray& arrData)
109 {
110  SimpleDeserializer d(arrData);
111 
112  if (!d.isValid())
113  {
114  resetToDefaults();
115  return false;
116  }
117 
118  if (d.getVersion() == 1)
119  {
120  QByteArray bytetmp;
121  int tmp;
122 
123  d.readS32(1, &m_intFrequencyOffset, 0);
124  // TODO: rgb color
125  d.readS32(3, &tmp, 100);
126  m_fltVoltLevelSynchroTop = tmp / 1000.0f;
127  d.readS32(4, &tmp, 310);
128  m_fltVoltLevelSynchroBlack = tmp / 1000.0f;
129  d.readS32(5, &m_lineTimeFactor, 0); // added UI
130  d.readS32(6, &m_topTimeFactor, 0); // added UI
131  d.readS32(7, &tmp, 0);
132  m_enmModulation = static_cast<ATVModulation>(tmp);
133  d.readS32(8, &m_fpsIndex, 1); // added UI
134  d.readBool(9, &m_blnHSync, false);
135  d.readBool(10, &m_blnVSync, false);
136  d.readBool(11, &m_halfImage, false); // added UI
137  d.readS32(12, &m_RFBandwidthFactor, 10); // added UI
138  d.readS32(13, &m_OppBandwidthFactor, 10); // added UI
139  d.readS32(14, &tmp, 10);
140  m_fltBFOFrequency = static_cast<float>(tmp);
141  d.readBool(15, &m_blnInvertVideo, false);
142  d.readS32(16, &m_nbLinesIndex, 1); // added UI
143  d.readS32(17, &tmp, 250);
144  m_fmDeviation = tmp / 500.0f;
145  d.readS32(18, &tmp, 1);
146  m_enmATVStandard = static_cast<ATVStd>(tmp);
147 
148  // TODO: calculate values from UI values
149 
150  return true;
151  }
152  else
153  {
154  resetToDefaults();
155  return false;
156  }
157 }
158 
160 {
162 }
163 
164 
165 float ATVDemodSettings::getFps(int fpsIndex)
166 {
167  switch(fpsIndex)
168  {
169  case 0:
170  return 30.0f;
171  break;
172  case 2:
173  return 20.0f;
174  break;
175  case 3:
176  return 16.0f;
177  break;
178  case 4:
179  return 12.0f;
180  break;
181  case 5:
182  return 10.0f;
183  break;
184  case 6:
185  return 8.0f;
186  break;
187  case 7:
188  return 5.0f;
189  break;
190  case 8:
191  return 2.0f;
192  break;
193  case 9:
194  return 1.0f;
195  break;
196  case 1:
197  default:
198  return 25.0f;
199  break;
200  }
201 }
202 
204 {
205  int fpsi = roundf(fps);
206 
207  if (fpsi <= 1) {
208  return 9;
209  } else if (fps <= 2) {
210  return 8;
211  } else if (fps <= 5) {
212  return 7;
213  } else if (fps <= 8) {
214  return 6;
215  } else if (fps <= 10) {
216  return 5;
217  } else if (fps <= 12) {
218  return 4;
219  } else if (fps <= 16) {
220  return 3;
221  } else if (fps <= 20) {
222  return 2;
223  } else if (fps <= 25) {
224  return 1;
225  } else {
226  return 0;
227  }
228 }
229 
231 {
232  switch(nbLinesIndex)
233  {
234  case 0:
235  return 640;
236  break;
237  case 2:
238  return 525;
239  break;
240  case 3:
241  return 480;
242  break;
243  case 4:
244  return 405;
245  break;
246  case 5:
247  return 360;
248  break;
249  case 6:
250  return 343;
251  break;
252  case 7:
253  return 240;
254  break;
255  case 8:
256  return 180;
257  break;
258  case 9:
259  return 120;
260  break;
261  case 10:
262  return 90;
263  break;
264  case 11:
265  return 60;
266  break;
267  case 12:
268  return 32;
269  break;
270  case 1:
271  default:
272  return 625;
273  break;
274  }
275 }
276 
278 {
279  if (nbLines <= 32) {
280  return 12;
281  } else if (nbLines <= 60) {
282  return 11;
283  } else if (nbLines <= 90) {
284  return 10;
285  } else if (nbLines <= 120) {
286  return 9;
287  } else if (nbLines <= 180) {
288  return 8;
289  } else if (nbLines <= 240) {
290  return 7;
291  } else if (nbLines <= 343) {
292  return 6;
293  } else if (nbLines <= 360) {
294  return 5;
295  } else if (nbLines <= 405) {
296  return 4;
297  } else if (nbLines <= 480) {
298  return 3;
299  } else if (nbLines <= 525) {
300  return 2;
301  } else if (nbLines <= 625) {
302  return 1;
303  } else {
304  return 0;
305  }
306 }
307 
308 float ATVDemodSettings::getNominalLineTime(int nbLinesIndex, int fpsIndex)
309 {
310  float fps = getFps(fpsIndex);
311  int nbLines = getNumberOfLines(nbLinesIndex);
312 
313  return 1.0f / (nbLines * fps);
314 }
315 
320 {
321  float nominalLineTime = getNominalLineTime(m_nbLinesIndex, m_fpsIndex);
322  int lineTimeScaleFactor = (int) std::log10(nominalLineTime);
323 
324  if (getEffectiveSampleRate() == 0) {
325  m_fltLineTimeMultiplier = std::pow(10.0, lineTimeScaleFactor-3);
326  } else {
328  }
329 }
330 
332 {
334 }
335 
337 {
339 }
340 
345 {
346  float nominalTopTime = getNominalLineTime(m_nbLinesIndex, m_fpsIndex) * (4.7f / 64.0f);
347  int topTimeScaleFactor = (int) std::log10(nominalTopTime);
348 
349  if (getEffectiveSampleRate() == 0) {
350  m_fltTopTimeMultiplier = std::pow(10.0, topTimeScaleFactor-3);
351  } else {
353  }
354 }
355 
357 {
359 }
360 
362 {
364 }
365 
367 {
368  lineTimeUpdate();
370  topTimeUpdate();
376 }
377 
379 {
387 }
388 
390 {
391  int sampleRate = getEffectiveSampleRate();
392  int scaleFactor = (int) std::log10(sampleRate/2);
393  return std::pow(10.0, scaleFactor-1);
394 }
395 
396 
static int getFpsIndex(float fps)
ATVModulation m_enmModulation
void writeBlob(quint32 id, const QByteArray &value)
static int getNumberOfLinesIndex(int nbLines)
float m_fltVoltLevelSynchroTop
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
static float getFps(int fpsIndex)
bool deserialize(const QByteArray &data)
int m_topTimeFactor
added: +/- 30 something
QByteArray serialize() const
float m_fltRatioOfRowsToDisplay
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
int m_lineTimeFactor
added: +/- 100 something
Classical frequency modulation with discriminator #1.
int m_fpsIndex
added: FPS list index
float m_fltVoltLevelSynchroBlack
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
bool m_halfImage
added: true => m_fltRatioOfRowsToDisplay = 0.5, false => m_fltRatioOfRowsToDisplay = 1...
int m_nbLinesIndex
added: #lines list index
static int getNumberOfLines(int nbLinesIndex)
void writeU32(quint32 id, quint32 value)
int m_RFBandwidthFactor
added: [1:100]
static float getNominalLineTime(int nbLinesIndex, int fpsIndex)
virtual QByteArray serialize() const =0
void writeBool(quint32 id, bool value)
void writeString(quint32 id, const QString &value)
Serializable * m_channelMarker
int m_OppBandwidthFactor
added: [0:100]
const QByteArray & final()