spectrum plot drawGraticule() working OK with nice labels
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 23 Oct 2012 21:03:44 +0000 (21:03 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 23 Oct 2012 21:03:44 +0000 (21:03 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@798 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/Makefile.linux
fdmdv2/src/fdmdv2_defines.h
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_plot.cpp
fdmdv2/src/fdmdv2_plot.h
fdmdv2/src/fdmdv2_plot_spectrum.cpp
fdmdv2/src/fdmdv2_plot_spectrum.h

index 8af2e7b75affaa0635a8934f2c1bbe83e5ba165d..8c37f6bda10ac93fb698d013372164d81cc7a429 100644 (file)
@@ -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
 
index aa13ddb758fac9f28701cbd9f447493912e79fa6..637bd890b978ca13317a44b61003a548a2710bec 100644 (file)
 
 #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 
 #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)
index 2d536713ee73f6410ab0dc595bd20394ee5688d9..9c8182e22ac72bc74886b27621233b6c5cd92d4b 100644 (file)
@@ -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);
index c95ba7648c4e763aadf1cf8dfec504611795e352..26d5cae2a2235cf5f9fc7ee8ccaa7c716c41b0b8 100644 (file)
@@ -63,7 +63,7 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent)
 //-------------------------------------------------------------------------
 PlotPanel::~PlotPanel()
 {
-    if(!m_pBmp->IsNull())
+    if(m_pBmp != NULL)
     {
         delete m_pBmp;
     }
index 5c7f8e8101a2e59724c7e6eaff5d8f128a3c2fb7..fb220e492dda0ec2b9f5f110dd059c2fc0e85d1a 100644 (file)
 #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)
index c04e6d0db38f71a85c1b51bfe765e7faa35111c1..2f278681982aa0f8330a8d2dd4c7cb228c8cca07 100644 (file)
@@ -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<MAX_HZ; f+=STEP_HZ) {
+       x = f*freq_hz_to_px;
+       x += PLOT_BORDER + XLEFT_OFFSET;
+        dc.DrawLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, PLOT_BORDER);
+        sprintf(buf, "%4.0fHz", f);
+       GetTextExtent(buf, &text_w, &text_h);
+        dc.DrawText(buf, x - text_w/2, m_rGrid.GetHeight() + PLOT_BORDER + YBOTTOM_TEXT_OFFSET);
+    }
 
     // Horizontal gridlines
-    dc.SetPen(m_penDotDash);
-    for(p = 0; (y_zero + p) < m_rGrid.GetHeight() ; p += GRID_INCREMENT)
-    {
-        if(p > 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<MAX_DB; dB+=STEP_DB) {
+       y = m_rGrid.GetHeight() + dB*ampl_dB_to_px;
+       y += PLOT_BORDER;
+       dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y, 
+                   (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y);
+        sprintf(buf, "%3.0fdB", dB);
+       GetTextExtent(buf, &text_w, &text_h);
+        dc.DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2);
+   }
 
-    // Label the X-Axis
-    dc.SetPen(wxPen(GREY_COLOR, 1));
-    for(p = GRID_INCREMENT; p < (m_rCtrl.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT)
-    {
-        sprintf(buf, "%1.1f Hz",(double)(p / 10));
-        dc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rCtrl.GetHeight() + YBOTTOM_OFFSET/2);
-    }
-}
 
-//----------------------------------------------------------------
-// OnPaint()
-//----------------------------------------------------------------
-void PlotSpectrum::OnPaint(wxPaintEvent& event)
-{
-    wxAutoBufferedPaintDC dc(this);
-    draw(dc);
 }
 
-//----------------------------------------------------------------
-// OnShow()
-//----------------------------------------------------------------
-void PlotSpectrum::OnShow(wxShowEvent& event)
-{
-//   wxAutoBufferedPaintDC dc(this);
-//   draw(dc);
-}
index 03e51b2c57897af125f917c4a81da3cf00d79e56..a437a34548d3245d1e9b72c5846a10c106c1c53e 100644 (file)
@@ -41,8 +41,8 @@ class PlotSpectrum : public PlotPanel
         void        OnPaint(wxPaintEvent& event);
         void        OnSize(wxSizeEvent& event);
         void        OnShow(wxShowEvent& event);
-        void        drawGraticule(wxAutoBufferedPaintDC&  dc);
-        void        draw(wxAutoBufferedPaintDC&  dc);
+        void        drawGraticule(wxAutoBufferedPaintDC& dc);
+        void        draw(wxAutoBufferedPaintDC& dc);
 
         DECLARE_EVENT_TABLE()
 };