From 060e8c4c5c074b48f7604062310c76ee2ed77c9c Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 27 Nov 2012 02:41:12 +0000 Subject: [PATCH] added play file to From Radio option git-svn-id: https://svn.code.sf.net/p/freetel/code@1080 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/src/fdmdv2_main.cpp | 116 ++++++++++++++++++++++++++++++++++++- fdmdv2/src/fdmdv2_main.h | 2 + fdmdv2/src/topFrame.cpp | 11 +++- fdmdv2/src/topFrame.h | 1 + 4 files changed, 126 insertions(+), 4 deletions(-) diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 8b574003..21657650 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -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(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; iGetId(); 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)); diff --git a/fdmdv2/src/topFrame.h b/fdmdv2/src/topFrame.h index c2abea71..fd962489 100644 --- a/fdmdv2/src/topFrame.h +++ b/fdmdv2/src/topFrame.h @@ -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(); } -- 2.25.1