From 50e2068042aa1f8cb83bcf1a23b853efbb22a35c Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 23 Oct 2012 21:03:44 +0000 Subject: [PATCH] spectrum plot drawGraticule() working OK with nice labels git-svn-id: https://svn.code.sf.net/p/freetel/code@798 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/src/Makefile.linux | 11 +-- fdmdv2/src/fdmdv2_defines.h | 21 ++--- fdmdv2/src/fdmdv2_main.cpp | 8 +- fdmdv2/src/fdmdv2_plot.cpp | 2 +- fdmdv2/src/fdmdv2_plot.h | 3 +- fdmdv2/src/fdmdv2_plot_spectrum.cpp | 132 +++++++++++++++++----------- fdmdv2/src/fdmdv2_plot_spectrum.h | 4 +- 7 files changed, 106 insertions(+), 75 deletions(-) diff --git a/fdmdv2/src/Makefile.linux b/fdmdv2/src/Makefile.linux index 8af2e7b7..8c37f6bd 100644 --- a/fdmdv2/src/Makefile.linux +++ b/fdmdv2/src/Makefile.linux @@ -10,7 +10,7 @@ CODEC2_PATH=/home/david/codec2-dev WX_CONFIG=$(WX_GTK_PATH)/wx-config WX_CPPFLAGS = $(shell $(WX_CONFIG) --cxxflags) -WX_LIBS = $(shell $(WX_CONFIG) --libs core, base, aui) +WX_LIBS = $(shell $(WX_CONFIG) --libs core, base, aui, adv) CODEC2_INC=-I$(CODEC2_PATH)/src CODEC2_LIB=$(CODEC2_PATH)/src/.libs/libcodec2.a @@ -30,16 +30,17 @@ dlg_audio.o \ dlg_comports.o \ dlg_options.o +HDRS = fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h + all: fdmdv2 -fdmdv2: $(OBJS) fdmdv2_main.h +fdmdv2: $(OBJS) g++ -o fdmdv2 $(OBJS) $(CPP_FLAGS) $(LIBS) -fdmdv2_main.h: fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h - -%.o: %.cpp +%.o: %.cpp $(HDRS) g++ $(CPP_FLAGS) -c $< -o $@ + clean: rm -f *.o fdmdv2 diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index aa13ddb7..637bd890 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -32,13 +32,15 @@ #define FDMDV_NSPEC 512 -#define MIN_DB -40.0 +#define MIN_DB -40.0 // minimum of spectram/waterfall DB axis #define MAX_DB 0.0 +#define STEP_DB 10.0 #define BETA 0.1 // constant for time averageing spectrum data -#define MIN_HZ 0 -#define MAX_HZ 4000 +#define MIN_HZ 0 // min freq on Waterfall and Spectrum +#define MAX_HZ 4000 // max freq on Waterfall and Spectrum +#define STEP_HZ 500 // freq step on Waterfall and Spectrum graticule #define WATERFALL_SECS_Y 5 // number of seconds respresented by y axis of waterfall -#define DT 0.5 // time between samples +#define DT 0.1 // time between Waterfall updates #define FS 8000 // FDMDV modem sample rate // Scatter diagram @@ -47,16 +49,9 @@ #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 - // sample rate I/O & conversion constants -#define MAX_FPB 2048 // maximum value of framesPerBuffer -#define PA_FPB 512 // nominal value of framesPerBuffer +#define MAX_FPB 2048 // maximum value of portAudio framesPerBuffer +#define PA_FPB 512 // nominal value of portAudio framesPerBuffer #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) diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 2d536713..9c8182e2 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -161,7 +161,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) #ifdef _USE_TIMER Bind(wxEVT_TIMER, &MainFrame::OnTimer, this); // ID_MY_WINDOW); m_plotTimer.SetOwner(this, ID_TIMER_WATERFALL); - m_panelWaterfall->Refresh(); + //m_panelWaterfall->Refresh(); #endif #ifdef _USE_ONIDLE @@ -236,8 +236,8 @@ void MainFrame::OnTimer(wxTimerEvent &evt) { m_panelWaterfall->m_newdata = true; m_panelWaterfall->Refresh(); - //m_panelSpectrum->m_newdata = true; - //m_panelSpectrum->Refresh(); + m_panelSpectrum->m_newdata = true; + m_panelSpectrum->Refresh(); } #endif @@ -1245,10 +1245,12 @@ int MainFrame::rxCallback( } // test: echo input to output, make this loopback option + /* for(i=0; i < N8; i++) { in8k[MEM8+i] = out8k[i]; } + */ // Convert output speech to 48 kHz sample rate // upsample and update filter memory fdmdv_8_to_48(out48k, &in8k[MEM8], N8); diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index c95ba764..26d5cae2 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -63,7 +63,7 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent) //------------------------------------------------------------------------- PlotPanel::~PlotPanel() { - if(!m_pBmp->IsNull()) + if(m_pBmp != NULL) { delete m_pBmp; } diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index 5c7f8e81..fb220e49 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -30,10 +30,11 @@ #define wxUSE_PCX 1 #define wxUSE_LIBTIFF 1 -#define PLOT_BORDER 3 +#define PLOT_BORDER 8 #define XLEFT_OFFSET 30 #define XLEFT_TEXT_OFFSET 8 #define YBOTTOM_OFFSET 25 +#define YBOTTOM_TEXT_OFFSET 8 #define GRID_INCREMENT 50 #define BLACK_COLOR wxColor(0x00, 0x00, 0x00) diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index c04e6d0d..2f278681 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -26,7 +26,6 @@ #include "wx/wx.h" #include "fdmdv2_main.h" -#include "fdmdv2_plot_spectrum.h" extern float g_avmag[]; @@ -66,11 +65,57 @@ PlotSpectrum::~PlotSpectrum() { } +//---------------------------------------------------------------- +// OnSize() +//---------------------------------------------------------------- +void PlotSpectrum::OnSize(wxSizeEvent& event) { + printf("PlotSpectrum::OnSize\n"); +} + +//---------------------------------------------------------------- +// OnPaint() +//---------------------------------------------------------------- +void PlotSpectrum::OnPaint(wxPaintEvent& event) +{ + printf("PlotSpectrum::OnPaint\n"); + wxAutoBufferedPaintDC dc(this); + draw(dc); +} + +//---------------------------------------------------------------- +// OnShow() +//---------------------------------------------------------------- +void PlotSpectrum::OnShow(wxShowEvent& event) +{ +} + //---------------------------------------------------------------- // draw() //---------------------------------------------------------------- -void PlotSpectrum::draw(wxAutoBufferedPaintDC& pDC) +void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc) { + m_rCtrl = GetClientRect(); + + // m_rGrid is coords of inner window we actually plot to. We deflate it a bit + // to leave room for axis labels. + + m_rGrid = m_rCtrl; + m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); + + // black background + + m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight()); + wxBrush ltGraphBkgBrush = wxBrush(BLACK_COLOR); + dc.SetBrush(ltGraphBkgBrush); + dc.SetPen(wxPen(BLACK_COLOR, 0)); + dc.DrawRectangle(m_rPlot); + + // graticule + + drawGraticule(dc); + +#ifdef OLD + wxMemoryDC m_mDC; m_mDC.SelectObject(*m_pBmp); m_rCtrl = GetClientRect(); @@ -123,6 +168,7 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& pDC) } m_mDC.SetBrush(wxNullBrush); m_mDC.SelectObject(wxNullBitmap); +#endif } //------------------------------------------------------------------------- @@ -130,63 +176,49 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& pDC) //------------------------------------------------------------------------- void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) { - int p; - char buf[15]; + int x, y, text_w, text_h; + char buf[15]; wxString s; - //int h_mod_inc = 0; + float f, dB, freq_hz_to_px, ampl_dB_to_px; + + wxBrush ltGraphBkgBrush; + ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT); + ltGraphBkgBrush.SetColour(*wxBLACK); + dc.SetBrush(ltGraphBkgBrush); + dc.SetPen(wxPen(BLACK_COLOR, 1)); + + freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_HZ-MIN_HZ); + ampl_dB_to_px = (float)m_rGrid.GetHeight()/(MAX_DB-MIN_DB); + + // upper LH coords of plot area are (PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER) + // lower RH coords of plot area are (PLOT_BORDER + XLEFT_OFFSET + m_rGrid.GetWidth(), + // PLOT_BORDER + m_rGrid.GetHeight()) // Vertical gridlines + dc.SetPen(m_penShortDash); - for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rGrid.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT) - { - dc.DrawLine(p, (m_rGrid.GetHeight() + PLOT_BORDER), p, PLOT_BORDER); - } - int y_zero = (m_rGrid.GetHeight() - m_top) / 2 ; - dc.SetPen(m_penSolid); - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y_zero, (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y_zero); - sprintf(buf, "%6.0f", 0.0); - dc.DrawText(buf, XLEFT_TEXT_OFFSET, y_zero + TEXT_BASELINE_OFFSET_Y); + for(f=STEP_HZ; f 0) - { - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero + p), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero + p)); - sprintf(buf, "%6.0f", (double)(p) * -10); - dc.DrawText(buf, XLEFT_TEXT_OFFSET, (y_zero + p + TEXT_BASELINE_OFFSET_Y)); - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero - p), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero - p)); - sprintf(buf, "%6.0f", (double)(p) * 10); - dc.DrawText(buf, XLEFT_TEXT_OFFSET, (y_zero - p + TEXT_BASELINE_OFFSET_Y)); - } - } + for(dB=MIN_DB; dB