From: wittend99 Date: Wed, 29 Aug 2012 03:50:53 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@645 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=ceab20dc9968a1b1178998251f678b65275b6715;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@645 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/build/Debug/fdmdv2.exe b/fdmdv2/build/Debug/fdmdv2.exe index 789f00a3..7163699e 100644 Binary files a/fdmdv2/build/Debug/fdmdv2.exe and b/fdmdv2/build/Debug/fdmdv2.exe differ diff --git a/fdmdv2/build/Release/fdmdv2.exe b/fdmdv2/build/Release/fdmdv2.exe index c4be3ae8..adb29340 100644 Binary files a/fdmdv2/build/Release/fdmdv2.exe and b/fdmdv2/build/Release/fdmdv2.exe differ diff --git a/fdmdv2/build/fdmdv2.mk b/fdmdv2/build/fdmdv2.mk index 0eb5eff8..4027dc43 100644 --- a/fdmdv2/build/fdmdv2.mk +++ b/fdmdv2/build/fdmdv2.mk @@ -2,10 +2,10 @@ ## Auto Generated makefile by CodeLite IDE ## any manual changes will be erased ## -## Release +## Debug ProjectName :=fdmdv2 -ConfigurationName :=Release -IntermediateDirectory :=./Release +ConfigurationName :=Debug +IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) WorkspacePath := "C:\bin\Projects\Radio\fdmdv2\build" ProjectPath := "C:\bin\Projects\Radio\fdmdv2\build" @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=OFA-Staff -Date :=8/27/2012 +Date :=8/28/2012 CodeLitePath :="C:\bin\CodeLite" LinkerName :=g++ ArchiveTool :=ar rcus @@ -38,9 +38,9 @@ PreprocessOnlySwitch :=-E ObjectsFileList :="C:\bin\Projects\Radio\fdmdv2\build\fdmdv2.txt" PCHCompileFlags := MakeDirCommand :=makedir -CmpOptions := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors) -C_CmpOptions := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) $(Preprocessors) -LinkOptions := -mwindows -s $(shell wx-config --debug=no --libs --unicode=yes) +CmpOptions := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) -DSVN_REVISION=\"631\" $(Preprocessors) +C_CmpOptions := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) -DSVN_REVISION=\"631\" $(Preprocessors) +LinkOptions := -mwindows $(shell wx-config --debug=yes --libs --unicode=yes) IncludePath := $(IncludeSwitch). $(IncludeSwitch)/bin/MinGW/msys/1.0/local/include $(IncludeSwitch)../../codec2-dev/src $(IncludeSwitch)../3rdparty/portaudio/include $(IncludeSwitch)../3rdparty/portaudio/bindings/cpp/include $(IncludeSwitch)../3rdparty/libsndfile/include $(IncludeSwitch)../3rdparty/libsamplerate-0.1.8/src IncludePCH := RcIncludePath := @@ -72,7 +72,7 @@ $(OutputFile): $(IntermediateDirectory)/.d $(Objects) $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) $(IntermediateDirectory)/.d: - @$(MakeDirCommand) "./Release" + @$(MakeDirCommand) "./Debug" PreBuild: @@ -231,6 +231,6 @@ clean: $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_scalar$(PreprocessSuffix) $(RM) $(OutputFile) $(RM) $(OutputFile).exe - $(RM) "C:\bin\Projects\Radio\fdmdv2\build\.build-release\fdmdv2" + $(RM) "C:\bin\Projects\Radio\fdmdv2\build\.build-debug\fdmdv2" diff --git a/fdmdv2/build/fdmdv2.txt b/fdmdv2/build/fdmdv2.txt index b569c15b..21368bcd 100644 --- a/fdmdv2/build/fdmdv2.txt +++ b/fdmdv2/build/fdmdv2.txt @@ -1 +1 @@ -./Release/src_dlg_about.o ./Release/src_dlg_audio.o ./Release/src_dlg_comports.o ./Release/src_dlg_options.o ./Release/src_fdmdv2_main.o ./Release/src_fdmdv2_plot.o ./Release/src_topFrame.o ./Release/src_fdmdv2_plot_scatter.o ./Release/src_fdmdv2_plot_waterfall.o ./Release/src_fdmdv2_plot_spectrum.o ./Release/src_fdmdv2_pa_wrapper.o ./Release/src_fdmdv2_process_audio.o ./Release/src_fdmdv2_plot_scalar.o +./Debug/src_dlg_about.o ./Debug/src_dlg_audio.o ./Debug/src_dlg_comports.o ./Debug/src_dlg_options.o ./Debug/src_fdmdv2_main.o ./Debug/src_fdmdv2_plot.o ./Debug/src_topFrame.o ./Debug/src_fdmdv2_plot_scatter.o ./Debug/src_fdmdv2_plot_waterfall.o ./Debug/src_fdmdv2_plot_spectrum.o ./Debug/src_fdmdv2_pa_wrapper.o ./Debug/src_fdmdv2_process_audio.o ./Debug/src_fdmdv2_plot_scalar.o diff --git a/fdmdv2/build/fdmdv2.workspace b/fdmdv2/build/fdmdv2.workspace index e70810b8..5fb58e85 100644 --- a/fdmdv2/build/fdmdv2.workspace +++ b/fdmdv2/build/fdmdv2.workspace @@ -2,10 +2,10 @@ - + - + diff --git a/fdmdv2/build/fdmdv2_wsp.mk b/fdmdv2/build/fdmdv2_wsp.mk index 359a9f63..dd8060fa 100644 --- a/fdmdv2/build/fdmdv2_wsp.mk +++ b/fdmdv2/build/fdmdv2_wsp.mk @@ -1,8 +1,8 @@ .PHONY: clean All All: - @echo ----------Building project:[ fdmdv2 - Release ]---------- + @echo ----------Building project:[ fdmdv2 - Debug ]---------- @"mingw32-make.exe" -j 2 -f "fdmdv2.mk" clean: - @echo ----------Cleaning project:[ fdmdv2 - Release ]---------- + @echo ----------Cleaning project:[ fdmdv2 - Debug ]---------- @"mingw32-make.exe" -j 2 -f "fdmdv2.mk" clean diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h new file mode 100644 index 00000000..39c23658 --- /dev/null +++ b/fdmdv2/src/fdmdv2_defines.h @@ -0,0 +1,89 @@ +//========================================================================== +// Name: fdmdv2_defines.h +// Purpose: Definitions used by plots derived from fdmdv2_plot class. +// Created: August 27, 2012 +// Initial author: David Witten +// Derived from: code written by David Rowe +// License: +// +// Copyright (C) 2012 David Witten +// +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License version 2.1, +// as published by the Free Software Foundation. This program is +// distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, see . +// +//========================================================================== +#ifndef __FDMDV2_DEFINES__ +#define __FDMDV2_DEFINES__ + +/* FFT points */ +#define FDMDV_NSPEC 512 + +#define MIN_DB -40.0 +#define MAX_DB 0.0 +#define BETA 0.1 // constant for time averageing spectrum data +#define MIN_HZ 0 +#define MAX_HZ 4000 +#define WATERFALL_SECS_Y 5 // number of seconds respresented by y axis of waterfall +#define DT 0.02 // time between samples +#define FS 8000 // FDMDV modem sample rate + +#define FDMDV_BITS_PER_FRAME 28 /* 20ms frames, 1400 bit/s */ +#define FDMDV_NOM_SAMPLES_PER_FRAME 160 /* modulator output samples/frame and nominal demod samples/frame */ + /* at 8000 Hz sample rate */ +#define FDMDV_MAX_SAMPLES_PER_FRAME 200 /* max demod samples/frame, use this to allocate storage */ +#define FDMDV_SCALE 1000 /* suggested scaling for 16 bit shorts */ +#define FDMDV_NSYM 15 + +#define MIN_DB -40.0 +#define MAX_DB 0.0 +#define BETA 0.1 // constant for time averageing spectrum data +#define MIN_HZ 0 +#define MAX_HZ 4000 +#define WATERFALL_SECS_Y 5 // number of seconds respresented by y axis of waterfall +#define DT 0.02 // time between samples +#define FS 8000 // FDMDV modem sample rate + +#define SCATTER_MEM (FDMDV_NSYM)*50 +#define SCATTER_X_MAX 3.0 +#define SCATTER_Y_MAX 3.0 + +// main window params +#define W 1200 +#define W3 (W/3) +#define H 600 +#define H2 (H/2) +#define SP 20 + +// sound card +#define SAMPLE_RATE 48000 // 48 kHz sampling rate rec. as we can trust accuracy of sound card +#define N8 FDMDV_NOM_SAMPLES_PER_FRAME // processing buffer size at 8 kHz +#define MEM8 (FDMDV_OS_TAPS/FDMDV_OS) +#define N48 (N8*FDMDV_OS) // processing buffer size at 48 kHz +#define NUM_CHANNELS 2 // I think most sound cards prefer stereo we will convert to mono + +#define BITS_PER_CODEC_FRAME (2*FDMDV_BITS_PER_FRAME) +#define BYTES_PER_CODEC_FRAME (BITS_PER_CODEC_FRAME/8) + +/* 8 to 48 kHz sample rate conversion */ +#define FDMDV_OS 6 /* oversampling rate */ +#define FDMDV_OS_TAPS 48 /* number of OS filter taps */ + +enum +{ + ID_ROTATE_LEFT = wxID_HIGHEST + 1, + ID_ROTATE_RIGHT, + ID_RESIZE, + ID_PAINT_BG +}; + +#endif //__FDMDV2_DEFINES__ diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 59a52e69..5aaeb075 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -64,11 +64,17 @@ bool MainApp::OnInit() // Create the main application window MainFrame *frame = new MainFrame(NULL); - frame->m_panelSpectrum = new PlotSpectrum((wxFrame*) frame->m_auiNbookCtrl ); - frame->m_auiNbookCtrl->AddPage(frame->m_panelSpectrum, _("Spectrum"), true, wxNullBitmap ); + frame->m_panelDefaultA = new PlotPanel((wxFrame*) frame->m_auiNbookCtrl ); + frame->m_auiNbookCtrl->AddPage(frame->m_panelDefaultA, _("Spectrum"), true, wxNullBitmap ); - frame->m_panelWaterfall = new PlotWaterfall((wxFrame*) frame->m_auiNbookCtrl ); - frame->m_auiNbookCtrl->AddPage(frame->m_panelWaterfall, _("Waterfall"), true, wxNullBitmap ); + frame->m_panelDefaultB = new PlotPanel((wxFrame*) frame->m_auiNbookCtrl ); + frame->m_auiNbookCtrl->AddPage(frame->m_panelDefaultB, _("Waterfall"), true, wxNullBitmap ); + +// frame->m_panelSpectrum = new PlotSpectrum((wxFrame*) frame->m_auiNbookCtrl ); +// frame->m_auiNbookCtrl->AddPage(frame->m_panelSpectrum, _("Spectrum"), true, wxNullBitmap ); + +// frame->m_panelWaterfall = new PlotWaterfall((wxFrame*) frame->m_auiNbookCtrl ); +// frame->m_auiNbookCtrl->AddPage(frame->m_panelWaterfall, _("Waterfall"), true, wxNullBitmap ); // frame->m_panelScatter = new PlotScatter((wxFrame*) frame->m_auiNbookCtrl ); // frame->m_auiNbookCtrl->AddPage(frame->m_panelWaterfall, _("Scatter"), true, wxNullBitmap ); diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 516a4def..c372752a 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -70,7 +70,8 @@ class MainFrame : public TopFrame public: MainFrame(wxWindow *parent); virtual ~MainFrame(); - PlotPanel* m_panelDefault; + PlotPanel* m_panelDefaultA; + PlotPanel* m_panelDefaultB; PlotSpectrum* m_panelSpectrum; PlotWaterfall* m_panelWaterfall; PlotScatter* m_panelScatter; diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index 55810aed..a54fc485 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -12,13 +12,6 @@ #include "fdmdv2_main.h" #include "fdmdv2_plot.h" -#define wxUSE_FILEDLG 1 -#define wxUSE_LIBPNG 1 -#define wxUSE_LIBJPEG 1 -#define wxUSE_GIF 1 -#define wxUSE_PCX 1 -#define wxUSE_LIBTIFF 1 - BEGIN_EVENT_TABLE(PlotPanel, wxPanel) EVT_PAINT (PlotPanel::OnPaint) EVT_MOTION (PlotPanel::OnMouseMove) @@ -27,7 +20,6 @@ BEGIN_EVENT_TABLE(PlotPanel, wxPanel) EVT_MOUSEWHEEL (PlotPanel::OnMouseWheelMoved) EVT_SIZE (PlotPanel::OnSize) EVT_SHOW (PlotPanel::OnShow) -// EVT_ERASE_BACKGROUND(PlotPanel::OnErase) END_EVENT_TABLE() //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= @@ -42,12 +34,12 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent) m_mouseDown = false; m_penShortDash = wxPen(wxColor(0xA0, 0xA0, 0xA0), 1, wxPENSTYLE_SHORT_DASH); m_penDotDash = wxPen(wxColor(0xD0, 0xD0, 0xD0), 1, wxPENSTYLE_DOT_DASH); - m_gridLeftOffset = 10; - m_gridRightOffset = 10; - m_gridTopOffset = 10; - m_gridBottomOffset = 10; +// m_gridLeftOffset = 20; +// m_gridRightOffset = 5; +// m_gridTopOffset = 5; +// m_gridBottomOffset = 10; + SetBackgroundStyle(wxBG_STYLE_PAINT); SetLabelSize(10.0); - paintNow(); } //------------------------------------------------------------------------- @@ -67,11 +59,11 @@ void PlotPanel::SetLabelSize(double size) } //------------------------------------------------------------------------- -// OnActivate() +// OnShow() //------------------------------------------------------------------------- void PlotPanel::OnShow(wxShowEvent& event) { - paintNow(); + this->Refresh(); } //------------------------------------------------------------------------- @@ -89,7 +81,7 @@ void PlotPanel::OnSize(wxSizeEvent& event) { if(m_bitmap) { - paintNow(); + this->Refresh(); } } @@ -147,41 +139,35 @@ double PlotPanel::GetZoomFactor(double zf) return m_zoomFactor; } -#define PLOT_BORDER 10 -#define XLEFT_OFFSET 0 -#define YBOTTOM_OFFSET 25 -#define GRID_INCREMENT 50 -#define GREY_COLOR wxColor(0x80, 0x80, 0x80) -#define BLACK_COLOR wxColor(0x00, 0x00, 0x00) - //------------------------------------------------------------------------- -// render() Temporary. Subclass for each view, overide this as needed. +// drawGraticule() //------------------------------------------------------------------------- -void PlotPanel::render(wxDC& dc) +void PlotPanel::drawGraticule(wxAutoBufferedPaintDC& dc) { + int p; + char buf[15]; + wxString s; + m_rectCtrl = GetClientRect(); m_rectGrid = m_rectCtrl; - m_rectGrid.Deflate(PLOT_BORDER, (PLOT_BORDER + (YBOTTOM_OFFSET/2))); - m_rectGrid.Offset(PLOT_BORDER, PLOT_BORDER); + m_rectGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); + //m_rectGrid.Offset(PLOT_BORDER + (XLEFT_OFFSET), PLOT_BORDER); + m_rectGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); int h = m_rectGrid.GetHeight(); int w = m_rectGrid.GetWidth(); - int p; - char buf[15]; - wxString s; - dc.Clear(); // Draw a filled rectangle with aborder dc.SetBrush(*wxBLUE_BRUSH); dc.SetPen(wxPen(BLACK_COLOR, 2)); - dc.DrawRectangle(PLOT_BORDER, PLOT_BORDER, w, h); + dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, w, h); // Vertical gridlines dc.SetPen(m_penShortDash); - for(p = (PLOT_BORDER + GRID_INCREMENT); p < w; p += GRID_INCREMENT) + for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < w; p += GRID_INCREMENT) { dc.DrawLine(p, (h + PLOT_BORDER), p, PLOT_BORDER); } @@ -189,17 +175,25 @@ void PlotPanel::render(wxDC& dc) dc.SetPen(m_penDotDash); for(p = (h - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) { - dc.DrawLine(PLOT_BORDER, (p + PLOT_BORDER), (w + PLOT_BORDER), (p + PLOT_BORDER)); + dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (p + PLOT_BORDER), (w + PLOT_BORDER + XLEFT_OFFSET), (p + PLOT_BORDER)); } // Label the X-Axis dc.SetPen(wxPen(GREY_COLOR, 1)); for(p = GRID_INCREMENT; p < (w - YBOTTOM_OFFSET); p += GRID_INCREMENT) { sprintf(buf, "%1.1f Hz",(double)(p / 10)); - dc.DrawText(buf, p - PLOT_BORDER, h + YBOTTOM_OFFSET/2); + dc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, h + YBOTTOM_OFFSET/2); } } +//------------------------------------------------------------------------- +// draw() +//------------------------------------------------------------------------- +void PlotPanel::draw(wxAutoBufferedPaintDC& dc) +{ + drawGraticule(dc); +} + //------------------------------------------------------------------------- // paintEvent() // @@ -209,8 +203,8 @@ void PlotPanel::render(wxDC& dc) //------------------------------------------------------------------------- void PlotPanel::OnPaint(wxPaintEvent & evt) { - wxPaintDC dc(this); - render(dc); + wxAutoBufferedPaintDC dc(this); + draw(dc); } //------------------------------------------------------------------------- @@ -227,12 +221,9 @@ void PlotPanel::OnPaint(wxPaintEvent & evt) // paint events and calling Refresh() when a refresh is needed // will do the job. //------------------------------------------------------------------------- -void PlotPanel::paintNow() -{ - wxClientDC dc(this); - render(dc); -} - -// general purpose way of plotting scalar values that are -// updated once per frame - +//void PlotPanel::paintNow() +//{ +// wxClientDC dc(this); +// draw(dc); +// draw(); +//} diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index d7d5ded4..f5108739 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -13,6 +13,26 @@ //#include "fdmdv.h" #include #include +#include + +#define wxUSE_FILEDLG 1 +#define wxUSE_LIBPNG 1 +#define wxUSE_LIBJPEG 1 +#define wxUSE_GIF 1 +#define wxUSE_PCX 1 +#define wxUSE_LIBTIFF 1 + +#define PLOT_BORDER 2 +#define XLEFT_OFFSET 20 +#define YBOTTOM_OFFSET 25 +#define GRID_INCREMENT 50 +#define GREY_COLOR wxColor(0x80, 0x80, 0x80) +#define BLACK_COLOR wxColor(0x00, 0x00, 0x00) +#define BLUE_COLOR wxColor(0x00, 0x00, 0xFF) +#define GREEN_COLOR wxColor(0xFF, 0x00, 0xFF) +#define RED_COLOR wxColor(0xFF, 0x00, 0x00) +#define YELLOW_COLOR wxColor(0x00, 0xFF, 0x00) + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class PlotPanel @@ -21,54 +41,55 @@ class PlotPanel : public wxPanel { public: PlotPanel(wxFrame* parent); - void paintEvent(wxPaintEvent & evt); - void paintNow(); - void render(wxDC& dc); - wxPen m_penShortDash; - wxPen m_penDotDash; - wxRect m_rectCtrl; - wxRect m_rectGrid; - wxRect m_rectPlot; - int m_gridLeftOffset; - int m_gridRightOffset; - int m_gridTopOffset; - int m_gridBottomOffset; - double m_label_size; - wxBitmap *m_bmp; + void paintEvent(wxPaintEvent & evt); + void draw(wxAutoBufferedPaintDC& dc); + void drawGraticule(wxAutoBufferedPaintDC& dc); + wxPen m_penShortDash; + wxPen m_penDotDash; + wxRect m_rectCtrl; + wxRect m_rectGrid; + wxRect m_rectPlot; +// int m_gridLeftOffset; +// int m_gridRightOffset; +// int m_gridTopOffset; +// int m_gridBottomOffset; + double m_label_size; + wxSize m_Bufsz; + wxBitmap *m_bmp; + wxImagePixelData *m_pBmp; //wxNativePixelData *m_pBmp; //wxAlphaPixelData *m_pBmp; - wxImagePixelData *m_pBmp; // some useful events - void OnMouseMove(wxMouseEvent& event); - void OnMouseDown(wxMouseEvent& event); - void OnMouseUp(wxMouseEvent& event); - void OnMouseWheelMoved(wxMouseEvent& event); - void OnPaint(wxPaintEvent& event); - void OnClose( wxCloseEvent& event ){ event.Skip(); } - void OnSize( wxSizeEvent& event ); - void OnErase(wxEraseEvent& event); - double SetZoomFactor(double zf); - double GetZoomFactor(double zf); + void OnMouseMove(wxMouseEvent& event); + void OnMouseDown(wxMouseEvent& event); + void OnMouseUp(wxMouseEvent& event); + void OnMouseWheelMoved(wxMouseEvent& event); + void OnClose(wxCloseEvent& event ){ event.Skip(); } + void OnSize( wxSizeEvent& event ); + void OnErase(wxEraseEvent& event); + void OnPaint(wxPaintEvent& event); + double SetZoomFactor(double zf); + double GetZoomFactor(double zf); //void OnUpdateUI( wxUpdateUIEvent& event ){ event.Skip(); } - void OnShow(wxShowEvent& event); - double GetLabelSize(); - void SetLabelSize(double size); + void OnShow(wxShowEvent& event); + double GetLabelSize(); + void SetLabelSize(double size); protected: - int m_x; - int m_y; - int m_w; - int m_h; - int m_prev_w; - int m_prev_h; - int m_prev_x; - int m_prev_y; - bool m_bitmap; - bool m_clip; - bool m_rubberBand; - bool m_mouseDown; - double m_zoomFactor; + int m_x; + int m_y; + int m_w; + int m_h; + int m_prev_w; + int m_prev_h; + int m_prev_x; + int m_prev_y; + bool m_bitmap; + bool m_clip; + bool m_rubberBand; + bool m_mouseDown; + double m_zoomFactor; DECLARE_EVENT_TABLE() }; #endif //__FDMDV2_PLOT__ diff --git a/fdmdv2/src/fdmdv2_plot_scalar.cpp b/fdmdv2/src/fdmdv2_plot_scalar.cpp new file mode 100644 index 00000000..3ccfb423 --- /dev/null +++ b/fdmdv2/src/fdmdv2_plot_scalar.cpp @@ -0,0 +1,222 @@ +//========================================================================== +// Name: fdmdv2_plot_scalar.cpp +// Purpose: Implements a waterfall plot derivative of fdmdv2_plot. +// Created: June 22, 2012 +// Initial author: David Witten +// Derived from: code written by David Rowe +// License: +// +// Copyright (C) 2012 David Witten +// +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License version 2.1, +// as published by the Free Software Foundation. This program is +// distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, see . +// +//========================================================================== +#include +#include "wx/wx.h" +#include "fdmdv2_main.h" +#include "fdmdv2_plot_scalar.h" + +BEGIN_EVENT_TABLE(PlotScalar, PlotPanel) + EVT_PAINT (PlotScalar::OnPaint) + EVT_MOTION (PlotScalar::OnMouseMove) + EVT_LEFT_DOWN (PlotScalar::OnMouseDown) + EVT_LEFT_UP (PlotScalar::OnMouseUp) + EVT_MOUSEWHEEL (PlotScalar::OnMouseWheelMoved) + EVT_SIZE (PlotScalar::OnSize) + EVT_SHOW (PlotScalar::OnShow) +// EVT_ERASE_BACKGROUND(PlotScalar::OnErase) +END_EVENT_TABLE() + +//---------------------------------------------------------------- +// +//---------------------------------------------------------------- +//PlotScalar::PlotScalar(wxFrame* parent, int x, int y, int w, int h, int x_max_, int y_max_, const char name[]): PlotPanel(parent) +PlotScalar::PlotScalar(wxFrame* parent, int x_max_, int y_max_): PlotPanel(parent) +{ + int i; + + //align(FL_ALIGN_TOP); + //labelsize(10); + + m_x_max = x_max_; + m_y_max = y_max_; + m_mem = new float[m_x_max]; + + for(i = 0; i < m_x_max; i++) + { + m_mem[i] = 0.0; + } + m_prev_w = 0; + m_prev_h = 0; + m_prev_x = 0; + m_prev_y = 0; + m_index = 0; +} + +//---------------------------------------------------------------- +// +//---------------------------------------------------------------- +PlotScalar::~PlotScalar() +{ + delete m_mem; +} + +//---------------------------------------------------------------- +// +//---------------------------------------------------------------- +void PlotScalar::add_new_sample(float sample) +{ + m_new_sample = sample; +} + +//---------------------------------------------------------------- +// +//---------------------------------------------------------------- +int PlotScalar::clip(int y1) +{ + if(y1 > (m_h/2 - 10)) + { + y1 = m_h/2 - 10; + } + if(y1 < -(m_h/2 - 10)) + { + y1 = -(m_h/2 - 10); + } + return y1; +} + +//---------------------------------------------------------------- +// +//---------------------------------------------------------------- +void PlotScalar::draw(wxAutoBufferedPaintDC& dc) +{ + float x_scale; + float y_scale; + int i; + int x1; + int y1; + int x2; + int y2; + char label[100]; + +// PlotPanel::draw(); + + /* detect resizing of window */ + if((m_h != m_prev_h) || (m_w != m_prev_w) || (m_x != m_prev_x) || (m_y != m_prev_y)) + { + //fl_color(FL_BLACK); + //fl_rectf(m_x, m_y, m_w, m_h); + m_prev_h = m_h; + m_prev_w = m_w; + m_prev_x = m_x; + m_prev_y = m_y; + } + + //fl_push_clip(m_x, m_y, m_w, m_h); + x_scale = (float)m_x_max; + y_scale = (float)m_h /(2.0 * m_y_max); + + // erase last sample + //fl_color(FL_BLACK); + x1 = x_scale * m_index + m_x; + y1 = y_scale * m_mem[m_index]; + y1 = clip(y1); + y1 = m_y + m_h/2 - y1; + //fl_point(x1, y1); + + // draw new sample + //fl_color(FL_GREEN); + x1 = x_scale * m_index + m_x; + y1 = y_scale * m_new_sample; + y1 = clip(y1); + y1 = m_y + m_h/2 - y1; +// fl_point(x1, y1); + m_mem[m_index] = m_new_sample; + m_index++; + if(m_index >= m_x_max) + { + m_index = 0; + } + + // y axis graticule + m_step = 10; + while((2.0 * m_y_max/m_step) > 10) + { + m_step *= 2.0; + } + while((2.0 * m_y_max/m_step) < 4) + { + m_step /= 2.0; + } + // fl_color(FL_DARK_GREEN); + // fl_line_style(FL_DOT); + for(i =- m_y_max; i < m_y_max; i += m_step) + { + x1 = m_x; + y1 = m_y + m_h/2 - i * y_scale; + x2 = m_x + m_w; + y2 = y1; + //fl_line(x1, y1, x2, y2); + } + + // y axis graticule labels + // fl_color(FL_GREEN); + // fl_line_style(FL_SOLID); + for(i =- m_y_max; i < m_y_max; i += m_step) + { + x1 = m_x; + y1 = m_y + m_h/2 - i * y_scale; + sprintf(label, "%d", i); + //fl_draw(label, x1, y1); + } + //fl_pop_clip(); +} + +// // update average of each spectrum point +// void new_data(float mag_dB[]) +// { +// int i; +// +// for(i=0; i. +// +//========================================================================== +#ifndef __FDMDV2_PLOT_SCALAR__ +#define __FDMDV2_PLOT_SCALAR__ + +#include "fdmdv2_plot.h" +#include "fdmdv2_defines.h" + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// Class PlotScalar +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +class PlotScalar: public PlotPanel +{ + public: + + //PlotScalar(wxFrame* parent, int x, int y, int w, int h, int x_max_, int y_max_, const char name[]); + PlotScalar(wxFrame* parent, int x_max_, int y_max_); + ~PlotScalar(); + void add_new_sample(float sample); + + protected: + + int m_x_max; + int m_y_max; + float *m_mem; /* array of x_max samples */ + float m_new_sample; + int m_index; + int m_step; + + int clip(int y1); + void draw(wxAutoBufferedPaintDC& dc); + void OnPaint(wxPaintEvent& event); + void OnSize(wxSizeEvent& event); + void OnShow(wxShowEvent& event); + + DECLARE_EVENT_TABLE() +}; + +//// update average of each spectrum point +//void new_data(float mag_dB[]) +//{ +// int i; +// +// for(i=0; i x()) && (Fl::event_x() < (x() + w())) && (Fl::event_y() > y()) && (Fl::event_y() < (y() + h()))) - { - // show zoomed spectrum window - zoomSpectrumWindow->show(); - } - } -*/ - return 0; -} - -//---------------------------------------------------------------- -// -//---------------------------------------------------------------- -void PlotSpectrum::draw() +void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc) { float x_px_per_point = 0.0; float y_px_per_dB = 0.0; @@ -82,7 +61,8 @@ void PlotSpectrum::draw() int y2; float mag1, mag2; char label[20]; - float px_per_hz; + float px_per_hz; + /* Fl_Box::draw(); fl_color(FL_BLACK); @@ -93,12 +73,16 @@ void PlotSpectrum::draw() fl_push_clip(x(),y(),w(),h()); //printf("%d %d\n", w(), h()); */ + dc.SetBrush(*wxBLUE_BRUSH); + dc.SetPen(wxPen(YELLOW_COLOR, 2)); + dc.DrawRectangle(PLOT_BORDER, PLOT_BORDER, m_w, m_h); + x_px_per_point = (float)m_w / FDMDV_NSPEC; y_px_per_dB = (float)m_h / (MAX_DB - MIN_DB); // plot spectrum - for(i=0; iIsOk()) + { + delete m_bmp; + } } +/* //---------------------------------------------------------------- // new_pixel_buf() //---------------------------------------------------------------- void PlotWaterfall::new_pixel_buf(int w, int h) { - int buf_sz; - int i; - - prev_w = w; - prev_h = h; - buf_sz = h * w; - - // pixel_buf = new unsigned[buf_sz]; - //for(i = 0; i < buf_sz; i++) - //{ - // pixel_buf[i] = 0; - //} +// int i; + + m_prev_w = w; + m_prev_h = h; + +// wxMemoryDC m_memDC = new wxMemoryDC(); + if(m_bmp->IsOk()) + { + delete m_bmp; + //m_Bufsz = h * w; + + //m_img = new wxImage(sz, pdata, alpha,false); + m_bmp = new wxBitmap(w, h, wxBITMAP_SCREEN_DEPTH); + //m_pBmp = m_bmp->GetBitmapData(); + } +// pixel_buf = new unsigned[buf_sz]; +// for(i = 0; i < buf_sz; i++) +// { +// pixel_buf[i] = 0; +// } } //---------------------------------------------------------------- @@ -103,7 +111,6 @@ void PlotWaterfall::new_pixel_buf(int w, int h) int PlotWaterfall::handle(int event) { // detect a left mouse down if inside the window -/* if ((event == FL_NO_EVENT) && (Fl::event_button() == 1)) { if ((Fl::event_x() > x()) && (Fl::event_x() < (x() + w())) && (Fl::event_y() > y()) && (Fl::event_y() < (y() + h()))) @@ -112,9 +119,9 @@ int PlotWaterfall::handle(int event) zoomWaterfallWindow->show(); } } -*/ return 0; } +*/ //---------------------------------------------------------------- // heatmap() @@ -155,7 +162,7 @@ unsigned PlotWaterfall::heatmap(float val, float min, float max) //---------------------------------------------------------------- // draw() //---------------------------------------------------------------- -void PlotWaterfall::draw() +void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) { float spec_index_per_px; float intensity_per_dB; @@ -172,12 +179,35 @@ void PlotWaterfall::draw() unsigned *pdest; unsigned *psrc; + m_rectCtrl = GetClientRect(); + m_rectGrid = m_rectCtrl; + + m_rectGrid.Deflate(PLOT_BORDER, (PLOT_BORDER + (YBOTTOM_OFFSET/2))); + m_rectGrid.Offset(PLOT_BORDER, PLOT_BORDER); + + int m_h = m_rectGrid.GetHeight(); + int m_w = m_rectGrid.GetWidth(); + /* detect resizing of window */ +/* if ((m_h != m_prev_h) || (m_w != m_prev_w)) { - delete pixel_buf; + //delete m_pBmp; new_pixel_buf(m_w, m_h); - } + } +*/ + //int p; + //char buf[15]; + wxString s; + + dc.Clear(); +// PlotPanel::draw(dc); + + // Draw a filled rectangle with aborder + dc.SetBrush(*wxBLUE_BRUSH); + dc.SetPen(wxPen(GREEN_COLOR, 2)); + dc.DrawRectangle(PLOT_BORDER, PLOT_BORDER, m_w, m_h); + // Fl_Box::draw(); // determine dy, the height of one "block" px_per_sec = (float)m_h / WATERFALL_SECS_Y; @@ -212,7 +242,7 @@ void PlotWaterfall::draw() { for(py = 0; py < dy; py++) { - last_row[px + py * m_w] = intensity<<8; + last_row[px + py * m_w] = intensity << 8; } } else @@ -224,7 +254,49 @@ void PlotWaterfall::draw() } } // update bit map - //fl_draw_image((unsigned char*)pixel_buf, m_x, m_y, m_w, m_h, 4, 0); + //fl_draw_image((unsigned char*)pixel_buf, m_x, m_y, m_w, m_h, 4, 0); + //dc.DrawLines(4, m_pBmp, 0, 0 ); } - +//---------------------------------------------------------------- +// paintNow() +//---------------------------------------------------------------- +void PlotWaterfall::paintNow() +{ +// wxClientDC dc(this); +// draw(dc); +// draw(); +} + +//---------------------------------------------------------------- +// paintEvent() +// +// Called by the system of by wxWidgets when the panel needs +// to be redrawn. You can also trigger this call by calling +// Refresh()/Update(). +//---------------------------------------------------------------- +void PlotWaterfall::OnPaint(wxPaintEvent & evt) +{ + wxAutoBufferedPaintDC dc(this); + draw(dc); +} + +//---------------------------------------------------------------- +// OnSize() +//---------------------------------------------------------------- +void PlotWaterfall::OnSize(wxSizeEvent& event) +{ + if(m_bitmap) + { + this->Refresh(); + } +} + +//---------------------------------------------------------------- +// OnShow() +//---------------------------------------------------------------- +void PlotWaterfall::OnShow(wxShowEvent& event) +{ +// wxAutoBufferedPaintDC dc(this); +// draw(); +} diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.h b/fdmdv2/src/fdmdv2_plot_waterfall.h index 5d629e41..ee56df24 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall.h +++ b/fdmdv2/src/fdmdv2_plot_waterfall.h @@ -34,23 +34,21 @@ class PlotWaterfall : public PlotPanel { public: - //PlotWaterfall(int x, int y, int w, int h); - //PlotWaterfall(wxFrame* parent, int x, int y, int w, int h, const char name[]); PlotWaterfall(wxFrame* parent); ~PlotWaterfall(); protected: - int prev_w; - int prev_h; unsigned *pixel_buf; unsigned heatmap_lut[256]; int greyscale; - void new_pixel_buf(int w, int h); - int handle(int event); - unsigned heatmap(float val, float min, float max); - void draw(); - + unsigned heatmap(float val, float min, float max); + void draw(wxAutoBufferedPaintDC& dc); + + void OnPaint(wxPaintEvent & evt); + void OnSize(wxSizeEvent& event); + void OnShow(wxShowEvent& event); + void paintNow(); DECLARE_EVENT_TABLE() }; diff --git a/fdmdv2/src/fdmdv2_scalar.cpp b/fdmdv2/src/fdmdv2_scalar.cpp deleted file mode 100644 index e0ed6cff..00000000 --- a/fdmdv2/src/fdmdv2_scalar.cpp +++ /dev/null @@ -1,169 +0,0 @@ -//========================================================================== -// Name: fdmdv2_plot_waterfall.cpp -// Purpose: Implements a waterfall plot derivative of fdmdv2_plot. -// Created: June 22, 2012 -// Initial author: David Witten -// Derived from: code written by David Rowe -// License: -// -// Copyright (C) 2012 David Witten -// -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License version 2.1, -// as published by the Free Software Foundation. This program is -// distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -// License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, see . -// -//========================================================================== -#include -#include "wx/wx.h" -#include "fdmdv2_main.h" -#include "fdmdv2_plot.h" -#include "fdmdv2_scalar.h" - -Scalar::Scalar(wxFrame* parent, int x, int y, int w, int h, int x_max_, int y_max_, const char name[]): DrawPanel(parent) -{ - int i; - - //align(FL_ALIGN_TOP); - //labelsize(10); - - m_x_max = x_max_; - m_y_max = y_max_; - m_mem = new float[m_x_max]; - - for(i = 0; i < m_x_max; i++) - { - m_mem[i] = 0.0; - } - m_prev_w = 0; - m_prev_h = 0; - m_prev_x = 0; - m_prev_y = 0; - m_index = 0; -} - -Scalar::~Scalar() -{ - delete m_mem; -} - -void Scalar::add_new_sample(float sample) -{ - m_new_sample = sample; -} - -int Scalar::clip(int y1) -{ - if(y1 > (m_h/2 - 10)) - { - y1 = m_h/2 - 10; - } - if(y1 < -(m_h/2 - 10)) - { - y1 = -(m_h/2 - 10); - } - return y1; -} - -void Scalar::draw() -{ - float x_scale; - float y_scale; - int i; - int x1; - int y1; - int x2; - int y2; - char label[100]; - -// DrawPanel::draw(); - - /* detect resizing of window */ - if((m_h != m_prev_h) || (m_w != m_prev_w) || (m_x != m_prev_x) || (m_y != m_prev_y)) - { - //fl_color(FL_BLACK); - //fl_rectf(m_x, m_y, m_w, m_h); - m_prev_h = m_h; - m_prev_w = m_w; - m_prev_x = m_x; - m_prev_y = m_y; - } - - //fl_push_clip(m_x, m_y, m_w, m_h); - x_scale = (float)m_x_max; - y_scale = (float)m_h /(2.0 * m_y_max); - - // erase last sample - //fl_color(FL_BLACK); - x1 = x_scale * m_index + m_x; - y1 = y_scale * m_mem[m_index]; - y1 = clip(y1); - y1 = m_y + m_h/2 - y1; - //fl_point(x1, y1); - - // draw new sample - //fl_color(FL_GREEN); - x1 = x_scale * m_index + m_x; - y1 = y_scale * m_new_sample; - y1 = clip(y1); - y1 = m_y + m_h/2 - y1; -// fl_point(x1, y1); - m_mem[m_index] = m_new_sample; - m_index++; - if(m_index >= m_x_max) - { - m_index = 0; - } - - // y axis graticule - m_step = 10; - while((2.0 * m_y_max/m_step) > 10) - { - m_step *= 2.0; - } - while((2.0 * m_y_max/m_step) < 4) - { - m_step /= 2.0; - } - // fl_color(FL_DARK_GREEN); - // fl_line_style(FL_DOT); - for(i =- m_y_max; i < m_y_max; i += m_step) - { - x1 = m_x; - y1 = m_y + m_h/2 - i * y_scale; - x2 = m_x + m_w; - y2 = y1; - //fl_line(x1, y1, x2, y2); - } - - // y axis graticule labels - // fl_color(FL_GREEN); - // fl_line_style(FL_SOLID); - for(i =- m_y_max; i < m_y_max; i += m_step) - { - x1 = m_x; - y1 = m_y + m_h/2 - i * y_scale; - sprintf(label, "%d", i); - //fl_draw(label, x1, y1); - } - //fl_pop_clip(); -} - -// // update average of each spectrum point -// void new_data(float mag_dB[]) -// { -// int i; -// -// for(i=0; i. -// -//========================================================================== -#ifndef __FDMDV2_PLOT_SCALAR__ -#define __FDMDV2_PLOT_SCALAR__ - - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -// Class Scalar -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -class Scalar: public DrawPanel -{ -public: - - Scalar(wxFrame* parent, int x, int y, int w, int h, int x_max_, int y_max_, const char name[]); - ~Scalar(); - void add_new_sample(float sample); - -protected: - - int m_x_max; - int m_y_max; - float *m_mem; /* array of x_max samples */ - float m_new_sample; - int m_index; - int m_step; - - int clip(int y1); - void draw(); -}; - -//// update average of each spectrum point -//void new_data(float mag_dB[]) -//{ -// int i; -// -// for(i=0; i