From ffc62c792c9a5196cb4ce7a353287dfe20db6524 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Fri, 9 Oct 2026 14:12:35 +0200 Subject: New upstream version 3.3.0~beta1+dfsg --- widgets/JttySpectrum.hpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 widgets/JttySpectrum.hpp (limited to 'widgets/JttySpectrum.hpp') diff --git a/widgets/JttySpectrum.hpp b/widgets/JttySpectrum.hpp new file mode 100644 index 00000000..d5e67f08 --- /dev/null +++ b/widgets/JttySpectrum.hpp @@ -0,0 +1,66 @@ +#ifndef JTTY_SPECTRUM_HPP +#define JTTY_SPECTRUM_HPP + +#include +#include +#include + +struct JttyWaterfallRow +{ + quint64 reception = 0; + qint64 beginSample = 0; + qint64 endSample = 0; + qint64 utcEndMs = 0; + bool gap = false; + + bool hasAudio () const { return reception != 0 && !gap && endSample > beginSample; } +}; + +struct JttySpectrumFrame +{ + static constexpr int BinCount = 6827; + static constexpr float BinWidth = 12000.0f / 16384; + JttyWaterfallRow row; + std::array bins {}; + std::array cumulative {}; + std::array linearAverage {}; + float powerDb = 0; + float maxPowerDb = 0; +}; + +// Consumes new PCM once; FFT scratch is used only on the serialized DSP thread. +class JttySpectrum +{ +public: + static constexpr int FftSize = 16384; + static constexpr int Hop = 3456; + + JttySpectrum (); + JttySpectrum (JttySpectrum const&) = delete; + JttySpectrum& operator= (JttySpectrum const&) = delete; + + void begin (quint64 reception, qint64 firstSample, qint64 utcFirstSampleMs); + bool process (qint64 firstSample, qint16 const * pcm, int count, + int inputGain, bool lowSidelobes, int smoothing, + std::function const& emitFrame); + +private: + void transform (int inputGain, bool lowSidelobes, int smoothing); + + quint64 reception_ = 0; + qint64 origin_ = 0; + qint64 nextSample_ = 0; + qint64 utcOriginMs_ = 0; + quint64 frameCount_ = 0; + int pending_ = 0; + int write_ = 0; + double power_ = 0; + float peak_ = 0; + std::array pcm_ {}; + std::array window_ {}; + std::array fft_ {}; + std::array average_ {}; + JttySpectrumFrame frame_; +}; + +#endif -- cgit v1.2.3