2019-11-15 00:04:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2019 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 //
|
|
|
|
// (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_AMMODSOURCE_H
|
|
|
|
#define INCLUDE_AMMODSOURCE_H
|
|
|
|
|
2020-11-22 11:34:12 +00:00
|
|
|
#include <QObject>
|
2019-11-15 00:04:24 +00:00
|
|
|
#include <QMutex>
|
2020-12-20 18:01:54 +00:00
|
|
|
#include <QVector>
|
2019-11-15 00:04:24 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "dsp/channelsamplesource.h"
|
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/ncof.h"
|
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "util/movingaverage.h"
|
|
|
|
#include "dsp/cwkeyer.h"
|
|
|
|
#include "audio/audiofifo.h"
|
|
|
|
|
|
|
|
#include "ammodsettings.h"
|
|
|
|
|
2020-12-20 00:53:03 +00:00
|
|
|
class ChannelAPI;
|
|
|
|
|
2020-11-22 11:34:12 +00:00
|
|
|
class AMModSource : public QObject, public ChannelSampleSource
|
2019-11-15 00:04:24 +00:00
|
|
|
{
|
2020-11-22 11:34:12 +00:00
|
|
|
Q_OBJECT
|
2019-11-15 00:04:24 +00:00
|
|
|
public:
|
|
|
|
AMModSource();
|
|
|
|
virtual ~AMModSource();
|
|
|
|
|
|
|
|
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; }
|
2020-12-20 00:53:03 +00:00
|
|
|
void setChannel(ChannelAPI *channel) { m_channel = channel; }
|
2020-08-02 08:11:41 +00:00
|
|
|
void applyAudioSampleRate(int sampleRate);
|
|
|
|
void applyFeedbackAudioSampleRate(int sampleRate);
|
|
|
|
int getAudioSampleRate() const { return m_audioSampleRate; }
|
|
|
|
int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; }
|
2019-11-15 00:04:24 +00:00
|
|
|
CWKeyer& getCWKeyer() { return m_cwKeyer; }
|
|
|
|
double getMagSq() const { return m_magsq; }
|
2019-12-07 10:47:52 +00:00
|
|
|
void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const
|
2019-11-15 00:04:24 +00:00
|
|
|
{
|
|
|
|
rmsLevel = m_rmsLevel;
|
2019-12-07 10:47:52 +00:00
|
|
|
peakLevel = m_peakLevelOut;
|
2019-11-15 00:04:24 +00:00
|
|
|
numSamples = m_levelNbSamples;
|
|
|
|
}
|
|
|
|
void applySettings(const AMModSettings& settings, bool force = false);
|
|
|
|
void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_channelSampleRate;
|
|
|
|
int m_channelFrequencyOffset;
|
|
|
|
AMModSettings m_settings;
|
2020-12-20 00:53:03 +00:00
|
|
|
ChannelAPI *m_channel;
|
2019-11-15 00:04:24 +00:00
|
|
|
|
|
|
|
NCO m_carrierNco;
|
|
|
|
NCOF m_toneNco;
|
|
|
|
Complex m_modSample;
|
|
|
|
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_interpolatorDistance;
|
|
|
|
Real m_interpolatorDistanceRemain;
|
|
|
|
bool m_interpolatorConsumed;
|
|
|
|
|
|
|
|
Interpolator m_feedbackInterpolator;
|
|
|
|
Real m_feedbackInterpolatorDistance;
|
|
|
|
Real m_feedbackInterpolatorDistanceRemain;
|
|
|
|
|
|
|
|
double m_magsq;
|
|
|
|
MovingAverageUtil<double, double, 16> m_movingAverage;
|
|
|
|
|
2020-08-02 08:11:41 +00:00
|
|
|
int m_audioSampleRate;
|
2019-11-15 00:04:24 +00:00
|
|
|
AudioVector m_audioBuffer;
|
2020-11-22 11:34:12 +00:00
|
|
|
unsigned int m_audioBufferFill;
|
|
|
|
AudioVector m_audioReadBuffer;
|
|
|
|
unsigned int m_audioReadBufferFill;
|
2019-11-15 00:04:24 +00:00
|
|
|
AudioFifo m_audioFifo;
|
|
|
|
|
2020-08-02 08:11:41 +00:00
|
|
|
int m_feedbackAudioSampleRate;
|
2019-11-15 00:04:24 +00:00
|
|
|
AudioVector m_feedbackAudioBuffer;
|
|
|
|
uint m_feedbackAudioBufferFill;
|
|
|
|
AudioFifo m_feedbackAudioFifo;
|
2020-12-20 00:53:03 +00:00
|
|
|
QVector<qint16> m_demodBuffer;
|
|
|
|
int m_demodBufferFill;
|
|
|
|
bool m_demodBufferEnabled;
|
2019-11-15 00:04:24 +00:00
|
|
|
|
|
|
|
quint32 m_levelCalcCount;
|
2019-12-07 10:47:52 +00:00
|
|
|
qreal m_rmsLevel;
|
|
|
|
qreal m_peakLevelOut;
|
2019-11-15 00:04:24 +00:00
|
|
|
Real m_peakLevel;
|
|
|
|
Real m_levelSum;
|
|
|
|
|
|
|
|
std::ifstream *m_ifstream;
|
|
|
|
CWKeyer m_cwKeyer;
|
|
|
|
|
2020-11-22 11:34:12 +00:00
|
|
|
QMutex m_mutex;
|
|
|
|
|
2019-11-15 00:04:24 +00:00
|
|
|
static const int m_levelNbSamples;
|
|
|
|
|
|
|
|
void processOneSample(Complex& ci);
|
|
|
|
void pullAF(Real& sample);
|
|
|
|
void pullAudio(unsigned int nbSamples);
|
|
|
|
void pushFeedback(Real sample);
|
|
|
|
void calculateLevel(Real& sample);
|
|
|
|
void modulateSample();
|
2020-11-22 11:34:12 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleAudio();
|
2019-11-15 00:04:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // INCLUDE_AMMODSOURCE_H
|