mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-05 00:41:17 -05:00
Prototype waterfall rate smoothing / fps matching
This commit is contained in:
parent
7163cd13f2
commit
a1bf5b839e
@ -395,6 +395,7 @@ AppFrame::AppFrame() :
|
||||
|
||||
waterfallSpeedMeter->setLevel(sqrt(wflps));
|
||||
waterfallDataThread->setLinesPerSecond(wflps);
|
||||
waterfallCanvas->setLinesPerSecond(wflps);
|
||||
|
||||
ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme());
|
||||
|
||||
@ -507,6 +508,7 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
||||
spectrumCanvas->setBandwidth(wxGetApp().getSampleRate());
|
||||
spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency());
|
||||
waterfallDataThread->setLinesPerSecond(DEFAULT_WATERFALL_LPS);
|
||||
waterfallCanvas->setLinesPerSecond(DEFAULT_WATERFALL_LPS);
|
||||
waterfallSpeedMeter->setLevel(sqrt(DEFAULT_WATERFALL_LPS));
|
||||
wxGetApp().getSpectrumProcessor()->setFFTAverageRate(0.65);
|
||||
spectrumAvgMeter->setLevel(0.65);
|
||||
@ -832,6 +834,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
||||
float val = waterfallSpeedMeter->getInputValue();
|
||||
waterfallSpeedMeter->setLevel(val);
|
||||
waterfallDataThread->setLinesPerSecond((int)ceil(val*val));
|
||||
waterfallCanvas->setLinesPerSecond((int)ceil(val*val));
|
||||
GetStatusBar()->SetStatusText(wxString::Format(wxT("Waterfall max speed changed to %d lines per second."),(int)ceil(val*val)));
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "ThreadQueue.h"
|
||||
#include "Timer.h"
|
||||
|
||||
struct map_string_less : public std::binary_function<std::string,std::string,bool>
|
||||
{
|
||||
@ -112,9 +113,9 @@ public:
|
||||
void setOutputQueue(std::string qname, ThreadQueueBase *threadQueue);
|
||||
void *getOutputQueue(std::string qname);
|
||||
|
||||
|
||||
protected:
|
||||
std::map<std::string, ThreadQueueBase *, map_string_less> input_queues;
|
||||
std::map<std::string, ThreadQueueBase *, map_string_less> output_queues;
|
||||
std::atomic_bool terminated;
|
||||
Timer gTimer;
|
||||
};
|
||||
|
@ -47,11 +47,11 @@ void FFTDataDistributor::process() {
|
||||
if (inputBuffer.data.size() >= fftSize) {
|
||||
int numProcessed = 0;
|
||||
|
||||
// if (lineRateAccum + (lineRateStep * floor((double)inputBuffer.data.size()/(double)fftSize)) < 1.0) {
|
||||
// // move along, nothing to see here..
|
||||
// lineRateAccum += (lineRateStep * inputBuffer.data.size()/fftSize);
|
||||
// numProcessed = inputBuffer.data.size()/fftSize;
|
||||
// } else {
|
||||
if (lineRateAccum + (lineRateStep * ((double)inputBuffer.data.size()/(double)fftSize)) < 1.0) {
|
||||
// move along, nothing to see here..
|
||||
lineRateAccum += (lineRateStep * ((double)inputBuffer.data.size()/(double)fftSize));
|
||||
numProcessed = inputBuffer.data.size();
|
||||
} else {
|
||||
for (int i = 0, iMax = inputBuffer.data.size(); i < iMax; i += fftSize) {
|
||||
if ((i + fftSize) > iMax) {
|
||||
break;
|
||||
@ -72,7 +72,7 @@ void FFTDataDistributor::process() {
|
||||
|
||||
numProcessed += fftSize;
|
||||
}
|
||||
// }
|
||||
}
|
||||
if (numProcessed) {
|
||||
inputBuffer.data.erase(inputBuffer.data.begin(), inputBuffer.data.begin() + numProcessed);
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <mmsystem.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), num_updates(0), paused_time(0), offset(0), paused_state(false), lock_state(0), lock_rate(0)
|
||||
{
|
||||
}
|
||||
@ -157,3 +159,14 @@ bool Timer::paused()
|
||||
{
|
||||
return paused_state;
|
||||
}
|
||||
|
||||
void Timer::timerTestFunc() {
|
||||
update();
|
||||
if (getNumUpdates() % 120 == 0) {
|
||||
std::cout << getNumUpdates() << "," << getSeconds() << " Rate: " << ((double)getNumUpdates()/getSeconds()) << "/sec" << std::endl;
|
||||
}
|
||||
if (getNumUpdates() >= 600) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,9 @@ public:
|
||||
* \return Current pause state, true if paused, false otherwise
|
||||
*/
|
||||
bool paused();
|
||||
|
||||
|
||||
void timerTestFunc();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -39,7 +39,9 @@ WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
|
||||
dragOfs(0), mouseZoom(1), zoom(1), freqMove(0.0), freqMoving(false), hoverAlpha(1.0) {
|
||||
|
||||
glContext = new PrimaryGLContext(this, &wxGetApp().GetContext(this));
|
||||
|
||||
linesPerSecond = 30;
|
||||
lpsIndex = 0;
|
||||
preBuf = false;
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
}
|
||||
|
||||
@ -54,6 +56,8 @@ void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
|
||||
waterfall_lines = waterfall_lines_in;
|
||||
|
||||
waterfallPanel.setup(fft_size, waterfall_lines);
|
||||
gTimer.start();
|
||||
testTimer.start();
|
||||
}
|
||||
|
||||
WaterfallCanvas::DragState WaterfallCanvas::getDragState() {
|
||||
@ -75,25 +79,47 @@ void WaterfallCanvas::processInputQueue() {
|
||||
glContext->SetCurrent(*this);
|
||||
|
||||
bool processed = false;
|
||||
int numVis = visualDataQueue.size();
|
||||
for (int i = 0; i < numVis; i++) {
|
||||
SpectrumVisualData *vData;
|
||||
visualDataQueue.pop(vData);
|
||||
|
||||
if (vData) {
|
||||
waterfallPanel.setPoints(vData->spectrum_points);
|
||||
waterfallPanel.step();
|
||||
vData->decRefCount();
|
||||
processed = true;
|
||||
// int numVis = visualDataQueue.size();
|
||||
|
||||
gTimer.update();
|
||||
// if (visualDataQueue.size() < 10 && !preBuf) {
|
||||
// return;
|
||||
// } else {
|
||||
// preBuf = true;
|
||||
// if (visualDataQueue.size() < 2) {
|
||||
// preBuf = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
double targetVis = 1.0 / (double)linesPerSecond;
|
||||
lpsIndex += gTimer.lastUpdateSeconds();
|
||||
|
||||
if (linesPerSecond) {
|
||||
if (lpsIndex >= targetVis) {
|
||||
while (lpsIndex >= targetVis) {
|
||||
SpectrumVisualData *vData;
|
||||
if (!visualDataQueue.empty()) {
|
||||
visualDataQueue.pop(vData);
|
||||
|
||||
if (vData) {
|
||||
waterfallPanel.setPoints(vData->spectrum_points);
|
||||
waterfallPanel.step();
|
||||
vData->decRefCount();
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
lpsIndex-=targetVis;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (processed) {
|
||||
Refresh();
|
||||
// Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
// wxClientDC dc(this);
|
||||
testTimer.timerTestFunc();
|
||||
wxPaintDC dc(this);
|
||||
|
||||
//#ifdef __APPLE__
|
||||
@ -401,11 +427,11 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
|
||||
}
|
||||
void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
|
||||
// Refresh();
|
||||
Refresh();
|
||||
// processInputQueue();
|
||||
// Refresh();
|
||||
// event.RequestMore();
|
||||
event.Skip();
|
||||
event.RequestMore();
|
||||
// event.Skip();
|
||||
}
|
||||
|
||||
void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
@ -793,3 +819,8 @@ void WaterfallCanvas::updateCenterFrequency(long long freq) {
|
||||
|
||||
}
|
||||
|
||||
void WaterfallCanvas::setLinesPerSecond(int lps) {
|
||||
linesPerSecond = lps;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "MouseTracker.h"
|
||||
#include "SpectrumCanvas.h"
|
||||
#include "WaterfallPanel.h"
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
class WaterfallCanvas: public InteractiveCanvas {
|
||||
public:
|
||||
@ -29,6 +29,8 @@ public:
|
||||
void processInputQueue();
|
||||
SpectrumVisualDataQueue *getVisualDataQueue();
|
||||
|
||||
void setLinesPerSecond(int lps);
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
@ -64,9 +66,12 @@ private:
|
||||
bool freqMoving;
|
||||
long double freqMove;
|
||||
float hoverAlpha;
|
||||
|
||||
int linesPerSecond;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
|
||||
Timer gTimer, testTimer;
|
||||
double lpsIndex;
|
||||
bool preBuf;
|
||||
// event table
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user