From: drowe67 Date: Fri, 8 Mar 2013 03:15:29 +0000 (+0000) Subject: added multi-channel support to plot scalar, tested OK with 1 channel X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=2a9130d525720ca353192154f70bef07c5875291;p=freetel-svn-tracking.git added multi-channel support to plot scalar, tested OK with 1 channel git-svn-id: https://svn.code.sf.net/p/freetel/code@1199 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/src/dlg_audiooptions.cpp b/fdmdv2/src/dlg_audiooptions.cpp index ccf34836..3d7f3eee 100644 --- a/fdmdv2/src/dlg_audiooptions.cpp +++ b/fdmdv2/src/dlg_audiooptions.cpp @@ -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(); } } diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 20ed922a..c6156efe 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -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 ------------------------------------------------------------ diff --git a/fdmdv2/src/fdmdv2_plot_scalar.cpp b/fdmdv2/src/fdmdv2_plot_scalar.cpp index 8b5d8184..a29911f2 100644 --- a/fdmdv2/src/fdmdv2_plot_scalar.cpp +++ b/fdmdv2/src/fdmdv2_plot_scalar.cpp @@ -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_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); diff --git a/fdmdv2/src/fdmdv2_plot_scalar.h b/fdmdv2/src/fdmdv2_plot_scalar.h index 8abded49..70439872 100644 --- a/fdmdv2/src/fdmdv2_plot_scalar.h +++ b/fdmdv2/src/fdmdv2_plot_scalar.h @@ -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;