2017-01-02 21:07:43 -05:00
|
|
|
// Copyright (c) Charles J. Cliffe
|
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2015-07-31 21:47:44 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "VisualProcessor.h"
|
2015-08-03 01:38:38 -04:00
|
|
|
#include "DemodDefs.h"
|
2015-08-11 19:03:46 -04:00
|
|
|
#include <cmath>
|
2015-07-31 21:47:44 -04:00
|
|
|
|
2015-12-08 22:17:00 -05:00
|
|
|
#define SPECTRUM_VZM 2
|
2016-01-02 01:38:17 -05:00
|
|
|
#define PEAK_RESET_COUNT 30
|
2015-12-08 22:17:00 -05:00
|
|
|
|
2015-07-31 21:47:44 -04:00
|
|
|
class SpectrumVisualData : public ReferenceCounter {
|
2015-08-03 01:38:38 -04:00
|
|
|
public:
|
|
|
|
std::vector<float> spectrum_points;
|
2015-12-31 20:44:39 -05:00
|
|
|
std::vector<float> spectrum_hold_points;
|
2015-08-03 01:38:38 -04:00
|
|
|
double fft_ceiling, fft_floor;
|
2015-12-11 22:58:58 -05:00
|
|
|
long long centerFreq;
|
|
|
|
int bandwidth;
|
2015-07-31 21:47:44 -04:00
|
|
|
};
|
|
|
|
|
2017-02-09 13:12:12 -05:00
|
|
|
typedef ThreadBlockingQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
|
2015-08-03 01:38:38 -04:00
|
|
|
|
2015-07-31 21:47:44 -04:00
|
|
|
class SpectrumVisualProcessor : public VisualProcessor<DemodulatorThreadIQData, SpectrumVisualData> {
|
2015-08-03 01:38:38 -04:00
|
|
|
public:
|
|
|
|
SpectrumVisualProcessor();
|
|
|
|
~SpectrumVisualProcessor();
|
|
|
|
|
|
|
|
bool isView();
|
|
|
|
void setView(bool bView);
|
2015-12-12 17:28:17 -05:00
|
|
|
void setView(bool bView, long long centerFreq_in, long bandwidth_in);
|
2015-08-03 01:38:38 -04:00
|
|
|
|
2015-08-12 22:14:14 -04:00
|
|
|
void setFFTAverageRate(float fftAverageRate);
|
2015-08-13 22:00:05 -04:00
|
|
|
float getFFTAverageRate();
|
2015-08-12 22:14:14 -04:00
|
|
|
|
2015-08-03 01:38:38 -04:00
|
|
|
void setCenterFrequency(long long centerFreq_in);
|
|
|
|
long long getCenterFrequency();
|
|
|
|
|
|
|
|
void setBandwidth(long bandwidth_in);
|
|
|
|
long getBandwidth();
|
|
|
|
|
2015-12-31 20:44:39 -05:00
|
|
|
void setPeakHold(bool peakHold_in);
|
|
|
|
bool getPeakHold();
|
|
|
|
|
2015-08-11 00:50:43 -04:00
|
|
|
int getDesiredInputSize();
|
|
|
|
|
2016-01-28 15:49:31 -05:00
|
|
|
void setup(unsigned int fftSize);
|
|
|
|
void setFFTSize(unsigned int fftSize);
|
2016-03-31 21:32:50 -04:00
|
|
|
unsigned int getFFTSize();
|
2015-10-21 19:50:53 -04:00
|
|
|
void setHideDC(bool hideDC);
|
2015-08-03 01:38:38 -04:00
|
|
|
|
2015-10-25 00:07:01 -04:00
|
|
|
void setScaleFactor(float sf);
|
|
|
|
float getScaleFactor();
|
|
|
|
|
2015-07-31 21:47:44 -04:00
|
|
|
protected:
|
2017-02-04 04:32:35 -05:00
|
|
|
virtual void process();
|
2015-08-03 01:38:38 -04:00
|
|
|
|
|
|
|
ReBuffer<SpectrumVisualData> outputBuffers;
|
|
|
|
std::atomic_bool is_view;
|
2016-01-28 15:49:31 -05:00
|
|
|
std::atomic_uint fftSize, newFFTSize;
|
|
|
|
std::atomic_uint fftSizeInternal;
|
2015-08-03 01:38:38 -04:00
|
|
|
std::atomic_llong centerFreq;
|
|
|
|
std::atomic_long bandwidth;
|
|
|
|
|
|
|
|
private:
|
|
|
|
long lastInputBandwidth;
|
|
|
|
long lastBandwidth;
|
2015-12-13 16:07:28 -05:00
|
|
|
bool lastView;
|
2016-03-20 18:56:13 -04:00
|
|
|
|
|
|
|
liquid_float_complex *fftInput, *fftOutput, *fftInData, *fftLastData;
|
|
|
|
fftplan fftPlan;
|
|
|
|
|
|
|
|
unsigned int lastDataSize;
|
2015-08-03 01:38:38 -04:00
|
|
|
|
2015-08-12 22:28:39 -04:00
|
|
|
double fft_ceil_ma, fft_ceil_maa;
|
|
|
|
double fft_floor_ma, fft_floor_maa;
|
2015-12-31 20:44:39 -05:00
|
|
|
double fft_ceil_peak, fft_floor_peak;
|
2015-08-23 17:51:20 -04:00
|
|
|
std::atomic<float> fft_average_rate;
|
2015-08-03 01:38:38 -04:00
|
|
|
|
2015-08-12 22:28:39 -04:00
|
|
|
std::vector<double> fft_result;
|
|
|
|
std::vector<double> fft_result_ma;
|
|
|
|
std::vector<double> fft_result_maa;
|
2015-12-31 20:44:39 -05:00
|
|
|
std::vector<double> fft_result_peak;
|
2015-12-12 17:28:17 -05:00
|
|
|
std::vector<double> fft_result_temp;
|
2015-08-03 01:38:38 -04:00
|
|
|
|
|
|
|
msresamp_crcf resampler;
|
|
|
|
double resamplerRatio;
|
|
|
|
nco_crcf freqShifter;
|
|
|
|
long shiftFrequency;
|
|
|
|
|
|
|
|
std::vector<liquid_float_complex> shiftBuffer;
|
|
|
|
std::vector<liquid_float_complex> resampleBuffer;
|
2015-08-23 17:51:20 -04:00
|
|
|
std::atomic_int desiredInputSize;
|
2016-06-02 17:56:31 -04:00
|
|
|
|
2015-08-23 17:51:20 -04:00
|
|
|
std::mutex busy_run;
|
2015-12-31 20:44:39 -05:00
|
|
|
std::atomic_bool hideDC, peakHold;
|
2016-01-02 01:38:17 -05:00
|
|
|
std::atomic_int peakReset;
|
2015-10-25 00:07:01 -04:00
|
|
|
std::atomic<float> scaleFactor;
|
2015-12-29 20:52:49 -05:00
|
|
|
std::atomic_bool fftSizeChanged;
|
2015-08-11 00:50:43 -04:00
|
|
|
};
|