1
0
mirror of https://github.com/JvanKatwijk/dabradio synced 2025-10-06 00:02:49 +02:00

stupid error in rtlsdr handler

This commit is contained in:
jan van Katwijk
2019-01-31 15:58:19 +01:00
parent 375e937cbb
commit c6dfaba9a1
8 changed files with 104 additions and 79 deletions

View File

@@ -68,7 +68,7 @@ int32_t i;
this -> nrBlocks = params. get_L ();
this -> carriers = params. get_carriers ();
this -> carrierDiff = params. get_carrierDiff ();
this -> giveSignal = false;
this -> scanMode = false;
ofdmBuffer. resize (2 * T_s);
ofdmBufferIndex = 0;
@@ -92,9 +92,10 @@ int32_t i;
}
}
void dabProcessor::start (int frequency, bool giveSignal) {
this -> frequency = frequency;
this -> giveSignal = giveSignal;
void dabProcessor::start (int frequency, bool scanMode) {
this -> frequency = frequency;
this -> scanMode = scanMode;
startFailures = 0;
this -> QThread::start ();
}
@@ -137,7 +138,7 @@ notSynced:
break; // yes, we are ready
case NO_DIP_FOUND:
if (giveSignal && (++ attempts >= 5)) {
if (scanMode && (++ attempts >= 5)) {
emit (No_Signal_Found ());
attempts = 0;
}
@@ -174,9 +175,15 @@ SyncOnPhase:
if (!correctionNeeded) {
setSyncLost ();
}
startFailures ++;
if (scanMode && (startFailures > 3)) {
emit (No_Signal_Found ());
startFailures = 0;
}
goto notSynced;
}
startFailures = 0;
/**
* Once here, we are synchronized, we need to copy the data we
* used for synchronization for block 0
@@ -252,6 +259,21 @@ NewOffset:
*/
myReader. getSamples (ofdmBuffer. data (),
T_null, coarseOffset);
float sum = 0;
for (i = 0; i < T_null; i ++)
sum += abs (ofdmBuffer [i]);
sum /= T_null;
static float snr = 0;
snr = 0.9 * snr +
0.1 * 20 * log10 ((myReader. get_sLevel () + 0.005) / sum);
static int ccc = 0;
if (++ccc > 10) {
ccc = 0;
show_snr ((int)snr);
}
/**
* The first sample to be found for the next frame should be T_g
* samples ahead. Before going for the next frame, we

View File

@@ -4,19 +4,19 @@
* Jan van Katwijk (J.vanKatwijk@gmail.com)
* Lazy Chair Computing
*
* This file is part of the Qt-DAB program
* Qt-DAB is free software; you can redistribute it and/or modify
* This file is part of the dabradio
* dabradio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Qt-DAB is distributed in the hope that it will be useful,
* dabradio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qt-DAB; if not, write to the Free Software
* along with dabradio; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#
@@ -92,7 +92,8 @@ private:
mscHandler my_mscHandler;
int32_t frequency;
int16_t attempts;
bool giveSignal;
bool scanMode;
int startFailures;
int32_t T_null;
int32_t T_u;
int32_t T_s;
@@ -112,7 +113,6 @@ private:
uint32_t ofdmSymbolCount;
phaseReference phaseSynchronizer;
ofdmDecoder my_ofdmDecoder;
bool wasSecond (int16_t, dabParams *);
virtual void run (void);
bool isReset;
signals:
@@ -120,8 +120,8 @@ signals:
void No_Signal_Found (void);
void setSyncLost (void);
void showCoordinates (int, int);
// void showCoordinates (float, float);
void show_Spectrum (int);
void show_snr (int);
};
#endif

View File

@@ -167,12 +167,12 @@ int i, k;
gains = new int [gainsCount];
gainsCount = rtlsdr_get_tuner_gains (device, gains);
for (i = gainsCount; i > 0; i--) {
fprintf(stderr, "%.1f ", gains [i - 1] / 10.0);
fprintf (stderr, "%.1f ", gains [i - 1] / 10.0);
}
fprintf(stderr, "\n");
rtlsdr_set_tuner_gain_mode (device, 1);
rtlsdr_set_agc_mode (device, 0);
_I_Buffer = new RingBuffer<uint8_t>(8 * 1024 * 1024);
//
// See what the saved values are and restore the GUI settings
@@ -212,7 +212,8 @@ int i, k;
#endif
return;
}
//
// library was open
stopReader ();
this -> rtlsdr_close (device);
@@ -233,7 +234,7 @@ int i, k;
}
//
//
bool rtlsdrHandler::restartReader (void) {
bool rtlsdrHandler::restartReader (int32_t frequency) {
int32_t r;
if (workerHandle != NULL)
@@ -244,7 +245,7 @@ int32_t r;
if (r < 0)
return false;
this -> rtlsdr_set_center_freq (device, lastFrequency);
this -> rtlsdr_set_center_freq (device, frequency);
workerHandle = new dll_driver (this);
rtlsdr_set_agc_mode (device, agcControl -> isChecked ());
rtlsdr_set_tuner_gain (device,
@@ -268,8 +269,10 @@ void rtlsdrHandler::stopReader (void) {
//
// when selecting the gain from a table, use the table value
void rtlsdrHandler::set_ifgain (int gain) {
fprintf (stderr, "gain will be set %d to %d\n",
gain, gains [gain * gainsCount / 100]);
rtlsdr_set_tuner_gain (device,
gain * gainsCount / 100);
gains [gain * gainsCount / 100]);
}
//
void rtlsdrHandler::set_agcControl (int dummy) {
@@ -277,21 +280,42 @@ void rtlsdrHandler::set_agcControl (int dummy) {
rtlsdr_set_tuner_gain (device,
gains [(int)(ifgainSelector -> value () * gainsCount / 100)]);
}
//
// we only have 8 bits, so rather than doing a float division to get
// the float value we want, we precompute the possibilities
static
float convTable [] = {
-128 / 128.0 , -127 / 128.0 , -126 / 128.0 , -125 / 128.0 , -124 / 128.0 , -123 / 128.0 , -122 / 128.0 , -121 / 128.0 , -120 / 128.0 , -119 / 128.0 , -118 / 128.0 , -117 / 128.0 , -116 / 128.0 , -115 / 128.0 , -114 / 128.0 , -113 / 128.0
, -112 / 128.0 , -111 / 128.0 , -110 / 128.0 , -109 / 128.0 , -108 / 128.0 , -107 / 128.0 , -106 / 128.0 , -105 / 128.0 , -104 / 128.0 , -103 / 128.0 , -102 / 128.0 , -101 / 128.0 , -100 / 128.0 , -99 / 128.0 , -98 / 128.0 , -97 / 128.0
, -96 / 128.0 , -95 / 128.0 , -94 / 128.0 , -93 / 128.0 , -92 / 128.0 , -91 / 128.0 , -90 / 128.0 , -89 / 128.0 , -88 / 128.0 , -87 / 128.0 , -86 / 128.0 , -85 / 128.0 , -84 / 128.0 , -83 / 128.0 , -82 / 128.0 , -81 / 128.0
, -80 / 128.0 , -79 / 128.0 , -78 / 128.0 , -77 / 128.0 , -76 / 128.0 , -75 / 128.0 , -74 / 128.0 , -73 / 128.0 , -72 / 128.0 , -71 / 128.0 , -70 / 128.0 , -69 / 128.0 , -68 / 128.0 , -67 / 128.0 , -66 / 128.0 , -65 / 128.0
, -64 / 128.0 , -63 / 128.0 , -62 / 128.0 , -61 / 128.0 , -60 / 128.0 , -59 / 128.0 , -58 / 128.0 , -57 / 128.0 , -56 / 128.0 , -55 / 128.0 , -54 / 128.0 , -53 / 128.0 , -52 / 128.0 , -51 / 128.0 , -50 / 128.0 , -49 / 128.0
, -48 / 128.0 , -47 / 128.0 , -46 / 128.0 , -45 / 128.0 , -44 / 128.0 , -43 / 128.0 , -42 / 128.0 , -41 / 128.0 , -40 / 128.0 , -39 / 128.0 , -38 / 128.0 , -37 / 128.0 , -36 / 128.0 , -35 / 128.0 , -34 / 128.0 , -33 / 128.0
, -32 / 128.0 , -31 / 128.0 , -30 / 128.0 , -29 / 128.0 , -28 / 128.0 , -27 / 128.0 , -26 / 128.0 , -25 / 128.0 , -24 / 128.0 , -23 / 128.0 , -22 / 128.0 , -21 / 128.0 , -20 / 128.0 , -19 / 128.0 , -18 / 128.0 , -17 / 128.0
, -16 / 128.0 , -15 / 128.0 , -14 / 128.0 , -13 / 128.0 , -12 / 128.0 , -11 / 128.0 , -10 / 128.0 , -9 / 128.0 , -8 / 128.0 , -7 / 128.0 , -6 / 128.0 , -5 / 128.0 , -4 / 128.0 , -3 / 128.0 , -2 / 128.0 , -1 / 128.0
, 0 / 128.0 , 1 / 128.0 , 2 / 128.0 , 3 / 128.0 , 4 / 128.0 , 5 / 128.0 , 6 / 128.0 , 7 / 128.0 , 8 / 128.0 , 9 / 128.0 , 10 / 128.0 , 11 / 128.0 , 12 / 128.0 , 13 / 128.0 , 14 / 128.0 , 15 / 128.0
, 16 / 128.0 , 17 / 128.0 , 18 / 128.0 , 19 / 128.0 , 20 / 128.0 , 21 / 128.0 , 22 / 128.0 , 23 / 128.0 , 24 / 128.0 , 25 / 128.0 , 26 / 128.0 , 27 / 128.0 , 28 / 128.0 , 29 / 128.0 , 30 / 128.0 , 31 / 128.0
, 32 / 128.0 , 33 / 128.0 , 34 / 128.0 , 35 / 128.0 , 36 / 128.0 , 37 / 128.0 , 38 / 128.0 , 39 / 128.0 , 40 / 128.0 , 41 / 128.0 , 42 / 128.0 , 43 / 128.0 , 44 / 128.0 , 45 / 128.0 , 46 / 128.0 , 47 / 128.0
, 48 / 128.0 , 49 / 128.0 , 50 / 128.0 , 51 / 128.0 , 52 / 128.0 , 53 / 128.0 , 54 / 128.0 , 55 / 128.0 , 56 / 128.0 , 57 / 128.0 , 58 / 128.0 , 59 / 128.0 , 60 / 128.0 , 61 / 128.0 , 62 / 128.0 , 63 / 128.0
, 64 / 128.0 , 65 / 128.0 , 66 / 128.0 , 67 / 128.0 , 68 / 128.0 , 69 / 128.0 , 70 / 128.0 , 71 / 128.0 , 72 / 128.0 , 73 / 128.0 , 74 / 128.0 , 75 / 128.0 , 76 / 128.0 , 77 / 128.0 , 78 / 128.0 , 79 / 128.0
, 80 / 128.0 , 81 / 128.0 , 82 / 128.0 , 83 / 128.0 , 84 / 128.0 , 85 / 128.0 , 86 / 128.0 , 87 / 128.0 , 88 / 128.0 , 89 / 128.0 , 90 / 128.0 , 91 / 128.0 , 92 / 128.0 , 93 / 128.0 , 94 / 128.0 , 95 / 128.0
, 96 / 128.0 , 97 / 128.0 , 98 / 128.0 , 99 / 128.0 , 100 / 128.0 , 101 / 128.0 , 102 / 128.0 , 103 / 128.0 , 104 / 128.0 , 105 / 128.0 , 106 / 128.0 , 107 / 128.0 , 108 / 128.0 , 109 / 128.0 , 110 / 128.0 , 111 / 128.0
, 112 / 128.0 , 113 / 128.0 , 114 / 128.0 , 115 / 128.0 , 116 / 128.0 , 117 / 128.0 , 118 / 128.0 , 119 / 128.0 , 120 / 128.0 , 121 / 128.0 , 122 / 128.0 , 123 / 128.0 , 124 / 128.0 , 125 / 128.0 , 126 / 128.0 , 127 / 128.0 };
//
// The brave old getSamples. For the dab stick, we get
// size samples: still in I/Q pairs, but we have to convert the data from
// uint8_t to std::complex<float> *
// uint8_t to DSPCOMPLEX *
int32_t rtlsdrHandler::getSamples (std::complex<float> *V, int32_t size) {
int32_t amount, i;
uint8_t *tempBuffer = (uint8_t *)alloca (2 * size * sizeof (uint8_t));
//
amount = _I_Buffer -> getDataFromBuffer (tempBuffer, 2 * size);
for (i = 0; i < amount / 2; i ++)
V [i] = std::complex<float>
((float (tempBuffer [2 * i] - 128)) / 128.0,
(float (tempBuffer [2 * i + 1] - 128)) / 128.0);
(convTable [tempBuffer [2 * i]],
convTable [tempBuffer [2 * i + 1]]);;
return amount / 2;
}

View File

@@ -72,7 +72,7 @@ public:
QCheckBox *);
~rtlsdrHandler (void);
// interface to the reader
bool restartReader (void);
bool restartReader (int32_t frequency);
void stopReader (void);
int32_t getSamples (std::complex<float> *, int32_t);
int32_t Samples (void);

View File

@@ -433,6 +433,25 @@
<string>agc</string>
</property>
</widget>
<widget class="QLCDNumber" name="snrDisplay">
<property name="geometry">
<rect>
<x>300</x>
<y>30</y>
<width>64</width>
<height>23</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="digitCount">
<number>3</number>
</property>
<property name="segmentStyle">
<enum>QLCDNumber::Flat</enum>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>

View File

@@ -4,19 +4,19 @@
* Jan van Katwijk (J.vanKatwijk@gmail.com)
* Lazy Chair Computing
*
* This file is part of the Qt-DAB program
* Qt-DAB is free software; you can redistribute it and/or modify
* This file is part of the dabradio
* dabradio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Qt-DAB is distributed in the hope that it will be useful,
* dabradio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qt-DAB; if not, write to the Free Software
* along with dabradio; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __OFDM_DECODER__
@@ -55,7 +55,6 @@ public:
void decode (std::vector<std::complex<float> >,
int32_t n, int16_t *);
int16_t get_snr (std::complex<float> *);
void stop (void);
void reset (void);
private:
@@ -71,17 +70,13 @@ private:
int32_t T_g;
int32_t nrBlocks;
int32_t carriers;
int16_t getMiddle (void);
std::vector<complex<float>> phaseReference;
std::vector<int16_t> ibits;
std::complex<float> *fft_buffer;
phaseTable *phasetable;
int32_t blockIndex;
int16_t snrCount;
int16_t snr;
int16_t maxSignal;
signals:
void show_snr (int);
void showIQ (int);
void showQuality (float);

View File

@@ -177,6 +177,8 @@ QString h;
picturesPath);
connect (my_dabProcessor, SIGNAL (setSynced (char)),
this, SLOT (setSynced (char)));
connect (my_dabProcessor, SIGNAL (show_snr (int)),
this, SLOT (show_snr (int)));
//
serviceCharacteristics = NULL;
secondsTimer. setInterval (1000);
@@ -290,6 +292,7 @@ void RadioInterface::nextChannel (void) {
void RadioInterface::reset (void) {
my_dabProcessor -> stop ();
disconnect (ensembleDisplay,
SIGNAL (clicked (QModelIndex)),
this, SLOT (selectService (QModelIndex)));
@@ -445,7 +448,7 @@ void RadioInterface::showQuality (float f) {
}
void RadioInterface::show_snr (int s) {
(void)s;
snrDisplay -> display (s);
}
void RadioInterface::set_CorrectorDisplay (int c) {
@@ -590,15 +593,16 @@ void RadioInterface::TerminateProcess (void) {
displayTimer. stop ();
signalTimer. stop ();
inputDevice -> stopReader ();
my_dabProcessor -> stop (); // definitely concurrent
soundOut -> stop ();
// everything should be halted by now
delete soundOut;
if (inputDevice != NULL)
delete inputDevice;
fprintf (stderr, "going to delete dabProcessor\n");
delete my_dabProcessor;
fprintf (stderr, "deleted dabProcessor\n");
delete soundOut;
if (inputDevice != NULL)
delete inputDevice;
if (ensembleDisplay != NULL)
delete ensembleDisplay;
if (serviceDescription != NULL)

View File

@@ -4,19 +4,19 @@
* Jan van Katwijk (J.vanKatwijk@gmail.com)
* Lazy Chair Computing
*
* This file is part of Qt-DAB
* Qt-DAB is free software; you can redistribute it and/or modify
* This file is part of dabradio
* dabradio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Qt-DAB is distributed in the hope that it will be useful,
* dabradio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qt-DAB; if not, write to the Free Software
* along with dabradio; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Once the bits are "in", interpretation and manipulation
@@ -68,12 +68,6 @@ int16_t i;
this -> T_g = T_s - T_u;
fft_buffer = my_fftHandler. getVector ();
phaseReference .resize (T_u);
connect (this, SIGNAL (show_snr (int)),
mr, SLOT (show_snr (int)));
snrCount = 0;
snr = 0;
}
ofdmDecoder::~ofdmDecoder (void) {
@@ -93,17 +87,6 @@ void ofdmDecoder::processBlock_0 (std::vector <std::complex<float> > buffer) {
T_u * sizeof (std::complex<float>));
my_fftHandler. do_FFT ();
/**
* The SNR is determined by looking at a segment of bins
* within the signal region and bits outside.
* It is just an indication
*/
if (++snrCount > 10) {
snr = 0.8 * snr + 0.2 * get_snr (fft_buffer);
// show_snr (snr);
snrCount = 0;
}
/**
* we are now in the frequency domain, and we keep the carriers
* as coming from the FFT as phase reference.
@@ -205,26 +188,4 @@ toBitsLabel:
}
}
}
/**
* for the snr we have a full T_u wide vector, with in the middle
* K carriers.
* Just get the strength from the selected carriers compared
* to the strength of the carriers outside that region
*/
int16_t ofdmDecoder::get_snr (std::complex<float> *v) {
int16_t i;
float noise = 0;
float signal = 0;
for (i = -100; i < 100; i ++)
noise += abs (v [(T_u / 2 + i)]);
noise /= 200;
for (i = - carriers / 4; i < carriers / 4; i ++)
signal += abs (v [(T_u + i) % T_u]);
signal /= (carriers / 2);
return 20 * log10 ((signal + 0.005) / (noise + 0.005));
}