2017-03-06 02:39:34 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 PLUGINS_CHANNELTX_MODATV_ATVMOD_H_
|
|
|
|
#define PLUGINS_CHANNELTX_MODATV_ATVMOD_H_
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMutex>
|
|
|
|
|
2017-03-08 07:36:28 +00:00
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
|
2017-03-06 02:39:34 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "dsp/basebandsamplesource.h"
|
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "dsp/movingaverage.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
|
|
|
|
class ATVMod : public BasebandSampleSource {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef enum
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
ATVStdPAL625,
|
|
|
|
ATVStdPAL525
|
2017-03-06 02:39:34 +00:00
|
|
|
} ATVStd;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ATVModInputUniform,
|
2017-03-07 00:38:19 +00:00
|
|
|
ATVModInputHBars,
|
|
|
|
ATVModInputVBars,
|
2017-03-07 21:55:11 +00:00
|
|
|
ATVModInputCheckbox,
|
2017-03-07 00:38:19 +00:00
|
|
|
ATVModInputHGradient,
|
2017-03-08 00:35:18 +00:00
|
|
|
ATVModInputVGradient,
|
|
|
|
ATVModInputImage,
|
|
|
|
ATVModInputVideo
|
2017-03-06 02:39:34 +00:00
|
|
|
} ATVModInput;
|
|
|
|
|
2017-03-07 18:19:54 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ATVModulationAM,
|
|
|
|
ATVModulationFM
|
|
|
|
} ATVModulation;
|
|
|
|
|
2017-03-08 00:35:18 +00:00
|
|
|
class MsgConfigureImageFileName : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const QString& getFileName() const { return m_fileName; }
|
|
|
|
|
|
|
|
static MsgConfigureImageFileName* create(const QString& fileName)
|
|
|
|
{
|
|
|
|
return new MsgConfigureImageFileName(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_fileName;
|
|
|
|
|
|
|
|
MsgConfigureImageFileName(const QString& fileName) :
|
|
|
|
Message(),
|
|
|
|
m_fileName(fileName)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2017-03-06 02:39:34 +00:00
|
|
|
ATVMod();
|
|
|
|
~ATVMod();
|
|
|
|
|
|
|
|
void configure(MessageQueue* messageQueue,
|
|
|
|
Real rfBandwidth,
|
|
|
|
ATVStd atvStd,
|
|
|
|
ATVModInput atvModInput,
|
|
|
|
Real uniformLevel,
|
2017-03-07 18:19:54 +00:00
|
|
|
ATVModulation atvModulation,
|
2017-03-06 02:39:34 +00:00
|
|
|
bool channelMute);
|
|
|
|
|
|
|
|
virtual void pull(Sample& sample);
|
|
|
|
virtual void pullAudio(int nbSamples); // this is used for video signal actually
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& cmd);
|
|
|
|
|
|
|
|
Real getMagSq() const { return m_movingAverage.average(); }
|
|
|
|
|
2017-03-06 17:40:14 +00:00
|
|
|
static int getSampleRateUnits(ATVStd std);
|
2017-03-06 02:39:34 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* Level changed
|
|
|
|
* \param rmsLevel RMS level in range 0.0 - 1.0
|
|
|
|
* \param peakLevel Peak level in range 0.0 - 1.0
|
|
|
|
* \param numSamples Number of audio samples analyzed
|
|
|
|
*/
|
|
|
|
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class MsgConfigureATVMod : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
Real getRFBandwidth() const { return m_rfBandwidth; }
|
|
|
|
ATVStd getATVStd() const { return m_atvStd; }
|
|
|
|
ATVModInput getATVModInput() const { return m_atvModInput; }
|
|
|
|
Real getUniformLevel() const { return m_uniformLevel; }
|
2017-03-07 18:19:54 +00:00
|
|
|
ATVModulation getModulation() const { return m_atvModulation; }
|
2017-03-06 02:39:34 +00:00
|
|
|
|
|
|
|
static MsgConfigureATVMod* create(
|
|
|
|
Real rfBandwidth,
|
|
|
|
ATVStd atvStd,
|
|
|
|
ATVModInput atvModInput,
|
2017-03-07 18:19:54 +00:00
|
|
|
Real uniformLevel,
|
|
|
|
ATVModulation atvModulation)
|
2017-03-06 02:39:34 +00:00
|
|
|
{
|
2017-03-07 18:19:54 +00:00
|
|
|
return new MsgConfigureATVMod(rfBandwidth, atvStd, atvModInput, uniformLevel, atvModulation);
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-07 18:19:54 +00:00
|
|
|
Real m_rfBandwidth;
|
|
|
|
ATVStd m_atvStd;
|
|
|
|
ATVModInput m_atvModInput;
|
|
|
|
Real m_uniformLevel;
|
|
|
|
ATVModulation m_atvModulation;
|
2017-03-06 02:39:34 +00:00
|
|
|
|
|
|
|
MsgConfigureATVMod(
|
|
|
|
Real rfBandwidth,
|
|
|
|
ATVStd atvStd,
|
|
|
|
ATVModInput atvModInput,
|
2017-03-07 18:19:54 +00:00
|
|
|
Real uniformLevel,
|
|
|
|
ATVModulation atvModulation) :
|
2017-03-06 02:39:34 +00:00
|
|
|
Message(),
|
|
|
|
m_rfBandwidth(rfBandwidth),
|
|
|
|
m_atvStd(atvStd),
|
|
|
|
m_atvModInput(atvModInput),
|
2017-03-07 18:19:54 +00:00
|
|
|
m_uniformLevel(uniformLevel),
|
|
|
|
m_atvModulation(atvModulation)
|
2017-03-06 02:39:34 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config
|
|
|
|
{
|
2017-03-07 18:19:54 +00:00
|
|
|
int m_outputSampleRate; //!< sample rate from channelizer
|
|
|
|
qint64 m_inputFrequencyOffset; //!< offset from baseband center frequency
|
|
|
|
Real m_rfBandwidth; //!< Bandwidth of modulated signal
|
|
|
|
ATVStd m_atvStd; //!< Standard
|
|
|
|
ATVModInput m_atvModInput; //!< Input source type
|
|
|
|
Real m_uniformLevel; //!< Percentage between black and white for uniform screen display
|
|
|
|
ATVModulation m_atvModulation; //!< RF modulation type
|
2017-03-06 02:39:34 +00:00
|
|
|
|
|
|
|
Config() :
|
|
|
|
m_outputSampleRate(-1),
|
|
|
|
m_inputFrequencyOffset(0),
|
|
|
|
m_rfBandwidth(0),
|
|
|
|
m_atvStd(ATVStdPAL625),
|
2017-03-07 00:38:19 +00:00
|
|
|
m_atvModInput(ATVModInputHBars),
|
2017-03-07 18:19:54 +00:00
|
|
|
m_uniformLevel(0.5f),
|
|
|
|
m_atvModulation(ATVModulationAM)
|
2017-03-06 02:39:34 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
Config m_config;
|
|
|
|
Config m_running;
|
|
|
|
|
|
|
|
NCO m_carrierNco;
|
|
|
|
Complex m_modSample;
|
2017-03-07 18:19:54 +00:00
|
|
|
float m_modPhasor; //!< For FM modulation
|
2017-03-06 02:39:34 +00:00
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_interpolatorDistance;
|
|
|
|
Real m_interpolatorDistanceRemain;
|
|
|
|
int m_tvSampleRate; //!< sample rate for generating signal
|
|
|
|
uint32_t m_pointsPerSync; //!< number of line points for the horizontal sync
|
|
|
|
uint32_t m_pointsPerBP; //!< number of line points for the back porch
|
2017-03-06 17:40:14 +00:00
|
|
|
uint32_t m_pointsPerImgLine; //!< number of line points for the image line
|
2017-03-06 02:39:34 +00:00
|
|
|
uint32_t m_pointsPerFP; //!< number of line points for the front porch
|
|
|
|
uint32_t m_pointsPerFSync; //!< number of line points for the field first sync
|
2017-03-07 00:38:19 +00:00
|
|
|
uint32_t m_pointsPerHBar; //!< number of line points for a bar of the bar chart
|
|
|
|
uint32_t m_linesPerVBar; //!< number of lines for a bar of the bar chart
|
2017-03-06 02:39:34 +00:00
|
|
|
uint32_t m_pointsPerTU; //!< number of line points per time unit
|
|
|
|
uint32_t m_nbLines; //!< number of lines per complete frame
|
2017-03-07 00:38:19 +00:00
|
|
|
uint32_t m_nbLines2;
|
|
|
|
uint32_t m_nbImageLines;
|
|
|
|
uint32_t m_nbImageLines2;
|
2017-03-06 02:39:34 +00:00
|
|
|
uint32_t m_nbHorizPoints; //!< number of line points per horizontal line
|
2017-03-07 21:55:11 +00:00
|
|
|
uint32_t m_nbBlankLines;
|
2017-03-07 00:38:19 +00:00
|
|
|
float m_hBarIncrement;
|
|
|
|
float m_vBarIncrement;
|
2017-03-06 02:39:34 +00:00
|
|
|
bool m_interlaced; //!< true if image is interlaced (2 half frames per frame)
|
|
|
|
bool m_evenImage;
|
|
|
|
QMutex m_settingsMutex;
|
|
|
|
int m_horizontalCount; //!< current point index on line
|
|
|
|
int m_lineCount; //!< current line index in frame
|
|
|
|
|
|
|
|
MovingAverage<Real> m_movingAverage;
|
|
|
|
quint32 m_levelCalcCount;
|
|
|
|
Real m_peakLevel;
|
|
|
|
Real m_levelSum;
|
|
|
|
|
2017-03-08 07:36:28 +00:00
|
|
|
cv::Mat m_image;
|
|
|
|
|
2017-03-06 02:39:34 +00:00
|
|
|
static const float m_blackLevel;
|
|
|
|
static const float m_spanLevel;
|
|
|
|
static const int m_levelNbSamples;
|
|
|
|
|
|
|
|
void apply(bool force = false);
|
|
|
|
void pullFinalize(Complex& ci, Sample& sample);
|
|
|
|
void pullVideo(Real& sample);
|
|
|
|
void calculateLevel(Real& sample);
|
|
|
|
void modulateSample();
|
|
|
|
void applyStandard();
|
|
|
|
|
|
|
|
inline void pullImageLine(Real& sample)
|
|
|
|
{
|
|
|
|
if (m_horizontalCount < m_pointsPerSync) // sync pulse
|
|
|
|
{
|
|
|
|
sample = 0.0f; // ultra-black
|
|
|
|
}
|
|
|
|
else if (m_horizontalCount < m_pointsPerSync + m_pointsPerBP) // back porch
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = m_blackLevel; // black
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
2017-03-06 17:40:14 +00:00
|
|
|
else if (m_horizontalCount < m_pointsPerSync + m_pointsPerBP + m_pointsPerImgLine)
|
2017-03-06 02:39:34 +00:00
|
|
|
{
|
|
|
|
int pointIndex = m_horizontalCount - (m_pointsPerSync + m_pointsPerBP);
|
2017-03-07 00:38:19 +00:00
|
|
|
int iLine = m_lineCount % m_nbLines2;
|
2017-03-06 02:39:34 +00:00
|
|
|
|
|
|
|
switch(m_running.m_atvModInput)
|
|
|
|
{
|
2017-03-07 00:38:19 +00:00
|
|
|
case ATVModInputHBars:
|
|
|
|
sample = (pointIndex / m_pointsPerHBar) * m_hBarIncrement + m_blackLevel;
|
2017-03-06 02:39:34 +00:00
|
|
|
break;
|
2017-03-07 00:38:19 +00:00
|
|
|
case ATVModInputVBars:
|
|
|
|
sample = (iLine / m_linesPerVBar) * m_vBarIncrement + m_blackLevel;
|
|
|
|
break;
|
2017-03-07 21:55:11 +00:00
|
|
|
case ATVModInputCheckbox:
|
|
|
|
|
|
|
|
sample = (((iLine / m_linesPerVBar)*5 + (pointIndex / m_pointsPerHBar)) % 2) * m_spanLevel * m_running.m_uniformLevel + m_blackLevel;
|
|
|
|
break;
|
2017-03-07 00:38:19 +00:00
|
|
|
case ATVModInputHGradient:
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = (pointIndex / (float) m_pointsPerImgLine) * m_spanLevel + m_blackLevel;
|
2017-03-06 02:39:34 +00:00
|
|
|
break;
|
2017-03-07 00:38:19 +00:00
|
|
|
case ATVModInputVGradient:
|
|
|
|
sample = ((iLine -5) / (float) m_nbImageLines2) * m_spanLevel + m_blackLevel;
|
|
|
|
break;
|
2017-03-06 02:39:34 +00:00
|
|
|
case ATVModInputUniform:
|
|
|
|
default:
|
|
|
|
sample = m_spanLevel * m_running.m_uniformLevel + m_blackLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // front porch
|
|
|
|
{
|
|
|
|
sample = m_blackLevel; // black
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 17:40:14 +00:00
|
|
|
inline void pullVSyncLine(Real& sample)
|
2017-03-06 02:39:34 +00:00
|
|
|
{
|
|
|
|
switch (m_lineCount)
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
case 0:
|
2017-03-06 02:39:34 +00:00
|
|
|
case 1:
|
|
|
|
case 313:
|
2017-03-06 17:40:14 +00:00
|
|
|
case 314: // Whole line "long" pulses
|
2017-03-06 02:39:34 +00:00
|
|
|
{
|
|
|
|
int halfIndex = m_horizontalCount % (m_nbHorizPoints/2);
|
|
|
|
|
|
|
|
if (halfIndex < (m_nbHorizPoints/2) - m_pointsPerSync) // ultra-black
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
else // black
|
|
|
|
{
|
|
|
|
sample = m_blackLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-03-06 17:40:14 +00:00
|
|
|
case 3:
|
2017-03-06 02:39:34 +00:00
|
|
|
case 4:
|
|
|
|
case 310:
|
|
|
|
case 311:
|
|
|
|
case 315:
|
|
|
|
case 316:
|
|
|
|
case 622:
|
|
|
|
case 623:
|
2017-03-06 17:40:14 +00:00
|
|
|
case 624: // Whole line equalizing pulses
|
2017-03-06 02:39:34 +00:00
|
|
|
{
|
|
|
|
int halfIndex = m_horizontalCount % (m_nbHorizPoints/2);
|
|
|
|
|
|
|
|
if (halfIndex < m_pointsPerFSync) // ultra-black
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
else // black
|
|
|
|
{
|
|
|
|
sample = m_blackLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-03-06 17:40:14 +00:00
|
|
|
case 2: // long pulse then equalizing pulse
|
|
|
|
if (m_horizontalCount < (m_nbHorizPoints/2) - m_pointsPerSync)
|
|
|
|
{
|
|
|
|
sample = 0.0f; // ultra-black
|
|
|
|
}
|
|
|
|
else if (m_horizontalCount < (m_nbHorizPoints/2))
|
|
|
|
{
|
|
|
|
sample = m_blackLevel; // black
|
|
|
|
}
|
|
|
|
else if (m_horizontalCount < (m_nbHorizPoints/2) + m_pointsPerFSync)
|
|
|
|
{
|
|
|
|
sample = 0.0f; // ultra-black
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = m_blackLevel; // black
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 312: // equalizing pulse then long pulse
|
2017-03-06 02:39:34 +00:00
|
|
|
if (m_horizontalCount < m_pointsPerFSync)
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = 0.0f; // ultra-black
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
|
|
|
else if (m_horizontalCount < (m_nbHorizPoints/2))
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = m_blackLevel; // black
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
|
|
|
else if (m_horizontalCount < m_nbHorizPoints - m_pointsPerSync)
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = 0.0f; // ultra-black
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-06 17:40:14 +00:00
|
|
|
sample = m_blackLevel; // black
|
2017-03-06 02:39:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: // black images
|
|
|
|
if (m_horizontalCount < m_pointsPerSync)
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = m_blackLevel;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* PLUGINS_CHANNELTX_MODATV_ATVMOD_H_ */
|