Merge pull request #124 from cjcliffe/ui_visuals_to_panels

Ui visuals to panels
This commit is contained in:
Charles J. Cliffe 2015-08-04 17:09:07 -04:00
commit 5f96f4c839
30 changed files with 675 additions and 994 deletions

View File

@ -262,7 +262,6 @@ SET (cubicsdr_sources
src/process/VisualProcessor.cpp
src/process/ScopeVisualProcessor.cpp
src/process/SpectrumVisualProcessor.cpp
src/process/WaterfallVisualProcessor.cpp
src/ui/GLPanel.cpp
external/rtaudio/RtAudio.cpp
external/lodepng/lodepng.cpp
@ -315,7 +314,6 @@ SET (cubicsdr_headers
src/process/VisualProcessor.h
src/process/ScopeVisualProcessor.h
src/process/SpectrumVisualProcessor.h
src/process/WaterfallVisualProcessor.h
src/ui/GLPanel.h
src/ui/UITestCanvas.cpp
src/ui/UITestCanvas.h

View File

@ -91,10 +91,11 @@ AppFrame::AppFrame() :
// demodTray->AddSpacer(2);
wxGetApp().getDemodSpectrumProcesor()->setup(1024);
demodSpectrumCanvas = new SpectrumCanvas(this, attribList);
demodSpectrumCanvas->setup(1024);
demodSpectrumCanvas->setView(wxGetApp().getConfig()->getCenterFreq(), 300000);
demodVisuals->Add(demodSpectrumCanvas, 3, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcesor()->attachOutput(demodSpectrumCanvas->getVisualDataQueue());
demodVisuals->AddSpacer(1);
@ -104,6 +105,7 @@ AppFrame::AppFrame() :
demodWaterfallCanvas->attachSpectrumCanvas(demodSpectrumCanvas);
demodSpectrumCanvas->attachWaterfallCanvas(demodWaterfallCanvas);
demodVisuals->Add(demodWaterfallCanvas, 6, wxEXPAND | wxALL, 0);
wxGetApp().getDemodSpectrumProcesor()->attachOutput(demodWaterfallCanvas->getVisualDataQueue());
demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0);
@ -118,6 +120,7 @@ AppFrame::AppFrame() :
scopeCanvas = new ScopeCanvas(this, attribList);
demodScopeTray->Add(scopeCanvas, 8, wxEXPAND | wxALL, 0);
wxGetApp().getScopeProcessor()->attachOutput(scopeCanvas->getInputQueue());
demodScopeTray->AddSpacer(1);
@ -136,17 +139,19 @@ AppFrame::AppFrame() :
vbox->Add(demodTray, 12, wxEXPAND | wxALL, 0);
vbox->AddSpacer(1);
wxGetApp().getSpectrumProcesor()->setup(2048);
spectrumCanvas = new SpectrumCanvas(this, attribList);
spectrumCanvas->setup(2048);
vbox->Add(spectrumCanvas, 5, wxEXPAND | wxALL, 0);
vbox->AddSpacer(1);
wxGetApp().getSpectrumProcesor()->attachOutput(spectrumCanvas->getVisualDataQueue());
waterfallCanvas = new WaterfallCanvas(this, attribList);
waterfallCanvas->setup(2048, 512);
waterfallCanvas->attachSpectrumCanvas(spectrumCanvas);
waterfallCanvas->attachWaterfallCanvas(demodWaterfallCanvas);
spectrumCanvas->attachWaterfallCanvas(waterfallCanvas);
vbox->Add(waterfallCanvas, 20, wxEXPAND | wxALL, 0);
wxGetApp().getSpectrumProcesor()->attachOutput(waterfallCanvas->getVisualDataQueue());
/*
vbox->AddSpacer(1);
testCanvas = new UITestCanvas(this, attribList);
@ -582,12 +587,6 @@ void AppFrame::OnThread(wxCommandEvent& event) {
}
void AppFrame::OnIdle(wxIdleEvent& event) {
bool work_done = false;
//#ifdef __APPLE__
// std::this_thread::sleep_for(std::chrono::milliseconds(4));
// std::this_thread::yield();
//#endif
DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
@ -734,6 +733,25 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
scopeCanvas->setPPMMode(demodTuner->isAltDown());
wxGetApp().getSpectrumDistributor()->run();
SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor();
proc->setView(waterfallCanvas->getViewState());
proc->setBandwidth(waterfallCanvas->getBandwidth());
proc->setCenterFrequency(waterfallCanvas->getCenterFrequency());
proc->run();
SpectrumVisualProcessor *dproc = wxGetApp().getDemodSpectrumProcesor();
dproc->setView(demodWaterfallCanvas->getViewState());
dproc->setBandwidth(demodWaterfallCanvas->getBandwidth());
dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency());
dproc->run();
event.Skip();
}

View File

@ -78,9 +78,25 @@ bool CubicSDR::OnInit() {
pipeIQVisualData = new DemodulatorThreadInputQueue();
pipeIQVisualData->set_max_num_items(1);
spectrumDistributor.setInput(pipeIQVisualData);
pipeDemodIQVisualData = new DemodulatorThreadInputQueue();
pipeIQVisualData->set_max_num_items(1);
pipeSpectrumIQVisualData = new DemodulatorThreadInputQueue();
pipeIQVisualData->set_max_num_items(1);
spectrumDistributor.attachOutput(pipeDemodIQVisualData);
spectrumDistributor.attachOutput(pipeSpectrumIQVisualData);
demodSpectrumProcessor.setInput(pipeDemodIQVisualData);
spectrumProcessor.setInput(pipeSpectrumIQVisualData);
pipeAudioVisualData = new DemodulatorThreadOutputQueue();
pipeAudioVisualData->set_max_num_items(1);
scopeProcessor.setInput(pipeAudioVisualData);
// I/Q Data
pipeSDRIQData = new SDRThreadIQDataQueue;
pipeSDRCommand = new SDRThreadCommandQueue();
@ -271,6 +287,23 @@ long long CubicSDR::getFrequency() {
return frequency;
}
ScopeVisualProcessor *CubicSDR::getScopeProcessor() {
return &scopeProcessor;
}
SpectrumVisualProcessor *CubicSDR::getSpectrumProcesor() {
return &spectrumProcessor;
}
SpectrumVisualProcessor *CubicSDR::getDemodSpectrumProcesor() {
return &demodSpectrumProcessor;
}
VisualDataDistributor<DemodulatorThreadIQData> *CubicSDR::getSpectrumDistributor() {
return &spectrumDistributor;
}
DemodulatorThreadOutputQueue* CubicSDR::getAudioVisualQueue() {
return pipeAudioVisualData;
}

View File

@ -17,6 +17,9 @@
#include "AppConfig.h"
#include "AppFrame.h"
#include "ScopeVisualProcessor.h"
#include "SpectrumVisualProcessor.h"
#include <wx/cmdline.h>
#define NUM_DEMODULATORS 1
@ -52,6 +55,11 @@ public:
void setDevice(int deviceId);
int getDevice();
ScopeVisualProcessor *getScopeProcessor();
SpectrumVisualProcessor *getSpectrumProcesor();
SpectrumVisualProcessor *getDemodSpectrumProcesor();
VisualDataDistributor<DemodulatorThreadIQData> *getSpectrumDistributor();
DemodulatorThreadOutputQueue* getAudioVisualQueue();
DemodulatorThreadInputQueue* getIQVisualQueue();
DemodulatorMgr &getDemodMgr();
@ -91,6 +99,14 @@ private:
SDRThreadIQDataQueue* pipeSDRIQData;
DemodulatorThreadInputQueue* pipeIQVisualData;
DemodulatorThreadOutputQueue* pipeAudioVisualData;
DemodulatorThreadInputQueue* pipeDemodIQVisualData;
DemodulatorThreadInputQueue* pipeSpectrumIQVisualData;
ScopeVisualProcessor scopeProcessor;
SpectrumVisualProcessor spectrumProcessor;
SpectrumVisualProcessor demodSpectrumProcessor;
VisualDataDistributor<DemodulatorThreadIQData> spectrumDistributor;
std::thread *t_SDR;
std::thread *t_PostSDR;

View File

@ -12,13 +12,13 @@ std::map<int, int> AudioThread::deviceSampleRate;
std::map<int, std::thread *> AudioThread::deviceThread;
AudioThread::AudioThread() : IOThread(),
currentInput(NULL), inputQueue(NULL), gain(
1.0), threadQueueNotify(NULL), sampleRate(0), nBufferFrames(1024) {
currentInput(NULL), inputQueue(NULL), nBufferFrames(1024), threadQueueNotify(NULL), sampleRate(0) {
audioQueuePtr.store(0);
underflowCount.store(0);
active.store(false);
outputDevice.store(-1);
gain.store(1.0);
boundThreads = new std::vector<AudioThread *>;
}

View File

@ -1,7 +1,7 @@
#include "DemodulatorInstance.h"
DemodulatorInstance::DemodulatorInstance() :
pipeIQInputData(NULL), demodulatorThread(NULL), t_PreDemod(NULL), t_Demod(NULL), t_Audio(NULL), currentAudioGain(1.0) {
t_PreDemod(NULL), t_Demod(NULL), t_Audio(NULL) {
terminated.store(true);
audioTerminated.store(true);
@ -16,7 +16,7 @@ DemodulatorInstance::DemodulatorInstance() :
currentFrequency.store(0);
currentBandwidth.store(0);
currentOutputDevice.store(-1);
currentAudioGain.store(1.0);
label = new std::string("Unnamed");
pipeIQInputData = new DemodulatorThreadInputQueue;
@ -30,17 +30,17 @@ DemodulatorInstance::DemodulatorInstance() :
demodulatorPreThread->setOutputQueue("NotifyQueue",pipeDemodNotify);
demodulatorPreThread->setInputQueue("CommandQueue",pipeDemodCommand);
audioInputQueue = new AudioThreadInputQueue;
pipeAudioData = new AudioThreadInputQueue;
threadQueueControl = new DemodulatorThreadControlCommandQueue;
demodulatorThread = new DemodulatorThread();
demodulatorThread->setInputQueue("IQDataInput",pipeIQDemodData);
demodulatorThread->setInputQueue("ControlQueue",threadQueueControl);
demodulatorThread->setOutputQueue("NotifyQueue",pipeDemodNotify);
demodulatorThread->setOutputQueue("AudioDataOutput", audioInputQueue);
demodulatorThread->setOutputQueue("AudioDataOutput", pipeAudioData);
audioThread = new AudioThread();
audioThread->setInputQueue("AudioDataInput", audioInputQueue);
audioThread->setInputQueue("AudioDataInput", pipeAudioData);
audioThread->setOutputQueue("NotifyQueue", pipeDemodNotify);
currentDemodType = demodulatorThread->getDemodulatorType();
@ -56,7 +56,7 @@ DemodulatorInstance::~DemodulatorInstance() {
delete pipeDemodCommand;
delete pipeDemodNotify;
delete threadQueueControl;
delete audioInputQueue;
delete pipeAudioData;
}
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {

View File

@ -18,7 +18,6 @@ public:
std::thread *t_Demod;
#endif
AudioThreadInputQueue *audioInputQueue;
AudioThread *audioThread;
std::thread *t_Audio;
@ -86,6 +85,7 @@ public:
protected:
DemodulatorThreadInputQueue* pipeIQInputData;
DemodulatorThreadPostInputQueue* pipeIQDemodData;
AudioThreadInputQueue *pipeAudioData;
DemodulatorThreadCommandQueue* pipeDemodCommand;
DemodulatorThreadCommandQueue* pipeDemodNotify;
DemodulatorPreThread *demodulatorPreThread;

View File

@ -266,7 +266,6 @@ void DemodulatorThread::run() {
} else if (demodulatorType == DEMOD_TYPE_RAW) {
// do nothing here..
} else {
float p;
switch (demodulatorType.load()) {
case DEMOD_TYPE_LSB:
currentDemodLock = false;

View File

@ -1 +1,34 @@
#include "ScopeVisualProcessor.h"
void ScopeVisualProcessor::process() {
if (!isOutputEmpty()) {
return;
}
if (!input->empty()) {
AudioThreadInput *audioInputData;
input->pop(audioInputData);
if (!audioInputData) {
return;
}
int iMax = audioInputData->data.size();
if (!iMax) {
audioInputData->decRefCount();
return;
}
ScopeRenderData *renderData = outputBuffers.getBuffer();
renderData->channels = audioInputData->channels;
if (renderData->waveform_points.size() != iMax * 2) {
renderData->waveform_points.resize(iMax * 2);
}
for (int i = 0; i < iMax; i++) {
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] * 0.5f;
renderData->waveform_points[i * 2] = ((double) i / (double) iMax);
}
distribute(renderData);
}
}

View File

@ -3,61 +3,16 @@
#include "VisualProcessor.h"
#include "AudioThread.h"
class ScopeVisualProcessor : public VisualProcessor {
protected:
class ScopeRenderData: public ReferenceCounter {
public:
std::vector<float> waveform_points;
virtual void process() {
if (!input->empty()) {
ReferenceCounter *ati_ref;
input->pop(ati_ref);
AudioThreadInput *ati = (AudioThreadInput *)ati_ref;
if (!ati) {
return;
}
int iMax = ati->data.size();
if (!iMax) {
ati->decRefCount();
return;
}
if (waveform_points.size() != iMax * 2) {
waveform_points.resize(iMax * 2);
}
for (int i = 0; i < iMax; i++) {
waveform_points[i * 2 + 1] = ati->data[i] * 0.5f;
waveform_points[i * 2] = ((double) i / (double) iMax);
}
// ati->channels
}
/*
if (!wxGetApp().getAudioVisualQueue()->empty()) {
AudioThreadInput *demodAudioData;
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
int iMax = demodAudioData?demodAudioData->data.size():0;
if (demodAudioData && iMax) {
if (waveform_points.size() != iMax * 2) {
waveform_points.resize(iMax * 2);
}
demodAudioData->busy_update.lock();
for (int i = 0; i < iMax; i++) {
waveform_points[i * 2 + 1] = demodAudioData->data[i] * 0.5f;
waveform_points[i * 2] = ((double) i / (double) iMax);
}
demodAudioData->busy_update.unlock();
setStereo(demodAudioData->channels == 2);
} else {
std::cout << "Incoming Demodulator data empty?" << std::endl;
}
}
*/
}
int channels;
};
typedef ThreadQueue<ScopeRenderData *> ScopeRenderDataQueue;
class ScopeVisualProcessor : public VisualProcessor<AudioThreadInput, ScopeRenderData> {
protected:
void process();
ReBuffer<ScopeRenderData> outputBuffers;
};

View File

@ -1 +1,284 @@
#include "SpectrumVisualProcessor.h"
#include "CubicSDR.h"
SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), lastBandwidth(0), fftwInput(NULL), fftwOutput(NULL), fftInData(NULL), fftLastData(NULL), lastDataSize(0), fftw_plan(NULL), resampler(NULL), resamplerRatio(0) {
is_view.store(false);
fftSize.store(0);
centerFreq.store(0);
bandwidth.store(0);
freqShifter = nco_crcf_create(LIQUID_NCO);
shiftFrequency = 0;
fft_ceil_ma = fft_ceil_maa = 100.0;
fft_floor_ma = fft_floor_maa = 0.0;
}
SpectrumVisualProcessor::~SpectrumVisualProcessor() {
nco_crcf_destroy(freqShifter);
}
bool SpectrumVisualProcessor::isView() {
return is_view.load();
}
void SpectrumVisualProcessor::setView(bool bView) {
is_view.store(bView);
}
void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) {
centerFreq.store(centerFreq_in);
}
long long SpectrumVisualProcessor::getCenterFrequency() {
return centerFreq.load();
}
void SpectrumVisualProcessor::setBandwidth(long bandwidth_in) {
bandwidth.store(bandwidth_in);
}
long SpectrumVisualProcessor::getBandwidth() {
return bandwidth.load();
}
void SpectrumVisualProcessor::setup(int fftSize_in) {
fftSize = fftSize_in;
if (fftwInput) {
free(fftwInput);
}
fftwInput = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fftSize);
if (fftInData) {
free(fftInData);
}
fftInData = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fftSize);
if (fftLastData) {
free(fftLastData);
}
fftLastData = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fftSize);
if (fftwOutput) {
free(fftwOutput);
}
fftwOutput = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fftSize);
if (fftw_plan) {
fftwf_destroy_plan(fftw_plan);
}
fftw_plan = fftwf_plan_dft_1d(fftSize, fftwInput, fftwOutput, FFTW_FORWARD, FFTW_ESTIMATE);
}
void SpectrumVisualProcessor::process() {
if (!isOutputEmpty()) {
return;
}
if (!input || input->empty()) {
return;
}
DemodulatorThreadIQData *iqData;
input->pop(iqData);
std::vector<liquid_float_complex> *data = &iqData->data;
if (data && data->size()) {
SpectrumVisualData *output = outputBuffers.getBuffer();
if (output->spectrum_points.size() < fftSize * 2) {
output->spectrum_points.resize(fftSize * 2);
}
unsigned int num_written;
if (is_view.load()) {
if (!iqData->frequency || !iqData->sampleRate) {
return;
}
resamplerRatio = (double) (bandwidth) / (double) iqData->sampleRate;
int desired_input_size = fftSize / resamplerRatio;
if (iqData->data.size() < desired_input_size) {
// std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl;
desired_input_size = iqData->data.size();
}
if (centerFreq != iqData->frequency) {
if ((centerFreq - iqData->frequency) != shiftFrequency || lastInputBandwidth != iqData->sampleRate) {
if (abs(iqData->frequency - centerFreq) < (wxGetApp().getSampleRate() / 2)) {
shiftFrequency = centerFreq - iqData->frequency;
nco_crcf_reset(freqShifter);
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) iqData->sampleRate)));
}
}
if (shiftBuffer.size() != desired_input_size) {
if (shiftBuffer.capacity() < desired_input_size) {
shiftBuffer.reserve(desired_input_size);
}
shiftBuffer.resize(desired_input_size);
}
if (shiftFrequency < 0) {
nco_crcf_mix_block_up(freqShifter, &iqData->data[0], &shiftBuffer[0], desired_input_size);
} else {
nco_crcf_mix_block_down(freqShifter, &iqData->data[0], &shiftBuffer[0], desired_input_size);
}
} else {
shiftBuffer.assign(iqData->data.begin(), iqData->data.end());
}
if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != iqData->sampleRate) {
float As = 60.0f;
if (resampler) {
msresamp_crcf_destroy(resampler);
}
resampler = msresamp_crcf_create(resamplerRatio, As);
lastBandwidth = bandwidth;
lastInputBandwidth = iqData->sampleRate;
}
int out_size = ceil((double) (desired_input_size) * resamplerRatio) + 512;
if (resampleBuffer.size() != out_size) {
if (resampleBuffer.capacity() < out_size) {
resampleBuffer.reserve(out_size);
}
resampleBuffer.resize(out_size);
}
msresamp_crcf_execute(resampler, &shiftBuffer[0], desired_input_size, &resampleBuffer[0], &num_written);
resampleBuffer.resize(fftSize);
if (num_written < fftSize) {
for (int i = 0; i < num_written; i++) {
fftInData[i][0] = resampleBuffer[i].real;
fftInData[i][1] = resampleBuffer[i].imag;
}
for (int i = num_written; i < fftSize; i++) {
fftInData[i][0] = 0;
fftInData[i][1] = 0;
}
} else {
for (int i = 0; i < fftSize; i++) {
fftInData[i][0] = resampleBuffer[i].real;
fftInData[i][1] = resampleBuffer[i].imag;
}
}
} else {
num_written = data->size();
if (data->size() < fftSize) {
for (int i = 0, iMax = data->size(); i < iMax; i++) {
fftInData[i][0] = (*data)[i].real;
fftInData[i][1] = (*data)[i].imag;
}
for (int i = data->size(); i < fftSize; i++) {
fftInData[i][0] = 0;
fftInData[i][1] = 0;
}
} else {
for (int i = 0; i < fftSize; i++) {
fftInData[i][0] = (*data)[i].real;
fftInData[i][1] = (*data)[i].imag;
}
}
}
bool execute = false;
if (num_written >= fftSize) {
execute = true;
memcpy(fftwInput, fftInData, fftSize * sizeof(fftwf_complex));
memcpy(fftLastData, fftwInput, fftSize * sizeof(fftwf_complex));
} else {
if (lastDataSize + num_written < fftSize) { // priming
unsigned int num_copy = fftSize - lastDataSize;
if (num_written > num_copy) {
num_copy = num_written;
}
memcpy(fftLastData, fftInData, num_copy * sizeof(fftwf_complex));
lastDataSize += num_copy;
} else {
unsigned int num_last = (fftSize - num_written);
memcpy(fftwInput, fftLastData + (lastDataSize - num_last), num_last * sizeof(fftwf_complex));
memcpy(fftwInput + num_last, fftInData, num_written * sizeof(fftwf_complex));
memcpy(fftLastData, fftwInput, fftSize * sizeof(fftwf_complex));
execute = true;
}
}
if (execute) {
fftwf_execute(fftw_plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() < fftSize) {
fft_result.resize(fftSize);
fft_result_ma.resize(fftSize);
fft_result_maa.resize(fftSize);
}
for (int i = 0, iMax = fftSize / 2; i < iMax; i++) {
float a = fftwOutput[i][0];
float b = fftwOutput[i][1];
float c = sqrt(a * a + b * b);
float x = fftwOutput[fftSize / 2 + i][0];
float y = fftwOutput[fftSize / 2 + i][1];
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fftSize / 2 + i] = (c);
}
for (int i = 0, iMax = fftSize; i < iMax; i++) {
if (is_view.load()) {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
} else {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
}
if (fft_result_maa[i] > fft_ceil) {
fft_ceil = fft_result_maa[i];
}
if (fft_result_maa[i] < fft_floor) {
fft_floor = fft_result_maa[i];
}
}
fft_ceil += 0.25;
fft_floor -= 1;
fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.05;
fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.05;
fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.05;
fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.05;
for (int i = 0, iMax = fftSize; i < iMax; i++) {
float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa));
output->spectrum_points[i * 2] = ((float) i / (float) iMax);
output->spectrum_points[i * 2 + 1] = v;
}
output->fft_ceiling = fft_ceil_maa;
output->fft_floor = fft_floor_maa;
}
distribute(output);
}
}

View File

@ -1,85 +1,62 @@
#pragma once
#include "VisualProcessor.h"
#include "DemodDefs.h"
#include "fftw3.h"
class SpectrumVisualProcessor : public VisualProcessor {
protected:
virtual void process() {
/*
std::vector<liquid_float_complex> *data = &input->data;
if (data && data->size()) {
if (fft_size != data->size()) {
setup(data->size());
}
if (spectrum_points.size() < fft_size * 2) {
if (spectrum_points.capacity() < fft_size * 2) {
spectrum_points.reserve(fft_size * 2);
}
spectrum_points.resize(fft_size * 2);
}
for (int i = 0; i < fft_size; i++) {
in[i][0] = (*data)[i].real;
in[i][1] = (*data)[i].imag;
}
fftwf_execute(plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() != fft_size) {
if (fft_result.capacity() < fft_size) {
fft_result.reserve(fft_size);
fft_result_ma.reserve(fft_size);
fft_result_maa.reserve(fft_size);
}
fft_result.resize(fft_size);
fft_result_ma.resize(fft_size);
fft_result_maa.resize(fft_size);
}
int n;
for (int i = 0, iMax = fft_size / 2; i < iMax; i++) {
float a = out[i][0];
float b = out[i][1];
float c = sqrt(a * a + b * b);
float x = out[fft_size / 2 + i][0];
float y = out[fft_size / 2 + i][1];
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fft_size / 2 + i] = (c);
}
for (int i = 0, iMax = fft_size; i < iMax; i++) {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
if (fft_result_maa[i] > fft_ceil) {
fft_ceil = fft_result_maa[i];
}
if (fft_result_maa[i] < fft_floor) {
fft_floor = fft_result_maa[i];
}
}
fft_ceil += 1;
fft_floor -= 1;
fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.01;
fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.01;
fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.01;
fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.01;
for (int i = 0, iMax = fft_size; i < iMax; i++) {
float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa));
spectrum_points[i * 2] = ((float) i / (float) iMax);
spectrum_points[i * 2 + 1] = v;
}
}
*/
}
class SpectrumVisualData : public ReferenceCounter {
public:
std::vector<float> spectrum_points;
double fft_ceiling, fft_floor;
};
typedef ThreadQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
class SpectrumVisualProcessor : public VisualProcessor<DemodulatorThreadIQData, SpectrumVisualData> {
public:
SpectrumVisualProcessor();
~SpectrumVisualProcessor();
bool isView();
void setView(bool bView);
void setCenterFrequency(long long centerFreq_in);
long long getCenterFrequency();
void setBandwidth(long bandwidth_in);
long getBandwidth();
void setup(int fftSize);
protected:
void process();
ReBuffer<SpectrumVisualData> outputBuffers;
std::atomic_bool is_view;
std::atomic_int fftSize;
std::atomic_llong centerFreq;
std::atomic_long bandwidth;
private:
long lastInputBandwidth;
long lastBandwidth;
fftwf_complex *fftwInput, *fftwOutput, *fftInData, *fftLastData;
unsigned int lastDataSize;
fftwf_plan fftw_plan;
float fft_ceil_ma, fft_ceil_maa;
float fft_floor_ma, fft_floor_maa;
std::vector<float> fft_result;
std::vector<float> fft_result_ma;
std::vector<float> fft_result_maa;
msresamp_crcf resampler;
double resamplerRatio;
nco_crcf freqShifter;
long shiftFrequency;
std::vector<liquid_float_complex> shiftBuffer;
std::vector<liquid_float_complex> resampleBuffer;
};

View File

@ -5,27 +5,30 @@
#include "IOThread.h"
#include <algorithm>
typedef ThreadQueue<ReferenceCounter *> VisualDataQueue;
template<class InputDataType = ReferenceCounter, class OutputDataType = ReferenceCounter>
class VisualProcessor {
public:
void setInput(VisualDataQueue *vis_in) {
virtual ~VisualProcessor() {
}
void setInput(ThreadQueue<InputDataType *> *vis_in) {
busy_update.lock();
input = vis_in;
busy_update.unlock();
}
void attachOutput(VisualDataQueue *vis_out) {
void attachOutput(ThreadQueue<OutputDataType *> *vis_out) {
// attach an output queue
busy_update.lock();
outputs.push_back(vis_out);
busy_update.unlock();
}
void removeOutput(VisualDataQueue *vis_out) {
void removeOutput(ThreadQueue<OutputDataType *> *vis_out) {
// remove an output queue
busy_update.lock();
std::vector<VisualDataQueue *>::iterator i = std::find(outputs.begin(), outputs.end(), vis_out);
typename std::vector<ThreadQueue<OutputDataType *> *>::iterator i = std::find(outputs.begin(), outputs.end(), vis_out);
if (i != outputs.end()) {
outputs.erase(i);
}
@ -46,29 +49,55 @@ protected:
// distribute(output);
}
void distribute(ReferenceCounter *output) {
void distribute(OutputDataType *output) {
// distribute outputs
output->setRefCount(outputs.size());
std::vector<VisualDataQueue *>::iterator outputs_i;
for (outputs_i = outputs.begin(); outputs_i != outputs.begin(); outputs_i++) {
for (outputs_i = outputs.begin(); outputs_i != outputs.end(); outputs_i++) {
if ((*outputs_i)->full()) {
output->decRefCount();
} else {
(*outputs_i)->push(output);
}
}
}
VisualDataQueue * input;
std::vector<VisualDataQueue *> outputs;
bool isOutputEmpty() {
for (outputs_i = outputs.begin(); outputs_i != outputs.end(); outputs_i++) {
if (!(*outputs_i)->empty()) {
return false;
}
}
return true;
}
bool isAnyOutputEmpty() {
for (outputs_i = outputs.begin(); outputs_i != outputs.end(); outputs_i++) {
if ((*outputs_i)->empty()) {
return true;
}
}
return false;
}
ThreadQueue<InputDataType *> *input;
std::vector<ThreadQueue<OutputDataType *> *> outputs;
typename std::vector<ThreadQueue<OutputDataType *> *>::iterator outputs_i;
std::mutex busy_update;
};
class VisualDataDistributor : public VisualProcessor {
template<class OutputDataType = ReferenceCounter>
class VisualDataDistributor : public VisualProcessor<OutputDataType, OutputDataType> {
protected:
virtual void process() {
while (!input->empty()) {
ReferenceCounter *inp;
input->pop(inp);
void process() {
if (!VisualProcessor<OutputDataType, OutputDataType>::isOutputEmpty()) {
return;
}
while (!VisualProcessor<OutputDataType, OutputDataType>::input->empty()) {
OutputDataType *inp;
VisualProcessor<OutputDataType, OutputDataType>::input->pop(inp);
if (inp) {
distribute(inp);
VisualProcessor<OutputDataType, OutputDataType>::distribute(inp);
}
}
}

View File

@ -1 +0,0 @@
#include "WaterfallVisualProcessor.h"

View File

@ -1,281 +0,0 @@
#pragma once
#include "VisualProcessor.h"
class WaterfallVisualProcessor : public VisualProcessor {
protected:
virtual void process() {
/*
long double currentZoom = zoom;
if (mouseZoom != 1) {
currentZoom = mouseZoom;
mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2;
if (fabs(mouseZoom-1.0)<0.01) {
mouseZoom = 1;
}
}
long long bw;
if (currentZoom != 1) {
long long freq = wxGetApp().getFrequency();
if (currentZoom < 1) {
centerFreq = getCenterFrequency();
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw < 100000) {
bw = 100000;
}
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
setView(centerFreq, bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
} else {
if (isView) {
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw >= wxGetApp().getSampleRate()) {
disableView();
if (spectrumCanvas) {
spectrumCanvas->disableView();
}
} else {
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
setView(getCenterFrequency(), bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
}
}
}
if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2;
}
if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
}
}
std::vector<liquid_float_complex> *data = &input->data;
if (data && data->size()) {
// if (fft_size != data->size() && !isView) {
// Setup(data->size(), waterfall_lines);
// }
// if (last_bandwidth != bandwidth && !isView) {
// Setup(bandwidth, waterfall_lines);
// }
if (spectrum_points.size() < fft_size * 2) {
spectrum_points.resize(fft_size * 2);
}
unsigned int num_written;
if (isView) {
if (!input->frequency || !input->sampleRate) {
return;
}
resamplerRatio = (double) (bandwidth) / (double) input->sampleRate;
int desired_input_size = fft_size / resamplerRatio;
if (input->data.size() < desired_input_size) {
// std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl;
desired_input_size = input->data.size();
}
if (centerFreq != input->frequency) {
if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->sampleRate) {
if (abs(input->frequency - centerFreq) < (wxGetApp().getSampleRate() / 2)) {
shiftFrequency = centerFreq - input->frequency;
nco_crcf_reset(freqShifter);
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->sampleRate)));
}
}
if (shiftBuffer.size() != desired_input_size) {
if (shiftBuffer.capacity() < desired_input_size) {
shiftBuffer.reserve(desired_input_size);
}
shiftBuffer.resize(desired_input_size);
}
if (shiftFrequency < 0) {
nco_crcf_mix_block_up(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size);
} else {
nco_crcf_mix_block_down(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size);
}
} else {
shiftBuffer.assign(input->data.begin(), input->data.end());
}
if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != input->sampleRate) {
float As = 60.0f;
if (resampler) {
msresamp_crcf_destroy(resampler);
}
resampler = msresamp_crcf_create(resamplerRatio, As);
lastBandwidth = bandwidth;
lastInputBandwidth = input->sampleRate;
}
int out_size = ceil((double) (desired_input_size) * resamplerRatio) + 512;
if (resampleBuffer.size() != out_size) {
if (resampleBuffer.capacity() < out_size) {
resampleBuffer.reserve(out_size);
}
resampleBuffer.resize(out_size);
}
msresamp_crcf_execute(resampler, &shiftBuffer[0], desired_input_size, &resampleBuffer[0], &num_written);
resampleBuffer.resize(fft_size);
if (num_written < fft_size) {
for (int i = 0; i < num_written; i++) {
fft_in_data[i][0] = resampleBuffer[i].real;
fft_in_data[i][1] = resampleBuffer[i].imag;
}
for (int i = num_written; i < fft_size; i++) {
fft_in_data[i][0] = 0;
fft_in_data[i][1] = 0;
}
} else {
for (int i = 0; i < fft_size; i++) {
fft_in_data[i][0] = resampleBuffer[i].real;
fft_in_data[i][1] = resampleBuffer[i].imag;
}
}
} else {
num_written = data->size();
if (data->size() < fft_size) {
for (int i = 0, iMax = data->size(); i < iMax; i++) {
fft_in_data[i][0] = (*data)[i].real;
fft_in_data[i][1] = (*data)[i].imag;
}
for (int i = data->size(); i < fft_size; i++) {
fft_in_data[i][0] = 0;
fft_in_data[i][1] = 0;
}
} else {
for (int i = 0; i < fft_size; i++) {
fft_in_data[i][0] = (*data)[i].real;
fft_in_data[i][1] = (*data)[i].imag;
}
}
}
bool execute = false;
if (num_written >= fft_size) {
execute = true;
memcpy(in, fft_in_data, fft_size * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
} else {
if (last_data_size + num_written < fft_size) { // priming
unsigned int num_copy = fft_size - last_data_size;
if (num_written > num_copy) {
num_copy = num_written;
}
memcpy(fft_last_data, fft_in_data, num_copy * sizeof(fftwf_complex));
last_data_size += num_copy;
} else {
unsigned int num_last = (fft_size - num_written);
memcpy(in, fft_last_data + (last_data_size - num_last), num_last * sizeof(fftwf_complex));
memcpy(in + num_last, fft_in_data, num_written * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
execute = true;
}
}
if (execute) {
fftwf_execute(plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() < fft_size) {
fft_result.resize(fft_size);
fft_result_ma.resize(fft_size);
fft_result_maa.resize(fft_size);
}
int n;
for (int i = 0, iMax = fft_size / 2; i < iMax; i++) {
float a = out[i][0];
float b = out[i][1];
float c = sqrt(a * a + b * b);
float x = out[fft_size / 2 + i][0];
float y = out[fft_size / 2 + i][1];
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fft_size / 2 + i] = (c);
}
for (int i = 0, iMax = fft_size; i < iMax; i++) {
if (isView) {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
} else {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
}
if (fft_result_maa[i] > fft_ceil) {
fft_ceil = fft_result_maa[i];
}
if (fft_result_maa[i] < fft_floor) {
fft_floor = fft_result_maa[i];
}
}
fft_ceil += 0.25;
fft_floor -= 1;
fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.05;
fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.05;
fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.05;
fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.05;
for (int i = 0, iMax = fft_size; i < iMax; i++) {
float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa));
spectrum_points[i * 2] = ((float) i / (float) iMax);
spectrum_points[i * 2 + 1] = v;
}
if (spectrumCanvas) {
spectrumCanvas->spectrum_points.assign(spectrum_points.begin(), spectrum_points.end());
spectrumCanvas->getSpectrumContext()->setCeilValue(fft_ceil_maa);
spectrumCanvas->getSpectrumContext()->setFloorValue(fft_floor_maa);
}
}
}
*/
}
};

View File

@ -1598,8 +1598,8 @@ bool DataTree::LoadFromFile(const std::string& filename) {
string compressionType(*header->getNext("compression"));
dataSize = *header->getNext("uncompressed_size");
bool uncompress = false;
#if USE_FASTLZ
bool uncompress = false;
if (compressionType == "FastLZ") {
uncompress = true;
}

View File

@ -36,8 +36,6 @@ void initGLExtensions() {
std::cout << std::endl << "Supported GL Extensions: " << std::endl << extensions << std::endl << std::endl;
int interval = 2;
#ifdef _WIN32
if (GLExtSupported("WGL_EXT_swap_control")) {
std::cout << "Initializing WGL swap control extensions.." << std::endl;

View File

@ -103,7 +103,7 @@ int GLFontChar::getIndex() {
}
GLFont::GLFont() :
numCharacters(0), lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0) {
lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0) {
}

View File

@ -76,7 +76,6 @@ private:
std::string getParamKey(std::string param_str);
std::string getParamValue(std::string param_str);
int numCharacters;
int lineHeight;
int base;
int imageWidth, imageHeight;

View File

@ -211,6 +211,15 @@ public:
return m_queue.empty();
}
/**
* Check if the queue is full.
* \return true if queue is full.
*/
bool full() const {
std::lock_guard < std::mutex > lock(m_mutex);
return (m_max_num_items != 0) && (m_queue.size() >= m_max_num_items);
}
/**
* Remove any items in the queue.
*/

View File

@ -21,19 +21,16 @@ wxEND_EVENT_TABLE()
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), parent(parent), stereo(false), ppmMode(false) {
wxFULL_REPAINT_ON_RESIZE), stereo(false), ppmMode(false) {
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
inputData.set_max_num_items(1);
}
ScopeCanvas::~ScopeCanvas() {
}
void ScopeCanvas::setWaveformPoints(std::vector<float> &waveform_points_in) {
waveform_points = waveform_points_in;
}
void ScopeCanvas::setStereo(bool state) {
stereo = state;
}
@ -58,30 +55,26 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
#endif
const wxSize ClientSize = GetClientSize();
if (!wxGetApp().getAudioVisualQueue()->empty()) {
AudioThreadInput *demodAudioData;
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
wxGetApp().getScopeProcessor()->run();
if (!inputData.empty()) {
ScopeRenderData *avData;
inputData.pop(avData);
int iMax = demodAudioData?demodAudioData->data.size():0;
if (demodAudioData && iMax) {
if (waveform_points.size() != iMax * 2) {
waveform_points.resize(iMax * 2);
if (!avData) {
return;
}
demodAudioData->busy_update.lock();
int iMax = avData->waveform_points.size();
for (int i = 0; i < iMax; i++) {
waveform_points[i * 2 + 1] = demodAudioData->data[i] * 0.5f;
waveform_points[i * 2] = ((double) i / (double) iMax);
if (!iMax) {
avData->decRefCount();
return;
}
demodAudioData->busy_update.unlock();
waveform_points.assign(avData->waveform_points.begin(),avData->waveform_points.end());
setStereo(avData->channels == 2);
setStereo(demodAudioData->channels == 2);
} else {
std::cout << "Incoming Demodulator data empty?" << std::endl;
}
avData->decRefCount();
}
glContext->SetCurrent(*this);
@ -103,3 +96,7 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
void ScopeCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
}
ScopeRenderDataQueue *ScopeCanvas::getInputQueue() {
return &inputData;
}

View File

@ -7,6 +7,7 @@
#include <queue>
#include "ScopeContext.h"
#include "ScopeVisualProcessor.h"
#include "fftw3.h"
class ScopeCanvas: public wxGLCanvas {
@ -16,19 +17,18 @@ public:
ScopeCanvas(wxWindow *parent, int *attribList = NULL);
~ScopeCanvas();
void setWaveformPoints(std::vector<float> &waveform_points_in);
void setStereo(bool state);
void setDeviceName(std::string device_name);
void setPPMMode(bool ppmMode);
bool getPPMMode();
ScopeRenderDataQueue *getInputQueue();
private:
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent &event);
wxWindow *parent;
ScopeRenderDataQueue inputData;
ScopeContext *glContext;
std::string deviceName;
bool stereo;

View File

@ -27,8 +27,7 @@ EVT_MOUSEWHEEL(SpectrumCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE()
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), fft_size(0), in(NULL), out(NULL), plan(NULL), fft_ceil_ma(1), fft_ceil_maa(1), fft_floor_ma(0), fft_floor_maa(
0), waterfallCanvas(NULL), trackingRate(0) {
InteractiveCanvas(parent, attribList), waterfallCanvas(NULL) {
glContext = new SpectrumContext(this, &wxGetApp().GetContext(this));
@ -37,30 +36,6 @@ SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
SetCursor(wxCURSOR_SIZEWE);
}
void SpectrumCanvas::setup(int fft_size_in) {
if (fft_size == fft_size_in) {
return;
}
fft_size = fft_size_in;
if (in) {
free(in);
}
in = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (out) {
free(out);
}
out = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (plan) {
fftwf_destroy_plan(plan);
}
plan = fftwf_plan_dft_1d(fft_size, in, out, FFTW_FORWARD, FFTW_MEASURE);
fft_ceil_ma = fft_ceil_maa = 100.0;
fft_floor_ma = fft_floor_maa = 0.0;
}
SpectrumCanvas::~SpectrumCanvas() {
}
@ -72,6 +47,22 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
#endif
const wxSize ClientSize = GetClientSize();
if (visualDataQueue.empty()) {
return;
}
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (!vData) {
return;
}
spectrum_points.assign(vData->spectrum_points.begin(),vData->spectrum_points.end());
vData->decRefCount();
glContext->SetCurrent(*this);
initGLExtensions();
@ -91,85 +82,6 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
SwapBuffers();
}
void SpectrumCanvas::setData(DemodulatorThreadIQData *input) {
if (!input) {
return;
}
std::vector<liquid_float_complex> *data = &input->data;
if (data && data->size()) {
if (fft_size != data->size()) {
setup(data->size());
}
if (spectrum_points.size() < fft_size * 2) {
if (spectrum_points.capacity() < fft_size * 2) {
spectrum_points.reserve(fft_size * 2);
}
spectrum_points.resize(fft_size * 2);
}
for (int i = 0; i < fft_size; i++) {
in[i][0] = (*data)[i].real;
in[i][1] = (*data)[i].imag;
}
fftwf_execute(plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() != fft_size) {
if (fft_result.capacity() < fft_size) {
fft_result.reserve(fft_size);
fft_result_ma.reserve(fft_size);
fft_result_maa.reserve(fft_size);
}
fft_result.resize(fft_size);
fft_result_ma.resize(fft_size);
fft_result_maa.resize(fft_size);
}
int n;
for (int i = 0, iMax = fft_size / 2; i < iMax; i++) {
float a = out[i][0];
float b = out[i][1];
float c = sqrt(a * a + b * b);
float x = out[fft_size / 2 + i][0];
float y = out[fft_size / 2 + i][1];
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fft_size / 2 + i] = (c);
}
for (int i = 0, iMax = fft_size; i < iMax; i++) {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
if (fft_result_maa[i] > fft_ceil) {
fft_ceil = fft_result_maa[i];
}
if (fft_result_maa[i] < fft_floor) {
fft_floor = fft_result_maa[i];
}
}
fft_ceil += 1;
fft_floor -= 1;
fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.01;
fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.01;
fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.01;
fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.01;
for (int i = 0, iMax = fft_size; i < iMax; i++) {
float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa));
spectrum_points[i * 2] = ((float) i / (float) iMax);
spectrum_points[i * 2 + 1] = v;
}
}
}
void SpectrumCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
@ -250,3 +162,7 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
SpectrumContext* SpectrumCanvas::getSpectrumContext() {
return glContext;
}
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
return &visualDataQueue;
}

View File

@ -11,6 +11,7 @@
#include "fftw3.h"
#include "MouseTracker.h"
#include "SpectrumVisualProcessor.h"
class WaterfallCanvas;
@ -19,14 +20,13 @@ public:
std::vector<float> spectrum_points;
SpectrumCanvas(wxWindow *parent, int *attribList = NULL);
void setup(int fft_size_in);
~SpectrumCanvas();
void setData(DemodulatorThreadIQData *input);
void attachWaterfallCanvas(WaterfallCanvas *canvas_in);
void moveCenterFrequency(long long freqChange);
SpectrumContext* getSpectrumContext();
SpectrumVisualDataQueue *getVisualDataQueue();
private:
void OnPaint(wxPaintEvent& event);
@ -39,20 +39,11 @@ private:
void OnMouseReleased(wxMouseEvent& event);
void OnMouseLeftWindow(wxMouseEvent& event);
fftwf_complex *in, *out;
fftwf_plan plan;
float fft_ceil_ma, fft_ceil_maa;
float fft_floor_ma, fft_floor_maa;
std::vector<float> fft_result;
std::vector<float> fft_result_ma;
std::vector<float> fft_result_maa;
SpectrumContext *glContext;
WaterfallCanvas *waterfallCanvas;
int fft_size;
int trackingRate;
SpectrumVisualDataQueue visualDataQueue;
// event table
wxDECLARE_EVENT_TABLE();
};

View File

@ -7,7 +7,7 @@
#include "ColorTheme.h"
SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext), fft_size(0), floorValue(0), ceilValue(1) {
PrimaryGLContext(canvas, sharedContext), floorValue(0), ceilValue(1) {
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);

View File

@ -19,6 +19,5 @@ public:
void setCeilValue(float ceilValue);
private:
int fft_size;
float floorValue, ceilValue;
};

View File

@ -31,7 +31,7 @@ EVT_KEY_UP(TuningCanvas::OnKeyUp)
wxEND_EVENT_TABLE()
TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), dragAccum(0), top(false), bottom(false), uxDown(0) {
InteractiveCanvas(parent, attribList), dragAccum(0), uxDown(0), top(false), bottom(false) {
glContext = new TuningContext(this, &wxGetApp().GetContext(this));

View File

@ -35,23 +35,15 @@ EVT_MOUSEWHEEL(WaterfallCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(
0), plan(
NULL), in(NULL), out(NULL), resampler(NULL), resamplerRatio(0), lastInputBandwidth(0), zoom(1), mouseZoom(1), otherWaterfallCanvas(NULL), polling(true), last_data_size(0), fft_in_data(NULL), fft_last_data(NULL), hoverAlpha(1.0), dragOfs(0) {
InteractiveCanvas(parent, attribList), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(
0), mouseZoom(1), zoom(1), hoverAlpha(1.0), dragOfs(0) {
glContext = new WaterfallContext(this, &wxGetApp().GetContext(this));
freqShifter = nco_crcf_create(LIQUID_NCO);
shiftFrequency = 0;
fft_ceil_ma = fft_ceil_maa = 100.0;
fft_floor_ma = fft_floor_maa = 0.0;
SetCursor(wxCURSOR_CROSS);
}
WaterfallCanvas::~WaterfallCanvas() {
nco_crcf_destroy(freqShifter);
}
void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
@ -61,27 +53,6 @@ void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
fft_size = fft_size_in;
waterfall_lines = waterfall_lines_in;
if (in) {
free(in);
}
in = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (fft_in_data) {
free(fft_in_data);
}
fft_in_data = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (fft_last_data) {
free(fft_last_data);
}
fft_last_data = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (out) {
free(out);
}
out = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (plan) {
fftwf_destroy_plan(plan);
}
plan = fftwf_plan_dft_1d(fft_size, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
glContext->Setup(fft_size, waterfall_lines);
}
@ -104,25 +75,85 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
#endif
const wxSize ClientSize = GetClientSize();
long double currentZoom = zoom;
if (mouseZoom != 1) {
currentZoom = mouseZoom;
mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2;
if (fabs(mouseZoom-1.0)<0.01) {
mouseZoom = 1;
}
}
if (polling && !wxGetApp().getIQVisualQueue()->empty()) {
DemodulatorThreadIQData *iqData;
wxGetApp().getIQVisualQueue()->pop(iqData);
long long bw;
if (currentZoom != 1) {
long long freq = wxGetApp().getFrequency();
iqData->busy_rw.lock();
if (currentZoom < 1) {
centerFreq = getCenterFrequency();
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw < 100000) {
bw = 100000;
}
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
if (iqData && iqData->data.size()) {
setData(iqData);
if (otherWaterfallCanvas) {
otherWaterfallCanvas->setData(iqData);
setView(centerFreq, bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
} else {
std::cout << "Incoming IQ data empty?" << std::endl;
if (isView) {
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw >= wxGetApp().getSampleRate()) {
disableView();
if (spectrumCanvas) {
spectrumCanvas->disableView();
}
} else {
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
iqData->busy_rw.unlock();
setView(getCenterFrequency(), bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
}
}
}
if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2;
}
if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
}
}
if (visualDataQueue.empty()) {
return;
}
SpectrumVisualData *vData;
visualDataQueue.pop(vData);
if (!vData) {
return;
}
spectrum_points.assign(vData->spectrum_points.begin(),vData->spectrum_points.end());
vData->decRefCount();
glContext->SetCurrent(*this);
initGLExtensions();
@ -142,7 +173,6 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
int currentBandwidth = getBandwidth();
long long currentCenterFreq = getCenterFrequency();
float demodColor, selectorColor;
ColorTheme *currentTheme = ThemeMgr::mgr.currentTheme;
int last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
@ -229,13 +259,11 @@ void WaterfallCanvas::OnKeyUp(wxKeyEvent& event) {
void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
InteractiveCanvas::OnKeyDown(event);
float angle = 5.0;
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getActiveDemodulator();
long long freq;
long long originalFreq;
unsigned int bw;
switch (event.GetKeyCode()) {
case 'A':
zoom = 0.95;
@ -323,283 +351,6 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
return;
}
}
void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
if (!input) {
return;
}
long double currentZoom = zoom;
if (mouseZoom != 1) {
currentZoom = mouseZoom;
mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2;
if (fabs(mouseZoom-1.0)<0.01) {
mouseZoom = 1;
}
}
long long bw;
if (currentZoom != 1) {
long long freq = wxGetApp().getFrequency();
if (currentZoom < 1) {
centerFreq = getCenterFrequency();
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw < 100000) {
bw = 100000;
}
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
setView(centerFreq, bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
} else {
if (isView) {
bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom);
if (bw >= wxGetApp().getSampleRate()) {
disableView();
if (spectrumCanvas) {
spectrumCanvas->disableView();
}
} else {
if (mouseTracker.mouseInView()) {
long long mfreqA = getFrequencyAt(mouseTracker.getMouseX());
setBandwidth(bw);
long long mfreqB = getFrequencyAt(mouseTracker.getMouseX());
centerFreq += mfreqA - mfreqB;
}
setView(getCenterFrequency(), bw);
if (spectrumCanvas) {
spectrumCanvas->setView(centerFreq, bw);
}
}
}
}
if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2;
}
if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
}
}
std::vector<liquid_float_complex> *data = &input->data;
if (data && data->size()) {
// if (fft_size != data->size() && !isView) {
// Setup(data->size(), waterfall_lines);
// }
// if (last_bandwidth != bandwidth && !isView) {
// Setup(bandwidth, waterfall_lines);
// }
if (spectrum_points.size() < fft_size * 2) {
spectrum_points.resize(fft_size * 2);
}
unsigned int num_written;
if (isView) {
if (!input->frequency || !input->sampleRate) {
return;
}
resamplerRatio = (double) (bandwidth) / (double) input->sampleRate;
int desired_input_size = fft_size / resamplerRatio;
if (input->data.size() < desired_input_size) {
// std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl;
desired_input_size = input->data.size();
}
if (centerFreq != input->frequency) {
if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->sampleRate) {
if (abs(input->frequency - centerFreq) < (wxGetApp().getSampleRate() / 2)) {
shiftFrequency = centerFreq - input->frequency;
nco_crcf_reset(freqShifter);
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->sampleRate)));
}
}
if (shiftBuffer.size() != desired_input_size) {
if (shiftBuffer.capacity() < desired_input_size) {
shiftBuffer.reserve(desired_input_size);
}
shiftBuffer.resize(desired_input_size);
}
if (shiftFrequency < 0) {
nco_crcf_mix_block_up(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size);
} else {
nco_crcf_mix_block_down(freqShifter, &input->data[0], &shiftBuffer[0], desired_input_size);
}
} else {
shiftBuffer.assign(input->data.begin(), input->data.end());
}
if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != input->sampleRate) {
float As = 60.0f;
if (resampler) {
msresamp_crcf_destroy(resampler);
}
resampler = msresamp_crcf_create(resamplerRatio, As);
lastBandwidth = bandwidth;
lastInputBandwidth = input->sampleRate;
}
int out_size = ceil((double) (desired_input_size) * resamplerRatio) + 512;
if (resampleBuffer.size() != out_size) {
if (resampleBuffer.capacity() < out_size) {
resampleBuffer.reserve(out_size);
}
resampleBuffer.resize(out_size);
}
msresamp_crcf_execute(resampler, &shiftBuffer[0], desired_input_size, &resampleBuffer[0], &num_written);
resampleBuffer.resize(fft_size);
if (num_written < fft_size) {
for (int i = 0; i < num_written; i++) {
fft_in_data[i][0] = resampleBuffer[i].real;
fft_in_data[i][1] = resampleBuffer[i].imag;
}
for (int i = num_written; i < fft_size; i++) {
fft_in_data[i][0] = 0;
fft_in_data[i][1] = 0;
}
} else {
for (int i = 0; i < fft_size; i++) {
fft_in_data[i][0] = resampleBuffer[i].real;
fft_in_data[i][1] = resampleBuffer[i].imag;
}
}
} else {
num_written = data->size();
if (data->size() < fft_size) {
for (int i = 0, iMax = data->size(); i < iMax; i++) {
fft_in_data[i][0] = (*data)[i].real;
fft_in_data[i][1] = (*data)[i].imag;
}
for (int i = data->size(); i < fft_size; i++) {
fft_in_data[i][0] = 0;
fft_in_data[i][1] = 0;
}
} else {
for (int i = 0; i < fft_size; i++) {
fft_in_data[i][0] = (*data)[i].real;
fft_in_data[i][1] = (*data)[i].imag;
}
}
}
bool execute = false;
if (num_written >= fft_size) {
execute = true;
memcpy(in, fft_in_data, fft_size * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
} else {
if (last_data_size + num_written < fft_size) { // priming
unsigned int num_copy = fft_size - last_data_size;
if (num_written > num_copy) {
num_copy = num_written;
}
memcpy(fft_last_data, fft_in_data, num_copy * sizeof(fftwf_complex));
last_data_size += num_copy;
} else {
unsigned int num_last = (fft_size - num_written);
memcpy(in, fft_last_data + (last_data_size - num_last), num_last * sizeof(fftwf_complex));
memcpy(in + num_last, fft_in_data, num_written * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
execute = true;
}
}
if (execute) {
fftwf_execute(plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() < fft_size) {
fft_result.resize(fft_size);
fft_result_ma.resize(fft_size);
fft_result_maa.resize(fft_size);
}
int n;
for (int i = 0, iMax = fft_size / 2; i < iMax; i++) {
float a = out[i][0];
float b = out[i][1];
float c = sqrt(a * a + b * b);
float x = out[fft_size / 2 + i][0];
float y = out[fft_size / 2 + i][1];
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fft_size / 2 + i] = (c);
}
for (int i = 0, iMax = fft_size; i < iMax; i++) {
if (isView) {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
} else {
fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65;
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65;
}
if (fft_result_maa[i] > fft_ceil) {
fft_ceil = fft_result_maa[i];
}
if (fft_result_maa[i] < fft_floor) {
fft_floor = fft_result_maa[i];
}
}
fft_ceil += 0.25;
fft_floor -= 1;
fft_ceil_ma = fft_ceil_ma + (fft_ceil - fft_ceil_ma) * 0.05;
fft_ceil_maa = fft_ceil_maa + (fft_ceil_ma - fft_ceil_maa) * 0.05;
fft_floor_ma = fft_floor_ma + (fft_floor - fft_floor_ma) * 0.05;
fft_floor_maa = fft_floor_maa + (fft_floor_ma - fft_floor_maa) * 0.05;
for (int i = 0, iMax = fft_size; i < iMax; i++) {
float v = (log10(fft_result_maa[i] - fft_floor_maa) / log10(fft_ceil_maa - fft_floor_maa));
spectrum_points[i * 2] = ((float) i / (float) iMax);
spectrum_points[i * 2 + 1] = v;
}
if (spectrumCanvas) {
spectrumCanvas->spectrum_points.assign(spectrum_points.begin(), spectrum_points.end());
spectrumCanvas->getSpectrumContext()->setCeilValue(fft_ceil_maa);
spectrumCanvas->getSpectrumContext()->setFloorValue(fft_floor_maa);
}
}
}
}
void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
}
@ -671,7 +422,6 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
setStatusText("Click and drag to set the current demodulator range.");
}
} else if (demodsHover->size() && !shiftDown) {
int hovered = -1;
long near_dist = getBandwidth();
DemodulatorInstance *activeDemodulator = NULL;
@ -963,16 +713,6 @@ void WaterfallCanvas::OnMouseRightReleased(wxMouseEvent& event) {
mouseZoom = 1.0;
}
void WaterfallCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
otherWaterfallCanvas = canvas_in;
otherWaterfallCanvas->setPolling(false);
}
bool WaterfallCanvas::isPolling() {
return polling;
}
void WaterfallCanvas::setPolling(bool polling) {
this->polling = polling;
SpectrumVisualDataQueue *WaterfallCanvas::getVisualDataQueue() {
return &visualDataQueue;
}

View File

@ -11,7 +11,6 @@
#include "MouseTracker.h"
#include "SpectrumCanvas.h"
#include "fftw3.h"
class WaterfallCanvas: public InteractiveCanvas {
public:
@ -23,16 +22,11 @@ public:
void setup(int fft_size_in, int waterfall_lines_in);
~WaterfallCanvas();
void setData(DemodulatorThreadIQData *input);
DragState getDragState();
DragState getNextDragState();
void attachSpectrumCanvas(SpectrumCanvas *canvas_in);
void attachWaterfallCanvas(WaterfallCanvas *canvas_in);
bool isPolling();
void setPolling(bool polling);
SpectrumVisualDataQueue *getVisualDataQueue();
private:
void OnPaint(wxPaintEvent& event);
@ -53,19 +47,6 @@ private:
std::vector<float> spectrum_points;
SpectrumCanvas *spectrumCanvas;
WaterfallCanvas *otherWaterfallCanvas;
bool polling;
fftwf_complex *in, *out, *fft_in_data, *fft_last_data;
unsigned int last_data_size;
fftwf_plan plan;
float fft_ceil_ma, fft_ceil_maa;
float fft_floor_ma, fft_floor_maa;
std::vector<float> fft_result;
std::vector<float> fft_result_ma;
std::vector<float> fft_result_maa;
WaterfallContext *glContext;
@ -76,18 +57,10 @@ private:
int waterfall_lines;
int dragOfs;
msresamp_crcf resampler;
double resamplerRatio;
nco_crcf freqShifter;
long shiftFrequency;
int lastInputBandwidth;
float mouseZoom, zoom;
float hoverAlpha;
std::vector<liquid_float_complex> shiftBuffer;
std::vector<liquid_float_complex> resampleBuffer;
SpectrumVisualDataQueue visualDataQueue;
// event table
wxDECLARE_EVENT_TABLE();

View File

@ -3,7 +3,7 @@
#include "CubicSDR.h"
WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext), waterfall_lines(0), waterfall_slice(NULL), fft_size(0), activeTheme(NULL) {
PrimaryGLContext(canvas, sharedContext), fft_size(0), waterfall_lines(0), waterfall_slice(NULL), activeTheme(NULL) {
for (int i = 0; i < 2; i++) {
waterfall[i] = 0;
}