1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 18:43:28 -05:00
sdrangel/plugins/channeltx/modssb/ssbmodsource.h

157 lines
5.3 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai> //
// //
// 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_SSBMODSOURCE_H
#define INCLUDE_SSBMODSOURCE_H
#include <QObject>
#include <QRecursiveMutex>
#include <QVector>
#include <iostream>
#include <fstream>
#include "dsp/channelsamplesource.h"
#include "dsp/ncof.h"
#include "dsp/interpolator.h"
#include "dsp/fftfilt.h"
#include "dsp/cwkeyer.h"
#include "util/movingaverage.h"
#include "audio/audiocompressorsnd.h"
#include "audio/audiofifo.h"
#include "ssbmodsettings.h"
class ChannelAPI;
class SpectrumVis;
2024-08-18 07:36:30 -04:00
class CWKeyer;
class SSBModSource : public QObject, public ChannelSampleSource
{
Q_OBJECT
public:
SSBModSource();
2024-08-24 07:17:02 -04:00
~SSBModSource() final;
2024-08-24 07:17:02 -04:00
void pull(SampleVector::iterator begin, unsigned int nbSamples) final;
void pullOne(Sample& sample) final;
void prefetch(unsigned int nbSamples) final;
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; }
2024-08-18 07:36:30 -04:00
CWKeyer* getCWKeyer() { return m_cwKeyer; }
void setCWKeyer(CWKeyer *cwKeyer) { m_cwKeyer = cwKeyer; }
double getMagSq() const { return m_magsq; }
2019-12-07 05:47:52 -05:00
void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const
{
rmsLevel = m_rmsLevel;
2019-12-07 05:47:52 -05:00
peakLevel = m_peakLevelOut;
numSamples = m_levelNbSamples;
}
void applySettings(const SSBModSettings& settings, bool force = false);
2024-08-24 07:17:02 -04:00
void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false);
void setSpectrumSink(SpectrumVis *sampleSink) { m_spectrumSink = sampleSink; }
private:
2024-08-24 07:17:02 -04:00
int m_channelSampleRate = 48000;
int m_channelFrequencyOffset = 0;
SSBModSettings m_settings;
ChannelAPI *m_channel;
NCOF 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;
bool m_feedbackInterpolatorConsumed;
QVector<qint16> m_demodBuffer;
int m_demodBufferFill;
fftfilt* m_SSBFilter;
fftfilt* m_DSBFilter;
Complex* m_SSBFilterBuffer;
Complex* m_DSBFilterBuffer;
int m_SSBFilterBufferIndex;
int m_DSBFilterBufferIndex;
static const int m_ssbFftLen;
2024-08-24 07:17:02 -04:00
SpectrumVis* m_spectrumSink = nullptr;
SampleVector m_sampleBuffer;
fftfilt::cmplx m_sum;
int m_undersampleCount;
int m_sumCount;
double m_magsq;
MovingAverageUtil<double, double, 16> m_movingAverage;
2024-08-24 07:17:02 -04:00
int m_audioSampleRate = 48000;
AudioVector m_audioBuffer;
unsigned int m_audioBufferFill;
AudioVector m_audioReadBuffer;
unsigned int m_audioReadBufferFill;
AudioFifo m_audioFifo;
int m_feedbackAudioSampleRate;
AudioVector m_feedbackAudioBuffer;
uint m_feedbackAudioBufferFill;
AudioFifo m_feedbackAudioFifo;
2024-08-24 07:17:02 -04:00
quint32 m_levelCalcCount = 0;
2019-12-07 05:47:52 -05:00
qreal m_rmsLevel;
qreal m_peakLevelOut;
2024-08-24 07:17:02 -04:00
Real m_peakLevel = 0.0f;
Real m_levelSum = 0.0f;
2024-08-24 07:17:02 -04:00
std::ifstream *m_ifstream = nullptr;
CWKeyer *m_cwKeyer = nullptr;
AudioCompressorSnd m_audioCompressor;
int m_agcStepLength;
QRecursiveMutex m_mutex;
static const int m_levelNbSamples;
2024-08-24 07:17:02 -04:00
void processOneSample(const Complex& ci);
void pullAF(Complex& sample);
void pullAudio(unsigned int nbSamples);
void pushFeedback(Complex sample);
2024-08-24 07:17:02 -04:00
void calculateLevel(const Complex& sample);
void modulateSample();
private slots:
void handleAudio();
};
#endif // INCLUDE_SSBMODSOURCE_H