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.
devicesamplesink.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016-2019 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 
21 #include "dsp/devicesamplesink.h"
22 
24  m_sampleSourceFifo(1<<19),
25  m_guiMessageQueue(0)
26 {
27  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
28 }
29 
31 {
32 }
33 
35 {
36  Message* message;
37 
38  while ((message = m_inputMessageQueue.pop()) != 0)
39  {
40  if (handleMessage(*message))
41  {
42  delete message;
43  }
44  }
45 }
46 
48  quint64 centerFrequency,
49  qint64 transverterDeltaFrequency,
50  int log2Interp,
51  fcPos_t fcPos,
52  quint32 devSampleRate,
53  bool transverterMode)
54 {
55  qint64 deviceCenterFrequency = centerFrequency;
56  deviceCenterFrequency -= transverterMode ? transverterDeltaFrequency : 0;
57  deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency;
58  qint64 f_img = deviceCenterFrequency;
59 
60  deviceCenterFrequency -= calculateFrequencyShift(log2Interp, fcPos, devSampleRate);
61  f_img -= 2*calculateFrequencyShift(log2Interp, fcPos, devSampleRate);
62 
63  qDebug() << "DeviceSampleSink::calculateDeviceCenterFrequency:"
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<<log2Interp) << "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 log2Interp,
78  fcPos_t fcPos,
79  quint32 devSampleRate,
80  bool transverterMode)
81 {
82  qint64 centerFrequency = deviceCenterFrequency;
83  centerFrequency += calculateFrequencyShift(log2Interp, fcPos, devSampleRate);
84  centerFrequency += transverterMode ? transverterDeltaFrequency : 0;
85  centerFrequency = centerFrequency < 0 ? 0 : centerFrequency;
86 
87  qDebug() << "DeviceSampleSink::calculateCenterFrequency:"
88  << " desired center freq: " << centerFrequency << " Hz"
89  << " device center freq: " << deviceCenterFrequency << " Hz"
90  << " device sample rate: " << devSampleRate << "S/s"
91  << " Actual sample rate: " << devSampleRate/(1<<log2Interp) << "S/s"
92  << " center freq position code: " << fcPos;
93 
94  return centerFrequency;
95 }
96 
115  int log2Interp,
116  fcPos_t fcPos,
117  quint32 devSampleRate)
118 {
119  if (fcPos == FC_POS_CENTER) {
120  return 0;
121  }
122 
123  int sign = fcPos == FC_POS_INFRA ? -1 : 1;
124  int halfSampleRate = devSampleRate / 2; // fractions are relative to sideband thus based on half the sample rate
125 
126  if (log2Interp == 0) {
127  return 0;
128  } else if (log2Interp == 1) {
129  return sign * (halfSampleRate / 2);
130  } else if (log2Interp == 2) {
131  return sign * ((halfSampleRate * 3) / 4);
132  } else if (log2Interp == 3) {
133  return sign * ((halfSampleRate * 5) / 8);
134  } else if (log2Interp == 4) {
135  return sign * ((halfSampleRate * 11) / 16);
136  } else if (log2Interp == 5) {
137  return sign * ((halfSampleRate * 21) / 32);
138  } else if (log2Interp == 6) {
139  return sign * ((halfSampleRate * 21) / 64);
140  } else {
141  return 0;
142  }
143 }
144 
Message * pop()
Pop message from queue.
MessageQueue m_inputMessageQueue
Input queue to the sink.
virtual ~DeviceSampleSink()
static qint64 calculateCenterFrequency(quint64 deviceCenterFrequency, qint64 transverterDeltaFrequency, int log2Interp, fcPos_t fcPos, quint32 devSampleRate, bool transverterMode=false)
static qint32 calculateFrequencyShift(int log2Interp, fcPos_t fcPos, quint32 devSampleRate)
static qint64 calculateDeviceCenterFrequency(quint64 centerFrequency, qint64 transverterDeltaFrequency, int log2Interp, fcPos_t fcPos, quint32 devSampleRate, bool transverterMode=false)
virtual bool handleMessage(const Message &message)=0