2022-06-09 19:42:24 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 00:36:53 -05:00
|
|
|
// Copyright (C) 2019-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai> //
|
2022-06-09 19:42:24 -04:00
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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_M17MODSOURCE_H
|
|
|
|
#define INCLUDE_M17MODSOURCE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2022-09-15 15:59:42 -04:00
|
|
|
#include <QRecursiveMutex>
|
2022-06-09 19:42:24 -04:00
|
|
|
#include <QVector>
|
2022-06-29 02:45:44 -04:00
|
|
|
#include <QThread>
|
2022-06-09 19:42:24 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "dsp/channelsamplesource.h"
|
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/ncof.h"
|
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "dsp/firfilter.h"
|
|
|
|
#include "dsp/filterrc.h"
|
|
|
|
#include "util/movingaverage.h"
|
|
|
|
#include "audio/audiofifo.h"
|
|
|
|
|
|
|
|
#include "m17modsettings.h"
|
|
|
|
|
|
|
|
class ChannelAPI;
|
2022-06-12 16:51:18 -04:00
|
|
|
class M17ModProcessor;
|
2022-06-29 16:55:17 -04:00
|
|
|
class BasebandSampleSink;
|
2022-06-09 19:42:24 -04:00
|
|
|
|
|
|
|
class M17ModSource : public QObject, public ChannelSampleSource
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
M17ModSource();
|
|
|
|
virtual ~M17ModSource();
|
|
|
|
|
|
|
|
virtual void pull(SampleVector::iterator begin, unsigned int nbSamples);
|
|
|
|
virtual void pullOne(Sample& sample);
|
|
|
|
virtual void prefetch(unsigned int nbSamples);
|
|
|
|
|
|
|
|
void setInputFileStream(std::ifstream *ifstream) { m_ifstream = ifstream; }
|
|
|
|
AudioFifo *getAudioFifo() { return &m_audioFifo; }
|
|
|
|
AudioFifo *getFeedbackAudioFifo() { return &m_feedbackAudioFifo; }
|
|
|
|
void applyAudioSampleRate(int sampleRate);
|
|
|
|
void applyFeedbackAudioSampleRate(int sampleRate);
|
|
|
|
int getAudioSampleRate() const { return m_audioSampleRate; }
|
|
|
|
int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; }
|
|
|
|
void setChannel(ChannelAPI *channel) { m_channel = channel; }
|
|
|
|
double getMagSq() const { return m_magsq; }
|
|
|
|
void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const
|
|
|
|
{
|
|
|
|
rmsLevel = m_rmsLevel;
|
|
|
|
peakLevel = m_peakLevelOut;
|
|
|
|
numSamples = m_levelNbSamples;
|
|
|
|
}
|
2022-07-10 03:42:50 -04:00
|
|
|
void applySettings(const M17ModSettings& settings, const QList<QString>& settingsKeys, bool force = false);
|
2022-06-09 19:42:24 -04:00
|
|
|
void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false);
|
|
|
|
|
2022-06-12 16:51:18 -04:00
|
|
|
void sendPacket();
|
|
|
|
|
2022-06-09 19:42:24 -04:00
|
|
|
private:
|
|
|
|
int m_channelSampleRate;
|
|
|
|
int m_channelFrequencyOffset;
|
|
|
|
M17ModSettings m_settings;
|
|
|
|
ChannelAPI *m_channel;
|
|
|
|
|
|
|
|
NCO m_carrierNco;
|
|
|
|
NCOF m_toneNco;
|
|
|
|
float m_modPhasor; //!< baseband modulator phasor
|
|
|
|
Complex m_modSample;
|
|
|
|
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_interpolatorDistance;
|
|
|
|
Real m_interpolatorDistanceRemain;
|
|
|
|
bool m_interpolatorConsumed;
|
|
|
|
|
|
|
|
Interpolator m_feedbackInterpolator;
|
|
|
|
Real m_feedbackInterpolatorDistance;
|
|
|
|
Real m_feedbackInterpolatorDistanceRemain;
|
|
|
|
bool m_feedbackInterpolatorConsumed;
|
|
|
|
|
2022-06-30 23:56:12 -04:00
|
|
|
QVector<qint16> m_modBuffer;
|
|
|
|
int m_modBufferFill;
|
2022-06-09 19:42:24 -04:00
|
|
|
|
|
|
|
Lowpass<Real> m_lowpass;
|
|
|
|
|
|
|
|
double m_magsq;
|
|
|
|
MovingAverageUtil<double, double, 16> m_movingAverage;
|
|
|
|
|
|
|
|
int m_audioSampleRate;
|
|
|
|
AudioVector m_audioBuffer;
|
|
|
|
unsigned int m_audioBufferFill;
|
|
|
|
AudioVector m_audioReadBuffer;
|
|
|
|
unsigned int m_audioReadBufferFill;
|
2022-06-29 14:23:07 -04:00
|
|
|
unsigned int m_audioReadBufferIndex;
|
2022-06-09 19:42:24 -04:00
|
|
|
AudioFifo m_audioFifo;
|
2022-06-29 02:45:44 -04:00
|
|
|
bool m_m17PullAudio;
|
|
|
|
int m_m17PullCount;
|
2022-07-04 16:45:16 -04:00
|
|
|
bool m_m17PullBERT;
|
2022-06-09 19:42:24 -04:00
|
|
|
|
|
|
|
int m_feedbackAudioSampleRate;
|
|
|
|
AudioVector m_feedbackAudioBuffer;
|
|
|
|
uint m_feedbackAudioBufferFill;
|
|
|
|
AudioFifo m_feedbackAudioFifo;
|
|
|
|
|
|
|
|
quint32 m_levelCalcCount;
|
|
|
|
qreal m_rmsLevel;
|
|
|
|
qreal m_peakLevelOut;
|
|
|
|
Real m_peakLevel;
|
|
|
|
Real m_levelSum;
|
|
|
|
|
|
|
|
std::ifstream *m_ifstream;
|
2022-06-12 16:51:18 -04:00
|
|
|
M17ModProcessor *m_processor;
|
2022-06-29 02:45:44 -04:00
|
|
|
QThread m_processorThread;
|
2022-06-16 20:25:34 -04:00
|
|
|
HighPassFilterRC m_preemphasisFilter;
|
2022-06-09 19:42:24 -04:00
|
|
|
|
2022-09-15 15:59:42 -04:00
|
|
|
QRecursiveMutex m_mutex;
|
2022-06-09 19:42:24 -04:00
|
|
|
|
|
|
|
static const int m_levelNbSamples;
|
|
|
|
static const float m_preemphasis;
|
|
|
|
|
2022-06-29 14:23:07 -04:00
|
|
|
void processOneFeedbackSample(Complex& ci);
|
2022-06-12 16:51:18 -04:00
|
|
|
void pullAF(Real& sample, bool& carrier);
|
|
|
|
void pullM17(Real& sample, bool& carrier);
|
2022-06-09 19:42:24 -04:00
|
|
|
void pullAudio(unsigned int nbSamples);
|
|
|
|
void pushFeedback(Real sample);
|
2022-06-29 14:23:07 -04:00
|
|
|
void pushFeedback(std::array<int16_t, 1920>& audioFrame);
|
2022-06-09 19:42:24 -04:00
|
|
|
void calculateLevel(Real& sample);
|
|
|
|
void modulateSample();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleAudio();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // INCLUDE_M17MODSOURCE_H
|