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.
devicesamplesource.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015-2017 F4EXB //
3 // written by Edouard Griffiths //
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 #include <QDebug>
20 #include <dsp/devicesamplesource.h>
21 
23  m_guiMessageQueue(0)
24 {
25  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
26 }
27 
29 {
30 }
31 
33 {
34  Message* message;
35 
36  while ((message = m_inputMessageQueue.pop()) != 0)
37  {
38  if (handleMessage(*message))
39  {
40  delete message;
41  }
42  }
43 }
44 
46  quint64 centerFrequency,
47  qint64 transverterDeltaFrequency,
48  int log2Decim,
49  fcPos_t fcPos,
50  quint32 devSampleRate,
51  FrequencyShiftScheme frequencyShiftScheme,
52  bool transverterMode)
53 {
54  qint64 deviceCenterFrequency = centerFrequency;
55  deviceCenterFrequency -= transverterMode ? transverterDeltaFrequency : 0;
56  deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency;
57  qint64 f_img = deviceCenterFrequency;
58 
59  deviceCenterFrequency -= calculateFrequencyShift(log2Decim, fcPos, devSampleRate, frequencyShiftScheme);
60  f_img -= 2*calculateFrequencyShift(log2Decim, fcPos, devSampleRate, frequencyShiftScheme);
61 
62  qDebug() << "DeviceSampleSource::calculateDeviceCenterFrequency:"
63  << " frequencyShiftScheme: " << frequencyShiftScheme
64  << " desired center freq: " << centerFrequency << " Hz"
65  << " device center freq: " << deviceCenterFrequency << " Hz"
66  << " device sample rate: " << devSampleRate << "S/s"
67  << " Actual sample rate: " << devSampleRate/(1<<log2Decim) << "S/s"
68  << " center freq position code: " << fcPos
69  << " image frequency: " << f_img << "Hz";
70 
71  return deviceCenterFrequency;
72 }
73 
75  quint64 deviceCenterFrequency,
76  qint64 transverterDeltaFrequency,
77  int log2Decim,
78  fcPos_t fcPos,
79  quint32 devSampleRate,
80  FrequencyShiftScheme frequencyShiftScheme,
81  bool transverterMode)
82 {
83  qint64 centerFrequency = deviceCenterFrequency;
84  centerFrequency += calculateFrequencyShift(log2Decim, fcPos, devSampleRate, frequencyShiftScheme);
85  centerFrequency += transverterMode ? transverterDeltaFrequency : 0;
86  centerFrequency = centerFrequency < 0 ? 0 : centerFrequency;
87 
88  qDebug() << "DeviceSampleSource::calculateCenterFrequency:"
89  << " frequencyShiftScheme: " << frequencyShiftScheme
90  << " desired center freq: " << centerFrequency << " Hz"
91  << " device center freq: " << deviceCenterFrequency << " Hz"
92  << " device sample rate: " << devSampleRate << "S/s"
93  << " Actual sample rate: " << devSampleRate/(1<<log2Decim) << "S/s"
94  << " center freq position code: " << fcPos;
95 
96  return centerFrequency;
97 }
98 
115  int log2Decim,
116  fcPos_t fcPos,
117  quint32 devSampleRate,
118  FrequencyShiftScheme frequencyShiftScheme)
119 {
120  if (frequencyShiftScheme == FSHIFT_STD)
121  {
122  if (log2Decim == 0) { // no shift at all
123  return 0;
124  } else if (log2Decim < 3) {
125  if (fcPos == FC_POS_INFRA) { // shift in the square next to center frequency
126  return -(devSampleRate / (1<<(log2Decim+1)));
127  } else if (fcPos == FC_POS_SUPRA) {
128  return devSampleRate / (1<<(log2Decim+1));
129  } else {
130  return 0;
131  }
132  } else {
133  if (fcPos == FC_POS_INFRA) { // shift centered in the square next to center frequency
134  return -(devSampleRate / (1<<(log2Decim)));
135  } else if (fcPos == FC_POS_SUPRA) {
136  return devSampleRate / (1<<(log2Decim));
137  } else {
138  return 0;
139  }
140  }
141  }
142  else // frequencyShiftScheme == FSHIFT_TXSYNC
143  {
144  if (fcPos == FC_POS_CENTER) {
145  return 0;
146  }
147 
148  int sign = fcPos == FC_POS_INFRA ? -1 : 1;
149  int halfSampleRate = devSampleRate / 2; // fractions are relative to sideband thus based on half the sample rate
150 
151  if (log2Decim == 0) {
152  return 0;
153  } else if (log2Decim == 1) {
154  return sign * (halfSampleRate / 2); // inf or sup: 1/2
155  } else if (log2Decim == 2) {
156  return sign * ((halfSampleRate * 3) / 4); // inf, inf or sup, sup: 1/2 + 1/4
157  } else if (log2Decim == 3) {
158  return sign * ((halfSampleRate * 5) / 8); // inf, inf, sup or sup, sup, inf: 1/2 + 1/4 - 1/8 = 5/8
159  } else if (log2Decim == 4) {
160  return sign * ((halfSampleRate * 11) / 16); // inf, inf, sup, inf or sup, sup, inf, sup: 1/2 + 1/4 - 1/8 + 1/16 = 11/16
161  } else if (log2Decim == 5) {
162  return sign * ((halfSampleRate * 21) / 32); // inf, inf, sup, inf, sup or sup, sup, inf, sup, inf: 1/2 + 1/4 - 1/8 + 1/16 - 1/32 = 21/32
163  } else if (log2Decim == 6) {
164  return sign * ((halfSampleRate * 21) / 64); // inf, sup, inf, sup, inf, sup or sup, inf, sup, inf, sup, inf: 1/2 - 1/4 + 1/8 -1/16 + 1/32 - 1/64 = 21/64
165  } else {
166  return 0;
167  }
168  }
169 }
Message * pop()
Pop message from queue.
static qint32 calculateFrequencyShift(int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme)
static qint64 calculateDeviceCenterFrequency(quint64 centerFrequency, qint64 transverterDeltaFrequency, int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme, bool transverterMode=false)
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual bool handleMessage(const Message &message)=0
static qint64 calculateCenterFrequency(quint64 deviceCenterFrequency, qint64 transverterDeltaFrequency, int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme, bool transverterMode=false)