diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /widgets/JttySpectrum.hpp | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'widgets/JttySpectrum.hpp')
| -rw-r--r-- | widgets/JttySpectrum.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
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 <QtGlobal> +#include <array> +#include <functional> + +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<float, BinCount> bins {}; + std::array<float, BinCount> cumulative {}; + std::array<float, BinCount> 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<void (JttySpectrumFrame const&)> 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<qint16, FftSize> pcm_ {}; + std::array<float, FftSize> window_ {}; + std::array<float, FftSize + 2> fft_ {}; + std::array<double, JttySpectrumFrame::BinCount> average_ {}; + JttySpectrumFrame frame_; +}; + +#endif |
