mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-08 10:06:07 -05:00
Right drag spectrum vertically to adjust scale
This commit is contained in:
parent
010d899895
commit
11aa8e9b05
@ -977,3 +977,8 @@ bool AppFrame::loadSession(std::string fileName) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FFTVisualDataThread *AppFrame::getWaterfallDataThread() {
|
||||
return waterfallDataThread;
|
||||
}
|
||||
|
||||
|
@ -54,12 +54,14 @@ public:
|
||||
void saveSession(std::string fileName);
|
||||
bool loadSession(std::string fileName);
|
||||
|
||||
FFTVisualDataThread *getWaterfallDataThread();
|
||||
|
||||
private:
|
||||
void OnMenu(wxCommandEvent& event);
|
||||
void OnClose(wxCloseEvent& event);
|
||||
void OnNewWindow(wxCommandEvent& event);
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
|
||||
|
||||
ScopeCanvas *scopeCanvas;
|
||||
SpectrumCanvas *spectrumCanvas;
|
||||
WaterfallCanvas *waterfallCanvas;
|
||||
|
@ -17,6 +17,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last
|
||||
fft_floor_ma = fft_floor_maa = 0.0;
|
||||
desiredInputSize.store(0);
|
||||
fft_average_rate = 0.65;
|
||||
scaleFactor.store(1.0);
|
||||
}
|
||||
|
||||
SpectrumVisualProcessor::~SpectrumVisualProcessor() {
|
||||
@ -307,10 +308,12 @@ void SpectrumVisualProcessor::process() {
|
||||
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;
|
||||
|
||||
float sf = scaleFactor.load();
|
||||
|
||||
for (int i = 0, iMax = fftSize; i < iMax; i++) {
|
||||
float v = (log10(fft_result_maa[i]+0.25 - (fft_floor_maa-0.75)) / log10((fft_ceil_maa+0.25) - (fft_floor_maa-0.75)));
|
||||
output->spectrum_points[i * 2] = ((float) i / (float) iMax);
|
||||
output->spectrum_points[i * 2 + 1] = v;
|
||||
output->spectrum_points[i * 2 + 1] = v*sf;
|
||||
}
|
||||
|
||||
if (hideDC.load()) { // DC-spike removal
|
||||
@ -349,7 +352,7 @@ void SpectrumVisualProcessor::process() {
|
||||
}
|
||||
}
|
||||
|
||||
output->fft_ceiling = fft_ceil_maa;
|
||||
output->fft_ceiling = fft_ceil_maa/sf;
|
||||
output->fft_floor = fft_floor_maa;
|
||||
}
|
||||
|
||||
@ -361,3 +364,13 @@ void SpectrumVisualProcessor::process() {
|
||||
busy_run.unlock();
|
||||
}
|
||||
|
||||
|
||||
void SpectrumVisualProcessor::setScaleFactor(float sf) {
|
||||
scaleFactor.store(sf);
|
||||
}
|
||||
|
||||
|
||||
float SpectrumVisualProcessor::getScaleFactor() {
|
||||
return scaleFactor.load();
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
void setup(int fftSize);
|
||||
void setHideDC(bool hideDC);
|
||||
|
||||
void setScaleFactor(float sf);
|
||||
float getScaleFactor();
|
||||
|
||||
protected:
|
||||
void process();
|
||||
|
||||
@ -70,4 +73,5 @@ private:
|
||||
std::atomic_int desiredInputSize;
|
||||
std::mutex busy_run;
|
||||
std::atomic_bool hideDC;
|
||||
std::atomic<float> scaleFactor;
|
||||
};
|
||||
|
@ -13,8 +13,8 @@ public:
|
||||
|
||||
long long getFrequencyAt(float x);
|
||||
|
||||
void setView(long long center_freq_in, int bandwidth_in);
|
||||
void disableView();
|
||||
virtual void setView(long long center_freq_in, int bandwidth_in);
|
||||
virtual void disableView();
|
||||
bool getViewState();
|
||||
|
||||
void setCenterFrequency(long long center_freq_in);
|
||||
|
@ -25,6 +25,8 @@ EVT_LEFT_UP(SpectrumCanvas::OnMouseReleased)
|
||||
EVT_ENTER_WINDOW(SpectrumCanvas::OnMouseEnterWindow)
|
||||
EVT_LEAVE_WINDOW(SpectrumCanvas::OnMouseLeftWindow)
|
||||
EVT_MOUSEWHEEL(SpectrumCanvas::OnMouseWheelMoved)
|
||||
EVT_RIGHT_DOWN(SpectrumCanvas::OnMouseRightDown)
|
||||
EVT_RIGHT_UP(SpectrumCanvas::OnMouseRightReleased)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
|
||||
@ -36,6 +38,9 @@ SpectrumCanvas::SpectrumCanvas(wxWindow *parent, int *attribList) :
|
||||
visualDataQueue.set_max_num_items(1);
|
||||
|
||||
SetCursor(wxCURSOR_SIZEWE);
|
||||
scaleFactor = 1.0;
|
||||
resetScaleFactor = false;
|
||||
bwChange = 0.0;
|
||||
}
|
||||
|
||||
SpectrumCanvas::~SpectrumCanvas() {
|
||||
@ -59,6 +64,15 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (resetScaleFactor) {
|
||||
scaleFactor += (1.0-scaleFactor)*0.05;
|
||||
if (fabs(scaleFactor-1.0) < 0.01) {
|
||||
scaleFactor = 1.0;
|
||||
resetScaleFactor = false;
|
||||
}
|
||||
updateScaleFactor(scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
glContext->SetCurrent(*this);
|
||||
initGLExtensions();
|
||||
@ -137,6 +151,29 @@ bool SpectrumCanvas::getShowDb() {
|
||||
return spectrumPanel.getShowDb();
|
||||
}
|
||||
|
||||
void SpectrumCanvas::setView(long long center_freq_in, int bandwidth_in) {
|
||||
bwChange += bandwidth_in-bandwidth;
|
||||
#define BW_RESET_TH 400000
|
||||
if (bwChange > BW_RESET_TH || bwChange < -BW_RESET_TH) {
|
||||
resetScaleFactor = true;
|
||||
bwChange = 0;
|
||||
}
|
||||
InteractiveCanvas::setView(center_freq_in, bandwidth_in);
|
||||
}
|
||||
|
||||
void SpectrumCanvas::disableView() {
|
||||
InteractiveCanvas::disableView();
|
||||
}
|
||||
|
||||
void SpectrumCanvas::updateScaleFactor(float factor) {
|
||||
SpectrumVisualProcessor *sp = wxGetApp().getSpectrumProcessor();
|
||||
FFTVisualDataThread *wdt = wxGetApp().getAppFrame()->getWaterfallDataThread();
|
||||
SpectrumVisualProcessor *wp = wdt->getProcessor();
|
||||
|
||||
scaleFactor = factor;
|
||||
sp->setScaleFactor(factor);
|
||||
wp->setScaleFactor(factor);
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseMoved(event);
|
||||
@ -146,8 +183,23 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
|
||||
if (freqChange != 0) {
|
||||
moveCenterFrequency(freqChange);
|
||||
}
|
||||
}
|
||||
else if (mouseTracker.mouseRightDown()) {
|
||||
|
||||
float yDelta = mouseTracker.getDeltaMouseY();
|
||||
|
||||
scaleFactor += yDelta*2.0;
|
||||
if (scaleFactor < 0.25) {
|
||||
scaleFactor = 0.25;
|
||||
}
|
||||
if (scaleFactor > 10.0) {
|
||||
scaleFactor = 10.0;
|
||||
}
|
||||
|
||||
resetScaleFactor = false;
|
||||
updateScaleFactor(scaleFactor);
|
||||
} else {
|
||||
setStatusText("Click and drag to adjust center frequency. 'B' to toggle decibels display.");
|
||||
setStatusText("Drag horitontal to adjust center frequency. Right-drag to adjust vertical scale, click to reset. 'B' to toggle decibels display.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,3 +234,14 @@ void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) {
|
||||
SpectrumVisualDataQueue *SpectrumCanvas::getVisualDataQueue() {
|
||||
return &visualDataQueue;
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseRightDown(wxMouseEvent& event) {
|
||||
mouseTracker.OnMouseRightDown(event);
|
||||
}
|
||||
|
||||
void SpectrumCanvas::OnMouseRightReleased(wxMouseEvent& event) {
|
||||
if (!mouseTracker.getOriginDeltaMouseY()) {
|
||||
resetScaleFactor = true;
|
||||
}
|
||||
mouseTracker.OnMouseRightReleased(event);
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public:
|
||||
void setShowDb(bool showDb);
|
||||
bool getShowDb();
|
||||
|
||||
void setView(long long center_freq_in, int bandwidth_in);
|
||||
void disableView();
|
||||
|
||||
SpectrumVisualDataQueue *getVisualDataQueue();
|
||||
|
||||
private:
|
||||
@ -35,10 +38,17 @@ private:
|
||||
void OnMouseReleased(wxMouseEvent& event);
|
||||
void OnMouseEnterWindow(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
void OnMouseRightDown(wxMouseEvent& event);
|
||||
void OnMouseRightReleased(wxMouseEvent& event);
|
||||
|
||||
void updateScaleFactor(float factor);
|
||||
|
||||
PrimaryGLContext *glContext;
|
||||
WaterfallCanvas *waterfallCanvas;
|
||||
SpectrumPanel spectrumPanel;
|
||||
float scaleFactor;
|
||||
int bwChange;
|
||||
bool resetScaleFactor;
|
||||
|
||||
SpectrumVisualDataQueue visualDataQueue;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user