2017-02-23 02:18:56 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 F4HKW //
|
|
|
|
// for F4EXB / SDRAngel //
|
|
|
|
// //
|
|
|
|
// This program 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 as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program 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 V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef INCLUDE_ATVDEMOD_H
|
|
|
|
#define INCLUDE_ATVDEMOD_H
|
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <vector>
|
2017-03-17 06:46:38 -04:00
|
|
|
|
|
|
|
#include "dsp/basebandsamplesink.h"
|
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "dsp/downchannelizer.h"
|
2017-02-23 02:18:56 -05:00
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "dsp/movingaverage.h"
|
2017-03-17 06:46:38 -04:00
|
|
|
#include "dsp/fftfilt.h"
|
2017-02-23 02:18:56 -05:00
|
|
|
#include "dsp/agc.h"
|
2017-03-19 05:28:54 -04:00
|
|
|
#include "dsp/phaselock.h"
|
|
|
|
#include "dsp/recursivefilters.h"
|
2017-02-23 02:18:56 -05:00
|
|
|
#include "audio/audiofifo.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
#include "atvscreen.h"
|
|
|
|
|
|
|
|
|
|
|
|
class ATVDemod : public BasebandSampleSink
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-03-16 15:45:31 -04:00
|
|
|
enum ATVModulation {
|
2017-03-17 06:46:38 -04:00
|
|
|
ATV_FM1, //!< Classical frequency modulation with discriminator #1
|
|
|
|
ATV_FM2, //!< Classical frequency modulation with discriminator #2
|
|
|
|
ATV_AM, //!< Classical amplitude modulation
|
2017-03-19 05:28:54 -04:00
|
|
|
ATV_USB, //!< AM with vestigial lower side band (main signal is in the upper side)
|
|
|
|
ATV_LSB //!< AM with vestigial upper side band (main signal is in the lower side)
|
2017-03-16 15:45:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ATVConfig
|
|
|
|
{
|
2017-03-16 18:29:22 -04:00
|
|
|
int m_intSampleRate;
|
2017-03-20 17:37:11 -04:00
|
|
|
float m_fltLineDuration;
|
2017-03-16 18:29:22 -04:00
|
|
|
float m_fltTopDurationUs;
|
2017-03-16 19:12:12 -04:00
|
|
|
float m_fltFramePerS;
|
|
|
|
float m_fltRatioOfRowsToDisplay;
|
2017-03-16 15:45:31 -04:00
|
|
|
float m_fltVoltLevelSynchroTop;
|
|
|
|
float m_fltVoltLevelSynchroBlack;
|
|
|
|
bool m_blnHSync;
|
|
|
|
bool m_blnVSync;
|
2017-03-19 14:10:48 -04:00
|
|
|
bool m_blnInvertVideo;
|
2017-03-16 15:45:31 -04:00
|
|
|
|
|
|
|
ATVConfig() :
|
2017-03-16 18:29:22 -04:00
|
|
|
m_intSampleRate(0),
|
2017-03-20 17:37:11 -04:00
|
|
|
m_fltLineDuration(0.0f),
|
2017-03-16 18:29:22 -04:00
|
|
|
m_fltTopDurationUs(0.0f),
|
2017-03-16 19:12:12 -04:00
|
|
|
m_fltFramePerS(0.0f),
|
|
|
|
m_fltRatioOfRowsToDisplay(0.0f),
|
2017-03-16 19:33:14 -04:00
|
|
|
m_fltVoltLevelSynchroTop(0.0f),
|
|
|
|
m_fltVoltLevelSynchroBlack(1.0f),
|
2017-03-16 15:45:31 -04:00
|
|
|
m_blnHSync(false),
|
2017-03-19 14:10:48 -04:00
|
|
|
m_blnVSync(false),
|
|
|
|
m_blnInvertVideo(false)
|
2017-03-16 15:45:31 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-17 04:39:20 -04:00
|
|
|
struct ATVRFConfig
|
|
|
|
{
|
2017-03-17 19:11:48 -04:00
|
|
|
int64_t m_intFrequencyOffset;
|
2017-03-17 04:39:20 -04:00
|
|
|
ATVModulation m_enmModulation;
|
|
|
|
float m_fltRFBandwidth;
|
|
|
|
float m_fltRFOppBandwidth;
|
2017-03-17 05:04:00 -04:00
|
|
|
bool m_blnFFTFiltering;
|
2017-03-17 06:46:38 -04:00
|
|
|
bool m_blndecimatorEnable;
|
2017-03-19 05:28:54 -04:00
|
|
|
float m_fltBFOFrequency;
|
2017-03-17 04:39:20 -04:00
|
|
|
|
|
|
|
ATVRFConfig() :
|
2017-03-17 19:11:48 -04:00
|
|
|
m_intFrequencyOffset(0),
|
2017-03-17 04:39:20 -04:00
|
|
|
m_enmModulation(ATV_FM1),
|
|
|
|
m_fltRFBandwidth(0),
|
2017-03-17 05:04:00 -04:00
|
|
|
m_fltRFOppBandwidth(0),
|
2017-03-17 06:46:38 -04:00
|
|
|
m_blnFFTFiltering(false),
|
2017-03-19 05:28:54 -04:00
|
|
|
m_blndecimatorEnable(false),
|
|
|
|
m_fltBFOFrequency(0.0f)
|
2017-03-17 04:39:20 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-18 05:04:57 -04:00
|
|
|
class MsgReportEffectiveSampleRate : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getSampleRate() const { return m_sampleRate; }
|
|
|
|
|
|
|
|
static MsgReportEffectiveSampleRate* create(int sampleRate)
|
|
|
|
{
|
|
|
|
return new MsgReportEffectiveSampleRate(sampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_sampleRate;
|
|
|
|
|
|
|
|
MsgReportEffectiveSampleRate(int sampleRate) :
|
|
|
|
Message(),
|
|
|
|
m_sampleRate(sampleRate)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2017-03-20 06:57:52 -04:00
|
|
|
ATVDemod(BasebandSampleSink* objScopeSink);
|
2017-02-23 02:18:56 -05:00
|
|
|
~ATVDemod();
|
|
|
|
|
2017-02-25 01:12:41 -05:00
|
|
|
void configure(MessageQueue* objMessageQueue,
|
2017-03-16 19:12:12 -04:00
|
|
|
float fltLineDurationUs,
|
|
|
|
float fltTopDurationUs,
|
|
|
|
float fltFramePerS,
|
|
|
|
float fltRatioOfRowsToDisplay,
|
2017-02-25 01:12:41 -05:00
|
|
|
float fltVoltLevelSynchroTop,
|
|
|
|
float fltVoltLevelSynchroBlack,
|
|
|
|
bool blnHSync,
|
2017-03-19 14:10:48 -04:00
|
|
|
bool blnVSync,
|
|
|
|
bool blnInvertVideo);
|
2017-02-23 02:18:56 -05:00
|
|
|
|
2017-03-17 04:39:20 -04:00
|
|
|
void configureRF(MessageQueue* objMessageQueue,
|
|
|
|
ATVModulation enmModulation,
|
|
|
|
float fltRFBandwidth,
|
2017-03-17 05:04:00 -04:00
|
|
|
float fltRFOppBandwidth,
|
2017-03-17 06:46:38 -04:00
|
|
|
bool blnFFTFiltering,
|
2017-03-19 05:28:54 -04:00
|
|
|
bool blndecimatorEnable,
|
|
|
|
float fltBFOFrequency);
|
2017-03-17 04:39:20 -04:00
|
|
|
|
2017-02-23 02:18:56 -05:00
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& cmd);
|
|
|
|
|
2017-03-18 05:04:57 -04:00
|
|
|
void setATVScreen(ATVScreen *objScreen);
|
2017-03-16 21:05:13 -04:00
|
|
|
int getSampleRate();
|
2017-03-18 06:05:28 -04:00
|
|
|
int getEffectiveSampleRate();
|
2017-03-16 13:56:20 -04:00
|
|
|
double getMagSq() const { return m_objMagSqAverage.average(); } //!< Beware this is scaled to 2^30
|
2017-03-19 05:28:54 -04:00
|
|
|
bool getBFOLocked();
|
2017-02-23 02:18:56 -05:00
|
|
|
|
|
|
|
private:
|
2017-03-18 05:04:57 -04:00
|
|
|
struct ATVConfigPrivate
|
|
|
|
{
|
|
|
|
int m_intTVSampleRate;
|
|
|
|
|
|
|
|
ATVConfigPrivate() :
|
|
|
|
m_intTVSampleRate(0)
|
|
|
|
{}
|
|
|
|
};
|
2017-02-23 02:18:56 -05:00
|
|
|
|
|
|
|
class MsgConfigureATVDemod : public Message
|
|
|
|
{
|
2017-03-16 18:13:51 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
2017-02-23 02:18:56 -05:00
|
|
|
|
|
|
|
public:
|
2017-03-17 04:39:20 -04:00
|
|
|
static MsgConfigureATVDemod* create(
|
|
|
|
float fltLineDurationUs,
|
2017-03-16 18:29:22 -04:00
|
|
|
float fltTopDurationUs,
|
2017-03-16 19:12:12 -04:00
|
|
|
float fltFramePerS,
|
|
|
|
float fltRatioOfRowsToDisplay,
|
2017-02-25 01:12:41 -05:00
|
|
|
float fltVoltLevelSynchroTop,
|
|
|
|
float fltVoltLevelSynchroBlack,
|
|
|
|
bool blnHSync,
|
2017-03-19 14:10:48 -04:00
|
|
|
bool blnVSync,
|
|
|
|
bool blnInvertVideo)
|
2017-02-23 02:18:56 -05:00
|
|
|
{
|
2017-03-17 04:39:20 -04:00
|
|
|
return new MsgConfigureATVDemod(
|
|
|
|
fltLineDurationUs,
|
2017-03-16 18:29:22 -04:00
|
|
|
fltTopDurationUs,
|
2017-03-16 19:12:12 -04:00
|
|
|
fltFramePerS,
|
|
|
|
fltRatioOfRowsToDisplay,
|
2017-02-25 01:12:41 -05:00
|
|
|
fltVoltLevelSynchroTop,
|
|
|
|
fltVoltLevelSynchroBlack,
|
|
|
|
blnHSync,
|
2017-03-19 14:10:48 -04:00
|
|
|
blnVSync,
|
|
|
|
blnInvertVideo);
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ATVConfig m_objMsgConfig;
|
|
|
|
|
|
|
|
private:
|
2017-03-16 19:12:12 -04:00
|
|
|
MsgConfigureATVDemod(
|
|
|
|
float fltLineDurationUs,
|
2017-03-16 18:29:22 -04:00
|
|
|
float fltTopDurationUs,
|
2017-03-16 19:12:12 -04:00
|
|
|
float fltFramePerS,
|
|
|
|
float flatRatioOfRowsToDisplay,
|
2017-02-25 01:12:41 -05:00
|
|
|
float fltVoltLevelSynchroTop,
|
|
|
|
float fltVoltLevelSynchroBlack,
|
|
|
|
bool blnHSync,
|
2017-03-19 14:10:48 -04:00
|
|
|
bool blnVSync,
|
|
|
|
bool blnInvertVideo) :
|
2017-02-23 02:18:56 -05:00
|
|
|
Message()
|
|
|
|
{
|
|
|
|
m_objMsgConfig.m_fltVoltLevelSynchroBlack = fltVoltLevelSynchroBlack;
|
|
|
|
m_objMsgConfig.m_fltVoltLevelSynchroTop = fltVoltLevelSynchroTop;
|
2017-03-16 19:12:12 -04:00
|
|
|
m_objMsgConfig.m_fltFramePerS = fltFramePerS;
|
2017-03-20 17:37:11 -04:00
|
|
|
m_objMsgConfig.m_fltLineDuration = fltLineDurationUs;
|
2017-03-16 18:29:22 -04:00
|
|
|
m_objMsgConfig.m_fltTopDurationUs = fltTopDurationUs;
|
2017-03-16 19:12:12 -04:00
|
|
|
m_objMsgConfig.m_fltRatioOfRowsToDisplay = flatRatioOfRowsToDisplay;
|
2017-02-23 02:18:56 -05:00
|
|
|
m_objMsgConfig.m_blnHSync = blnHSync;
|
|
|
|
m_objMsgConfig.m_blnVSync = blnVSync;
|
2017-03-19 14:10:48 -04:00
|
|
|
m_objMsgConfig.m_blnInvertVideo = blnInvertVideo;
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-17 04:39:20 -04:00
|
|
|
class MsgConfigureRFATVDemod : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgConfigureRFATVDemod* create(
|
|
|
|
ATVModulation enmModulation,
|
|
|
|
float fltRFBandwidth,
|
2017-03-17 05:04:00 -04:00
|
|
|
float fltRFOppBandwidth,
|
2017-03-17 06:46:38 -04:00
|
|
|
bool blnFFTFiltering,
|
2017-03-19 05:28:54 -04:00
|
|
|
bool blndecimatorEnable,
|
|
|
|
int intBFOFrequency)
|
2017-03-17 04:39:20 -04:00
|
|
|
{
|
|
|
|
return new MsgConfigureRFATVDemod(
|
|
|
|
enmModulation,
|
|
|
|
fltRFBandwidth,
|
2017-03-17 05:04:00 -04:00
|
|
|
fltRFOppBandwidth,
|
2017-03-17 06:46:38 -04:00
|
|
|
blnFFTFiltering,
|
2017-03-19 05:28:54 -04:00
|
|
|
blndecimatorEnable,
|
|
|
|
intBFOFrequency);
|
2017-03-17 04:39:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ATVRFConfig m_objMsgConfig;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MsgConfigureRFATVDemod(
|
|
|
|
ATVModulation enmModulation,
|
|
|
|
float fltRFBandwidth,
|
2017-03-17 05:04:00 -04:00
|
|
|
float fltRFOppBandwidth,
|
2017-03-17 06:46:38 -04:00
|
|
|
bool blnFFTFiltering,
|
2017-03-19 05:28:54 -04:00
|
|
|
bool blndecimatorEnable,
|
|
|
|
float fltBFOFrequency) :
|
2017-03-17 04:39:20 -04:00
|
|
|
Message()
|
|
|
|
{
|
|
|
|
m_objMsgConfig.m_enmModulation = enmModulation;
|
|
|
|
m_objMsgConfig.m_fltRFBandwidth = fltRFBandwidth;
|
|
|
|
m_objMsgConfig.m_fltRFOppBandwidth = fltRFOppBandwidth;
|
2017-03-17 05:04:00 -04:00
|
|
|
m_objMsgConfig.m_blnFFTFiltering = blnFFTFiltering;
|
2017-03-18 04:19:51 -04:00
|
|
|
m_objMsgConfig.m_blndecimatorEnable = blndecimatorEnable;
|
2017-03-19 05:28:54 -04:00
|
|
|
m_objMsgConfig.m_fltBFOFrequency = fltBFOFrequency;
|
2017-03-17 04:39:20 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-20 06:57:52 -04:00
|
|
|
//*************** SCOPE ***************
|
|
|
|
|
|
|
|
BasebandSampleSink* m_objScopeSink;
|
|
|
|
SampleVector m_objScopeSampleBuffer;
|
|
|
|
|
2017-03-16 18:13:51 -04:00
|
|
|
//*************** ATV PARAMETERS ***************
|
|
|
|
ATVScreen * m_objRegisteredATVScreen;
|
|
|
|
|
|
|
|
int m_intNumberSamplePerLine;
|
|
|
|
int m_intNumberSamplePerTop;
|
|
|
|
int m_intNumberOfLines;
|
|
|
|
int m_intNumberOfRowsToDisplay;
|
|
|
|
|
|
|
|
//*************** PROCESSING ***************
|
|
|
|
|
|
|
|
int m_intImageIndex;
|
|
|
|
int m_intRowsLimit;
|
|
|
|
int m_intSynchroPoints;
|
|
|
|
|
|
|
|
bool m_blnSynchroDetected;
|
|
|
|
bool m_blnLineSynchronized;
|
|
|
|
bool m_blnImageDetecting;
|
|
|
|
bool m_blnVerticalSynchroDetected;
|
|
|
|
|
|
|
|
float m_fltAmpLineAverage;
|
|
|
|
|
|
|
|
float m_fltEffMin;
|
|
|
|
float m_fltEffMax;
|
|
|
|
|
|
|
|
float m_fltAmpMin;
|
|
|
|
float m_fltAmpMax;
|
|
|
|
float m_fltAmpDelta;
|
|
|
|
|
|
|
|
float m_fltBufferI[6];
|
|
|
|
float m_fltBufferQ[6];
|
|
|
|
|
|
|
|
int m_intColIndex;
|
|
|
|
int m_intRowIndex;
|
|
|
|
|
|
|
|
//*************** RF ***************
|
|
|
|
|
|
|
|
MovingAverage<double> m_objMagSqAverage;
|
|
|
|
|
2017-03-17 19:11:48 -04:00
|
|
|
NCO m_nco;
|
2017-03-19 05:28:54 -04:00
|
|
|
SimplePhaseLock m_bfoPLL;
|
|
|
|
SecondOrderRecursiveFilter m_bfoFilter;
|
2017-03-17 19:11:48 -04:00
|
|
|
|
2017-03-17 06:46:38 -04:00
|
|
|
// Interpolator group for decimation and/or double sideband RF filtering
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_interpolatorDistance;
|
|
|
|
Real m_interpolatorDistanceRemain;
|
|
|
|
|
|
|
|
// Used for vestigial SSB with asymmetrical filtering (needs double sideband scheme)
|
|
|
|
fftfilt* m_DSBFilter;
|
|
|
|
Complex* m_DSBFilterBuffer;
|
|
|
|
int m_DSBFilterBufferIndex;
|
|
|
|
static const int m_ssbFftLen;
|
|
|
|
|
2017-03-16 18:13:51 -04:00
|
|
|
//QElapsedTimer m_objTimer;
|
2017-02-23 02:18:56 -05:00
|
|
|
|
|
|
|
ATVConfig m_objRunning;
|
2017-03-16 16:07:51 -04:00
|
|
|
ATVConfig m_objConfig;
|
2017-02-23 02:18:56 -05:00
|
|
|
|
2017-03-17 05:04:00 -04:00
|
|
|
ATVRFConfig m_objRFRunning;
|
|
|
|
ATVRFConfig m_objRFConfig;
|
|
|
|
|
2017-03-18 05:04:57 -04:00
|
|
|
ATVConfigPrivate m_objRunningPrivate;
|
|
|
|
ATVConfigPrivate m_objConfigPrivate;
|
|
|
|
|
2017-02-23 02:18:56 -05:00
|
|
|
QMutex m_objSettingsMutex;
|
|
|
|
|
2017-03-16 18:13:51 -04:00
|
|
|
static const float m_fltSecondToUs;
|
|
|
|
|
2017-03-16 21:05:13 -04:00
|
|
|
void applySettings();
|
2017-03-18 00:37:52 -04:00
|
|
|
void demod(Complex& c);
|
2017-03-20 00:06:33 -04:00
|
|
|
static float getRFBandwidthDivisor(ATVModulation modulation);
|
2017-02-23 02:18:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_ATVDEMOD_H
|