From a9a327d642f772941e9404201d9faaccc645fffb Mon Sep 17 00:00:00 2001 From: wittend99 Date: Wed, 5 Sep 2012 02:47:34 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/freetel/code@662 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/build/fdmdv2.mk | 4 +- fdmdv2/src/fdmdv2_main.cpp | 3 - fdmdv2/src/fdmdv2_main.h | 4 +- fdmdv2/src/fdmdv2_plot.cpp | 13 ++-- fdmdv2/src/fdmdv2_plot.h | 39 +++++----- fdmdv2/src/fdmdv2_plot_spectrum.cpp | 14 ++-- fdmdv2/src/fdmdv2_plot_waterfall.cpp | 51 +++++++------ fdmdv2/src/fdmdv2_plot_waterfall.h | 10 ++- fdmdv2/src/fdmdv2_process_audio.cpp | 108 +++++++++++++++------------ 9 files changed, 130 insertions(+), 116 deletions(-) diff --git a/fdmdv2/build/fdmdv2.mk b/fdmdv2/build/fdmdv2.mk index ed18971c..734f6ed3 100644 --- a/fdmdv2/build/fdmdv2.mk +++ b/fdmdv2/build/fdmdv2.mk @@ -50,8 +50,8 @@ LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)/bin/MinGW/m AR := ar rcus CXX := g++ CC := gcc -CXXFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"647\" $(Preprocessors) -CFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"647\" $(Preprocessors) +CXXFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"658\" $(Preprocessors) +CFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"658\" $(Preprocessors) ## diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 668048b7..4cbd0f3e 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -469,7 +469,6 @@ void MainFrame::startTxStream() wxMessageBox(wxT("Tx Stream Start Error."), wxT("Error"), wxOK); return; } -// OnTogBtnOnOff->SetLabel(wxT("Stop")); } } @@ -483,7 +482,6 @@ void MainFrame::stopTxStream() m_TxRunning = false; m_txPa->stop(); m_txPa->streamClose(); -// OnTogBtnOnOff->SetLabel(wxT("Start")); } } @@ -496,7 +494,6 @@ void MainFrame::abortTxStream() { m_TxRunning = false; m_txPa->abort(); -// OnTogBtnOnOff->SetLabel(wxT("Start")); } } diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index c372752a..986743cc 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -69,7 +69,8 @@ class MainFrame : public TopFrame { public: MainFrame(wxWindow *parent); - virtual ~MainFrame(); + virtual ~MainFrame(); + PlotPanel* m_panelDefaultA; PlotPanel* m_panelDefaultB; PlotSpectrum* m_panelSpectrum; @@ -90,6 +91,7 @@ class MainFrame : public TopFrame PaError m_rxErr; PaError m_txErr; wxSound *m_sound; + float av_mag[FDMDV_NSPEC]; void DoStartThread(); void DoPauseThread(); diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index fd57b157..a1d4e9c9 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -148,12 +148,6 @@ void PlotPanel::drawGraticule(wxAutoBufferedPaintDC& dc) char buf[15]; wxString s; - // Draw a filled rectangle with aborder - wxBrush ltBlueBrush = wxBrush(LIGHT_BLUE_COLOR); - dc.SetBrush(ltBlueBrush); - dc.SetPen(wxPen(BLACK_COLOR, 1)); - dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); - // Vertical gridlines dc.SetPen(m_penShortDash); for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < m_w; p += GRID_INCREMENT) @@ -197,6 +191,13 @@ void PlotPanel::draw(wxAutoBufferedPaintDC& dc) m_w = m_rectGrid.GetWidth(); dc.Clear(); + + // Draw a filled rectangle with aborder + wxBrush ltBlueBrush = wxBrush(LIGHT_BLUE_COLOR); + dc.SetBrush(ltBlueBrush); + dc.SetPen(wxPen(BLACK_COLOR, 1)); + dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); + drawGraticule(dc); } diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index 069ff805..48200bfc 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -69,24 +69,24 @@ class PlotPanel : public wxPanel { public: PlotPanel(wxFrame* parent); - void paintEvent(wxPaintEvent & evt); - void draw(wxAutoBufferedPaintDC& dc); - void drawGraticule(wxAutoBufferedPaintDC& dc); - wxPen m_penShortDash; - wxPen m_penDotDash; - wxRect m_rectCtrl; - wxRect m_rectGrid; - wxRect m_rectPlot; -// int m_gridLeftOffset; -// int m_gridRightOffset; -// int m_gridTopOffset; -// int m_gridBottomOffset; - double m_label_size; - wxSize m_Bufsz; - wxBitmap *m_bmp; - wxImagePixelData *m_pBmp; - //wxNativePixelData *m_pBmp; - //wxAlphaPixelData *m_pBmp; + void paintEvent(wxPaintEvent & evt); + void draw(wxAutoBufferedPaintDC& dc); + void drawGraticule(wxAutoBufferedPaintDC& dc); + wxPen m_penShortDash; + wxPen m_penDotDash; + wxRect m_rectCtrl; + wxRect m_rectGrid; + wxRect m_rectPlot; +// int m_gridLeftOffset; +// int m_gridRightOffset; +// int m_gridTopOffset; +// int m_gridBottomOffset; + double m_label_size; + wxSize m_Bufsz; + wxBitmap *m_bmp; + wxImagePixelData *m_pBmp; + //wxNativePixelData *m_pBmp; + //wxAlphaPixelData *m_pBmp; // some useful events void OnMouseMove(wxMouseEvent& event); @@ -96,7 +96,8 @@ class PlotPanel : public wxPanel void OnClose(wxCloseEvent& event ){ event.Skip(); } void OnSize( wxSizeEvent& event ); void OnErase(wxEraseEvent& event); - void OnPaint(wxPaintEvent& event); + void OnPaint(wxPaintEvent& event); + double SetZoomFactor(double zf); double GetZoomFactor(double zf); //void OnUpdateUI( wxUpdateUIEvent& event ){ event.Skip(); } diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index 4751986a..fc5de616 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -56,12 +56,6 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) char buf[15]; wxString s; - // Draw a filled rectangle with aborder - wxBrush ltBlueBrush = wxBrush(LIGHT_YELLOW_COLOR); - dc.SetBrush(ltBlueBrush); - dc.SetPen(wxPen(BLACK_COLOR, 1)); - dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); - // Vertical gridlines dc.SetPen(m_penShortDash); for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < m_w; p += GRID_INCREMENT) @@ -82,7 +76,6 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) dc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_h + YBOTTOM_OFFSET/2); } // Label the Y-Axis - //for(p = GRID_INCREMENT; p < (h - YBOTTOM_OFFSET); p += GRID_INCREMENT) for(p = (m_h - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) { sprintf(buf, "%1.0f", (double)((m_h - p) * -10)); @@ -119,6 +112,13 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc) m_w = m_rectGrid.GetWidth(); dc.Clear(); + + // Draw a filled rectangle with aborder + wxBrush ltBlueBrush = wxBrush(LIGHT_YELLOW_COLOR); + dc.SetBrush(ltBlueBrush); + dc.SetPen(wxPen(BLACK_COLOR, 1)); + dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); + drawGraticule(dc); /* Fl_Box::draw(); diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.cpp b/fdmdv2/src/fdmdv2_plot_waterfall.cpp index 8dde733e..cdad731a 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall.cpp +++ b/fdmdv2/src/fdmdv2_plot_waterfall.cpp @@ -55,12 +55,13 @@ END_EVENT_TABLE() PlotWaterfall::PlotWaterfall(wxFrame* parent): PlotPanel(parent) { int i; - + + m_bmp = new wxBitmap(MAX_BMP_X, MAX_BMP_Y, wxBITMAP_SCREEN_DEPTH); for(i = 0; i < 255; i++) { - heatmap_lut[i] = heatmap((float)i, 0.0, 255.0); + m_heatmap_lut[i] = heatmap((float)i, 0.0, 255.0); } - greyscale = 0; + m_greyscale = 0; SetLabelSize(10.0); m_Bufsz = GetMaxClientSize(); }; @@ -70,10 +71,10 @@ PlotWaterfall::PlotWaterfall(wxFrame* parent): PlotPanel(parent) //---------------------------------------------------------------- PlotWaterfall::~PlotWaterfall() { -// if(m_bmp->IsOk()) -// { -// delete m_bmp; -// } + if(!m_bmp->IsNull()) + { + delete m_bmp; + } } /* @@ -98,10 +99,10 @@ void PlotWaterfall::new_pixel_buf(int w, int h) m_bmp = new wxBitmap(w, h, wxBITMAP_SCREEN_DEPTH); //m_pBmp = m_bmp->GetBitmapData(); } -// pixel_buf = new unsigned[buf_sz]; +// m_pixel_buf = new unsigned[buf_sz]; // for(i = 0; i < buf_sz; i++) // { -// pixel_buf[i] = 0; +// m_pixel_buf[i] = 0; // } } @@ -168,15 +169,6 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& dc) char buf[15]; wxString s; -// int h = m_rectGrid.GetHeight(); -// int w = m_rectGrid.GetWidth(); - - // Draw a filled rectangle with aborder - wxBrush ltBlueBrush = wxBrush(LIGHT_RED_COLOR); - dc.SetBrush(ltBlueBrush); - dc.SetPen(wxPen(BLACK_COLOR, 1)); - dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); - // Vertical gridlines dc.SetPen(m_penShortDash); for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < m_w; p += GRID_INCREMENT) @@ -240,6 +232,13 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) m_w = m_rectGrid.GetWidth(); dc.Clear(); + + // Draw a filled rectangle with aborder + wxBrush ltBlueBrush = wxBrush(LIGHT_RED_COLOR); + dc.SetBrush(ltBlueBrush); + dc.SetPen(wxPen(BLACK_COLOR, 1)); + dc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_w, m_h); + drawGraticule(dc); /* detect resizing of window */ @@ -250,7 +249,7 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) new_pixel_buf(m_w, m_h); } */ -/* + // determine dy, the height of one "block" px_per_sec = (float)m_h / WATERFALL_SECS_Y; dy = DT * px_per_sec; @@ -260,14 +259,14 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) bytes_in_row_of_blocks = dy * m_w * sizeof(unsigned); for(b = 0; b < dy_blocks - 1; b++) { - pdest = pixel_buf + b * m_w * dy; - psrc = pixel_buf + (b + 1) * m_w * dy; + pdest = m_pixel_buf + b * m_w * dy; + psrc = m_pixel_buf + (b + 1) * m_w * dy; memcpy(pdest, psrc, bytes_in_row_of_blocks); } // create a new row of blocks at bottom spec_index_per_px = (float)FDMDV_NSPEC / (float) m_w; intensity_per_dB = (float)256 /(MAX_DB - MIN_DB); - last_row = pixel_buf + dy *(dy_blocks - 1)* m_w; + last_row = m_pixel_buf + dy *(dy_blocks - 1)* m_w; for(px = 0; px < m_w; px++) { index = px * spec_index_per_px; @@ -280,7 +279,7 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) { intensity = 0; } - if (greyscale) + if (m_greyscale) { for(py = 0; py < dy; py++) { @@ -291,13 +290,13 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& dc) { for(py = 0; py < dy; py++) { - last_row[px + py * m_w] = heatmap_lut[intensity]; + last_row[px + py * m_w] = m_heatmap_lut[intensity]; } } } -*/ + // update bit map - //fl_draw_image((unsigned char*)pixel_buf, m_x, m_y, m_w, m_h, 4, 0); + //fl_draw_image((unsigned char*)m_pixel_buf, m_x, m_y, m_w, m_h, 4, 0); //dc.DrawLines(4, m_pBmp, 0, 0 ); } diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.h b/fdmdv2/src/fdmdv2_plot_waterfall.h index 43708ac3..c431c4d1 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall.h +++ b/fdmdv2/src/fdmdv2_plot_waterfall.h @@ -28,6 +28,10 @@ #include "fdmdv2_plot.h" #include "fdmdv2_defines.h" +#define MAX_ZOOM 7 +#define MAX_BMP_X (400 * MAX_ZOOM) +#define MAX_BMP_Y (400 * MAX_ZOOM) + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class PlotWaterfall //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= @@ -38,9 +42,9 @@ public: ~PlotWaterfall(); protected: - unsigned *pixel_buf; - unsigned heatmap_lut[256]; - int greyscale; + unsigned *m_pixel_buf; + unsigned m_heatmap_lut[256]; + int m_greyscale; unsigned heatmap(float val, float min, float max); diff --git a/fdmdv2/src/fdmdv2_process_audio.cpp b/fdmdv2/src/fdmdv2_process_audio.cpp index 99dfcbc5..f6866446 100644 --- a/fdmdv2/src/fdmdv2_process_audio.cpp +++ b/fdmdv2/src/fdmdv2_process_audio.cpp @@ -82,12 +82,12 @@ #include "codec2.h" //-- Globals: Eliminate!! -------------------------------- -char *fin_name = NULL; -char *fout_name = NULL; -char *sound_dev_name = NULL; -FILE *fin = NULL; -FILE *fout = NULL; -struct FDMDV *fdmdv; +//char *fin_name = NULL; +//char *fout_name = NULL; +//char *sound_dev_name = NULL; +//FILE *fin = NULL; +//FILE *fout = NULL; +struct FDMDV *fdmdv_state; struct CODEC2 *codec2; //float av_mag[FDMDV_NSPEC]; // shared between a few classes extern float *av_mag; @@ -98,7 +98,7 @@ float Ts = 0.0; short input_buf[2*FDMDV_NOM_SAMPLES_PER_FRAME]; int n_input_buf = 0; int nin = FDMDV_NOM_SAMPLES_PER_FRAME; -short *output_buf; +short *output_buf; int n_output_buf = 0; int codec_bits[2*FDMDV_BITS_PER_FRAME]; int state = 0; @@ -115,27 +115,30 @@ typedef struct } paCallBackData; //---------------------------------------------------------------- -// +// per_frame_rx_processing() //---------------------------------------------------------------- void per_frame_rx_processing( - short output_buf[], /* output buf of decoded speech samples */ - int *n_output_buf, /* how many samples currently in output_buf[] */ - int codec_bits[], /* current frame of bits for decoder */ - short input_buf[], /* input buf of modem samples input to demod */ - int *n_input_buf, /* how many samples currently in input_buf[] */ - int *nin, /* amount of samples demod needs for next call */ - int *state, /* used to collect codec_bits[] halves */ - struct CODEC2 *c2 /* Codec 2 states */ + short output_buf[], /* output buf of decoded speech samples */ + int *n_output_buf, /* how many samples currently in output_buf[] */ + int codec_bits[], /* current frame of bits for decoder */ + short input_buf[], /* input buf of modem samples input to demod */ + int *n_input_buf, /* how many samples currently in input_buf[] */ + int *nin, /* amount of samples demod needs for next call */ + int *state, /* used to collect codec_bits[] halves */ + struct CODEC2 *c2 /* Codec 2 states */ ) { - struct FDMDV_STATS stats; - int sync_bit; - float rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; - int rx_bits[FDMDV_BITS_PER_FRAME]; - unsigned char packed_bits[BYTES_PER_CODEC_FRAME]; - float rx_spec[FDMDV_NSPEC]; - int i, nin_prev, bit, byte; - int next_state; + struct FDMDV_STATS stats; + int sync_bit; + float rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; + int rx_bits[FDMDV_BITS_PER_FRAME]; + unsigned char packed_bits[BYTES_PER_CODEC_FRAME]; + float rx_spec[FDMDV_NSPEC]; + int i; + int nin_prev; + int bit; + int byte; + int next_state; assert(*n_input_buf <= (2 * FDMDV_NOM_SAMPLES_PER_FRAME)); @@ -158,12 +161,12 @@ void per_frame_rx_processing( while(*n_input_buf >= *nin) { // demod per frame processing - for(i=0; i<*nin; i++) + for(i = 0; i < *nin; i++) { rx_fdm[i] = (float)input_buf[i]/FDMDV_SCALE; } nin_prev = *nin; - fdmdv_demod(fdmdv, rx_bits, &sync_bit, rx_fdm, nin); + fdmdv_demod(fdmdv_state, rx_bits, &sync_bit, rx_fdm, nin); *n_input_buf -= nin_prev; assert(*n_input_buf >= 0); @@ -174,8 +177,8 @@ void per_frame_rx_processing( } // compute rx spectrum & get demod stats, and update GUI plot data - fdmdv_get_rx_spectrum(fdmdv, rx_spec, rx_fdm, nin_prev); - fdmdv_get_demod_stats(fdmdv, &stats); + fdmdv_get_rx_spectrum(fdmdv_state, rx_spec, rx_fdm, nin_prev); + fdmdv_get_demod_stats(fdmdv_state, &stats); new_data(rx_spec); // aScatter->add_new_samples(stats.rx_symbols); // aTimingEst->add_new_sample(stats.rx_timing); @@ -197,14 +200,15 @@ void per_frame_rx_processing( { case 0: // mute output audio when out of sync - if(*n_output_buf < 2*codec2_samples_per_frame(c2) - N8) + if(*n_output_buf < 2 * codec2_samples_per_frame(c2) - N8) { - for(i=0; i 3.0)) { next_state = 1; @@ -216,7 +220,7 @@ void per_frame_rx_processing( { next_state = 2; // first half of frame of codec bits - memcpy(codec_bits, rx_bits, FDMDV_BITS_PER_FRAME*sizeof(int)); + memcpy(codec_bits, rx_bits, FDMDV_BITS_PER_FRAME * sizeof(int)); } else { @@ -239,10 +243,10 @@ void per_frame_rx_processing( // second half of frame of codec bits memcpy(&codec_bits[FDMDV_BITS_PER_FRAME], rx_bits, FDMDV_BITS_PER_FRAME*sizeof(int)); // pack bits, MSB received first - bit = 7; + bit = 7; byte = 0; memset(packed_bits, 0, BYTES_PER_CODEC_FRAME); - for(i=0; i