From 040965c158b6e3a6f0fa84d54056515a4a5f860e Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 21 Nov 2012 04:57:41 +0000 Subject: [PATCH] rx click tune using globals resulted in a cleaner design although I would prefer not to have used globals. Maybe passing the address of the freq offset in the waterfall/spectrum constructor would have ben cleaner git-svn-id: https://svn.code.sf.net/p/freetel/code@1042 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/src/fdmdv2_defines.h | 2 +- fdmdv2/src/fdmdv2_main.cpp | 30 +++------------------- fdmdv2/src/fdmdv2_plot_spectrum.cpp | 6 +++-- fdmdv2/src/fdmdv2_plot_spectrum.h | 4 --- fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp | 16 +++++++++--- fdmdv2/src/fdmdv2_plot_waterfall_linux.h | 7 +++-- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index 7a53eaa8..b74966d0 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -31,7 +31,7 @@ #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 BETA 0.1 // constant for time averaging spectrum data #define MIN_F_HZ 0 // min freq on Waterfall and Spectrum #define MAX_F_HZ 4000 // max freq on Waterfall and Spectrum #define STEP_F_HZ 500 // freq step on Waterfall and Spectrum graticule diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 1c2f4741..7a8139f2 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -89,6 +89,9 @@ int sc1, sc2; int g_outfifo2_empty; // experimental mutex to make sound card callbacks mutually exclusive +// TODO: review code and see if we need this any more, as fifos should +// now be thread safe + wxMutex g_mutexProtectingCallbackData; // WxWidgets - initialize the application @@ -210,14 +213,12 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) // Add Waterfall Plot window m_panelWaterfall = new PlotWaterfall((wxFrame*) m_auiNbookCtrl); m_auiNbookCtrl->AddPage(m_panelWaterfall, _("Waterfall"), true, wxNullBitmap); - m_panelWaterfall->setClickFreq(FDMDV_FCENTRE); } if(wxGetApp().m_show_spect) { // Add Spectrum Plot window m_panelSpectrum = new PlotSpectrum((wxFrame*) m_auiNbookCtrl); m_auiNbookCtrl->AddPage(m_panelSpectrum, _("Spectrum"), true, wxNullBitmap); - m_panelSpectrum->setClickFreq(FDMDV_FCENTRE); } if(wxGetApp().m_show_scatter) { @@ -460,31 +461,6 @@ void MainFrame::OnTimer(wxTimerEvent &evt) m_panelScatter->add_new_samples(g_stats.rx_symbols); m_panelScatter->Refresh(); - // This is a convenient time to update the click-tune frequency - // The demod is hard-wired to expect a centre frequency of - // FDMDV_FCENTRE. So we want to take the signal centered on the - // click tune freq and re-centre it on FDMDV_FCENTRE. For example - // if the click tune freq is 1500Hz, and FDMDV_CENTRE is 1200 Hz, - // we need to shift the input signal centred on 1500Hz down to - // 1200Hz, an offset of -300Hz. - - // The current design has the last click freq stored in both the - // Waterfall and the Spectrum. This is messy. What would be - // better is the musedown event setting the global freq offset - // directl, or communicating via an event to this thread. - - if (m_auiNbookCtrl->GetCurrentPage() == m_panelWaterfall) { - g_RxFreqOffsetHz = FDMDV_FCENTRE - m_panelWaterfall->getClickFreq(); - m_panelSpectrum->setClickFreq(m_panelWaterfall->getClickFreq()); - //printf("Waterfall g_RxFreqOffsetHz: %f\n", g_RxFreqOffsetHz); - } - - if (m_auiNbookCtrl->GetCurrentPage() == m_panelSpectrum) { - g_RxFreqOffsetHz = FDMDV_FCENTRE - m_panelSpectrum->getClickFreq(); - m_panelWaterfall->setClickFreq(m_panelSpectrum->getClickFreq()); - //printf("Spectrum g_RxFreqOffsetHz: %f\n", g_RxFreqOffsetHz); - } - // Oscilliscope type speech plots ------------------------------------------------------- short speechInPlotSamples[WAVEFORM_PLOT_BUF]; diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index 0a18b9b6..4103ba03 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -217,7 +217,9 @@ void PlotSpectrum::OnMouseDown(wxMouseEvent& event) // valid click if inside of plot if ((pt.x >= 0) && (pt.x <= m_rGrid.GetWidth()) && (pt.y >=0) && (pt.y < m_rGrid.GetHeight())) { float freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ); - m_clickFreq = (float)pt.x/freq_hz_to_px; - printf("PlotSpectrum::OnMouseDown m_clickFreq: %f\n", m_clickFreq); + float clickFreq = (float)pt.x/freq_hz_to_px; + + // see PlotWaterfall::OnMouseDown() + g_RxFreqOffsetHz = FDMDV_FCENTRE - clickFreq; } } diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.h b/fdmdv2/src/fdmdv2_plot_spectrum.h index b7187f70..6a037636 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.h +++ b/fdmdv2/src/fdmdv2_plot_spectrum.h @@ -33,9 +33,6 @@ class PlotSpectrum : public PlotPanel PlotSpectrum(wxFrame* parent); ~PlotSpectrum(); - void setClickFreq(float clickFreq) { m_clickFreq = clickFreq; } - float getClickFreq(void) { return m_clickFreq; } - protected: void OnPaint(wxPaintEvent& event); void OnSize(wxSizeEvent& event); @@ -45,7 +42,6 @@ class PlotSpectrum : public PlotPanel void OnMouseDown(wxMouseEvent& event); private: - float m_clickFreq; DECLARE_EVENT_TABLE() }; diff --git a/fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp b/fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp index 9a019da1..421d3778 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp +++ b/fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp @@ -361,7 +361,6 @@ void PlotWaterfall::plotPixelData() //------------------------------------------------------------------------- void PlotWaterfall::OnMouseDown(wxMouseEvent& event) { - printf("PlotWaterfall::OnMouseDown\n"); m_mouseDown = true; wxClientDC dc(this); @@ -374,7 +373,18 @@ void PlotWaterfall::OnMouseDown(wxMouseEvent& event) // valid click if inside of plot if ((pt.x >= 0) && (pt.x <= m_rGrid.GetWidth()) && (pt.y >=0) && (pt.y < m_rGrid.GetHeight())) { float freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ); - m_clickFreq = (float)pt.x/freq_hz_to_px; - printf("PlotWaterfall::OnMouseDown m_clickFreq: %f\n", m_clickFreq); + float clickFreq = (float)pt.x/freq_hz_to_px; + + // The demod is hard-wired to expect a centre frequency of + // FDMDV_FCENTRE. So we want to take the signal centered on the + // click tune freq and re-centre it on FDMDV_FCENTRE. For example + // if the click tune freq is 1500Hz, and FDMDV_CENTRE is 1200 Hz, + // we need to shift the input signal centred on 1500Hz down to + // 1200Hz, an offset of -300Hz. + + // modifying a global is messy but an easy way to communicate + // to the tx/rx thread + + g_RxFreqOffsetHz = FDMDV_FCENTRE - clickFreq; } } diff --git a/fdmdv2/src/fdmdv2_plot_waterfall_linux.h b/fdmdv2/src/fdmdv2_plot_waterfall_linux.h index b54270c6..ad7c2614 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall_linux.h +++ b/fdmdv2/src/fdmdv2_plot_waterfall_linux.h @@ -39,9 +39,7 @@ class PlotWaterfall : public PlotPanel public: PlotWaterfall(wxFrame* parent); ~PlotWaterfall(); - void setClickFreq(float clickFreq) { m_clickFreq = clickFreq; } - float getClickFreq(void) { return m_clickFreq; } - + protected: unsigned m_heatmap_lut[256]; @@ -56,9 +54,10 @@ class PlotWaterfall : public PlotPanel void OnMouseDown(wxMouseEvent& event); private: - float m_clickFreq; DECLARE_EVENT_TABLE() }; +extern float g_RxFreqOffsetHz; + #endif //__FDMDV2_PLOT_WATERFALL__ -- 2.25.1