added multi-channel support to plot scalar, tested OK with 1 channel
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 8 Mar 2013 03:15:29 +0000 (03:15 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 8 Mar 2013 03:15:29 +0000 (03:15 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1199 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/dlg_audiooptions.cpp
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_plot_scalar.cpp
fdmdv2/src/fdmdv2_plot_scalar.h

index ccf3483670a2cf876e077548946d4888210cac36..3d7f3eee8cce4b7134efbbca8121bdb3315246f8 100644 (file)
@@ -55,7 +55,7 @@ void AudioOptsDialog::buildTestControls(PlotScalar **plotScalar, wxButton **btnT
     wxBoxSizer* bSizer1 = new wxBoxSizer(wxVERTICAL);
 
     wxPanel *panel = new wxPanel(parentPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
-    *plotScalar = new PlotScalar((wxFrame*) panel, TEST_WAVEFORM_PLOT_TIME, 1.0/TEST_WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "", 1);
+    *plotScalar = new PlotScalar((wxFrame*) panel, 1, TEST_WAVEFORM_PLOT_TIME, 1.0/TEST_WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "", 1);
     (*plotScalar)->SetClientSize(wxSize(TEST_WAVEFORM_X,TEST_WAVEFORM_Y));
     bSizer1->Add(panel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 8);
 
@@ -989,7 +989,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(int devNum, PlotScalar *plotSca
             short plotSamples[TEST_WAVEFORM_PLOT_BUF];
             if (fifo_read(fifo, plotSamples, TEST_WAVEFORM_PLOT_BUF))
                 memset(plotSamples, 0, TEST_WAVEFORM_PLOT_BUF*sizeof(short));
-            plotScalar->add_new_short_samples(plotSamples, TEST_WAVEFORM_PLOT_BUF, 32767);
+            plotScalar->add_new_short_samples(0, plotSamples, TEST_WAVEFORM_PLOT_BUF, 32767);
             plotScalar->Refresh();
        }
     }
@@ -1081,7 +1081,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(int devNum, PlotScalar *plotSc
             short plotSamples[TEST_WAVEFORM_PLOT_BUF];
             if (fifo_read(fifo, plotSamples, TEST_WAVEFORM_PLOT_BUF))
                 memset(plotSamples, 0, TEST_WAVEFORM_PLOT_BUF*sizeof(short));
-            plotScalar->add_new_short_samples(plotSamples, TEST_WAVEFORM_PLOT_BUF, 32767);
+            plotScalar->add_new_short_samples(0, plotSamples, TEST_WAVEFORM_PLOT_BUF, 32767);
             plotScalar->Refresh();
        }
     }
index 20ed922a73354b00300ab84858ef752e1e14c9d4..c6156efee972d1d6bb9e245305e0bc322079ea09 100644 (file)
@@ -232,7 +232,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     if(wxGetApp().m_show_demod_in)
     {
         // Add Demod Input window
-        m_panelDemodIn = new PlotScalar((wxFrame*) m_auiNbookCtrl, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
+        m_panelDemodIn = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
         m_auiNbookCtrl->AddPage(m_panelDemodIn, _("Frm Radio"), true, wxNullBitmap);
         g_plotDemodInFifo = fifo_create(2*WAVEFORM_PLOT_BUF);
     }
@@ -240,7 +240,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     if(wxGetApp().m_show_speech_in)
     {
         // Add Speech Input window
-        m_panelSpeechIn = new PlotScalar((wxFrame*) m_auiNbookCtrl, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
+        m_panelSpeechIn = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
         m_auiNbookCtrl->AddPage(m_panelSpeechIn, _("Frm Mic"), true, wxNullBitmap);
         g_plotSpeechInFifo = fifo_create(2*WAVEFORM_PLOT_BUF);
     }
@@ -248,7 +248,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     if(wxGetApp().m_show_speech_out)
     {
         // Add Speech Output window
-        m_panelSpeechOut = new PlotScalar((wxFrame*) m_auiNbookCtrl, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
+        m_panelSpeechOut = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, WAVEFORM_PLOT_TIME, 1.0/WAVEFORM_PLOT_FS, -1, 1, 1, 0.2, "%2.1f", 0);
         m_auiNbookCtrl->AddPage(m_panelSpeechOut, _("To Spkr/Hdphns"), true, wxNullBitmap);
         g_plotSpeechOutFifo = fifo_create(2*WAVEFORM_PLOT_BUF);
     }
@@ -256,13 +256,13 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     if(wxGetApp().m_show_timing)
     {
         // Add Timing Offset window
-        m_panelTimeOffset = new PlotScalar((wxFrame*) m_auiNbookCtrl, 5.0, DT, -0.5, 0.5, 1, 0.1, "%2.1f", 0);
+        m_panelTimeOffset = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, 5.0, DT, -0.5, 0.5, 1, 0.1, "%2.1f", 0);
         m_auiNbookCtrl->AddPage(m_panelTimeOffset, L"Timing \u0394", true, wxNullBitmap);
     }
     if(wxGetApp().m_show_freq)
     {
         // Add Frequency Offset window
-        m_panelFreqOffset = new PlotScalar((wxFrame*) m_auiNbookCtrl, 5.0, DT, -200, 200, 1, 50, "%3.0fHz", 0);
+        m_panelFreqOffset = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, 5.0, DT, -200, 200, 1, 50, "%3.0fHz", 0);
         m_auiNbookCtrl->AddPage(m_panelFreqOffset, L"Frequency \u0394", true, wxNullBitmap);
     }
 
@@ -559,27 +559,27 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
     short speechInPlotSamples[WAVEFORM_PLOT_BUF];
     if (fifo_read(g_plotSpeechInFifo, speechInPlotSamples, WAVEFORM_PLOT_BUF))
         memset(speechInPlotSamples, 0, WAVEFORM_PLOT_BUF*sizeof(short));
-    m_panelSpeechIn->add_new_short_samples(speechInPlotSamples, WAVEFORM_PLOT_BUF, 32767);
+    m_panelSpeechIn->add_new_short_samples(0, speechInPlotSamples, WAVEFORM_PLOT_BUF, 32767);
     m_panelSpeechIn->Refresh();
 
     short speechOutPlotSamples[WAVEFORM_PLOT_BUF];
     if (fifo_read(g_plotSpeechOutFifo, speechOutPlotSamples, WAVEFORM_PLOT_BUF))
         memset(speechOutPlotSamples, 0, WAVEFORM_PLOT_BUF*sizeof(short));
-    m_panelSpeechOut->add_new_short_samples(speechOutPlotSamples, WAVEFORM_PLOT_BUF, 32767);
+    m_panelSpeechOut->add_new_short_samples(0, speechOutPlotSamples, WAVEFORM_PLOT_BUF, 32767);
     m_panelSpeechOut->Refresh();
 
     short demodInPlotSamples[WAVEFORM_PLOT_BUF];
     if (fifo_read(g_plotDemodInFifo, demodInPlotSamples, WAVEFORM_PLOT_BUF))
         memset(demodInPlotSamples, 0, WAVEFORM_PLOT_BUF*sizeof(short));    
-    m_panelDemodIn->add_new_short_samples(demodInPlotSamples, WAVEFORM_PLOT_BUF, 32767);
+    m_panelDemodIn->add_new_short_samples(0,demodInPlotSamples, WAVEFORM_PLOT_BUF, 32767);
     m_panelDemodIn->Refresh();
 
     // Demod states -----------------------------------------------------------------------
 
-    m_panelTimeOffset->add_new_sample((float)g_stats.rx_timing/FDMDV_NOM_SAMPLES_PER_FRAME);
+    m_panelTimeOffset->add_new_sample(0, (float)g_stats.rx_timing/FDMDV_NOM_SAMPLES_PER_FRAME);
     m_panelTimeOffset->Refresh();
 
-    m_panelFreqOffset->add_new_sample(g_stats.foff);
+    m_panelFreqOffset->add_new_sample(0, g_stats.foff);
     m_panelFreqOffset->Refresh();
 
     // SNR text box and gauge ------------------------------------------------------------
index 8b5d8184c0d7d114fb648915fc8345e72f2bbed4..a29911f267d8d7ab228ae0005ef44130cf597fea 100644 (file)
@@ -36,6 +36,7 @@ END_EVENT_TABLE()
 // PlotScalar()
 //----------------------------------------------------------------
 PlotScalar::PlotScalar(wxFrame* parent, 
+                       int    channels,           // number on channel to plot
                       float  t_secs,             // time covered by entire x axis in seconds
                       float  sample_period_secs, // time between each sample in seconds
                       float  a_min,              // min ampltude of samples being plotted
@@ -50,6 +51,7 @@ PlotScalar::PlotScalar(wxFrame* parent,
 
     m_rCtrl = GetClientRect();
 
+    m_channels = channels;
     m_t_secs = t_secs;
     m_sample_period_secs = sample_period_secs;
     m_a_min = a_min;
@@ -63,9 +65,9 @@ PlotScalar::PlotScalar(wxFrame* parent,
     // work out number of samples we will store and allocate storage
 
     m_samples = m_t_secs/m_sample_period_secs;
-    m_mem = new float[m_samples];
+    m_mem = new float[m_samples*m_channels];
 
-    for(i = 0; i < m_samples; i++)
+    for(i = 0; i < m_samples*m_channels; i++)
     {
         m_mem[i] = 0.0;
     }
@@ -82,28 +84,34 @@ PlotScalar::~PlotScalar()
 //----------------------------------------------------------------
 // add_new_sample()
 //----------------------------------------------------------------
-void PlotScalar::add_new_sample(float sample)
+void PlotScalar::add_new_sample(int channel, float sample)
 {
     int i;
+    int offset = channel*m_samples;
+
+    assert(channel < m_channels);
 
     for(i = 0; i < m_samples-1; i++)
     {
-        m_mem[i] = m_mem[i+1];
+        m_mem[offset+i] = m_mem[offset+i+1];
     }
-    m_mem[m_samples-1] = sample;
+    m_mem[offset+m_samples-1] = sample;
 }
 
 //----------------------------------------------------------------
 // add_new_samples()
 //----------------------------------------------------------------
-void  PlotScalar::add_new_short_samples(short samples[], int length, float scale_factor)
+void  PlotScalar::add_new_short_samples(int channel, short samples[], int length, float scale_factor)
 {
     int i;
+    int offset = channel*m_samples;
+
+    assert(channel < m_channels);
 
     for(i = 0; i < m_samples-length; i++)
-        m_mem[i] = m_mem[i+length];
+        m_mem[offset+i] = m_mem[offset+i+length];
     for(; i < m_samples; i++)
-       m_mem[i] = (float)*samples++/scale_factor;
+       m_mem[offset+i] = (float)*samples++/scale_factor;
 }
 
 //----------------------------------------------------------------
@@ -151,27 +159,32 @@ void PlotScalar::draw(wxAutoBufferedPaintDC&  dc)
 
     prev_x = prev_y = 0; // stop warning
 
-    for(i = 0; i < m_samples; i++)
-    {
-        x = index_to_px * i;
-       a = m_mem[i];
-       if (a < m_a_min) a = m_a_min;
-       if (a > m_a_max) a = m_a_max;
+    // plot each channel 
 
-       // invert y axis and offset by minimum
+    int offset;
+    for(offset=0; offset<m_channels*m_samples; offset+=m_samples) {
 
-        y = m_rGrid.GetHeight() - a_to_py * a + m_a_min*a_to_py;
+        for(i = 0; i < m_samples; i++) {
+            x = index_to_px * i;
+            a = m_mem[offset+i];
+            if (a < m_a_min) a = m_a_min;
+            if (a > m_a_max) a = m_a_max;
 
-       // put inside plot window
+            // invert y axis and offset by minimum
 
-       if (!m_mini) {
-            x += PLOT_BORDER + XLEFT_OFFSET;
-            y += PLOT_BORDER;
-        }
+            y = m_rGrid.GetHeight() - a_to_py * a + m_a_min*a_to_py;
+
+            // put inside plot window
 
-       if (i)
-           dc.DrawLine(x, y, prev_x, prev_y);
-       prev_x = x; prev_y = y;
+            if (!m_mini) {
+                x += PLOT_BORDER + XLEFT_OFFSET;
+                y += PLOT_BORDER;
+            }
+
+            if (i)
+                dc.DrawLine(x, y, prev_x, prev_y);
+            prev_x = x; prev_y = y;
+        }
     }
 
     drawGraticule(dc);
index 8abded4997bdca273a63893c7878c896c3663b15..704398729fe12c4633166573652141acbfc6b326 100644 (file)
@@ -32,6 +32,7 @@ class PlotScalar: public PlotPanel
     public:
 
     PlotScalar(wxFrame* parent,
+               int   channels,
               float t_secs, 
               float sample_period_secs,
               float a_min,
@@ -42,11 +43,12 @@ class PlotScalar: public PlotPanel
                int   mini
               );
         ~PlotScalar();
-         void add_new_sample(float sample);
-         void add_new_short_samples(short samples[], int length, float scale_factor);
+         void add_new_sample(int channel, float sample);
+         void add_new_short_samples(int channel, short samples[], int length, float scale_factor);
 
     protected:
 
+         int      m_channels;
         float    m_t_secs;
         float    m_sample_period_secs;
         float    m_a_min;