From 1c64a10632a2c0e60037e08ead088d4b3e55696e Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 24 Oct 2012 00:50:22 +0000 Subject: [PATCH] renamed a few variables for consistency, spectrum now working git-svn-id: https://svn.code.sf.net/p/freetel/code@802 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/src/fdmdv2_defines.h | 6 +- fdmdv2/src/fdmdv2_plot_spectrum.cpp | 89 +++++++++------------- fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp | 33 +------- 3 files changed, 41 insertions(+), 87 deletions(-) diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index 96bc9c41..9b5cac7d 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -32,9 +32,9 @@ #define FDMDV_NSPEC 512 -#define MIN_AMP_DB -40.0 // min of spectrogram/waterfall amplitude axis -#define MAX_AMP_DB 0.0 // max of spectrogram/waterfall amplitude axis -#define STEP_AMP_DB 5.0 // amplitude axis step +#define MIN_MAG_DB -40.0 // min of spectrogram/waterfall magnitude axis +#define MAX_MAG_DB 0.0 // max of spectrogram/waterfall magnitude axis +#define STEP_MAG_DB 5.0 // magnitude axis step #define BETA 0.1 // constant for time averageing spectrum data #define MIN_F_HZ 0 // min freq on Waterfall and Spectrum #define MAX_F_HZ 4000 // max freq on Waterfall and Spectrum diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index 263f8697..2fcc0a13 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -95,7 +95,8 @@ 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. + // to leave room for axis labels. We need to work this out every time we draw + // as window may have been resized m_rGrid = m_rCtrl; m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); @@ -108,65 +109,45 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc) dc.SetPen(wxPen(BLACK_COLOR, 0)); dc.DrawRectangle(m_rPlot); - // graticule + // draw spectrum - drawGraticule(dc); - -#ifdef OLD - - wxMemoryDC m_mDC; - m_mDC.SelectObject(*m_pBmp); - m_rCtrl = GetClientRect(); - m_rGrid = m_rCtrl; - - m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); - m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); - - pDC.Clear(); - m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight()); - if(m_firstPass) - { - m_firstPass = false; - m_mDC.Clear(); - m_mDC.FloodFill(0, 0, VERY_LTGREY_COLOR); - - // Draw a filled rectangle with aborder -// wxBrush ltGraphBkgBrush = wxBrush(LIGHT_YELLOW_COLOR); - wxBrush ltGraphBkgBrush = wxBrush(DARK_GREY_COLOR); - m_mDC.SetBrush(ltGraphBkgBrush); - m_mDC.SetPen(wxPen(BLACK_COLOR, 0)); - m_mDC.DrawRectangle(m_rPlot); - } if(m_newdata) { + int x, y, prev_x, prev_y, index; + float index_to_px, mag_dB_to_py, mag; + m_newdata = false; -// plotPixelData(dc); -#ifdef _USE_TIMER - int t = m_rPlot.GetTop(); - int l = m_rPlot.GetLeft(); - int h = m_rPlot.GetHeight(); - int w = m_rPlot.GetWidth(); - //double stride = w / FDMDV_NSPEC; wxPen pen; pen.SetColour(DARK_GREEN_COLOR); pen.SetWidth(1); - m_mDC.SetPen(pen); + dc.SetPen(pen); + + index_to_px = (float)m_rGrid.GetWidth()/FDMDV_NSPEC; + mag_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_MAG_DB-MIN_MAG_DB); -// float *pData = m_pTopFrame->m_rxPa->m_av_mag; - float *pData = g_avmag; - for(int x = 1; x < w; x++) + prev_x = PLOT_BORDER + XLEFT_OFFSET; + prev_y = PLOT_BORDER; + for(index = 0; index < FDMDV_NSPEC; index++) { -// m_mDC.DrawPoint(x, (int)pData[x]); - m_mDC.DrawLine((x - 1), (int)pData[(x - 1)] + (h / 2), x, (int)pData[x] + (h / 2)); + x = index*index_to_px; + mag = g_avmag[index]; + if (mag > MAX_MAG_DB) mag = MAX_MAG_DB; + if (mag < MIN_MAG_DB) mag = MIN_MAG_DB; + y = -mag * mag_dB_to_py; + + x += PLOT_BORDER + XLEFT_OFFSET; + y += PLOT_BORDER; + + dc.DrawLine(x, y, prev_x, prev_y); + prev_x = x; prev_y = y; } - pDC.Blit(l, t, w, h, &m_mDC, l, t); -#endif - drawGraticule(pDC); } - m_mDC.SetBrush(wxNullBrush); - m_mDC.SelectObject(wxNullBitmap); -#endif + + // and finally draw Graticule + + drawGraticule(dc); + } //------------------------------------------------------------------------- @@ -177,7 +158,7 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) int x, y, text_w, text_h; char buf[15]; wxString s; - float f, amplitude, freq_hz_to_px, ampl_dB_to_py; + float f, mag, freq_hz_to_px, mag_dB_to_py; wxBrush ltGraphBkgBrush; ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT); @@ -186,7 +167,7 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) dc.SetPen(wxPen(BLACK_COLOR, 1)); freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ); - ampl_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_AMP_DB-MIN_AMP_DB); + mag_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_MAG_DB-MIN_MAG_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(), @@ -195,7 +176,6 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) // Vertical gridlines dc.SetPen(m_penShortDash); - for(f=STEP_F_HZ; f PLOT_BORDER; p -= GRID_INCREMENT) - { - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (p + PLOT_BORDER), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (p + PLOT_BORDER)); - } - // Label the X-Axis - dc.SetPen(wxPen(GREY_COLOR, 1)); - for(p = GRID_INCREMENT; p < (m_rGrid.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT) - { - sprintf(buf, "%1.1f Hz",(double)(p / 10)); - dc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/3); - } - // Label the Y-Axis - for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) - { - sprintf(buf, "%1.0f", (double)((m_rGrid.GetHeight() - p) * 10)); - dc.DrawText(buf, XLEFT_TEXT_OFFSET, p); - } -#endif } //------------------------------------------------------------------------- @@ -314,7 +287,7 @@ void PlotWaterfall::plotPixelData() // number of dy high blocks in spectrogram dy_blocks = m_rGrid.GetHeight()/ dy; - intensity_per_dB = (float)256 /(MAX_AMP_DB - MIN_AMP_DB); + intensity_per_dB = (float)256 /(MAX_MAG_DB - MIN_MAG_DB); spec_index_per_px = (float)FDMDV_NSPEC / (float) m_rGrid.GetWidth(); /* @@ -372,7 +345,7 @@ void PlotWaterfall::plotPixelData() index = px * spec_index_per_px; assert(index < FDMDV_NSPEC); - intensity = intensity_per_dB * (g_avmag[index] - MIN_AMP_DB); + intensity = intensity_per_dB * (g_avmag[index] - MIN_MAG_DB); if(intensity > 255) intensity = 255; if (intensity < 0) intensity = 0; //printf("%d %f %d \n", index, g_avmag[index], intensity); -- 2.25.1