added play file to From Radio option
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Nov 2012 02:41:12 +0000 (02:41 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Nov 2012 02:41:12 +0000 (02:41 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1080 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_main.h
fdmdv2/src/topFrame.cpp
fdmdv2/src/topFrame.h

index 8b574003777c1697ba34fcc07e670a00cbc700fd..216576502f03bedf5a12e6713fc387bdb5140449 100644 (file)
@@ -76,14 +76,22 @@ int                 g_soundCard2OutDeviceNum;
 int                 g_soundCard2SampleRate;
 
 // playing and recording from sound files
+
 SNDFILE            *g_sfPlayFile;
 bool                g_playFileToMicIn;
 bool                g_loopPlayFileToMicIn;
 int                 g_playFileToMicInEventId;
+
 SNDFILE            *g_sfRecFile;
 bool                g_recFileFromRadio;
 unsigned int        g_recFromRadioSamples;
 int                 g_recFileFromRadioEventId;
+
+SNDFILE            *g_sfPlayFileFromRadio;
+bool                g_playFileFromRadio;
+bool                g_loopPlayFileFromRadio;
+int                 g_playFileFromRadioEventId;
+
 wxWindow           *g_parent;
 
 // Click to tune rx and tx frequency offset states
@@ -301,6 +309,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     wxGetApp().m_playFileToMicInPath = pConfig->Read("/File/playFileToMicInPath", wxT(""));
     wxGetApp().m_recFileFromRadioPath = pConfig->Read("/File/recFileFromRadioPath", wxT(""));
     wxGetApp().m_recFileFromRadioSecs = pConfig->Read("/File/recFileFromRadioSecs", 30);
+    wxGetApp().m_playFileFromRadioPath = pConfig->Read("/File/playFileToFromRadioPath", wxT(""));
 
     bool slow = false; // prevents compile error when using default bool
     wxGetApp().m_snrSlow = pConfig->Read("/Audio/snrSlow", slow);
@@ -369,9 +378,14 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     g_sfPlayFile = NULL;
     g_playFileToMicIn = false;
     g_loopPlayFileToMicIn = false;
+
     g_sfRecFile = NULL;
     g_recFileFromRadio = false;
 
+    g_sfPlayFileFromRadio = NULL;
+    g_playFileFromRadio = false;
+    g_loopPlayFileFromRadio = false;
+
     // init click-tune states
 
     g_RxFreqOffsetHz = 0.0;
@@ -453,6 +467,7 @@ MainFrame::~MainFrame()
         pConfig->Write(wxT("/File/playFileToMicInPath"),    wxGetApp().m_playFileToMicInPath);
         pConfig->Write(wxT("/File/recFileFromRadioPath"),   wxGetApp().m_recFileFromRadioPath);
         pConfig->Write(wxT("/File/recFileFromRadioSecs"),   wxGetApp().m_recFileFromRadioSecs);
+        pConfig->Write(wxT("/File/playFileFromRadioPath"),wxGetApp().m_playFileFromRadioPath);
 
         pConfig->Write(wxT("/Audio/snrSlow"), wxGetApp().m_snrSlow);
 
@@ -977,6 +992,83 @@ void MainFrame::OnPlayFileToMicIn(wxCommandEvent& event)
     }
 }
 
+//-------------------------------------------------------------------------
+// OnPlayFileFromRadio()
+//-------------------------------------------------------------------------
+
+// This puppy "plays" a recorded file into the denmonulator input, allowing us
+// to replay off air signals.
+
+void MainFrame::OnPlayFileFromRadio(wxCommandEvent& event)
+{
+    wxUnusedVar(event);
+
+    printf("OnPlayFileFromRadio:: %d\n", (int)g_playFileFromRadio);
+    if (g_playFileFromRadio) {
+        printf("OnPlayFileFromRadio:: Stop\n");
+        g_mutexProtectingCallbackData.Lock();
+        g_playFileFromRadio = false;
+        sf_close(g_sfPlayFileFromRadio);
+        SetStatusText(wxT(""));
+        g_mutexProtectingCallbackData.Unlock();
+    }
+    else {
+
+        wxString    soundFile;
+        SF_INFO     sfInfo;
+
+        wxFileDialog openFileDialog(
+                                    this,
+                                    wxT("Play File - From Radio"),
+                                    wxGetApp().m_playFileFromRadioPath,
+                                    wxEmptyString,
+                                    wxT("WAV and RAW files (*.wav;*.raw)|*.wav;*.raw|")
+                                    wxT("All files (*.*)|*.*"),
+                                    wxFD_OPEN | wxFD_FILE_MUST_EXIST
+                                    );
+
+        // add the loop check box
+        openFileDialog.SetExtraControlCreator(&createMyExtraPlayFilePanel);
+        if(openFileDialog.ShowModal() == wxID_CANCEL)
+        {
+            return;     // the user changed their mind...
+        }
+
+        wxString fileName, extension;
+        soundFile = openFileDialog.GetPath();
+        wxFileName::SplitPath(soundFile, &wxGetApp().m_playFileFromRadioPath, &fileName, &extension);
+        //wxLogDebug("m_playFileToFromRadioPath: %s", wxGetApp().m_playFileFromRadioPath);
+        sfInfo.format = 0;
+
+        if(!extension.IsEmpty())
+        {
+            extension.LowerCase();
+            if(extension == wxT("raw"))
+            {
+                sfInfo.format     = SF_FORMAT_RAW | SF_FORMAT_PCM_16;
+                sfInfo.channels   = 1;
+                sfInfo.samplerate = FS;
+            }
+        }
+        g_sfPlayFileFromRadio = sf_open(soundFile, SFM_READ, &sfInfo);
+        if(g_sfPlayFileFromRadio == NULL)
+        {
+            wxString strErr = sf_strerror(NULL);
+            wxMessageBox(strErr, wxT("Couldn't open sound file"), wxOK);
+            return;
+        }
+        
+        wxWindow * const ctrl = openFileDialog.GetExtraControl();
+
+        // Huh?! I just copied wxWidgets-2.9.4/samples/dialogs ....
+        g_loopPlayFileFromRadio = static_cast<MyExtraPlayFilePanel*>(ctrl)->getLoopPlayFileToMicIn();
+
+        SetStatusText(wxT("Playing File: ") + fileName + wxT("into From Radio") , 0);
+        g_playFileFromRadio = true;
+    }
+}
+
 // extra panel added to file save dialog to set number of seconds to record for
 
 MyExtraRecFilePanel::MyExtraRecFilePanel(wxWindow *parent): wxPanel(parent)
@@ -1774,7 +1866,6 @@ void txRxProcessing()
         unsigned int n8k;
 
         n8k = resample(cbData->insrc1, in8k_short, in48k_short, FS, g_soundCard1SampleRate, N8, nsam);
-        fifo_write(cbData->rxinfifo, in8k_short, n8k);
 
         // optionally save signal from radio (demod input to file).
         // Really useful for testing and development as it allows to
@@ -1798,6 +1889,27 @@ void txRxProcessing()
         }
         g_mutexProtectingCallbackData.Unlock();
 
+        // optionally read signal from radio (file to demod input).
+        // Really useful for testing and development as it allows to
+        // develop using off air signals
+
+        g_mutexProtectingCallbackData.Lock();
+        if (g_playFileFromRadio && (g_sfPlayFileFromRadio != NULL)) {
+            int n = sf_read_short(g_sfPlayFileFromRadio, in8k_short, N8);
+            if (n != N8) {
+                if (g_loopPlayFileFromRadio)
+                    sf_seek(g_sfPlayFileFromRadio, 0, SEEK_SET);
+                else {
+                    printf("playFileFromRadio fnsihed, issuing event!\n");
+                    wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, g_playFileFromRadioEventId );
+                    // call stop/start play menu item, should be thread safe
+                    g_parent->GetEventHandler()->AddPendingEvent( event );
+                }
+            }
+        }
+        g_mutexProtectingCallbackData.Unlock();
+
+        fifo_write(cbData->rxinfifo, in8k_short, n8k);
         resample_for_plot(g_plotDemodInFifo, in8k_short, n8k);
 
         per_frame_rx_processing(cbData->rxoutfifo, g_CodecBits, cbData->rxinfifo, &g_nRxIn, &g_State, g_pCodec2);
@@ -2104,7 +2216,7 @@ void per_frame_rx_processing(
                     data_flag_index = codec2_get_spare_bit_index(c2);
                     assert(data_flag_index != -1); // not supported for all rates
                     
-                    if (codec_bits[data_flag_index]) {
+                    if (0/*codec_bits[data_flag_index]*/) {
                         //printf("data_flag_index: %d\n", data_flag_index);
                         //printf("rx data bits: ");
                         //for(i=0; i<BITS_PER_CODEC_FRAME; i++)
index 53a45e0550e67145fb6797e84e2a19a7fab88fa0..a2461d5ba2c8bf1397019b7106eff307877b1e23 100644 (file)
@@ -131,6 +131,7 @@ class MainApp : public wxApp
         wxString            m_playFileToMicInPath;
         wxString            m_recFileFromRadioPath;
         unsigned int        m_recFileFromRadioSecs;
+        wxString            m_playFileFromRadioPath;
 
         bool                m_snrSlow;
 
@@ -312,6 +313,7 @@ class MainFrame : public TopFrame
 
         void OnPlayFileToMicIn( wxCommandEvent& event );
         void OnRecFileFromRadio( wxCommandEvent& event );
+        void OnPlayFileFromRadio( wxCommandEvent& event );
 
         void OnHelpCheckUpdates( wxCommandEvent& event );
         void OnHelpCheckUpdatesUI( wxUpdateUIEvent& event );
index 6b2093547e86bc341acf1886297fda668dea64a1..8f7097a0e90c85aa99cacf66750f867819b99101 100644 (file)
@@ -23,6 +23,7 @@
 
 extern int g_playFileToMicInEventId;
 extern int g_recFileFromRadioEventId;
+extern int g_playFileFromRadioEventId;
 
 //=========================================================================
 // Code that lays out the main application window
@@ -63,15 +64,19 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const
     m_menuItemCaptTxInStream = new wxMenuItem(tools, wxID_ANY, wxString(_("&Capture Tx Input Stream")), wxEmptyString, wxITEM_NORMAL);
 
     wxMenuItem* m_menuItemPlayFileToMicIn;
-    m_menuItemPlayFileToMicIn = new wxMenuItem(tools, wxID_ANY, wxString(_("&Start/Stop Play File to Mic In")) , wxEmptyString, wxITEM_NORMAL);
+    m_menuItemPlayFileToMicIn = new wxMenuItem(tools, wxID_ANY, wxString(_("Start/Stop Play File - Mic In")) , wxEmptyString, wxITEM_NORMAL);
     g_playFileToMicInEventId = m_menuItemPlayFileToMicIn->GetId();
     tools->Append(m_menuItemPlayFileToMicIn);
 
     wxMenuItem* m_menuItemRecFileFromRadio;
-    m_menuItemRecFileFromRadio = new wxMenuItem(tools, wxID_ANY, wxString(_("S&tart/Stop Record File from Radio")) , wxEmptyString, wxITEM_NORMAL);
+    m_menuItemRecFileFromRadio = new wxMenuItem(tools, wxID_ANY, wxString(_("Start/Stop Record File - From Radio")) , wxEmptyString, wxITEM_NORMAL);
     g_recFileFromRadioEventId = m_menuItemRecFileFromRadio->GetId();
     tools->Append(m_menuItemRecFileFromRadio);
 
+    wxMenuItem* m_menuItemPlayFileFromRadio;
+    m_menuItemPlayFileFromRadio = new wxMenuItem(tools, wxID_ANY, wxString(_("Start/Stop Play File - From Radio")) , wxEmptyString, wxITEM_NORMAL);
+    g_playFileFromRadioEventId = m_menuItemPlayFileFromRadio->GetId();
+    tools->Append(m_menuItemPlayFileFromRadio);
     m_menubarMain->Append(tools, _("&Tools"));
 
     help = new wxMenu();
@@ -391,6 +396,7 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const
 
     this->Connect(m_menuItemPlayFileToMicIn->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnPlayFileToMicIn));
     this->Connect(m_menuItemRecFileFromRadio->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnRecFileFromRadio));
+    this->Connect(m_menuItemPlayFileFromRadio->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnPlayFileFromRadio));
 
     this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpCheckUpdates));
     this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI));
@@ -441,6 +447,7 @@ TopFrame::~TopFrame()
 
     this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnPlayFileToMicIn));
     this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnRecFileFromRadio));
+    this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnPlayFileFromRadio));
 
     this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpCheckUpdates));
     this->Disconnect(wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI));
index c2abea714ee52ac77c74a4ef763f81e06100a98a..fd962489969041aee70b19c0207695ce9b20b745 100644 (file)
@@ -113,6 +113,7 @@ class TopFrame : public wxFrame
         virtual void OnToolsComCfgUI( wxUpdateUIEvent& event ) { event.Skip(); }
         virtual void OnPlayFileToMicIn( wxCommandEvent& event ) { event.Skip(); }
         virtual void OnRecFileFromRadio( wxCommandEvent& event ) { event.Skip(); }
+        virtual void OnPlayFileFromRadio( wxCommandEvent& event ) { event.Skip(); }
 
         virtual void OnHelpCheckUpdates( wxCommandEvent& event ) { event.Skip(); }
         virtual void OnHelpCheckUpdatesUI( wxUpdateUIEvent& event ) { event.Skip(); }