From a1b5e08cfc9fc452ee548bd19c1f10dcbd09b4e2 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 16:57:48 +1030 Subject: [PATCH 01/18] fix warning --- src/callsign_encoder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/callsign_encoder.cpp b/src/callsign_encoder.cpp index 5d7f7e6d9..4ca111c7b 100644 --- a/src/callsign_encoder.cpp +++ b/src/callsign_encoder.cpp @@ -58,7 +58,7 @@ void CallsignEncoder::setCallsign(const char* callsign) convertDigitToASCII_(&translatedCallsign_[1], crcDigit2); int truncIndex = 0; - for(int index = 0; index < strlen(translatedCallsign_); index += 2, truncIndex += 4) + for(size_t index = 0; index < strlen(translatedCallsign_); index += 2, truncIndex += 4) { // Encode the character as four bytes with parity bits. int inputRaw = ((translatedCallsign_[index] & 0x3F) << 6) | (translatedCallsign_[index+1] & 0x3F); @@ -200,7 +200,7 @@ bool CallsignEncoder::isCallsignValid() const void CallsignEncoder::convert_callsign_to_ota_string_(const char* input, char* output) const { int outidx = 0; - for (int index = 0; index < strlen(input); index++) + for (size_t index = 0; index < strlen(input); index++) { bool addSync = false; if (input[index] >= 38 && input[index] <= 47) @@ -248,7 +248,7 @@ void CallsignEncoder::convert_callsign_to_ota_string_(const char* input, char* o void CallsignEncoder::convert_ota_string_to_callsign_(const char* input, char* output) { int outidx = 0; - for (int index = 0; index < strlen(input); index++) + for (size_t index = 0; index < strlen(input); index++) { if (input[index] >= 1 && input[index] <= 9) { From ccb50fe01c128a7b504a1bcd9fbc7f747234eca4 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 16:58:06 +1030 Subject: [PATCH 02/18] remove unused plugin support --- src/main.cpp | 80 +--------------------------------------------------- 1 file changed, 1 insertion(+), 79 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 275d271a5..3cb21262a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -218,66 +218,7 @@ bool MainApp::OnInit() m_strSampleRate.Empty(); m_strBitrate.Empty(); - // Look for Plug In - - m_plugIn = false; - #ifdef __WXMSW__ - wchar_t dll_path[] = L"afreedvplugin.dll"; - m_plugInHandle = LoadLibrary(dll_path); - #else - m_plugInHandle = dlopen("afreedvplugin.so", RTLD_LAZY); - #endif - - if (m_plugInHandle) { - printf("plugin: .so found\n"); - - // lets get some information abt the plugIn - - void (*plugin_namefp)(char s[]); - void *(*plugin_openfp)(char *param_names[], int *nparams, int (*aplugin_get_persistant)(char *, char *)); - - #ifdef __WXMSW__ - plugin_namefp = (void (*)(char*))GetProcAddress((HMODULE)m_plugInHandle, "plugin_name"); - plugin_openfp = (void* (*)(char**,int *, int (*)(char *, char *)))GetProcAddress((HMODULE)m_plugInHandle, "plugin_open"); - m_plugin_startfp = (void (*)(void *))GetProcAddress((HMODULE)m_plugInHandle, "plugin_start"); - m_plugin_stopfp = (void (*)(void *))GetProcAddress((HMODULE)m_plugInHandle, "plugin_stop"); - m_plugin_rx_samplesfp = (void (*)(void *, short *, int))GetProcAddress((HMODULE)m_plugInHandle, "plugin_rx_samples"); - #else - plugin_namefp = (void (*)(char*))dlsym(m_plugInHandle, "plugin_name"); - plugin_openfp = (void* (*)(char**,int *, int (*)(char *, char *)))dlsym(m_plugInHandle, "plugin_open"); - m_plugin_startfp = (void (*)(void *))dlsym(m_plugInHandle, "plugin_start"); - m_plugin_stopfp = (void (*)(void *))dlsym(m_plugInHandle, "plugin_stop"); - m_plugin_rx_samplesfp = (void (*)(void *, short *, int))dlsym(m_plugInHandle, "plugin_rx_samples"); - #endif - - if ((plugin_namefp != NULL) && (plugin_openfp != NULL)) { - - char s[256]; - m_plugIn = true; - (plugin_namefp)(s); - fprintf(stderr, "plugin name: %s\n", s); - m_plugInName = s; - - char param_name1[80], param_name2[80]; - char *param_names[2] = {param_name1, param_name2}; - int nparams, i; - m_plugInStates = (plugin_openfp)(param_names, &nparams, plugin_get_persistant); - m_numPlugInParam = nparams; - for(i=0; iRead(configStr, wxT("")); - //fprintf(stderr, " plugin param name[%d]: %s\n", i, param_names[i]); - fprintf(stderr, " plugin param name[%d]: %s values: %s\n", i, m_plugInParamName[i].mb_str().data(), m_txtPlugInParam[i].mb_str().data()); - } - } - - else { - fprintf(stderr, "plugin: fps not found...\n"); - } - } - - // Create the main application window + // Create the main application window frame = new MainFrame(m_plugInName, NULL); SetTopWindow(frame); @@ -4983,25 +4924,6 @@ void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, CO foff_phase_rect->imag /= mag; } -int plugin_get_persistant(char name[], char value[]) { - wxString n,v; - int i; - - for(i=0; i Date: Fri, 15 Jan 2021 17:09:04 +1030 Subject: [PATCH 03/18] remove unused experimental UDP system --- src/dlg_options.cpp | 108 -------------------- src/main.cpp | 234 -------------------------------------------- 2 files changed, 342 deletions(-) diff --git a/src/dlg_options.cpp b/src/dlg_options.cpp index 4aea5d869..029b8f677 100644 --- a/src/dlg_options.cpp +++ b/src/dlg_options.cpp @@ -272,73 +272,6 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c wxBoxSizer* sizerInterfacing; sizerInterfacing = new wxBoxSizer(wxVERTICAL); -#ifdef __EXPERIMENTAL_UDP__ - //------------------------------ - // Txt Encoding - //------------------------------ - - wxStaticBoxSizer* sbSizer_encoding = new wxStaticBoxSizer(new wxStaticBox(m_interfacingTab, wxID_ANY, _("Text Encoding")), wxHORIZONTAL); - -#ifdef SHORT_VARICODE - m_rb_textEncoding1 = new wxRadioButton( m_interfacingTab, wxID_ANY, wxT("Long varicode"), wxDefaultPosition, wxDefaultSize, 0); - m_rb_textEncoding1->SetValue(true); - sbSizer_encoding->Add(m_rb_textEncoding1, 0, wxALIGN_LEFT|wxALL, 1); - m_rb_textEncoding2 = new wxRadioButton( m_interfacingTab, wxID_ANY, wxT("Short Varicode"), wxDefaultPosition, wxDefaultSize, 0); - sbSizer_encoding->Add(m_rb_textEncoding2, 0, wxALIGN_LEFT|wxALL, 1); -#endif - - sizerInterfacing->Add(sbSizer_encoding,0, wxALL|wxEXPAND, 3); - - //------------------------------ - // Event processing - //------------------------------ - - wxStaticBoxSizer* sbSizer_events; - wxStaticBox *sb_events = new wxStaticBox(m_interfacingTab, wxID_ANY, _("Event Processing")); - sbSizer_events = new wxStaticBoxSizer(sb_events, wxVERTICAL); - - // event processing enable and spam timer - - wxStaticBoxSizer* sbSizer_events_top; - wxStaticBox* sb_events1 = new wxStaticBox(m_interfacingTab, wxID_ANY, _("")); - sbSizer_events_top = new wxStaticBoxSizer(sb_events1, wxHORIZONTAL); - - m_ckbox_events = new wxCheckBox(m_interfacingTab, wxID_ANY, _("Enable System Calls Syscall Spam Timer"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); - sb_events->SetToolTip(_("Enable processing of events and generation of system calls")); - sbSizer_events_top->Add(m_ckbox_events, 0, 0, 5); - m_txt_spam_timer = new wxTextCtrl(m_interfacingTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(40,-1), 0, wxTextValidator(wxFILTER_DIGITS)); - m_txt_spam_timer->SetToolTip(_("Many matching events can cause a flood of syscalls. Set minimum time (seconds) between syscalls for each event here")); - sbSizer_events_top->Add(m_txt_spam_timer, 0, 0, 5); - m_rb_spam_timer = new wxRadioButton( m_interfacingTab, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); - m_rb_spam_timer->SetForegroundColour( wxColour(0, 255, 0 ) ); - sbSizer_events_top->Add(m_rb_spam_timer, 0, 0, 10); - sbSizer_events->Add(sbSizer_events_top, 0, 0, 5); - - // list of regexps - - wxStaticBoxSizer* sbSizer_regexp = new wxStaticBoxSizer(new wxStaticBox(m_interfacingTab, wxID_ANY, _("Regular Expressions to Process Events")), wxHORIZONTAL); - m_txt_events_regexp_match = new wxTextCtrl(m_interfacingTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,100), wxTE_MULTILINE); - m_txt_events_regexp_match->SetToolTip(_("Enter regular expressions to match events")); - sbSizer_regexp->Add(m_txt_events_regexp_match, 1, wxEXPAND, 5); - m_txt_events_regexp_replace = new wxTextCtrl(m_interfacingTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,100), wxTE_MULTILINE); - m_txt_events_regexp_replace->SetToolTip(_("Enter regular expressions to replace events")); - sbSizer_regexp->Add(m_txt_events_regexp_replace, 1, wxEXPAND, 5); - sbSizer_events->Add(sbSizer_regexp, 1, wxEXPAND, 5); - - // log of events and responses - - wxStaticBoxSizer* sbSizer_event_log = new wxStaticBoxSizer(new wxStaticBox(m_interfacingTab, wxID_ANY, _("Log of Events and Responses")), wxVERTICAL); - wxBoxSizer* bSizer33 = new wxBoxSizer(wxHORIZONTAL); - m_txt_events_in = new wxTextCtrl(m_interfacingTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,50), wxTE_MULTILINE | wxTE_READONLY); - bSizer33->Add(m_txt_events_in, 1, wxEXPAND, 5); - m_txt_events_out = new wxTextCtrl(m_interfacingTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,50), wxTE_MULTILINE | wxTE_READONLY); - bSizer33->Add(m_txt_events_out, 1, wxEXPAND, 5); - sbSizer_event_log->Add(bSizer33, 1, wxEXPAND, 5); - sbSizer_events->Add(sbSizer_event_log, 1, wxEXPAND, 5); - - sizerInterfacing->Add(sbSizer_events,0, wxALL|wxEXPAND, 3); -#endif - //---------------------------------------------------------- // UDP Send Messages on Events //---------------------------------------------------------- @@ -565,22 +498,6 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckboxTxRxDumpFifoState->SetValue(g_dump_fifo_state); m_ckboxFreeDVAPIVerbose->SetValue(g_freedv_verbose); -#ifdef __EXPERIMENTAL_UDP__ - m_ckbox_events->SetValue(wxGetApp().m_events); - m_txt_spam_timer->SetValue(wxString::Format(wxT("%i"),wxGetApp().m_events_spam_timer)); - - m_txt_events_regexp_match->SetValue(wxGetApp().m_events_regexp_match); - m_txt_events_regexp_replace->SetValue(wxGetApp().m_events_regexp_replace); - - -#ifdef SHORT_VARICODE - if (wxGetApp().m_textEncoding == 1) - m_rb_textEncoding1->SetValue(true); - if (wxGetApp().m_textEncoding == 2) - m_rb_textEncoding2->SetValue(true); -#endif -#endif - m_ckboxFreeDV700txClip->SetValue(wxGetApp().m_FreeDV700txClip); m_ckboxFreeDV700txBPF->SetValue(wxGetApp().m_FreeDV700txBPF); m_ckboxFreeDV700Combine->SetValue(wxGetApp().m_FreeDV700Combine); @@ -692,31 +609,6 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) g_dump_fifo_state = m_ckboxTxRxDumpFifoState->GetValue(); g_freedv_verbose = m_ckboxFreeDVAPIVerbose->GetValue(); -#ifdef __EXPERIMENTAL_UDP__ - wxGetApp().m_events = m_ckbox_events->GetValue(); - long spam_timer; - m_txt_spam_timer->GetValue().ToLong(&spam_timer); - wxGetApp().m_events_spam_timer = (int)spam_timer; - - // make sure regexp lists are terminated by a \n - - if (m_txt_events_regexp_match->GetValue().Last() != '\n') { - m_txt_events_regexp_match->SetValue(m_txt_events_regexp_match->GetValue()+'\n'); - } - if (m_txt_events_regexp_replace->GetValue().Last() != '\n') { - m_txt_events_regexp_replace->SetValue(m_txt_events_regexp_replace->GetValue()+'\n'); - } - wxGetApp().m_events_regexp_match = m_txt_events_regexp_match->GetValue(); - wxGetApp().m_events_regexp_replace = m_txt_events_regexp_replace->GetValue(); - -#ifdef SHORT_VARICODE - if (m_rb_textEncoding1->GetValue()) - wxGetApp().m_textEncoding = 1; - if (m_rb_textEncoding2->GetValue()) - wxGetApp().m_textEncoding = 2; -#endif -#endif - wxGetApp().m_udp_enable = m_ckbox_udp_enable->GetValue(); long port; m_txt_udp_port->GetValue().ToLong(&port); diff --git a/src/main.cpp b/src/main.cpp index 3cb21262a..33ec823ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -635,13 +635,6 @@ MainFrame::MainFrame(wxString plugInName, wxWindow *parent) : TopFrame(plugInNam g_modal = false; -#ifdef __EXPERIMENTAL_UDP__ - // Start UDP listener thread - - m_UDPThread = NULL; - startUDPThread(); -#endif - optionsDlg = new OptionsDlg(NULL); m_schedule_restore = false; @@ -693,10 +686,6 @@ MainFrame::~MainFrame() fclose(g_logfile); #endif -#ifdef __EXPERIMENTAL_UDP__ - stopUDPThread(); -#endif - if (wxGetApp().m_serialport) { delete wxGetApp().m_serialport; @@ -1384,16 +1373,6 @@ void MainFrame::OnTimer(wxTimerEvent &evt) m_schedule_restore = false; } -#ifdef __UDP_EXPERIMENTAL__ - // Light Spam Timer LED if at least one timer is running - - int i; - optionsDlg->SetSpamTimerLight(false); - for(i=0; iSetSpamTimerLight(true); -#endif - // Blink file playback status line if (g_playFileFromRadio) { @@ -1607,10 +1586,6 @@ void MainFrame::togglePTT(void) { m_textSync->Disable(); -#ifdef __UDP_EXPERIMENTAL__ - char e[80]; sprintf(e,"ptt"); processTxtEvent(e); -#endif - // Disable On/Off button. m_togBtnOnOff->Enable(false); } @@ -3001,9 +2976,6 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) #endif // _USE_TIMER } -#ifdef __UDP_EXPERIMENTAL__ - char e[80]; sprintf(e,"start"); processTxtEvent(e); -#endif } // Stop was pressed or start up failed @@ -3015,10 +2987,6 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) // Stop Running ------------------------------------------------- // -#ifdef __UDP_EXPERIMENTAL__ - optionsDlg->SetSpamTimerLight(false); -#endif - #ifdef _USE_TIMER m_plotTimer.Stop(); m_pskReporterTimer.Stop(); @@ -3102,10 +3070,6 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) m_rb2020->Enable(); if (m_rbPlugIn != NULL) m_rbPlugIn->Enable(); - -#ifdef __UDP_EXPERIMENTAL__ - char e[80]; sprintf(e,"stop"); processTxtEvent(e); -#endif } optionsDlg->setSessionActive(m_RxRunning); @@ -3714,88 +3678,6 @@ void MainFrame::startRxStream() } } -#ifdef __UDP_EPERIMENTAL__ - -void MainFrame::processTxtEvent(char event[]) { - int rule = 0; - - //printf("processTxtEvent:\n"); - //printf(" event: %s\n", event); - - // process with regexp and issue system command - - // Each regexp in our list is separated by a newline. We want to try all of them. - - wxString event_str(event); - int match_end, replace_end; - match_end = replace_end = 0; - wxString regexp_match_list = wxGetApp().m_events_regexp_match; - wxString regexp_replace_list = wxGetApp().m_events_regexp_replace; - - bool found_match = false; - - while (((match_end = regexp_match_list.Find('\n')) != wxNOT_FOUND) && (rule < MAX_EVENT_RULES)) { - //printf("match_end: %d\n", match_end); - if ((replace_end = regexp_replace_list.Find('\n')) != wxNOT_FOUND) { - //printf("replace_end = %d\n", replace_end); - - // candidate match and replace regexps strings exist, so lets try them - - wxString regexp_match = regexp_match_list.SubString(0, match_end-1); - wxString regexp_replace = regexp_replace_list.SubString(0, replace_end-1); - //printf("match: %s replace: %s\n", (const char *)regexp_match.c_str(), (const char *)regexp_replace.c_str()); - wxRegEx re(regexp_match); - //printf(" checking for match against: %s\n", (const char *)regexp_match.c_str()); - - // if we found a match, lets run the replace regexp and issue the system command - - wxString event_str_rep = event_str; - - if (re.Replace(&event_str_rep, regexp_replace) != 0) { - fprintf(stderr, " found match! event_str: %s\n", (const char *)event_str.c_str()); - found_match = true; - - bool enableSystem = false; - if (wxGetApp().m_events) - enableSystem = true; - - // no syscall if spam timer still running - - if (spamTimer[rule].IsRunning()) { - enableSystem = false; - fprintf(stderr, " spam timer running\n"); - } - - const char *event_out = event_str_rep.ToUTF8(); - wxString event_out_with_return_code; - - if (enableSystem) { - int ret = wxExecute(event_str_rep); - event_out_with_return_code.Printf(_T("%s -> returned %d"), event_out, ret); - spamTimer[rule].Start((wxGetApp().m_events_spam_timer)*1000, wxTIMER_ONE_SHOT); - } - else - event_out_with_return_code.Printf(_T("%s T: %d"), event_out, spamTimer[rule].IsRunning()); - - // update event log GUI if currently displayed - - if (optionsDlg != NULL) { - optionsDlg->updateEventLog(wxString(event), event_out_with_return_code); - } - } - } - regexp_match_list = regexp_match_list.SubString(match_end+1, regexp_match_list.length()); - regexp_replace_list = regexp_replace_list.SubString(replace_end+1, regexp_replace_list.length()); - - rule++; - } - - if ((optionsDlg != NULL) && !found_match) { - optionsDlg->updateEventLog(wxString(event), _("")); - } -} -#endif - #define SBQ_MAX_ARGS 5 @@ -4766,122 +4648,6 @@ void MainFrame::checkAvxSupport(void) } #endif -#ifdef __UDP_SUPPORT__ - -//---------------------------------------------------------------- -// PollUDP() - see if any commands on UDP port -//---------------------------------------------------------------- - -// test this puppy with netcat: -// $ echo "hello" | nc -u -q1 localhost 3000 - -int MainFrame::PollUDP(void) -{ - // this will block until message received, so we put it in it's own thread - - char buf[1024]; - char reply[80]; - size_t n = m_udp_sock->RecvFrom(m_udp_addr, buf, sizeof(buf)).LastCount(); - - if (n) { - wxString bufstr = wxString::From8BitData(buf, n); - bufstr.Trim(); - wxString ipaddr = m_udp_addr.IPAddress(); - printf("Received: \"%s\" from %s:%u\n", - (const char *)bufstr.c_str(), - (const char *)ipaddr.c_str(), m_udp_addr.Service()); - - // for security only accept commands from local host - - sprintf(reply,"nope\n"); - if (ipaddr.Cmp(_("127.0.0.1")) == 0) { - - // process commands - - if (bufstr.Cmp(_("restore")) == 0) { - m_schedule_restore = true; // Make Restore happen in main thread to avoid crashing - sprintf(reply,"ok\n"); - } - - wxString itemToSet, val; - if (bufstr.StartsWith(_("set "), &itemToSet)) { - if (itemToSet.StartsWith("txtmsg ", &val)) { - // note: if options dialog is open this will get overwritten - wxGetApp().m_callSign = val; - } - sprintf(reply,"ok\n"); - } - if (bufstr.StartsWith(_("ptton"), &itemToSet)) { - // note: if options dialog is open this will get overwritten - m_btnTogPTT->SetValue(true); - togglePTT(); - sprintf(reply,"ok\n"); - } - if (bufstr.StartsWith(_("pttoff"), &itemToSet)) { - // note: if options dialog is open this will get overwritten - m_btnTogPTT->SetValue(false); - togglePTT(); - sprintf(reply,"ok\n"); - } - - } - else { - printf("We only accept messages from locahost!\n"); - } - - if ( m_udp_sock->SendTo(m_udp_addr, reply, strlen(reply)).LastCount() != strlen(reply)) { - printf("ERROR: failed to send data\n"); - } - } - - return n; -} - -void MainFrame::startUDPThread(void) { - fprintf(stderr, "starting UDP thread!\n"); - m_UDPThread = new UDPThread; - m_UDPThread->mf = this; - if (m_UDPThread->Create() != wxTHREAD_NO_ERROR ) { - wxLogError(wxT("Can't create thread!")); - } - if (m_UDPThread->Run() != wxTHREAD_NO_ERROR ) { - wxLogError(wxT("Can't start thread!")); - delete m_UDPThread; - } -} - -void MainFrame::stopUDPThread(void) { - printf("stopping UDP thread!\n"); - if ((m_UDPThread != NULL) && m_UDPThread->m_run) { - m_UDPThread->m_run = 0; - m_UDPThread->Wait(); - m_UDPThread = NULL; - } -} - -void *UDPThread::Entry() { - //fprintf(stderr, "UDP thread started!\n"); - while (m_run) { - if (wxGetApp().m_udp_enable) { - printf("m_udp_enable\n"); - mf->m_udp_addr.Service(wxGetApp().m_udp_port); - mf->m_udp_sock = new wxDatagramSocket(mf->m_udp_addr, wxSOCKET_NOWAIT); - - while (m_run && wxGetApp().m_udp_enable) { - if (mf->PollUDP() == 0) { - wxThread::Sleep(20); - } - } - - delete mf->m_udp_sock; - } - wxThread::Sleep(20); - } - return NULL; -} - -#endif - char my_get_next_tx_char(void *callback_state) { short ch = 0; From 925144f42ddf2f4e84ab83b4c70c896fb1e66f9d Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 17:15:51 +1030 Subject: [PATCH 04/18] udp moved to a separate source file --- src/CMakeLists.txt | 1 + src/main.cpp | 45 +------------------------------------------- src/udp.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 src/udp.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9fd8e9d2..1b993b3e8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,7 @@ set(FREEDV_SOURCES pskreporter.h callsign_encoder.cpp callsign_encoder.h + udp.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index 33ec823ec..d1f3859ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,7 +169,7 @@ FILE *g_logfile; // UDP socket available to send messages -wxDatagramSocket *g_sock; +extern wxDatagramSocket *g_sock; #ifdef __HORUS__ // Horus Balloon telemetry support @@ -4690,46 +4690,3 @@ void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, CO foff_phase_rect->imag /= mag; } -/* - Sending simple message via UDP - - http://cool-emerald.blogspot.com.au/2018/01/udptcp-socket-programming-with-wxwidgets.html#udp -*/ - - -void UDPInit(void) { - // Create the socket - - wxIPV4address addr_rx; - addr_rx.AnyAddress(); - //addr_rx.Service(3000); - g_sock = new wxDatagramSocket(addr_rx); - - // We use IsOk() here to see if the server is really listening - - if (!g_sock->IsOk()) { - fprintf(stderr, "UDPInit: Could not listen at the specified port !\n"); - return; - } - - wxIPV4address addrReal; - if (!g_sock->GetLocal(addrReal)){ - fprintf(stderr, "UDPInit: Couldn't get the address we bound to\n"); - } - else { - fprintf(stderr, "Server listening at %s:%u \n", (const char*)addrReal.IPAddress().c_str(), addrReal.Service()); - } -} - -void UDPSend(int port, char *buf, unsigned int n) { - fprintf(stderr, "UDPSend buf: %s n: %d\n", buf, n); - - wxIPV4address addr_tx; - addr_tx.Hostname("localhost"); - addr_tx.Service(port); - - if ( g_sock->SendTo(addr_tx, (const void*)buf, n).LastCount() != n ) { - fprintf(stderr, "UDPSend: failed to send data"); - return; - } -} diff --git a/src/udp.cpp b/src/udp.cpp new file mode 100644 index 000000000..217633c8c --- /dev/null +++ b/src/udp.cpp @@ -0,0 +1,47 @@ +/* + Sending simple message via UDP + + http://cool-emerald.blogspot.com.au/2018/01/udptcp-socket-programming-with-wxwidgets.html#udp +*/ + +#include "main.h" + +// UDP socket available to send messages +wxDatagramSocket *g_sock; + +void UDPInit(void) { + // Create the socket + + wxIPV4address addr_rx; + addr_rx.AnyAddress(); + //addr_rx.Service(3000); + g_sock = new wxDatagramSocket(addr_rx); + + // We use IsOk() here to see if the server is really listening + + if (!g_sock->IsOk()) { + fprintf(stderr, "UDPInit: Could not listen at the specified port !\n"); + return; + } + + wxIPV4address addrReal; + if (!g_sock->GetLocal(addrReal)){ + fprintf(stderr, "UDPInit: Couldn't get the address we bound to\n"); + } + else { + fprintf(stderr, "Server listening at %s:%u \n", (const char*)addrReal.IPAddress().c_str(), addrReal.Service()); + } +} + +void UDPSend(int port, char *buf, unsigned int n) { + fprintf(stderr, "UDPSend buf: %s n: %d\n", buf, n); + + wxIPV4address addr_tx; + addr_tx.Hostname("localhost"); + addr_tx.Service(port); + + if ( g_sock->SendTo(addr_tx, (const void*)buf, n).LastCount() != n ) { + fprintf(stderr, "UDPSend: failed to send data"); + return; + } +} From 9aa4d74387f0b320ffd9c92642b1c49399cfb253 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 17:25:11 +1030 Subject: [PATCH 05/18] moving some functions out of main.cpp into util.cpp --- src/CMakeLists.txt | 1 + src/main.cpp | 151 ----------------------------------------- src/util.cpp | 165 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 151 deletions(-) create mode 100644 src/util.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b993b3e8..fc413b83e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ set(FREEDV_SOURCES callsign_encoder.cpp callsign_encoder.h udp.cpp + util.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index d1f3859ea..e557f7118 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4539,154 +4539,3 @@ int MainFrame::txCallback( return paContinue; } -// Callback from plot_spectrum & plot_waterfall. would be nice to -// work out a way to do this without globals. - -void clickTune(float freq) { - - // The demod is hard-wired to expect a centre frequency of - // FDMDV_FCENTRE. So we want to take the signal centered on the - // click tune freq and re-centre it on FDMDV_FCENTRE. For example - // if the click tune freq is 1500Hz, and FDMDV_CENTRE is 1200 Hz, - // we need to shift the input signal centred on 1500Hz down to - // 1200Hz, an offset of -300Hz. - - // Bit of an "indent" as we are often trying to get it back - // exactly in the centre - - if (fabs(FDMDV_FCENTRE - freq) < 10.0) { - freq = FDMDV_FCENTRE; - fprintf(stderr, "indent!\n"); - } - - if (g_split) { - g_RxFreqOffsetHz = FDMDV_FCENTRE - freq; - } - else { - g_TxFreqOffsetHz = freq - FDMDV_FCENTRE; - g_RxFreqOffsetHz = FDMDV_FCENTRE - freq; - } - fprintf(stderr, "g_TxFreqOffsetHz: %f g_RxFreqOffsetHz: %f\n", g_TxFreqOffsetHz, g_RxFreqOffsetHz); -} - -//---------------------------------------------------------------- -// OpenSerialPort() -//---------------------------------------------------------------- - -void MainFrame::OpenSerialPort(void) -{ - Serialport *serialport = wxGetApp().m_serialport; - - if(!wxGetApp().m_strRigCtrlPort.IsEmpty()) { - serialport->openport(wxGetApp().m_strRigCtrlPort.c_str(), - wxGetApp().m_boolUseRTS, - wxGetApp().m_boolRTSPos, - wxGetApp().m_boolUseDTR, - wxGetApp().m_boolDTRPos); - if (serialport->isopen()) { - // always start PTT in Rx state - serialport->ptt(false); - } - else { - wxMessageBox("Couldn't open Serial Port", wxT("About"), wxOK | wxICON_ERROR, this); - } - } -} - - -//---------------------------------------------------------------- -// CloseSerialPort() -//---------------------------------------------------------------- - -void MainFrame::CloseSerialPort(void) -{ - Serialport *serialport = wxGetApp().m_serialport; - if (serialport->isopen()) { - // always end with PTT in rx state - - serialport->ptt(false); - serialport->closeport(); - } -} - -// -// checkAvxSupport -// -// Tests the underlying platform for AVX support. 2020 needs AVX support to run -// in real-time, and old processors do not offer AVX support -// - -#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) -void MainFrame::checkAvxSupport(void) -{ - - isAvxPresent = false; - uint32_t eax, ebx, ecx, edx; - eax = ebx = ecx = edx = 0; - __cpuid(1, eax, ebx, ecx, edx); - - if (ecx & (1<<27) && ecx & (1<<28)) { - // CPU supports XSAVE and AVX - uint32_t xcr0, xcr0_high; - asm("xgetbv" : "=a" (xcr0), "=d" (xcr0_high) : "c" (0)); - isAvxPresent = (xcr0 & 6) == 6; // AVX state saving enabled? - } -} -#elif defined(__APPLE__) && defined(__aarch64__) -void MainFrame::checkAvxSupport(void) -{ - // Force 2020 mode to be enabled on ARM Macs. This is experimental - // and may cause problems. During preliminary testing it seems to use - // NEON optimizations enabled in LPCNet and consumes less than 100% of a single - // core while decoding audio. - isAvxPresent = true; -} -#else -void MainFrame::checkAvxSupport(void) -{ - isAvxPresent = false; -} -#endif - -char my_get_next_tx_char(void *callback_state) { - short ch = 0; - - codec2_fifo_read(g_txDataInFifo, &ch, 1); - //fprintf(stderr, "get_next_tx_char: %c\n", (char)ch); - return (char)ch; -} - -void my_put_next_rx_char(void *callback_state, char c) { - short ch = (short)((unsigned char)c); - //fprintf(stderr, "put_next_rx_char: %c\n", (char)c); - codec2_fifo_write(g_rxDataOutFifo, &ch, 1); -} - -// Callback from FreeDv API to update error plots - -void my_freedv_put_error_pattern(void *state, short error_pattern[], int sz_error_pattern) { - codec2_fifo_write(g_error_pattern_fifo, error_pattern, sz_error_pattern); - //fprintf(stderr, "my_freedv_put_error_pattern: sz_error_pattern: %d ret: %d used: %d\n", - // sz_error_pattern, ret, codec2_fifo_used(g_error_pattern_fifo) ); -} - -void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, COMP *foff_phase_rect, int nin) -{ - COMP foff_rect; - float mag; - int i; - - foff_rect.real = cosf(2.0*M_PI*foff/Fs); - foff_rect.imag = sinf(2.0*M_PI*foff/Fs); - for(i=0; ireal /= mag; - foff_phase_rect->imag /= mag; -} - diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 000000000..681b8cf73 --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,165 @@ +/* + util.h + + Miscellaneous utility functions +*/ + +#include "main.h" + +// Callback from plot_spectrum & plot_waterfall. would be nice to +// work out a way to do this without globals. +extern float g_RxFreqOffsetHz; +extern float g_TxFreqOffsetHz; +extern int *g_split; + +void clickTune(float freq) { + + // The demod is hard-wired to expect a centre frequency of + // FDMDV_FCENTRE. So we want to take the signal centered on the + // click tune freq and re-centre it on FDMDV_FCENTRE. For example + // if the click tune freq is 1500Hz, and FDMDV_CENTRE is 1200 Hz, + // we need to shift the input signal centred on 1500Hz down to + // 1200Hz, an offset of -300Hz. + + // Bit of an "indent" as we are often trying to get it back + // exactly in the centre + + if (fabs(FDMDV_FCENTRE - freq) < 10.0) { + freq = FDMDV_FCENTRE; + fprintf(stderr, "indent!\n"); + } + + if (g_split) { + g_RxFreqOffsetHz = FDMDV_FCENTRE - freq; + } + else { + g_TxFreqOffsetHz = freq - FDMDV_FCENTRE; + g_RxFreqOffsetHz = FDMDV_FCENTRE - freq; + } + fprintf(stderr, "g_TxFreqOffsetHz: %f g_RxFreqOffsetHz: %f\n", g_TxFreqOffsetHz, g_RxFreqOffsetHz); +} + +//---------------------------------------------------------------- +// OpenSerialPort() +//---------------------------------------------------------------- + +void MainFrame::OpenSerialPort(void) +{ + Serialport *serialport = wxGetApp().m_serialport; + + if(!wxGetApp().m_strRigCtrlPort.IsEmpty()) { + serialport->openport(wxGetApp().m_strRigCtrlPort.c_str(), + wxGetApp().m_boolUseRTS, + wxGetApp().m_boolRTSPos, + wxGetApp().m_boolUseDTR, + wxGetApp().m_boolDTRPos); + if (serialport->isopen()) { + // always start PTT in Rx state + serialport->ptt(false); + } + else { + wxMessageBox("Couldn't open Serial Port", wxT("About"), wxOK | wxICON_ERROR, this); + } + } +} + + +//---------------------------------------------------------------- +// CloseSerialPort() +//---------------------------------------------------------------- + +void MainFrame::CloseSerialPort(void) +{ + Serialport *serialport = wxGetApp().m_serialport; + if (serialport->isopen()) { + // always end with PTT in rx state + + serialport->ptt(false); + serialport->closeport(); + } +} + +// +// checkAvxSupport +// +// Tests the underlying platform for AVX support. 2020 needs AVX support to run +// in real-time, and old processors do not offer AVX support +// + +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) +void MainFrame::checkAvxSupport(void) +{ + + isAvxPresent = false; + uint32_t eax, ebx, ecx, edx; + eax = ebx = ecx = edx = 0; + __cpuid(1, eax, ebx, ecx, edx); + + if (ecx & (1<<27) && ecx & (1<<28)) { + // CPU supports XSAVE and AVX + uint32_t xcr0, xcr0_high; + asm("xgetbv" : "=a" (xcr0), "=d" (xcr0_high) : "c" (0)); + isAvxPresent = (xcr0 & 6) == 6; // AVX state saving enabled? + } +} +#elif defined(__APPLE__) && defined(__aarch64__) +void MainFrame::checkAvxSupport(void) +{ + // Force 2020 mode to be enabled on ARM Macs. This is experimental + // and may cause problems. During preliminary testing it seems to use + // NEON optimizations enabled in LPCNet and consumes less than 100% of a single + // core while decoding audio. + isAvxPresent = true; +} +#else +void MainFrame::checkAvxSupport(void) +{ + isAvxPresent = false; +} +#endif + +struct FIFO extern *g_txDataInFifo; +struct FIFO extern *g_rxDataOutFifo; + +char my_get_next_tx_char(void *callback_state) { + short ch = 0; + + codec2_fifo_read(g_txDataInFifo, &ch, 1); + //fprintf(stderr, "get_next_tx_char: %c\n", (char)ch); + return (char)ch; +} + +void my_put_next_rx_char(void *callback_state, char c) { + short ch = (short)((unsigned char)c); + //fprintf(stderr, "put_next_rx_char: %c\n", (char)c); + codec2_fifo_write(g_rxDataOutFifo, &ch, 1); +} + +// Callback from FreeDv API to update error plots +struct FIFO extern *g_error_pattern_fifo; +void my_freedv_put_error_pattern(void *state, short error_pattern[], int sz_error_pattern) { + codec2_fifo_write(g_error_pattern_fifo, error_pattern, sz_error_pattern); + //fprintf(stderr, "my_freedv_put_error_pattern: sz_error_pattern: %d ret: %d used: %d\n", + // sz_error_pattern, ret, codec2_fifo_used(g_error_pattern_fifo) ); +} + +void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, COMP *foff_phase_rect, int nin) +{ + COMP foff_rect; + float mag; + int i; + + foff_rect.real = cosf(2.0*M_PI*foff/Fs); + foff_rect.imag = sinf(2.0*M_PI*foff/Fs); + for(i=0; ireal /= mag; + foff_phase_rect->imag /= mag; +} + From fb8b8f2910d75b9dfc7d40a72e3ba54a3c5356ed Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 17:32:48 +1030 Subject: [PATCH 06/18] moved equaliser GUI functions to eq.cpp --- src/CMakeLists.txt | 1 + src/eq.cpp | 85 +++++++++++++++++++++++++++ src/main.cpp | 143 --------------------------------------------- src/util.cpp | 67 +++++++++++++++++++++ 4 files changed, 153 insertions(+), 143 deletions(-) create mode 100644 src/eq.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc413b83e..ec88a66b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ set(FREEDV_SOURCES callsign_encoder.h udp.cpp util.cpp + eq.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/eq.cpp b/src/eq.cpp new file mode 100644 index 000000000..6f09cc2d0 --- /dev/null +++ b/src/eq.cpp @@ -0,0 +1,85 @@ +/* + eq.cpp + + On the fly microphone and speaker equaliser design. +*/ + +#include "main.h" + +#define SBQ_MAX_ARGS 5 + +void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float gaindB, float Q) +{ + char *arg[SBQ_MAX_ARGS]; + char argstorage[SBQ_MAX_ARGS][80]; + void *sbq; + int i, argc; + + assert((strcmp(filterType, "bass") == 0) || + (strcmp(filterType, "treble") == 0) || + (strcmp(filterType, "equalizer") == 0)); + + for(i=0; isbqMicInBass = designAnEQFilter("bass", wxGetApp().m_MicInBassFreqHz, wxGetApp().m_MicInBassGaindB); + cb->sbqMicInTreble = designAnEQFilter("treble", wxGetApp().m_MicInTrebleFreqHz, wxGetApp().m_MicInTrebleGaindB); + cb->sbqMicInMid = designAnEQFilter("equalizer", wxGetApp().m_MicInMidFreqHz, wxGetApp().m_MicInMidGaindB, wxGetApp().m_MicInMidQ); + } + + // init Spk Out Equaliser Filters + + if (m_newSpkOutFilter) { + //printf("designing new Spk Out filters\n"); + //printf("designEQFilters: wxGetApp().m_SpkOutBassFreqHz: %f\n",wxGetApp().m_SpkOutBassFreqHz); + cb->sbqSpkOutBass = designAnEQFilter("bass", wxGetApp().m_SpkOutBassFreqHz, wxGetApp().m_SpkOutBassGaindB); + cb->sbqSpkOutTreble = designAnEQFilter("treble", wxGetApp().m_SpkOutTrebleFreqHz, wxGetApp().m_SpkOutTrebleGaindB); + cb->sbqSpkOutMid = designAnEQFilter("equalizer", wxGetApp().m_SpkOutMidFreqHz, wxGetApp().m_SpkOutMidGaindB, wxGetApp().m_SpkOutMidQ); + } +} + +void MainFrame::deleteEQFilters(paCallBackData *cb) +{ + if (m_newMicInFilter) { + sox_biquad_destroy(cb->sbqMicInBass); + sox_biquad_destroy(cb->sbqMicInTreble); + sox_biquad_destroy(cb->sbqMicInMid); + } + if (m_newSpkOutFilter) { + sox_biquad_destroy(cb->sbqSpkOutBass); + sox_biquad_destroy(cb->sbqSpkOutTreble); + sox_biquad_destroy(cb->sbqSpkOutMid); + } +} + + diff --git a/src/main.cpp b/src/main.cpp index e557f7118..af19e66d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3679,149 +3679,6 @@ void MainFrame::startRxStream() } -#define SBQ_MAX_ARGS 5 - -void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float gaindB, float Q) -{ - char *arg[SBQ_MAX_ARGS]; - char argstorage[SBQ_MAX_ARGS][80]; - void *sbq; - int i, argc; - - assert((strcmp(filterType, "bass") == 0) || - (strcmp(filterType, "treble") == 0) || - (strcmp(filterType, "equalizer") == 0)); - - for(i=0; isbqMicInBass = designAnEQFilter("bass", wxGetApp().m_MicInBassFreqHz, wxGetApp().m_MicInBassGaindB); - cb->sbqMicInTreble = designAnEQFilter("treble", wxGetApp().m_MicInTrebleFreqHz, wxGetApp().m_MicInTrebleGaindB); - cb->sbqMicInMid = designAnEQFilter("equalizer", wxGetApp().m_MicInMidFreqHz, wxGetApp().m_MicInMidGaindB, wxGetApp().m_MicInMidQ); - } - - // init Spk Out Equaliser Filters - - if (m_newSpkOutFilter) { - //printf("designing new Spk Out filters\n"); - //printf("designEQFilters: wxGetApp().m_SpkOutBassFreqHz: %f\n",wxGetApp().m_SpkOutBassFreqHz); - cb->sbqSpkOutBass = designAnEQFilter("bass", wxGetApp().m_SpkOutBassFreqHz, wxGetApp().m_SpkOutBassGaindB); - cb->sbqSpkOutTreble = designAnEQFilter("treble", wxGetApp().m_SpkOutTrebleFreqHz, wxGetApp().m_SpkOutTrebleGaindB); - cb->sbqSpkOutMid = designAnEQFilter("equalizer", wxGetApp().m_SpkOutMidFreqHz, wxGetApp().m_SpkOutMidGaindB, wxGetApp().m_SpkOutMidQ); - } -} - -void MainFrame::deleteEQFilters(paCallBackData *cb) -{ - if (m_newMicInFilter) { - sox_biquad_destroy(cb->sbqMicInBass); - sox_biquad_destroy(cb->sbqMicInTreble); - sox_biquad_destroy(cb->sbqMicInMid); - } - if (m_newSpkOutFilter) { - sox_biquad_destroy(cb->sbqSpkOutBass); - sox_biquad_destroy(cb->sbqSpkOutTreble); - sox_biquad_destroy(cb->sbqSpkOutMid); - } -} - -// returns number of output samples generated by resampling -int resample(SRC_STATE *src, - short output_short[], - short input_short[], - int output_sample_rate, - int input_sample_rate, - int length_output_short, // maximum output array length in samples - int length_input_short - ) -{ - SRC_DATA src_data; - float input[length_input_short]; - float output[length_output_short]; - int ret; - - assert(src != NULL); - - src_short_to_float_array(input_short, input, length_input_short); - - src_data.data_in = input; - src_data.data_out = output; - src_data.input_frames = length_input_short; - src_data.output_frames = length_output_short; - src_data.end_of_input = 0; - src_data.src_ratio = (float)output_sample_rate/input_sample_rate; - - ret = src_process(src, &src_data); - assert(ret == 0); - - assert(src_data.output_frames_gen <= length_output_short); - src_float_to_short_array(output, output_short, src_data.output_frames_gen); - - return src_data.output_frames_gen; -} - - -// Decimates samples using an algorithm that produces nice plots of -// speech signals at a low sample rate. We want a low sample rate so -// we don't hammer the graphics system too hard. Saves decimated data -// to a fifo for plotting on screen. - -void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs) -{ - int decimation = fs/WAVEFORM_PLOT_FS; - int nSamples, sample; - int i, st, en, max, min; - short dec_samples[length]; - - nSamples = length/decimation; - - for(sample = 0; sample < nSamples; sample += 2) - { - st = decimation*sample; - en = decimation*(sample+2); - max = min = 0; - for(i=st; i buf[i]) min = buf[i]; - } - dec_samples[sample] = max; - dec_samples[sample+1] = min; - } - codec2_fifo_write(plotFifo, dec_samples, nSamples); -} - - //--------------------------------------------------------------------------------------------- // Main real time procesing for tx and rx of FreeDV signals, run in its own thread //--------------------------------------------------------------------------------------------- diff --git a/src/util.cpp b/src/util.cpp index 681b8cf73..e1739420d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -163,3 +163,70 @@ void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, CO foff_phase_rect->imag /= mag; } +// returns number of output samples generated by resampling +int resample(SRC_STATE *src, + short output_short[], + short input_short[], + int output_sample_rate, + int input_sample_rate, + int length_output_short, // maximum output array length in samples + int length_input_short + ) +{ + SRC_DATA src_data; + float input[length_input_short]; + float output[length_output_short]; + int ret; + + assert(src != NULL); + + src_short_to_float_array(input_short, input, length_input_short); + + src_data.data_in = input; + src_data.data_out = output; + src_data.input_frames = length_input_short; + src_data.output_frames = length_output_short; + src_data.end_of_input = 0; + src_data.src_ratio = (float)output_sample_rate/input_sample_rate; + + ret = src_process(src, &src_data); + assert(ret == 0); + + assert(src_data.output_frames_gen <= length_output_short); + src_float_to_short_array(output, output_short, src_data.output_frames_gen); + + return src_data.output_frames_gen; +} + + +// Decimates samples using an algorithm that produces nice plots of +// speech signals at a low sample rate. We want a low sample rate so +// we don't hammer the graphics system too hard. Saves decimated data +// to a fifo for plotting on screen. + +void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs) +{ + int decimation = fs/WAVEFORM_PLOT_FS; + int nSamples, sample; + int i, st, en, max, min; + short dec_samples[length]; + + nSamples = length/decimation; + + for(sample = 0; sample < nSamples; sample += 2) + { + st = decimation*sample; + en = decimation*(sample+2); + max = min = 0; + for(i=st; i buf[i]) min = buf[i]; + } + dec_samples[sample] = max; + dec_samples[sample+1] = min; + } + codec2_fifo_write(plotFifo, dec_samples, nSamples); +} + + From af716556174f9c99cf2bc5b4798a5aaafe93b8fc Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 17:39:59 +1030 Subject: [PATCH 07/18] moved voice keyer code to a separate file --- src/CMakeLists.txt | 1 + src/main.cpp | 164 +-------------------------------------------- src/voicekeyer.cpp | 161 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 163 deletions(-) create mode 100644 src/voicekeyer.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec88a66b5..c0eb304db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,7 @@ set(FREEDV_SOURCES udp.cpp util.cpp eq.cpp + voicekeyer.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index af19e66d0..b5da5fd35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1532,7 +1532,7 @@ int MainApp::FilterEvent(wxEvent& event) frame->togglePTT(); } - else // spavce bar stops keyer + else // space bar stops keyer frame->VoiceKeyerProcessEvent(VK_SPACE_BAR); return true; // absorb space so we don't toggle control with focus (e.g. Start) @@ -1618,168 +1618,6 @@ void MainFrame::togglePTT(void) { } -/* - Voice Keyer: - - + space bar turns keyer off - + 5 secs of valid sync turns it off - - [X] complete state machine and builds OK - [ ] file select dialog - [ ] test all states - [ ] restore size -*/ - -void MainFrame::OnTogBtnVoiceKeyerClick (wxCommandEvent& event) -{ - if (vk_state == VK_IDLE) - VoiceKeyerProcessEvent(VK_START); - else - VoiceKeyerProcessEvent(VK_SPACE_BAR); - - event.Skip(); -} - - -int MainFrame::VoiceKeyerStartTx(void) -{ - int next_state; - - // start playing wave file or die trying - - SF_INFO sfInfo; - sfInfo.format = 0; - - g_sfPlayFile = sf_open(wxGetApp().m_txtVoiceKeyerWaveFile.mb_str(), SFM_READ, &sfInfo); - if(g_sfPlayFile == NULL) { - wxString strErr = sf_strerror(NULL); - wxMessageBox(strErr, wxT("Couldn't open:") + wxGetApp().m_txtVoiceKeyerWaveFile, wxOK); - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - else { - SetStatusText(wxT("Voice Keyer: Playing File") + wxGetApp().m_txtVoiceKeyerWaveFile + wxT(" to Mic Input") , 0); - g_loopPlayFileToMicIn = false; - g_playFileToMicIn = true; - - m_btnTogPTT->SetValue(true); togglePTT(); - next_state = VK_TX; - } - - return next_state; -} - - -void MainFrame::VoiceKeyerProcessEvent(int vk_event) { - int next_state = vk_state; - - switch(vk_state) { - - case VK_IDLE: - if (vk_event == VK_START) { - // sample these puppies at start just in case they are changed while VK running - vk_rx_pause = wxGetApp().m_intVoiceKeyerRxPause; - vk_repeats = wxGetApp().m_intVoiceKeyerRepeats; - fprintf(stderr, "vk_rx_pause: %d vk_repeats: %d\n", vk_rx_pause, vk_repeats); - - vk_repeat_counter = 0; - next_state = VoiceKeyerStartTx(); - } - break; - - case VK_TX: - - // In this state we are transmitting and playing a wave file - // to Mic In - - if (vk_event == VK_SPACE_BAR) { - m_btnTogPTT->SetValue(false); togglePTT(); - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - CallAfter([&]() { StopPlayFileToMicIn(); }); - } - - if (vk_event == VK_PLAY_FINISHED) { - m_btnTogPTT->SetValue(false); togglePTT(); - vk_repeat_counter++; - if (vk_repeat_counter > vk_repeats) { - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - else { - vk_rx_time = 0.0; - next_state = VK_RX; - } - } - - break; - - case VK_RX: - - // in this state we are receiving and waiting for - // delay timer or valid sync - - if (vk_event == VK_DT) { - if (freedv_get_sync(g_pfreedv) == 1) { - // if we detect sync transition to SYNC_WAIT state - next_state = VK_SYNC_WAIT; - vk_rx_sync_time = 0.0; - } else { - vk_rx_time += DT; - if (vk_rx_time >= vk_rx_pause) { - next_state = VoiceKeyerStartTx(); - } - } - } - - if (vk_event == VK_SPACE_BAR) { - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - - break; - - case VK_SYNC_WAIT: - - // In this state we wait for valid sync to last - // VK_SYNC_WAIT_TIME seconds - - if (vk_event == VK_SPACE_BAR) { - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - - if (vk_event == VK_DT) { - if (freedv_get_sync(g_pfreedv) == 0) { - // if we lose sync transition to RX State - next_state = VK_RX; - } else { - vk_rx_time += DT; - vk_rx_sync_time += DT; - } - - // drop out of voice keyer if we get a few seconds of valid sync - - if (vk_rx_sync_time >= VK_SYNC_WAIT_TIME) { - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - } - break; - - default: - // catch anything we missed - - m_btnTogPTT->SetValue(false); togglePTT(); - m_togBtnVoiceKeyer->SetValue(false); - next_state = VK_IDLE; - } - - //if ((vk_event != VK_DT) || (vk_state != next_state)) - // fprintf(stderr, "VoiceKeyerProcessEvent: vk_state: %d vk_event: %d next_state: %d vk_repeat_counter: %d\n", vk_state, vk_event, next_state, vk_repeat_counter); - vk_state = next_state; -} - // State machine to detect sync and send a UDP message diff --git a/src/voicekeyer.cpp b/src/voicekeyer.cpp new file mode 100644 index 000000000..6bfa7c354 --- /dev/null +++ b/src/voicekeyer.cpp @@ -0,0 +1,161 @@ +/* + voicekeyer.cpp + + Voice Keyer implementation +*/ + +#include "main.h" + +void MainFrame::OnTogBtnVoiceKeyerClick (wxCommandEvent& event) +{ + if (vk_state == VK_IDLE) + VoiceKeyerProcessEvent(VK_START); + else + VoiceKeyerProcessEvent(VK_SPACE_BAR); + + event.Skip(); +} + +extern SNDFILE *g_sfPlayFile; +extern bool g_playFileToMicIn; +extern bool g_loopPlayFileToMicIn; +extern struct freedv *g_pfreedv; +int MainFrame::VoiceKeyerStartTx(void) +{ + int next_state; + + // start playing wave file or die trying + + SF_INFO sfInfo; + sfInfo.format = 0; + + g_sfPlayFile = sf_open(wxGetApp().m_txtVoiceKeyerWaveFile.mb_str(), SFM_READ, &sfInfo); + if(g_sfPlayFile == NULL) { + wxString strErr = sf_strerror(NULL); + wxMessageBox(strErr, wxT("Couldn't open:") + wxGetApp().m_txtVoiceKeyerWaveFile, wxOK); + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + else { + SetStatusText(wxT("Voice Keyer: Playing File") + wxGetApp().m_txtVoiceKeyerWaveFile + wxT(" to Mic Input") , 0); + g_loopPlayFileToMicIn = false; + g_playFileToMicIn = true; + + m_btnTogPTT->SetValue(true); togglePTT(); + next_state = VK_TX; + } + + return next_state; +} + + +void MainFrame::VoiceKeyerProcessEvent(int vk_event) { + int next_state = vk_state; + + switch(vk_state) { + + case VK_IDLE: + if (vk_event == VK_START) { + // sample these puppies at start just in case they are changed while VK running + vk_rx_pause = wxGetApp().m_intVoiceKeyerRxPause; + vk_repeats = wxGetApp().m_intVoiceKeyerRepeats; + fprintf(stderr, "vk_rx_pause: %d vk_repeats: %d\n", vk_rx_pause, vk_repeats); + + vk_repeat_counter = 0; + next_state = VoiceKeyerStartTx(); + } + break; + + case VK_TX: + + // In this state we are transmitting and playing a wave file + // to Mic In + + if (vk_event == VK_SPACE_BAR) { + m_btnTogPTT->SetValue(false); togglePTT(); + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + CallAfter([&]() { StopPlayFileToMicIn(); }); + } + + if (vk_event == VK_PLAY_FINISHED) { + m_btnTogPTT->SetValue(false); togglePTT(); + vk_repeat_counter++; + if (vk_repeat_counter > vk_repeats) { + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + else { + vk_rx_time = 0.0; + next_state = VK_RX; + } + } + + break; + + case VK_RX: + + // in this state we are receiving and waiting for + // delay timer or valid sync + + if (vk_event == VK_DT) { + if (freedv_get_sync(g_pfreedv) == 1) { + // if we detect sync transition to SYNC_WAIT state + next_state = VK_SYNC_WAIT; + vk_rx_sync_time = 0.0; + } else { + vk_rx_time += DT; + if (vk_rx_time >= vk_rx_pause) { + next_state = VoiceKeyerStartTx(); + } + } + } + + if (vk_event == VK_SPACE_BAR) { + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + + break; + + case VK_SYNC_WAIT: + + // In this state we wait for valid sync to last + // VK_SYNC_WAIT_TIME seconds + + if (vk_event == VK_SPACE_BAR) { + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + + if (vk_event == VK_DT) { + if (freedv_get_sync(g_pfreedv) == 0) { + // if we lose sync transition to RX State + next_state = VK_RX; + } else { + vk_rx_time += DT; + vk_rx_sync_time += DT; + } + + // drop out of voice keyer if we get a few seconds of valid sync + + if (vk_rx_sync_time >= VK_SYNC_WAIT_TIME) { + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + } + break; + + default: + // catch anything we missed + + m_btnTogPTT->SetValue(false); togglePTT(); + m_togBtnVoiceKeyer->SetValue(false); + next_state = VK_IDLE; + } + + //if ((vk_event != VK_DT) || (vk_state != next_state)) + // fprintf(stderr, "VoiceKeyerProcessEvent: vk_state: %d vk_event: %d next_state: %d vk_repeat_counter: %d\n", vk_state, vk_event, next_state, vk_repeat_counter); + vk_state = next_state; +} + From 1ef71a0c379f56f7f3c75c10b26ff4a9337575bf Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 18:03:06 +1030 Subject: [PATCH 08/18] removed unused ALC code --- src/main.cpp | 18 +----------------- src/topFrame.cpp | 20 -------------------- src/topFrame.h | 3 --- 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b5da5fd35..47f14ff1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -554,7 +554,6 @@ MainFrame::MainFrame(wxString plugInName, wxWindow *parent) : TopFrame(plugInNam m_togBtnOnOff->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnSplit->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this); m_togBtnAnalog->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); - //m_togBtnALC->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnALCClickUI), NULL, this); // m_btnTogPTT->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this); m_togBtnSplit->Disable(); @@ -563,7 +562,6 @@ MainFrame::MainFrame(wxString plugInName, wxWindow *parent) : TopFrame(plugInNam m_togBtnAnalog->Disable(); m_btnTogPTT->Disable(); m_togBtnVoiceKeyer->Disable(); - //m_togBtnALC->Disable(); // squelch settings char sqsnr[15]; @@ -808,8 +806,7 @@ MainFrame::~MainFrame() m_togBtnOnOff->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnSplit->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this); m_togBtnAnalog->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); - //m_togBtnALC->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnALCClickUI), NULL, this); - //m_btnTogPTT->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this); + //m_btnTogPTT->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this); sox_biquad_finish(); @@ -1774,18 +1771,6 @@ void MainFrame::OnBerReset(wxCommandEvent& event) } } -#ifdef ALC -//------------------------------------------------------------------------- -// OnTogBtnALCClick() -//------------------------------------------------------------------------- -void MainFrame::OnTogBtnALCClick(wxCommandEvent& event) -{ - wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnALCClick"), wxOK); - - event.Skip(); -} -#endif - // extra panel added to file open dialog to add loop checkbox MyExtraPlayFilePanel::MyExtraPlayFilePanel(wxWindow *parent): wxPanel(parent) { @@ -2327,7 +2312,6 @@ void MainFrame::OnExit(wxCommandEvent& event) //m_togRxID->Disable(); //m_togTxID->Disable(); m_togBtnAnalog->Disable(); - //m_togBtnALC->Disable(); //m_btnTogPTT->Disable(); Pa_Terminate(); diff --git a/src/topFrame.cpp b/src/topFrame.cpp index e5cf5e99b..6b4e8daa1 100644 --- a/src/topFrame.cpp +++ b/src/topFrame.cpp @@ -450,20 +450,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w bSizer13a->Add(m_togBtnVoiceKeyer, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1); sbSizer5->Add(bSizer13a, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1); - // not implemented on fdmdv2 -#ifdef ALC - //------------------------------ - // Toggle for ALC - //------------------------------ - wxBoxSizer* bSizer14; - bSizer14 = new wxBoxSizer(wxVERTICAL); - m_togBtnALC = new wxToggleButton(this, wxID_ANY, _("ALC"), wxDefaultPosition, wxDefaultSize, 0); - m_togBtnALC->SetToolTip(_("Toggle automatic level control mode.")); - - bSizer14->Add(m_togBtnALC, 0, wxALL, 1); - sbSizer5->Add(bSizer14, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALL, 1); -#endif - //------------------------------ // PTT button: Toggle Transmit/Receive mode //------------------------------ @@ -538,9 +524,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w m_togBtnSplit->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnSplitClick), NULL, this); m_togBtnAnalog->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnAnalogClick), NULL, this); m_togBtnVoiceKeyer->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnVoiceKeyerClick), NULL, this); -#ifdef ALC - m_togBtnALC->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnALCClick), NULL, this); -#endif m_btnTogPTT->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnPTT), NULL, this); m_BtnCallSignReset->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnCallSignReset), NULL, this); @@ -596,9 +579,6 @@ TopFrame::~TopFrame() m_togBtnSplit->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnSplitClick), NULL, this); m_togBtnAnalog->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnAnalogClick), NULL, this); m_togBtnVoiceKeyer->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnVoiceKeyerClick), NULL, this); -#ifdef ALC - m_togBtnALC->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnALCClick), NULL, this); -#endif m_btnTogPTT->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnPTT), NULL, this); } diff --git a/src/topFrame.h b/src/topFrame.h index 4841865bc..73518a3fa 100644 --- a/src/topFrame.h +++ b/src/topFrame.h @@ -172,12 +172,10 @@ class TopFrame : public wxFrame virtual void OnTogBtnSplitClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnTogBtnAnalogClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnTogBtnVoiceKeyerClick( wxCommandEvent& event ) { event.Skip(); } - virtual void OnTogBtnALCClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnTogBtnPTT( wxCommandEvent& event ) { event.Skip(); } virtual void OnTogBtnSplitClickUI(wxUpdateUIEvent& event) { event.Skip(); } virtual void OnTogBtnAnalogClickUI(wxUpdateUIEvent& event) { event.Skip(); } - virtual void OnTogBtnALCClickUI(wxUpdateUIEvent& event) { event.Skip(); } virtual void OnTogBtnRxIDUI(wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnTogBtnTxIDUI(wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnTogBtnPTT_UI(wxUpdateUIEvent& event ) { event.Skip(); } @@ -194,7 +192,6 @@ class TopFrame : public wxFrame wxToggleButton* m_togBtnSplit; wxToggleButton* m_togBtnAnalog; wxToggleButton* m_togBtnVoiceKeyer; - wxToggleButton* m_togBtnALC; wxToggleButton* m_btnTogPTT; wxToggleButton* m_togBtnLoopRx; wxToggleButton* m_togBtnLoopTx; From 66171a274c3e06d516d105f68964b387f395fb68 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 18:41:27 +1030 Subject: [PATCH 09/18] remove some more plugin code, RxID, TxID --- src/CMakeLists.txt | 1 - src/afreedvplugin.c | 117 ---------------------------------- src/dlg_plugin.cpp | 148 -------------------------------------------- src/dlg_plugin.h | 65 ------------------- src/main.cpp | 65 ++----------------- src/main.h | 28 +-------- src/topFrame.cpp | 59 +----------------- src/topFrame.h | 10 +-- 8 files changed, 7 insertions(+), 486 deletions(-) delete mode 100644 src/afreedvplugin.c delete mode 100644 src/dlg_plugin.cpp delete mode 100644 src/dlg_plugin.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c0eb304db..7a9eca840 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,6 @@ set(FREEDV_SOURCES dlg_filter.cpp dlg_options.cpp dlg_ptt.cpp - dlg_plugin.cpp main.cpp pa_wrapper.cpp plot.cpp diff --git a/src/afreedvplugin.c b/src/afreedvplugin.c deleted file mode 100644 index 5fdc424ef..000000000 --- a/src/afreedvplugin.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - afreedvplugin.c - David Rowe Feb 2016 - - Sample FreeDV plugin - - TODO: - [ ] plugin to call back to functions - [ ] ability to list .so's/DLLs and scan - [ ] where do we put plugins? - [ ] Windows build and test environment - - linux .so: - $ gcc -Wall -fPIC -c afreedvplugin.c - $ gcc -shared -Wl,-soname,afreedvplugin.so -o afreedvplugin.so afreedvplugin.o - win32 .dll: - $ i686-w64-mingw32-gcc -c afreedvplugin.c - $ i686-w64-mingw32-gcc -shared -o afreedvplugin.dll afreedvplugin.o -Wl,--out-implib,afreedvplugin_dll.a - -*/ - -#include -#include -#include - -#ifdef _WIN32_ -#define DLL __declspec(dllexport) -#else -#define DLL -#endif - - -#ifdef LATER -/* functions plugin can call - not sure how to link to these */ - -int plugin_alert(char string[]); -int plugin_get_persistant(char name[], char value[]); -int plugin_set_persistant(char name[], char value[]); -#endif -static int (*plugin_get_persistant)(char name[], char value[]); - -struct APLUGIN_STATES { - int symbol_rate; - int num_tones; - int counter; -}; - -/* plugin functions called by host, we need to write these */ - -void DLL plugin_name(char name[]) { - - sprintf(name, "aFreeDVplugIn"); -} - -/* - Text fields will be created for nparams, using the names - in *param_names[]. These fields we be saved to persistent - storage as name/param_names[0], name/param_names[1] .... -*/ - -void DLL *plugin_open(char *param_names[], - int *nparams, - int (*aplugin_get_persistant)(char *, char *)) -{ - struct APLUGIN_STATES *states; - - /* set up function ptrs */ - - plugin_get_persistant = aplugin_get_persistant; - - /* tell host how many persistent parameters we have and their names */ - - strcpy(param_names[0], "SymbolRate"); - strcpy(param_names[1], "NumTones"); - *nparams = 2; - - /* init local states */ - - states = (struct APLUGIN_STATES *)malloc(sizeof(struct APLUGIN_STATES)); - if (states == NULL) { - // TODO: plugin_alert("Problem starting plugin!"); - return NULL; - } - states->counter = 0; - - return (void*)states; -} - -void DLL plugin_close(void *states) { - free(states); -} - -void DLL plugin_start(void *s) { - struct APLUGIN_STATES *states = (struct APLUGIN_STATES*)s; - char txt[80]; - - fprintf(stderr, "\nplugin_start\n"); - - (plugin_get_persistant)("SymbolRate",txt); - states->symbol_rate = atoi(txt); - - (plugin_get_persistant)("NumTones",txt); - states->num_tones = atoi(txt); - - fprintf(stderr, "symbol_rate: %d num_tones: %d\n", states->symbol_rate, states->num_tones); -} - -void DLL plugin_stop(void *states) { - fprintf(stderr, "\nplugin_stop\n"); -} - -void DLL plugin_rx_samples(void *s, short samples[], int n) { - struct APLUGIN_STATES *states = (struct APLUGIN_STATES*)s; - //fprintf(stderr, "Got n=%d samples!\n", n); - //fprintf(stderr, "samples[0] = %d samples[%d-1] = %d counter = %d\n", samples[0], n, samples[n-1], states->counter++); -} - diff --git a/src/dlg_plugin.cpp b/src/dlg_plugin.cpp deleted file mode 100644 index 82744294d..000000000 --- a/src/dlg_plugin.cpp +++ /dev/null @@ -1,148 +0,0 @@ -//========================================================================== -// Name: dlg_plugin.cpp -// Purpose: Subclasses dialog GUI for PlugIn Config. Creates simple -// wxWidgets dialog GUI to set a few text strings. -// Date: Jan 2016 -// Authors: David Rowe -// -// License: -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2.1, -// as published by the Free Software Foundation. This program is -// distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -// License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see . -// -//========================================================================== - -#include "dlg_plugin.h" -#include "main.h" - -#ifdef __WIN32__ -#include -#endif -#if defined(__FreeBSD__) || defined(__WXOSX__) -#include -#include -#endif - -#include - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -// Class PlugInDlg -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -PlugInDlg::PlugInDlg(const wxString& title, int numParam, wxString paramName[], wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) -{ - m_name = title; - m_numParam = numParam; - assert(m_numParam <= PLUGIN_MAX_PARAMS); - - wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); - this->SetSizer(mainSizer); - - int i; - for (i=0; iAdd(m_txtCtrlParam[i], 0, 0, 5); - mainSizer->Add(staticBoxSizer28a, 0, wxEXPAND, 5); - } - - //---------------------------------------------------------------------- - // OK - Cancel - Apply - //---------------------------------------------------------------------- - - wxBoxSizer* boxSizer12 = new wxBoxSizer(wxHORIZONTAL); - - m_buttonOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxSize(-1,-1), 0); - m_buttonOK->SetDefault(); - boxSizer12->Add(m_buttonOK, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM, 5); - - m_buttonCancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(-1,-1), 0); - boxSizer12->Add(m_buttonCancel, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM, 5); - - mainSizer->Add(boxSizer12, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5); - - if ( GetSizer() ) - { - GetSizer()->Fit(this); - } - Centre(wxBOTH); - - // Connect events - this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(PlugInDlg::OnInitDialog), NULL, this); - m_buttonOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PlugInDlg::OnOK), NULL, this); - m_buttonCancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PlugInDlg::OnCancel), NULL, this); - -} - -//------------------------------------------------------------------------- -// ~PlugInDlg() -//------------------------------------------------------------------------- -PlugInDlg::~PlugInDlg() -{ - // Disconnect Events - this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(PlugInDlg::OnInitDialog), NULL, this); - m_buttonOK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PlugInDlg::OnOK), NULL, this); - m_buttonCancel->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PlugInDlg::OnCancel), NULL, this); -} - -//------------------------------------------------------------------------- -// OnInitDialog() -//------------------------------------------------------------------------- -void PlugInDlg::OnInitDialog(wxInitDialogEvent& event) -{ - ExchangeData(EXCHANGE_DATA_IN); -} - - -//------------------------------------------------------------------------- -// ExchangeData() -//------------------------------------------------------------------------- -void PlugInDlg::ExchangeData(int inout) -{ - wxConfigBase *pConfig = wxConfigBase::Get(); - wxString str; - int i; - - if(inout == EXCHANGE_DATA_IN) - { - for (i=0; iSetValue(wxGetApp().m_txtPlugInParam[i]); - } - } - if(inout == EXCHANGE_DATA_OUT) - { - for (i=0; iGetValue(); - wxString configStr = "/" + m_name + "/" + m_paramName[i]; - pConfig->Write(configStr, wxGetApp().m_txtPlugInParam[i]); - } - pConfig->Flush(); - } - delete wxConfigBase::Set((wxConfigBase *) NULL); -} - - -//------------------------------------------------------------------------- -// OnCancel() -//------------------------------------------------------------------------- -void PlugInDlg::OnCancel(wxCommandEvent& event) -{ - this->EndModal(wxID_CANCEL); -} - -//------------------------------------------------------------------------- -// OnClose() -//------------------------------------------------------------------------- -void PlugInDlg::OnOK(wxCommandEvent& event) -{ - ExchangeData(EXCHANGE_DATA_OUT); - this->EndModal(wxID_OK); -} diff --git a/src/dlg_plugin.h b/src/dlg_plugin.h deleted file mode 100644 index 3265a5dbe..000000000 --- a/src/dlg_plugin.h +++ /dev/null @@ -1,65 +0,0 @@ -//========================================================================== -// Name: dlg_ptt.h -// Purpose: Subclasses dialog GUI for PTT Config. -// -// Created: May. 11, 2012 -// Authors: David Rowe, David Witten -// -// License: -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2.1, -// as published by the Free Software Foundation. This program is -// distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -// License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see . -// -//========================================================================== -#ifndef __PLUGIN_DIALOG__ -#define __PLUGIN_DIALOG__ - -#include "main.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -// Class PlugInDlg -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -class PlugInDlg : public wxDialog -{ - public: - PlugInDlg(const wxString& title = _("PTT Config"), int numParam = 0, wxString paramNames[]=NULL, wxWindow* parent=NULL, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(450,300), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER); - virtual ~PlugInDlg(); - void ExchangeData(int inout); - - protected: - wxString m_name; - int m_numParam; - wxString m_paramName[PLUGIN_MAX_PARAMS]; - - wxTextCtrl* m_txtCtrlParam[PLUGIN_MAX_PARAMS]; - wxButton* m_buttonOK; - wxButton* m_buttonCancel; - - -protected: - - void OnOK(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); - virtual void OnInitDialog(wxInitDialogEvent& event); -}; - -#endif // __PLUGIN_DIALOG__ diff --git a/src/main.cpp b/src/main.cpp index 47f14ff1e..a75f94538 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,7 +220,7 @@ bool MainApp::OnInit() // Create the main application window - frame = new MainFrame(m_plugInName, NULL); + frame = new MainFrame(NULL); SetTopWindow(frame); // Should guarantee that the first plot tab defined is the one @@ -239,21 +239,13 @@ bool MainApp::OnInit() //------------------------------------------------------------------------- int MainApp::OnExit() { - //fprintf(stderr, "MainApp::OnExit\n"); - if (m_plugIn) { - #ifdef __WXMSW__ - FreeLibrary((HMODULE)m_plugInHandle); - #else - dlclose(m_plugInHandle); - #endif - } return 0; } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class MainFrame(wxFrame* pa->ent) : TopFrame(parent) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -MainFrame::MainFrame(wxString plugInName, wxWindow *parent) : TopFrame(plugInName, parent) +MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) { m_zoom = 1.; @@ -549,16 +541,12 @@ MainFrame::MainFrame(wxString plugInName, wxWindow *parent) : TopFrame(plugInNam pConfig->SetPath(wxT("/")); // this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI)); - //m_togRxID->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnRxIDUI), NULL, this); - //m_togTxID->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTxIDUI), NULL, this); - m_togBtnOnOff->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); + m_togBtnOnOff->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnSplit->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this); m_togBtnAnalog->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); // m_btnTogPTT->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this); m_togBtnSplit->Disable(); - //m_togRxID->Disable(); - //m_togTxID->Disable(); m_togBtnAnalog->Disable(); m_btnTogPTT->Disable(); m_togBtnVoiceKeyer->Disable(); @@ -801,8 +789,6 @@ MainFrame::~MainFrame() pConfig->Flush(); } - //m_togRxID->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnRxIDUI), NULL, this); - //m_togTxID->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTxIDUI), NULL, this); m_togBtnOnOff->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnSplit->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this); m_togBtnAnalog->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); @@ -1674,26 +1660,6 @@ void MainFrame::DetectSyncProcessEvent(void) { ds_state = next_state; } - -//------------------------------------------------------------------------- -// OnTogBtnRxID() -//------------------------------------------------------------------------- -void MainFrame::OnTogBtnRxID(wxCommandEvent& event) -{ - // empty any junk in rx data FIFO - short junk; - while(codec2_fifo_read(g_rxDataOutFifo,&junk,1) == 0); - event.Skip(); -} - -//------------------------------------------------------------------------- -// OnTogBtnTxID() -//------------------------------------------------------------------------- -void MainFrame::OnTogBtnTxID(wxCommandEvent& event) -{ - event.Skip(); -} - void MainFrame::OnTogBtnSplitClick(wxCommandEvent& event) { if (g_split) g_split = 0; @@ -2309,8 +2275,6 @@ void MainFrame::OnExit(wxCommandEvent& event) stopRxStream(); } m_togBtnSplit->Disable(); - //m_togRxID->Disable(); - //m_togTxID->Disable(); m_togBtnAnalog->Disable(); //m_btnTogPTT->Disable(); @@ -2401,23 +2365,6 @@ void MainFrame::OnToolsComCfgUI(wxUpdateUIEvent& event) event.Enable(!m_RxRunning); } -//------------------------------------------------------------------------- -// OnToolsPlugInCfg() -//------------------------------------------------------------------------- -void MainFrame::OnToolsPlugInCfg(wxCommandEvent& event) -{ - wxUnusedVar(event); - PlugInDlg *dlg = new PlugInDlg(wxGetApp().m_plugInName, wxGetApp().m_numPlugInParam, wxGetApp().m_plugInParamName); - dlg->ShowModal(); - delete dlg; -} - -void MainFrame::OnToolsPlugInCfgUI(wxUpdateUIEvent& event) -{ - event.Enable(!m_RxRunning && wxGetApp().m_plugIn); -} - - //------------------------------------------------------------------------- // OnHelpCheckUpdates() //------------------------------------------------------------------------- @@ -2594,8 +2541,6 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) m_rbHorusBinary->Disable(); #endif m_rb2020->Disable(); - if (m_rbPlugIn != NULL) - m_rbPlugIn->Disable(); m_textSync->Enable(); @@ -2890,9 +2835,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) #endif if(isAvxPresent) m_rb2020->Enable(); - if (m_rbPlugIn != NULL) - m_rbPlugIn->Enable(); - } + } optionsDlg->setSessionActive(m_RxRunning); } diff --git a/src/main.h b/src/main.h index f4dbfcb38..288add072 100644 --- a/src/main.h +++ b/src/main.h @@ -92,7 +92,6 @@ #include "dlg_options.h" #include "sox_biquad.h" #include "comp_prim.h" -#include "dlg_plugin.h" #include "hamlib.h" #include "serialport.h" #include "pskreporter.h" @@ -301,22 +300,6 @@ class MainApp : public wxApp bool loadConfig(); bool saveConfig(); - // Plugins ----------------------------------- - - wxString m_txtPlugInParam[PLUGIN_MAX_PARAMS]; - - // plugin details - - void *m_plugInHandle; - bool m_plugIn; - wxString m_plugInName; - int m_numPlugInParam; - wxString m_plugInParamName[PLUGIN_MAX_PARAMS]; - void *m_plugInStates; - void (*m_plugin_startfp)(void *); - void (*m_plugin_stopfp)(void *); - void (*m_plugin_rx_samplesfp)(void *, short *, int); - // misc bool m_testFrames; @@ -461,7 +444,7 @@ class UDPThread; class MainFrame : public TopFrame { public: - MainFrame(wxString plugInName, wxWindow *parent); + MainFrame(wxWindow *parent); virtual ~MainFrame(); PlotSpectrum* m_panelSpectrum; @@ -580,9 +563,6 @@ class MainFrame : public TopFrame void OnToolsOptions(wxCommandEvent& event); void OnToolsOptionsUI(wxUpdateUIEvent& event); - void OnToolsPlugInCfg( wxCommandEvent& event ); - void OnToolsPlugInCfgUI( wxUpdateUIEvent& event ); - void OnPlayFileToMicIn( wxCommandEvent& event ); void OnRecFileFromRadio( wxCommandEvent& event ); void OnRecFileFromModulator( wxCommandEvent& event); @@ -601,8 +581,6 @@ class MainFrame : public TopFrame // Toggle Buttons void OnTogBtnSplitClick(wxCommandEvent& event); void OnTogBtnAnalogClick(wxCommandEvent& event); - void OnTogBtnRxID( wxCommandEvent& event ); - void OnTogBtnTxID( wxCommandEvent& event ); void OnTogBtnPTT( wxCommandEvent& event ); void OnTogBtnVoiceKeyerClick (wxCommandEvent& event); void OnTogBtnOnOff( wxCommandEvent& event ); @@ -741,10 +719,6 @@ void my_put_next_rx_char(void *callback_state, char c); void freq_shift_coh(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, float Fs, COMP *foff_phase_rect, int nin); -// Helper function called by plugin - -int plugin_get_persistant(char name[], char value[]); - void UDPSend(int port, char *buf, unsigned int n); void UDPInit(void); diff --git a/src/topFrame.cpp b/src/topFrame.cpp index 6b4e8daa1..a6b3040a5 100644 --- a/src/topFrame.cpp +++ b/src/topFrame.cpp @@ -29,7 +29,7 @@ extern int g_recFileFromModulatorEventId; //========================================================================= // Code that lays out the main application window //========================================================================= -TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) +TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) { this->SetSizeHints(wxDefaultSize, wxDefaultSize); this->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); @@ -66,12 +66,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w m_menuItemFilter = new wxMenuItem(tools, wxID_ANY, wxString(_("&Filter...")) , wxEmptyString, wxITEM_NORMAL); tools->Append(m_menuItemFilter); - wxMenuItem* m_menuItemPlugIn; - if (!wxIsEmpty(plugInName)) { - m_menuItemPlugIn = new wxMenuItem(tools, wxID_ANY, plugInName + wxString(_(" Config...")) , wxEmptyString, wxITEM_NORMAL); - tools->Append(m_menuItemPlugIn); - } - m_menuItemPlayFileToMicIn = new wxMenuItem(tools, wxID_ANY, wxString(_("Start Play File - Mic In...")) , wxEmptyString, wxITEM_NORMAL); g_playFileToMicInEventId = m_menuItemPlayFileToMicIn->GetId(); tools->Append(m_menuItemPlayFileToMicIn); @@ -246,31 +240,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w bSizer15->Add(m_txtCtrlCallSign, 0, wxALL|wxEXPAND, 5); lowerSizer->Add(bSizer15, 1, wxEXPAND, 5); - //===================================================== - // These are the buttons that autosend the userid (?) - //===================================================== - - // DR 4 Dec - taken off for screen for Beta release to avoid questions on their use until - // we implement this feature - #ifdef UNIMPLEMENTED - wxBoxSizer* bSizer141; - bSizer141 = new wxBoxSizer(wxHORIZONTAL); - - // TxID - //--------- - m_togTxID = new wxToggleButton(this, wxID_ANY, _("TxID"), wxDefaultPosition, wxDefaultSize, 0); - m_togTxID->SetToolTip(_("Send Tx ID information")); - bSizer141->Add(m_togTxID, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); - - // RxID - //--------- - m_togRxID = new wxToggleButton(this, wxID_ANY, _("RxID"), wxDefaultPosition, wxDefaultSize, 0); - m_togRxID->SetToolTip(_("Enable reception of ID information")); - bSizer141->Add(m_togRxID, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 5); - - lowerSizer->Add(bSizer141, 0, wxALIGN_RIGHT, 5); -#endif - centerSizer->Add(lowerSizer, 0, wxEXPAND, 2); bSizer1->Add(centerSizer, 4, wxALL|wxEXPAND, 1); @@ -337,21 +306,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w m_rb1600->SetValue(true); - m_rbPlugIn = NULL; - if (!wxIsEmpty(plugInName)) { - // Optional plug in - - m_rbPlugIn = new wxRadioButton( this, wxID_ANY, plugInName, wxDefaultPosition, wxDefaultSize, 0); - sbSizer_mode->Add(m_rbPlugIn, 0, wxALIGN_LEFT|wxALL, 1); - } - -#ifdef DISABLED_FEATURE - m_rb1600Wide = new wxRadioButton( this, wxID_ANY, wxT("1600 Wide"), wxDefaultPosition, wxDefaultSize, 0); - sbSizer_mode->Add(m_rb1600Wide, 0, wxALIGN_LEFT|wxALL, 1); - m_rb2000 = new wxRadioButton( this, wxID_ANY, wxT("2000"), wxDefaultPosition, wxDefaultSize, 0); - sbSizer_mode->Add(m_rb2000, 0, wxALIGN_LEFT|wxALL, 1); -#endif - rightSizer->Add(sbSizer_mode,0, wxALL|wxEXPAND, 3); #ifdef MOVED_TO_OPTIONS_DIALOG @@ -489,11 +443,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w this->Connect(m_menuItemOptions->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnToolsOptions)); this->Connect(m_menuItemOptions->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnToolsOptionsUI)); - if (!wxIsEmpty(plugInName)) { - this->Connect(m_menuItemPlugIn->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnToolsPlugInCfg)); - this->Connect(m_menuItemPlugIn->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnToolsPlugInCfgUI)); - } - 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_menuItemRecFileFromModulator->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnRecFileFromModulator)); @@ -502,8 +451,6 @@ TopFrame::TopFrame(wxString plugInName, wxWindow* parent, wxWindowID id, const w this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpCheckUpdates)); this->Connect(m_menuItemHelpUpdates->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI)); this->Connect(m_menuItemAbout->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpAbout)); - //m_togRxID->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnRxID), NULL, this); - //m_togTxID->Connect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnTxID), NULL, this); m_sliderSQ->Connect(wxEVT_SCROLL_TOP, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); m_sliderSQ->Connect(wxEVT_SCROLL_BOTTOM, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); m_sliderSQ->Connect(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); @@ -550,8 +497,6 @@ TopFrame::~TopFrame() this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnToolsOptions)); this->Disconnect(wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnToolsOptionsUI)); - this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnToolsPlugInCfg)); - 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)); @@ -559,8 +504,6 @@ TopFrame::~TopFrame() this->Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpCheckUpdates)); this->Disconnect(wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TopFrame::OnHelpCheckUpdatesUI)); this->Disconnect(ID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(TopFrame::OnHelpAbout)); - //m_togRxID->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnRxID), NULL, this); - //m_togTxID->Disconnect(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(TopFrame::OnTogBtnTxID), NULL, this); m_sliderSQ->Disconnect(wxEVT_SCROLL_TOP, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); m_sliderSQ->Disconnect(wxEVT_SCROLL_BOTTOM, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); m_sliderSQ->Disconnect(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(TopFrame::OnCmdSliderScroll), NULL, this); diff --git a/src/topFrame.h b/src/topFrame.h index 73518a3fa..4ef7e878a 100644 --- a/src/topFrame.h +++ b/src/topFrame.h @@ -121,7 +121,6 @@ class TopFrame : public wxFrame wxRadioButton *m_rbHorusBinary; #endif wxRadioButton *m_rb2020; - wxRadioButton *m_rbPlugIn; wxMenuItem* m_menuItemPlayFileToMicIn; wxMenuItem* m_menuItemRecFileFromRadio; @@ -142,9 +141,6 @@ class TopFrame : public wxFrame virtual void OnToolsFilterUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnToolsOptions( wxCommandEvent& event ) { event.Skip(); } - virtual void OnToolsPlugInCfg( wxCommandEvent& event ) { event.Skip(); } - virtual void OnToolsPlugInCfgUI( wxUpdateUIEvent& event ) { event.Skip(); } - virtual void OnToolsUDP( wxCommandEvent& event ) { event.Skip(); } virtual void OnToolsOptionsUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnToolsComCfg( wxCommandEvent& event ) { event.Skip(); } @@ -157,8 +153,6 @@ class TopFrame : public wxFrame virtual void OnHelpCheckUpdates( wxCommandEvent& event ) { event.Skip(); } virtual void OnHelpCheckUpdatesUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnHelpAbout( wxCommandEvent& event ) { event.Skip(); } - virtual void OnTogBtnRxID( wxCommandEvent& event ) { event.Skip(); } - virtual void OnTogBtnTxID( wxCommandEvent& event ) { event.Skip(); } virtual void OnCmdSliderScroll( wxScrollEvent& event ) { event.Skip(); } virtual void OnSliderScrollBottom( wxScrollEvent& event ) { event.Skip(); } virtual void OnCmdSliderScrollChanged( wxScrollEvent& event ) { event.Skip(); } @@ -186,8 +180,6 @@ class TopFrame : public wxFrame virtual void OnReSync( wxCommandEvent& event ) { event.Skip(); } public: - wxToggleButton* m_togRxID; - wxToggleButton* m_togTxID; wxToggleButton* m_togBtnOnOff; wxToggleButton* m_togBtnSplit; wxToggleButton* m_togBtnAnalog; @@ -197,7 +189,7 @@ class TopFrame : public wxFrame wxToggleButton* m_togBtnLoopTx; wxAuiNotebook* m_auiNbookCtrl; - TopFrame( wxString plugInName, wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("FreeDV ") + _(FREEDV_VERSION), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(561,300 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL ); + TopFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("FreeDV ") + _(FREEDV_VERSION), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(561,300 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL ); ~TopFrame(); }; From 696fd9a3ecaa724be227d43b08696b55952647c1 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 18:49:01 +1030 Subject: [PATCH 10/18] moved file playing and recording to a new file --- src/CMakeLists.txt | 1 + src/main.cpp | 535 ++------------------------------------------- src/playrec.cpp | 527 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 549 insertions(+), 514 deletions(-) create mode 100644 src/playrec.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a9eca840..90ed4db3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,7 @@ set(FREEDV_SOURCES util.cpp eq.cpp voicekeyer.cpp + playrec.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index a75f94538..9563926b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -117,28 +117,27 @@ int g_PAframesPerBuffer2; // 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; -int g_sfFs; -bool g_loopPlayFileFromRadio; -int g_playFileFromRadioEventId; -float g_blink; - -SNDFILE *g_sfRecFileFromModulator; -bool g_recFileFromModulator = false; -int g_recFromModulatorSamples; -int g_recFileFromModulatorEventId; - +extern SNDFILE *g_sfPlayFile; +extern bool g_playFileToMicIn; +extern bool g_loopPlayFileToMicIn; +extern int g_playFileToMicInEventId; + +extern SNDFILE *g_sfRecFile; +extern bool g_recFileFromRadio; +extern unsigned int g_recFromRadioSamples; +extern int g_recFileFromRadioEventId; + +extern SNDFILE *g_sfPlayFileFromRadio; +extern bool g_playFileFromRadio; +extern int g_sfFs; +extern bool g_loopPlayFileFromRadio; +extern int g_playFileFromRadioEventId; +extern float g_blink; + +extern SNDFILE *g_sfRecFileFromModulator; +extern bool g_recFileFromModulator; +extern int g_recFromModulatorSamples; +extern int g_recFileFromModulatorEventId; wxWindow *g_parent; @@ -1737,498 +1736,6 @@ void MainFrame::OnBerReset(wxCommandEvent& event) } } -// extra panel added to file open dialog to add loop checkbox -MyExtraPlayFilePanel::MyExtraPlayFilePanel(wxWindow *parent): wxPanel(parent) -{ - m_cb = new wxCheckBox(this, -1, wxT("Loop")); - m_cb->SetToolTip(_("When checked file will repeat forever")); - m_cb->SetValue(g_loopPlayFileToMicIn); - - // bug: I can't this to align right..... - wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); - sizerTop->Add(m_cb, 0, 0, 0); - SetSizerAndFit(sizerTop); -} - -static wxWindow* createMyExtraPlayFilePanel(wxWindow *parent) -{ - return new MyExtraPlayFilePanel(parent); -} - -void MainFrame::StopPlayFileToMicIn(void) -{ - if (g_playFileToMicIn) - { - g_mutexProtectingCallbackData.Lock(); - g_playFileToMicIn = false; - sf_close(g_sfPlayFile); - SetStatusText(wxT("")); - m_menuItemPlayFileToMicIn->SetItemLabel(wxString(_("Start Play File - Mic In..."))); - g_mutexProtectingCallbackData.Unlock(); - VoiceKeyerProcessEvent(VK_PLAY_FINISHED); - } -} - -//------------------------------------------------------------------------- -// OnPlayFileToMicIn() -//------------------------------------------------------------------------- -void MainFrame::OnPlayFileToMicIn(wxCommandEvent& event) -{ - wxUnusedVar(event); - - if(g_playFileToMicIn) { - StopPlayFileToMicIn(); - } - else - { - wxString soundFile; - SF_INFO sfInfo; - - wxFileDialog openFileDialog( - this, - wxT("Play File to Mic In"), - wxGetApp().m_playFileToMicInPath, - 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_playFileToMicInPath, &fileName, &extension); - //wxLogDebug("m_playFileToMicInPath: %s", wxGetApp().m_playFileToMicInPath); - 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 = freedv_get_speech_sample_rate(g_pfreedv); - } - } - g_sfPlayFile = sf_open(soundFile.c_str(), SFM_READ, &sfInfo); - if(g_sfPlayFile == 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_loopPlayFileToMicIn = static_cast(ctrl)->getLoopPlayFileToMicIn(); - - SetStatusText(wxT("Playing File: ") + fileName + wxT(" to Mic Input") , 0); - g_playFileToMicIn = true; - - m_menuItemPlayFileToMicIn->SetItemLabel(wxString(_("Stop Play File - Mic In..."))); - } -} - -void MainFrame::StopPlaybackFileFromRadio() -{ - g_mutexProtectingCallbackData.Lock(); - g_playFileFromRadio = false; - sf_close(g_sfPlayFileFromRadio); - SetStatusText(wxT(""),0); - SetStatusText(wxT(""),1); - m_menuItemPlayFileFromRadio->SetItemLabel(wxString(_("Start Play File - From Radio..."))); - g_mutexProtectingCallbackData.Unlock(); -} - -//------------------------------------------------------------------------- -// OnPlayFileFromRadio() -// This puppy "plays" a recorded file into the demodulator 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) - { - fprintf(stderr, "OnPlayFileFromRadio:: Stop\n"); - StopPlaybackFileFromRadio(); - } - 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; - if (g_mode == -1) { -#ifdef __HORUS__ - sfInfo.samplerate = horus_get_Fs(g_horus); -#endif - } - else { - sfInfo.samplerate = freedv_get_modem_sample_rate(g_pfreedv); - } - } - } - g_sfPlayFileFromRadio = sf_open(soundFile.c_str(), SFM_READ, &sfInfo); - g_sfFs = sfInfo.samplerate; - 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 into from radio"), 0); - if(extension == wxT("raw")) { - wxString stringnumber = wxString::Format(wxT("%d"), (int)sfInfo.samplerate); - SetStatusText(wxT("raw file assuming Fs=") + stringnumber, 1); - } - fprintf(stderr, "OnPlayFileFromRadio:: Playing File Fs = %d\n", (int)sfInfo.samplerate); - m_menuItemPlayFileFromRadio->SetItemLabel(wxString(_("Stop Play File - From Radio..."))); - g_playFileFromRadio = true; - g_blink = 0.0; - } -} - -// extra panel added to file save dialog to set number of seconds to record for - -MyExtraRecFilePanel::MyExtraRecFilePanel(wxWindow *parent): wxPanel(parent) -{ - wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); - - wxStaticText* staticText = new wxStaticText(this, wxID_ANY, _("Seconds:"), wxDefaultPosition, wxDefaultSize, 0); - sizerTop->Add(staticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); - m_secondsToRecord = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); - m_secondsToRecord->SetToolTip(_("Number of seconds to record for")); - m_secondsToRecord->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_recFileFromRadioSecs)); - sizerTop->Add(m_secondsToRecord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); - SetSizerAndFit(sizerTop); -} - -static wxWindow* createMyExtraRecFilePanel(wxWindow *parent) -{ - return new MyExtraRecFilePanel(parent); -} - -void MainFrame::StopRecFileFromRadio() -{ - if (g_recFileFromRadio) - { - fprintf(stderr, "Stopping Record....\n"); - g_mutexProtectingCallbackData.Lock(); - g_recFileFromRadio = false; - sf_close(g_sfRecFile); - SetStatusText(wxT("")); - - m_menuItemRecFileFromRadio->SetItemLabel(wxString(_("Start Record File - From Radio..."))); - - wxMessageBox(wxT("Recording radio output to file complete") - , wxT("Recording radio Output"), wxOK); - - g_mutexProtectingCallbackData.Unlock(); - } -} - -//------------------------------------------------------------------------- -// OnRecFileFromRadio() -//------------------------------------------------------------------------- -void MainFrame::OnRecFileFromRadio(wxCommandEvent& event) -{ - wxUnusedVar(event); - - if (g_recFileFromRadio) { - StopRecFileFromRadio(); - } - else { - - wxString soundFile; - SF_INFO sfInfo; - - wxFileDialog openFileDialog( - this, - wxT("Record File From Radio"), - wxGetApp().m_recFileFromRadioPath, - wxT("Untitled.wav"), - wxT("WAV and RAW files (*.wav;*.raw)|*.wav;*.raw|") - wxT("All files (*.*)|*.*"), - wxFD_SAVE - ); - - // add the loop check box - openFileDialog.SetExtraControlCreator(&createMyExtraRecFilePanel); - - // Default to WAV. - openFileDialog.SetFilterIndex(0); - - if(openFileDialog.ShowModal() == wxID_CANCEL) - { - return; // the user changed their mind... - } - - wxString fileName, extension; - soundFile = openFileDialog.GetPath(); - wxFileName::SplitPath(soundFile, &wxGetApp().m_recFileFromRadioPath, &fileName, &extension); - wxLogDebug("m_recFileFromRadioPath: %s", wxGetApp().m_recFileFromRadioPath); - wxLogDebug("soundFile: %s", soundFile); - sfInfo.format = 0; - - int sample_rate; - if (g_mode == -1) { -#ifdef __HORUS__ - sample_rate = horus_get_Fs(g_horus); -#endif - } - else { - sample_rate = freedv_get_modem_sample_rate(g_pfreedv); - } - - if(!extension.IsEmpty()) - { - extension.LowerCase(); - if(extension == wxT("raw")) - { - sfInfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; - sfInfo.channels = 1; - sfInfo.samplerate = sample_rate; - } - else if(extension == wxT("wav")) - { - sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; - sfInfo.channels = 1; - sfInfo.samplerate = sample_rate; - } else { - wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); - return; - } - } - else { - wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); - return; - } - - // Bug: on Win32 I cant read m_recFileFromRadioSecs, so have hard coded it -#ifdef __WIN32__ - long secs = wxGetApp().m_recFileFromRadioSecs; - g_recFromRadioSamples = FS*(unsigned int)secs; -#else - // work out number of samples to record - - wxWindow * const ctrl = openFileDialog.GetExtraControl(); - wxString secsString = static_cast(ctrl)->getSecondsToRecord(); - wxLogDebug("test: %s secsString: %s\n", wxT("testing 123"), secsString); - - long secs; - if (secsString.ToLong(&secs)) { - wxGetApp().m_recFileFromRadioSecs = (unsigned int)secs; - //printf(" secondsToRecord: %d\n", (unsigned int)secs); - g_recFromRadioSamples = FS*(unsigned int)secs; - //printf("g_recFromRadioSamples: %d\n", g_recFromRadioSamples); - } - else { - wxMessageBox(wxT("Invalid number of Seconds"), wxT("Record File From Radio"), wxOK); - return; - } -#endif - - g_sfRecFile = sf_open(soundFile.c_str(), SFM_WRITE, &sfInfo); - if(g_sfRecFile == NULL) - { - wxString strErr = sf_strerror(NULL); - wxMessageBox(strErr, wxT("Couldn't open sound file"), wxOK); - return; - } - - SetStatusText(wxT("Recording File: ") + fileName + wxT(" From Radio") , 0); - m_menuItemRecFileFromRadio->SetItemLabel(wxString(_("Stop Record File - From Radio..."))); - g_recFileFromRadio = true; - } - -} - -void MainFrame::StopRecFileFromModulator() -{ - // If the event loop takes a while to execute, we may end up being called - // multiple times. We don't want to repeat the following more than once. - if (g_recFileFromModulator) { - g_mutexProtectingCallbackData.Lock(); - g_recFileFromModulator = false; - g_recFromModulatorSamples = 0; - sf_close(g_sfRecFileFromModulator); - SetStatusText(wxT("")); - m_menuItemRecFileFromModulator->SetItemLabel(wxString(_("Start Record File - From Modulator..."))); - wxMessageBox(wxT("Recording modulator output to file complete") - , wxT("Recording Modulation Output"), wxOK); - g_mutexProtectingCallbackData.Unlock(); - } -} - -//------------------------------------------------------------------------- -// OnRecFileFromModulator() -//------------------------------------------------------------------------- -void MainFrame::OnRecFileFromModulator(wxCommandEvent& event) -{ - wxUnusedVar(event); - - if (g_recFileFromModulator) { - StopRecFileFromModulator(); - } - else { - - wxString soundFile; - SF_INFO sfInfo; - - if (g_pfreedv == NULL) { - wxMessageBox(wxT("You need to press the Control - Start button before you can configure recording") - , wxT("Recording Modulation Output"), wxOK); - return; - } - - wxFileDialog openFileDialog( - this, - wxT("Record File From Modulator"), - wxGetApp().m_recFileFromModulatorPath, - wxT("Untitled.wav"), - wxT("WAV and RAW files (*.wav;*.raw)|*.wav;*.raw|") - wxT("All files (*.*)|*.*"), - wxFD_SAVE - ); - - // add the loop check box - openFileDialog.SetExtraControlCreator(&createMyExtraRecFilePanel); - - // Default to WAV. - openFileDialog.SetFilterIndex(0); - - if(openFileDialog.ShowModal() == wxID_CANCEL) - { - return; // the user changed their mind... - } - - wxString fileName, extension; - soundFile = openFileDialog.GetPath(); - wxFileName::SplitPath(soundFile, &wxGetApp().m_recFileFromModulatorPath, &fileName, &extension); - wxLogDebug("m_recFileFromModulatorPath: %s", wxGetApp().m_recFileFromModulatorPath); - wxLogDebug("soundFile: %s", soundFile); - sfInfo.format = 0; - - int sample_rate; - if (g_mode == -1) { -#ifdef __HORUS__ - sample_rate = horus_get_Fs(g_horus); -#endif - } - else { - sample_rate = freedv_get_modem_sample_rate(g_pfreedv); - } - - if(!extension.IsEmpty()) - { - extension.LowerCase(); - if(extension == wxT("raw")) - { - sfInfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; - sfInfo.channels = 1; - sfInfo.samplerate = sample_rate; - } - else if(extension == wxT("wav")) - { - sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; - sfInfo.channels = 1; - sfInfo.samplerate = sample_rate; - } else { - wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); - return; - } - } - else { - wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); - return; - } - - // Bug: on Win32 I cant read m_recFileFromModemSecs, so have hard coded it -#ifdef __WIN32__ - long secs = wxGetApp().m_recFileFromModulatorSecs; - g_recFromModulatorSamples = sample_rate * (unsigned int)secs; -#else - // work out number of samples to record - - wxWindow * const ctrl = openFileDialog.GetExtraControl(); - wxString secsString = static_cast(ctrl)->getSecondsToRecord(); - wxLogDebug("test: %s secsString: %s\n", wxT("testing 123"), secsString); - - long secs; - if (secsString.ToLong(&secs)) { - wxGetApp().m_recFileFromModulatorSecs = (unsigned int)secs; - //printf(" secondsToRecord: %d\n", (unsigned int)secs); - g_recFromModulatorSamples = sample_rate*(unsigned int)secs; - //printf("g_recFromRadioSamples: %d\n", g_recFromRadioSamples); - } - else { - wxMessageBox(wxT("Invalid number of Seconds"), wxT("Record File From Modulator"), wxOK); - return; - } -#endif - - g_sfRecFileFromModulator = sf_open(soundFile.c_str(), SFM_WRITE, &sfInfo); - if(g_sfRecFileFromModulator == NULL) - { - wxString strErr = sf_strerror(NULL); - wxMessageBox(strErr, wxT("Couldn't open sound file"), wxOK); - return; - } - - SetStatusText(wxT("Recording File: ") + fileName + wxT(" From Modulator") , 0); - m_menuItemRecFileFromModulator->SetItemLabel(wxString(_("Stop Record File - From Modulator..."))); - g_recFileFromModulator = true; - } - -} //------------------------------------------------------------------------- // OnExit() diff --git a/src/playrec.cpp b/src/playrec.cpp new file mode 100644 index 000000000..44d02c5f4 --- /dev/null +++ b/src/playrec.cpp @@ -0,0 +1,527 @@ +/* + + playrec.cpp + + Playing and recording files. +*/ + +#include "main.h" + +extern wxMutex g_mutexProtectingCallbackData; +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; +int g_sfFs; +bool g_loopPlayFileFromRadio; +int g_playFileFromRadioEventId; +float g_blink; + +SNDFILE *g_sfRecFileFromModulator; +bool g_recFileFromModulator = false; +int g_recFromModulatorSamples; +int g_recFileFromModulatorEventId; + +extern int g_mode; +extern struct freedv *g_pfreedv; + +// extra panel added to file open dialog to add loop checkbox +MyExtraPlayFilePanel::MyExtraPlayFilePanel(wxWindow *parent): wxPanel(parent) +{ + m_cb = new wxCheckBox(this, -1, wxT("Loop")); + m_cb->SetToolTip(_("When checked file will repeat forever")); + m_cb->SetValue(g_loopPlayFileToMicIn); + + // bug: I can't this to align right..... + wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); + sizerTop->Add(m_cb, 0, 0, 0); + SetSizerAndFit(sizerTop); +} + +static wxWindow* createMyExtraPlayFilePanel(wxWindow *parent) +{ + return new MyExtraPlayFilePanel(parent); +} + +void MainFrame::StopPlayFileToMicIn(void) +{ + if (g_playFileToMicIn) + { + g_mutexProtectingCallbackData.Lock(); + g_playFileToMicIn = false; + sf_close(g_sfPlayFile); + SetStatusText(wxT("")); + m_menuItemPlayFileToMicIn->SetItemLabel(wxString(_("Start Play File - Mic In..."))); + g_mutexProtectingCallbackData.Unlock(); + VoiceKeyerProcessEvent(VK_PLAY_FINISHED); + } +} + +//------------------------------------------------------------------------- +// OnPlayFileToMicIn() +//------------------------------------------------------------------------- +void MainFrame::OnPlayFileToMicIn(wxCommandEvent& event) +{ + wxUnusedVar(event); + + if(g_playFileToMicIn) { + StopPlayFileToMicIn(); + } + else + { + wxString soundFile; + SF_INFO sfInfo; + + wxFileDialog openFileDialog( + this, + wxT("Play File to Mic In"), + wxGetApp().m_playFileToMicInPath, + 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_playFileToMicInPath, &fileName, &extension); + //wxLogDebug("m_playFileToMicInPath: %s", wxGetApp().m_playFileToMicInPath); + 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 = freedv_get_speech_sample_rate(g_pfreedv); + } + } + g_sfPlayFile = sf_open(soundFile.c_str(), SFM_READ, &sfInfo); + if(g_sfPlayFile == 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_loopPlayFileToMicIn = static_cast(ctrl)->getLoopPlayFileToMicIn(); + + SetStatusText(wxT("Playing File: ") + fileName + wxT(" to Mic Input") , 0); + g_playFileToMicIn = true; + + m_menuItemPlayFileToMicIn->SetItemLabel(wxString(_("Stop Play File - Mic In..."))); + } +} + +void MainFrame::StopPlaybackFileFromRadio() +{ + g_mutexProtectingCallbackData.Lock(); + g_playFileFromRadio = false; + sf_close(g_sfPlayFileFromRadio); + SetStatusText(wxT(""),0); + SetStatusText(wxT(""),1); + m_menuItemPlayFileFromRadio->SetItemLabel(wxString(_("Start Play File - From Radio..."))); + g_mutexProtectingCallbackData.Unlock(); +} + +//------------------------------------------------------------------------- +// OnPlayFileFromRadio() +// This puppy "plays" a recorded file into the demodulator 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) + { + fprintf(stderr, "OnPlayFileFromRadio:: Stop\n"); + StopPlaybackFileFromRadio(); + } + 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; + if (g_mode == -1) { +#ifdef __HORUS__ + sfInfo.samplerate = horus_get_Fs(g_horus); +#endif + } + else { + sfInfo.samplerate = freedv_get_modem_sample_rate(g_pfreedv); + } + } + } + g_sfPlayFileFromRadio = sf_open(soundFile.c_str(), SFM_READ, &sfInfo); + g_sfFs = sfInfo.samplerate; + 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 into from radio"), 0); + if(extension == wxT("raw")) { + wxString stringnumber = wxString::Format(wxT("%d"), (int)sfInfo.samplerate); + SetStatusText(wxT("raw file assuming Fs=") + stringnumber, 1); + } + fprintf(stderr, "OnPlayFileFromRadio:: Playing File Fs = %d\n", (int)sfInfo.samplerate); + m_menuItemPlayFileFromRadio->SetItemLabel(wxString(_("Stop Play File - From Radio..."))); + g_playFileFromRadio = true; + g_blink = 0.0; + } +} + +// extra panel added to file save dialog to set number of seconds to record for + +MyExtraRecFilePanel::MyExtraRecFilePanel(wxWindow *parent): wxPanel(parent) +{ + wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); + + wxStaticText* staticText = new wxStaticText(this, wxID_ANY, _("Seconds:"), wxDefaultPosition, wxDefaultSize, 0); + sizerTop->Add(staticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + m_secondsToRecord = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); + m_secondsToRecord->SetToolTip(_("Number of seconds to record for")); + m_secondsToRecord->SetValue(wxString::Format(wxT("%i"), wxGetApp().m_recFileFromRadioSecs)); + sizerTop->Add(m_secondsToRecord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); + SetSizerAndFit(sizerTop); +} + +static wxWindow* createMyExtraRecFilePanel(wxWindow *parent) +{ + return new MyExtraRecFilePanel(parent); +} + +void MainFrame::StopRecFileFromRadio() +{ + if (g_recFileFromRadio) + { + fprintf(stderr, "Stopping Record....\n"); + g_mutexProtectingCallbackData.Lock(); + g_recFileFromRadio = false; + sf_close(g_sfRecFile); + SetStatusText(wxT("")); + + m_menuItemRecFileFromRadio->SetItemLabel(wxString(_("Start Record File - From Radio..."))); + + wxMessageBox(wxT("Recording radio output to file complete") + , wxT("Recording radio Output"), wxOK); + + g_mutexProtectingCallbackData.Unlock(); + } +} + +//------------------------------------------------------------------------- +// OnRecFileFromRadio() +//------------------------------------------------------------------------- +void MainFrame::OnRecFileFromRadio(wxCommandEvent& event) +{ + wxUnusedVar(event); + + if (g_recFileFromRadio) { + StopRecFileFromRadio(); + } + else { + + wxString soundFile; + SF_INFO sfInfo; + + wxFileDialog openFileDialog( + this, + wxT("Record File From Radio"), + wxGetApp().m_recFileFromRadioPath, + wxT("Untitled.wav"), + wxT("WAV and RAW files (*.wav;*.raw)|*.wav;*.raw|") + wxT("All files (*.*)|*.*"), + wxFD_SAVE + ); + + // add the loop check box + openFileDialog.SetExtraControlCreator(&createMyExtraRecFilePanel); + + // Default to WAV. + openFileDialog.SetFilterIndex(0); + + if(openFileDialog.ShowModal() == wxID_CANCEL) + { + return; // the user changed their mind... + } + + wxString fileName, extension; + soundFile = openFileDialog.GetPath(); + wxFileName::SplitPath(soundFile, &wxGetApp().m_recFileFromRadioPath, &fileName, &extension); + wxLogDebug("m_recFileFromRadioPath: %s", wxGetApp().m_recFileFromRadioPath); + wxLogDebug("soundFile: %s", soundFile); + sfInfo.format = 0; + + int sample_rate; + if (g_mode == -1) { +#ifdef __HORUS__ + sample_rate = horus_get_Fs(g_horus); +#endif + } + else { + sample_rate = freedv_get_modem_sample_rate(g_pfreedv); + } + + if(!extension.IsEmpty()) + { + extension.LowerCase(); + if(extension == wxT("raw")) + { + sfInfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; + sfInfo.channels = 1; + sfInfo.samplerate = sample_rate; + } + else if(extension == wxT("wav")) + { + sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; + sfInfo.channels = 1; + sfInfo.samplerate = sample_rate; + } else { + wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); + return; + } + } + else { + wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); + return; + } + + // Bug: on Win32 I cant read m_recFileFromRadioSecs, so have hard coded it +#ifdef __WIN32__ + long secs = wxGetApp().m_recFileFromRadioSecs; + g_recFromRadioSamples = FS*(unsigned int)secs; +#else + // work out number of samples to record + + wxWindow * const ctrl = openFileDialog.GetExtraControl(); + wxString secsString = static_cast(ctrl)->getSecondsToRecord(); + wxLogDebug("test: %s secsString: %s\n", wxT("testing 123"), secsString); + + long secs; + if (secsString.ToLong(&secs)) { + wxGetApp().m_recFileFromRadioSecs = (unsigned int)secs; + //printf(" secondsToRecord: %d\n", (unsigned int)secs); + g_recFromRadioSamples = FS*(unsigned int)secs; + //printf("g_recFromRadioSamples: %d\n", g_recFromRadioSamples); + } + else { + wxMessageBox(wxT("Invalid number of Seconds"), wxT("Record File From Radio"), wxOK); + return; + } +#endif + + g_sfRecFile = sf_open(soundFile.c_str(), SFM_WRITE, &sfInfo); + if(g_sfRecFile == NULL) + { + wxString strErr = sf_strerror(NULL); + wxMessageBox(strErr, wxT("Couldn't open sound file"), wxOK); + return; + } + + SetStatusText(wxT("Recording File: ") + fileName + wxT(" From Radio") , 0); + m_menuItemRecFileFromRadio->SetItemLabel(wxString(_("Stop Record File - From Radio..."))); + g_recFileFromRadio = true; + } + +} + +void MainFrame::StopRecFileFromModulator() +{ + // If the event loop takes a while to execute, we may end up being called + // multiple times. We don't want to repeat the following more than once. + if (g_recFileFromModulator) { + g_mutexProtectingCallbackData.Lock(); + g_recFileFromModulator = false; + g_recFromModulatorSamples = 0; + sf_close(g_sfRecFileFromModulator); + SetStatusText(wxT("")); + m_menuItemRecFileFromModulator->SetItemLabel(wxString(_("Start Record File - From Modulator..."))); + wxMessageBox(wxT("Recording modulator output to file complete") + , wxT("Recording Modulation Output"), wxOK); + g_mutexProtectingCallbackData.Unlock(); + } +} + +//------------------------------------------------------------------------- +// OnRecFileFromModulator() +//------------------------------------------------------------------------- +void MainFrame::OnRecFileFromModulator(wxCommandEvent& event) +{ + wxUnusedVar(event); + + if (g_recFileFromModulator) { + StopRecFileFromModulator(); + } + else { + + wxString soundFile; + SF_INFO sfInfo; + + if (g_pfreedv == NULL) { + wxMessageBox(wxT("You need to press the Control - Start button before you can configure recording") + , wxT("Recording Modulation Output"), wxOK); + return; + } + + wxFileDialog openFileDialog( + this, + wxT("Record File From Modulator"), + wxGetApp().m_recFileFromModulatorPath, + wxT("Untitled.wav"), + wxT("WAV and RAW files (*.wav;*.raw)|*.wav;*.raw|") + wxT("All files (*.*)|*.*"), + wxFD_SAVE + ); + + // add the loop check box + openFileDialog.SetExtraControlCreator(&createMyExtraRecFilePanel); + + // Default to WAV. + openFileDialog.SetFilterIndex(0); + + if(openFileDialog.ShowModal() == wxID_CANCEL) + { + return; // the user changed their mind... + } + + wxString fileName, extension; + soundFile = openFileDialog.GetPath(); + wxFileName::SplitPath(soundFile, &wxGetApp().m_recFileFromModulatorPath, &fileName, &extension); + wxLogDebug("m_recFileFromModulatorPath: %s", wxGetApp().m_recFileFromModulatorPath); + wxLogDebug("soundFile: %s", soundFile); + sfInfo.format = 0; + + int sample_rate; + if (g_mode == -1) { +#ifdef __HORUS__ + sample_rate = horus_get_Fs(g_horus); +#endif + } + else { + sample_rate = freedv_get_modem_sample_rate(g_pfreedv); + } + + if(!extension.IsEmpty()) + { + extension.LowerCase(); + if(extension == wxT("raw")) + { + sfInfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; + sfInfo.channels = 1; + sfInfo.samplerate = sample_rate; + } + else if(extension == wxT("wav")) + { + sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; + sfInfo.channels = 1; + sfInfo.samplerate = sample_rate; + } else { + wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); + return; + } + } + else { + wxMessageBox(wxT("Invalid file format"), wxT("Record File From Radio"), wxOK); + return; + } + + // Bug: on Win32 I cant read m_recFileFromModemSecs, so have hard coded it +#ifdef __WIN32__ + long secs = wxGetApp().m_recFileFromModulatorSecs; + g_recFromModulatorSamples = sample_rate * (unsigned int)secs; +#else + // work out number of samples to record + + wxWindow * const ctrl = openFileDialog.GetExtraControl(); + wxString secsString = static_cast(ctrl)->getSecondsToRecord(); + wxLogDebug("test: %s secsString: %s\n", wxT("testing 123"), secsString); + + long secs; + if (secsString.ToLong(&secs)) { + wxGetApp().m_recFileFromModulatorSecs = (unsigned int)secs; + //printf(" secondsToRecord: %d\n", (unsigned int)secs); + g_recFromModulatorSamples = sample_rate*(unsigned int)secs; + //printf("g_recFromRadioSamples: %d\n", g_recFromRadioSamples); + } + else { + wxMessageBox(wxT("Invalid number of Seconds"), wxT("Record File From Modulator"), wxOK); + return; + } +#endif + + g_sfRecFileFromModulator = sf_open(soundFile.c_str(), SFM_WRITE, &sfInfo); + if(g_sfRecFileFromModulator == NULL) + { + wxString strErr = sf_strerror(NULL); + wxMessageBox(strErr, wxT("Couldn't open sound file"), wxOK); + return; + } + + SetStatusText(wxT("Recording File: ") + fileName + wxT(" From Modulator") , 0); + m_menuItemRecFileFromModulator->SetItemLabel(wxString(_("Stop Record File - From Modulator..."))); + g_recFileFromModulator = true; + } + +} From 8acfdef268aaaebac99e3ff0dae64e9bc8c992b2 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 18:57:12 +1030 Subject: [PATCH 11/18] moved simpler GUI event handlers out of main.cpp --- src/CMakeLists.txt | 1 + src/main.cpp | 224 ------------------------------------------ src/ongui.cpp | 235 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 224 deletions(-) create mode 100644 src/ongui.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90ed4db3b..75999ea62 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,7 @@ set(FREEDV_SOURCES eq.cpp voicekeyer.cpp playrec.cpp + ongui.cpp ) set(FREEDV_SOURCES_OSX diff --git a/src/main.cpp b/src/main.cpp index 9563926b9..5650e6bf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1789,230 +1789,6 @@ void MainFrame::OnExit(wxCommandEvent& event) Destroy(); } -//------------------------------------------------------------------------- -// OnExitClick() -//------------------------------------------------------------------------- -void MainFrame::OnExitClick(wxCommandEvent& event) -{ - OnExit(event); -} - -//------------------------------------------------------------------------- -// OnToolsAudio() -//------------------------------------------------------------------------- -void MainFrame::OnToolsAudio(wxCommandEvent& event) -{ - wxUnusedVar(event); - int rv = 0; - AudioOptsDialog *dlg = new AudioOptsDialog(NULL); - rv = dlg->ShowModal(); - if(rv == wxID_OK) - { - dlg->ExchangeData(EXCHANGE_DATA_OUT); - } - delete dlg; -} - -//------------------------------------------------------------------------- -// OnToolsAudioUI() -//------------------------------------------------------------------------- -void MainFrame::OnToolsAudioUI(wxUpdateUIEvent& event) -{ - event.Enable(!m_RxRunning); -} - -//------------------------------------------------------------------------- -// OnToolsFilter() -//------------------------------------------------------------------------- -void MainFrame::OnToolsFilter(wxCommandEvent& event) -{ - wxUnusedVar(event); - FilterDlg *dlg = new FilterDlg(NULL, m_RxRunning, &m_newMicInFilter, &m_newSpkOutFilter); - dlg->ShowModal(); - delete dlg; -} - -//------------------------------------------------------------------------- -// OnToolsOptions() -//------------------------------------------------------------------------- -void MainFrame::OnToolsOptions(wxCommandEvent& event) -{ - wxUnusedVar(event); - g_modal = true; - //fprintf(stderr,"g_modal: %d\n", g_modal); - optionsDlg->Show(); -} - -//------------------------------------------------------------------------- -// OnToolsOptionsUI() -//------------------------------------------------------------------------- -void MainFrame::OnToolsOptionsUI(wxUpdateUIEvent& event) -{ -} - -//------------------------------------------------------------------------- -// OnToolsComCfg() -//------------------------------------------------------------------------- -void MainFrame::OnToolsComCfg(wxCommandEvent& event) -{ - wxUnusedVar(event); - - ComPortsDlg *dlg = new ComPortsDlg(NULL); - - dlg->ShowModal(); - - delete dlg; -} - -//------------------------------------------------------------------------- -// OnToolsComCfgUI() -//------------------------------------------------------------------------- -void MainFrame::OnToolsComCfgUI(wxUpdateUIEvent& event) -{ - event.Enable(!m_RxRunning); -} - -//------------------------------------------------------------------------- -// OnHelpCheckUpdates() -//------------------------------------------------------------------------- -void MainFrame::OnHelpCheckUpdates(wxCommandEvent& event) -{ - wxMessageBox("Got Click!", "OnHelpCheckUpdates", wxOK); - event.Skip(); -} - -//------------------------------------------------------------------------- -// OnHelpCheckUpdatesUI() -//------------------------------------------------------------------------- -void MainFrame::OnHelpCheckUpdatesUI(wxUpdateUIEvent& event) -{ - event.Enable(false); -} - -//------------------------------------------------------------------------- -//OnHelpAbout() -//------------------------------------------------------------------------- -void MainFrame::OnHelpAbout(wxCommandEvent& event) -{ - wxUnusedVar(event); - wxString msg; - msg.Printf( wxT("FreeDV GUI %s\n\n") - wxT("For Help and Support visit: http://freedv.org\n\n") - - wxT("GNU Public License V2.1\n\n") - wxT("Created by David Witten KD0EAG and David Rowe VK5DGR in 2012. ") - wxT("Currently (2020) maintaned by Mooneer Salem K6AQ and David Rowe VK5DGR.\n\n") - wxT("freedv-gui version: %s\n") - wxT("freedv-gui git hash: %s\n") - wxT("codec2 git hash: %s\n") - wxT("lpcnet git hash: %s\n"), - FREEDV_VERSION, FREEDV_VERSION, GIT_HASH, freedv_get_hash(), lpcnet_get_hash()); - - wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); -} - - -// Attempt to talk to rig using Hamlib - -bool MainFrame::OpenHamlibRig() { - if (wxGetApp().m_boolHamlibUseForPTT != true) - return false; - if (wxGetApp().m_intHamlibRig == 0) - return false; - if (wxGetApp().m_hamlib == NULL) - return false; - - int rig = wxGetApp().m_intHamlibRig; - wxString port = wxGetApp().m_strHamlibSerialPort; - int serial_rate = wxGetApp().m_intHamlibSerialRate; - bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, wxGetApp().m_intHamlibIcomCIVHex); - if (status == false) - { - if (wxGetApp().m_psk_enable) - { - wxMessageBox("Couldn't connect to Radio with hamlib. PSK Reporter reporting will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); - } - else - { - wxMessageBox("Couldn't connect to Radio with hamlib", wxT("Error"), wxOK | wxICON_ERROR, this); - } - } - else - { - wxGetApp().m_hamlib->enable_mode_detection(m_txtModeStatus, g_mode == FREEDV_MODE_2400B); - } - - // Initialize PSK Reporter reporting. - if (status && wxGetApp().m_psk_enable) - { - std::string currentMode = ""; - switch (g_mode) - { - case FREEDV_MODE_1600: - currentMode = "1600"; - break; - case FREEDV_MODE_700C: - currentMode = "700C"; - break; - case FREEDV_MODE_700D: - currentMode = "700D"; - break; - case FREEDV_MODE_800XA: - currentMode = "800XA"; - break; - case FREEDV_MODE_2400B: - currentMode = "2400B"; - break; - case FREEDV_MODE_2020: - currentMode = "2020"; - break; - case FREEDV_MODE_700E: - currentMode = "700E"; - break; - default: - currentMode = "unknown"; - break; - } - - if (wxGetApp().m_psk_callsign.ToStdString() == "" || wxGetApp().m_psk_grid_square.ToStdString() == "") - { - wxMessageBox("PSK Reporter reporting requires a valid callsign and grid square in Tools->Options. Reporting will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); - } - else - { - wxGetApp().m_callsignEncoder = new CallsignEncoder(); - wxGetApp().m_pskReporter = new PskReporter( - wxGetApp().m_psk_callsign.ToStdString(), - wxGetApp().m_psk_grid_square.ToStdString(), - std::string("FreeDV ") + FREEDV_VERSION + " " + currentMode); - wxGetApp().m_pskPendingCallsign = ""; - wxGetApp().m_pskPendingSnr = 0; - - // Send empty packet to verify network connectivity. - bool success = wxGetApp().m_pskReporter->send(); - if (success) - { - // Enable PSK Reporter timer (every 5 minutes). - m_pskReporterTimer.Start(5 * 60 * 1000); - } - else - { - wxMessageBox("Couldn't connect to PSK Reporter server. Reporting functionality will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); - delete wxGetApp().m_pskReporter; - delete wxGetApp().m_callsignEncoder; - wxGetApp().m_pskReporter = NULL; - wxGetApp().m_callsignEncoder = NULL; - } - } - } - else - { - wxGetApp().m_pskReporter = NULL; - wxGetApp().m_callsignEncoder = NULL; - } - - return status; -} //------------------------------------------------------------------------- // OnTogBtnOnOff() diff --git a/src/ongui.cpp b/src/ongui.cpp new file mode 100644 index 000000000..ddbd80ec2 --- /dev/null +++ b/src/ongui.cpp @@ -0,0 +1,235 @@ +/* + ongui.cpp + + The simpler GUI event handlers. +*/ + +#include "main.h" + +extern int g_mode; +extern bool g_modal; + +//------------------------------------------------------------------------- +// OnExitClick() +//------------------------------------------------------------------------- +void MainFrame::OnExitClick(wxCommandEvent& event) +{ + OnExit(event); +} + +//------------------------------------------------------------------------- +// OnToolsAudio() +//------------------------------------------------------------------------- +void MainFrame::OnToolsAudio(wxCommandEvent& event) +{ + wxUnusedVar(event); + int rv = 0; + AudioOptsDialog *dlg = new AudioOptsDialog(NULL); + rv = dlg->ShowModal(); + if(rv == wxID_OK) + { + dlg->ExchangeData(EXCHANGE_DATA_OUT); + } + delete dlg; +} + +//------------------------------------------------------------------------- +// OnToolsAudioUI() +//------------------------------------------------------------------------- +void MainFrame::OnToolsAudioUI(wxUpdateUIEvent& event) +{ + event.Enable(!m_RxRunning); +} + +//------------------------------------------------------------------------- +// OnToolsFilter() +//------------------------------------------------------------------------- +void MainFrame::OnToolsFilter(wxCommandEvent& event) +{ + wxUnusedVar(event); + FilterDlg *dlg = new FilterDlg(NULL, m_RxRunning, &m_newMicInFilter, &m_newSpkOutFilter); + dlg->ShowModal(); + delete dlg; +} + +//------------------------------------------------------------------------- +// OnToolsOptions() +//------------------------------------------------------------------------- +void MainFrame::OnToolsOptions(wxCommandEvent& event) +{ + wxUnusedVar(event); + g_modal = true; + //fprintf(stderr,"g_modal: %d\n", g_modal); + optionsDlg->Show(); +} + +//------------------------------------------------------------------------- +// OnToolsOptionsUI() +//------------------------------------------------------------------------- +void MainFrame::OnToolsOptionsUI(wxUpdateUIEvent& event) +{ +} + +//------------------------------------------------------------------------- +// OnToolsComCfg() +//------------------------------------------------------------------------- +void MainFrame::OnToolsComCfg(wxCommandEvent& event) +{ + wxUnusedVar(event); + + ComPortsDlg *dlg = new ComPortsDlg(NULL); + + dlg->ShowModal(); + + delete dlg; +} + +//------------------------------------------------------------------------- +// OnToolsComCfgUI() +//------------------------------------------------------------------------- +void MainFrame::OnToolsComCfgUI(wxUpdateUIEvent& event) +{ + event.Enable(!m_RxRunning); +} + +//------------------------------------------------------------------------- +// OnHelpCheckUpdates() +//------------------------------------------------------------------------- +void MainFrame::OnHelpCheckUpdates(wxCommandEvent& event) +{ + wxMessageBox("Got Click!", "OnHelpCheckUpdates", wxOK); + event.Skip(); +} + +//------------------------------------------------------------------------- +// OnHelpCheckUpdatesUI() +//------------------------------------------------------------------------- +void MainFrame::OnHelpCheckUpdatesUI(wxUpdateUIEvent& event) +{ + event.Enable(false); +} + +//------------------------------------------------------------------------- +//OnHelpAbout() +//------------------------------------------------------------------------- +void MainFrame::OnHelpAbout(wxCommandEvent& event) +{ + wxUnusedVar(event); + wxString msg; + msg.Printf( wxT("FreeDV GUI %s\n\n") + wxT("For Help and Support visit: http://freedv.org\n\n") + + wxT("GNU Public License V2.1\n\n") + wxT("Created by David Witten KD0EAG and David Rowe VK5DGR in 2012. ") + wxT("Currently (2020) maintaned by Mooneer Salem K6AQ and David Rowe VK5DGR.\n\n") + wxT("freedv-gui version: %s\n") + wxT("freedv-gui git hash: %s\n") + wxT("codec2 git hash: %s\n") + wxT("lpcnet git hash: %s\n"), + FREEDV_VERSION, FREEDV_VERSION, GIT_HASH, freedv_get_hash(), lpcnet_get_hash()); + + wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); +} + + +// Attempt to talk to rig using Hamlib + +bool MainFrame::OpenHamlibRig() { + if (wxGetApp().m_boolHamlibUseForPTT != true) + return false; + if (wxGetApp().m_intHamlibRig == 0) + return false; + if (wxGetApp().m_hamlib == NULL) + return false; + + int rig = wxGetApp().m_intHamlibRig; + wxString port = wxGetApp().m_strHamlibSerialPort; + int serial_rate = wxGetApp().m_intHamlibSerialRate; + bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate, wxGetApp().m_intHamlibIcomCIVHex); + if (status == false) + { + if (wxGetApp().m_psk_enable) + { + wxMessageBox("Couldn't connect to Radio with hamlib. PSK Reporter reporting will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); + } + else + { + wxMessageBox("Couldn't connect to Radio with hamlib", wxT("Error"), wxOK | wxICON_ERROR, this); + } + } + else + { + wxGetApp().m_hamlib->enable_mode_detection(m_txtModeStatus, g_mode == FREEDV_MODE_2400B); + } + + // Initialize PSK Reporter reporting. + if (status && wxGetApp().m_psk_enable) + { + std::string currentMode = ""; + switch (g_mode) + { + case FREEDV_MODE_1600: + currentMode = "1600"; + break; + case FREEDV_MODE_700C: + currentMode = "700C"; + break; + case FREEDV_MODE_700D: + currentMode = "700D"; + break; + case FREEDV_MODE_800XA: + currentMode = "800XA"; + break; + case FREEDV_MODE_2400B: + currentMode = "2400B"; + break; + case FREEDV_MODE_2020: + currentMode = "2020"; + break; + case FREEDV_MODE_700E: + currentMode = "700E"; + break; + default: + currentMode = "unknown"; + break; + } + + if (wxGetApp().m_psk_callsign.ToStdString() == "" || wxGetApp().m_psk_grid_square.ToStdString() == "") + { + wxMessageBox("PSK Reporter reporting requires a valid callsign and grid square in Tools->Options. Reporting will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); + } + else + { + wxGetApp().m_callsignEncoder = new CallsignEncoder(); + wxGetApp().m_pskReporter = new PskReporter( + wxGetApp().m_psk_callsign.ToStdString(), + wxGetApp().m_psk_grid_square.ToStdString(), + std::string("FreeDV ") + FREEDV_VERSION + " " + currentMode); + wxGetApp().m_pskPendingCallsign = ""; + wxGetApp().m_pskPendingSnr = 0; + + // Send empty packet to verify network connectivity. + bool success = wxGetApp().m_pskReporter->send(); + if (success) + { + // Enable PSK Reporter timer (every 5 minutes). + m_pskReporterTimer.Start(5 * 60 * 1000); + } + else + { + wxMessageBox("Couldn't connect to PSK Reporter server. Reporting functionality will be disabled.", wxT("Error"), wxOK | wxICON_ERROR, this); + delete wxGetApp().m_pskReporter; + delete wxGetApp().m_callsignEncoder; + wxGetApp().m_pskReporter = NULL; + wxGetApp().m_callsignEncoder = NULL; + } + } + } + else + { + wxGetApp().m_pskReporter = NULL; + wxGetApp().m_callsignEncoder = NULL; + } + + return status; +} From bb35df44462cf116744a1bb39500e21ab79d169b Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:13:49 +1030 Subject: [PATCH 12/18] moved some more code out of main --- src/main.cpp | 361 +------------------------------------------------- src/ongui.cpp | 312 +++++++++++++++++++++++++++++++++++++++++++ src/util.cpp | 66 ++++++++- 3 files changed, 377 insertions(+), 362 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5650e6bf3..5eaade19d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,7 @@ struct FIFO *g_txDataInFifo; struct FIFO *g_rxDataOutFifo; // tx/rx processing states -int g_State, g_prev_State, g_interleaverSyncState; +int g_State, g_prev_State; paCallBackData *g_rxUserdata; int g_dump_timing; int g_dump_fifo_state; @@ -1381,362 +1381,6 @@ void MainFrame::OnTimer(wxTimerEvent &evt) #endif -//------------------------------------------------------------------------- -// OnCloseFrame() -//------------------------------------------------------------------------- -void MainFrame::OnCloseFrame(wxCloseEvent& event) -{ - //fprintf(stderr, "MainFrame::OnCloseFrame()\n"); - Pa_Terminate(); - Destroy(); -} - -//------------------------------------------------------------------------- -// OnTop() -//------------------------------------------------------------------------- -void MainFrame::OnTop(wxCommandEvent& event) -{ - int style = GetWindowStyle(); - - if (style & wxSTAY_ON_TOP) - { - style &= ~wxSTAY_ON_TOP; - } - else - { - style |= wxSTAY_ON_TOP; - } - SetWindowStyle(style); -} - -//------------------------------------------------------------------------- -// OnDeleteConfig() -//------------------------------------------------------------------------- -void MainFrame::OnDeleteConfig(wxCommandEvent&) -{ - wxConfigBase *pConfig = wxConfigBase::Get(); - if(pConfig->DeleteAll()) - { - wxLogMessage(wxT("Config file/registry key successfully deleted. Please restart FreeDV.")); - - delete wxConfigBase::Set(NULL); - wxConfigBase::DontCreateOnDemand(); - } - else - { - wxLogError(wxT("Deleting config file/registry key failed.")); - } -} - -//------------------------------------------------------------------------- -// Paint() -//------------------------------------------------------------------------- -void MainFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) -{ - wxPaintDC dc(this); - - if(GetMenuBar()->IsChecked(ID_PAINT_BG)) - { - dc.Clear(); - } - dc.SetUserScale(m_zoom, m_zoom); -} - -//------------------------------------------------------------------------- -// OnCmdSliderScroll() -//------------------------------------------------------------------------- -void MainFrame::OnCmdSliderScroll(wxScrollEvent& event) -{ - char sqsnr[15]; - g_SquelchLevel = (float)m_sliderSQ->GetValue()/2.0 - 5.0; - sprintf(sqsnr, "%4.1f", g_SquelchLevel); // 0.5 dB steps - wxString sqsnr_string(sqsnr); - m_textSQ->SetLabel(sqsnr_string); - - event.Skip(); -} - -//------------------------------------------------------------------------- -// OnCheckSQClick() -//------------------------------------------------------------------------- -void MainFrame::OnCheckSQClick(wxCommandEvent& event) -{ - if(!g_SquelchActive) - { - g_SquelchActive = true; - } - else - { - g_SquelchActive = false; - } -} - -void MainFrame::setsnrBeta(bool snrSlow) -{ - if(snrSlow) - { - m_snrBeta = 0.95; // make this closer to 1.0 to smooth SNR est further - } - else - { - m_snrBeta = 0.0; // no smoothing of SNR estimate from demodulator - } -} - -//------------------------------------------------------------------------- -// OnCheckSQClick() -//------------------------------------------------------------------------- -void MainFrame::OnCheckSNRClick(wxCommandEvent& event) -{ - wxGetApp().m_snrSlow = m_ckboxSNR->GetValue(); - setsnrBeta(wxGetApp().m_snrSlow); - //printf("m_snrSlow: %d\n", (int)wxGetApp().m_snrSlow); -} - -// check for space bar press (only when running) - -int MainApp::FilterEvent(wxEvent& event) -{ - if ((event.GetEventType() == wxEVT_KEY_DOWN) && - (((wxKeyEvent&)event).GetKeyCode() == WXK_SPACE)) - { - // only use space to toggle PTT if we are running and no modal dialogs (like options) up - //fprintf(stderr,"frame->m_RxRunning: %d g_modal: %d\n", - // frame->m_RxRunning, g_modal); - if (frame->m_RxRunning && !g_modal) { - - // space bar controls rx/rx if keyer not running - if (frame->vk_state == VK_IDLE) { - if (frame->m_btnTogPTT->GetValue()) - frame->m_btnTogPTT->SetValue(false); - else - frame->m_btnTogPTT->SetValue(true); - - frame->togglePTT(); - } - else // space bar stops keyer - frame->VoiceKeyerProcessEvent(VK_SPACE_BAR); - - return true; // absorb space so we don't toggle control with focus (e.g. Start) - - } - } - - return -1; -} - -//------------------------------------------------------------------------- -// OnTogBtnPTT () -//------------------------------------------------------------------------- -void MainFrame::OnTogBtnPTT (wxCommandEvent& event) -{ - if (vk_state == VK_TX) - { - // Disable TX via VK code to prevent state inconsistencies. - VoiceKeyerProcessEvent(VK_SPACE_BAR); - } - else - { - togglePTT(); - } - event.Skip(); -} - -void MainFrame::togglePTT(void) { - - // Change tabbed page in centre panel depending on PTT state - - if (g_tx) - { - // tx-> rx transition, swap to the page we were on for last rx - m_auiNbookCtrl->ChangeSelection(wxGetApp().m_rxNbookCtrl); - - // enable sync text - - m_textSync->Enable(); - - // Reenable On/Off button. - m_togBtnOnOff->Enable(true); - } - else - { - // rx-> tx transition, swap to Mic In page to monitor speech - wxGetApp().m_rxNbookCtrl = m_auiNbookCtrl->GetSelection(); - m_auiNbookCtrl->ChangeSelection(m_auiNbookCtrl->GetPageIndex((wxWindow *)m_panelSpeechIn)); - - // disable sync text - - m_textSync->Disable(); - - // Disable On/Off button. - m_togBtnOnOff->Enable(false); - } - - g_tx = m_btnTogPTT->GetValue(); - - // Hamlib PTT - - if (wxGetApp().m_boolHamlibUseForPTT) { - Hamlib *hamlib = wxGetApp().m_hamlib; - wxString hamlibError; - if (wxGetApp().m_boolHamlibUseForPTT && hamlib != NULL) { - if (hamlib->ptt(g_tx, hamlibError) == false) { - wxMessageBox(wxString("Hamlib PTT Error: ") + hamlibError, wxT("Error"), wxOK | wxICON_ERROR, this); - } - } - } - - // Serial PTT - - if (wxGetApp().m_boolUseSerialPTT && (wxGetApp().m_serialport->isopen())) { - wxGetApp().m_serialport->ptt(g_tx); - } - - // reset level gauge - - m_maxLevel = 0; - m_textLevel->SetLabel(wxT("")); - m_gaugeLevel->SetValue(0); - -} - - -// State machine to detect sync and send a UDP message - -void MainFrame::DetectSyncProcessEvent(void) { - int next_state = ds_state; - - switch(ds_state) { - - case DS_IDLE: - if (freedv_get_sync(g_pfreedv) == 1) { - next_state = DS_SYNC_WAIT; - ds_rx_time = 0; - } - break; - - case DS_SYNC_WAIT: - - // In this state we wait fo a few seconds of valid sync, then - // send UDP message - - if (freedv_get_sync(g_pfreedv) == 0) { - next_state = DS_IDLE; - } else { - ds_rx_time += DT; - } - - if (ds_rx_time >= DS_SYNC_WAIT_TIME) { - char s[100]; sprintf(s, "rx sync"); - if (wxGetApp().m_udp_enable) { - UDPSend(wxGetApp().m_udp_port, s, strlen(s)+1); - } - ds_rx_time = 0; - next_state = DS_UNSYNC_WAIT; - } - break; - - case DS_UNSYNC_WAIT: - - // In this state we wait for sync to end - - if (freedv_get_sync(g_pfreedv) == 0) { - ds_rx_time += DT; - if (ds_rx_time >= DS_SYNC_WAIT_TIME) { - next_state = DS_IDLE; - } - } else { - ds_rx_time = 0; - } - break; - - default: - // catch anything we missed - - next_state = DS_IDLE; - } - - ds_state = next_state; -} - -void MainFrame::OnTogBtnSplitClick(wxCommandEvent& event) { - if (g_split) - g_split = 0; - else - g_split = 1; - event.Skip(); -} - -//------------------------------------------------------------------------- -// OnTogBtnAnalogClick() -//------------------------------------------------------------------------- -void MainFrame::OnTogBtnAnalogClick (wxCommandEvent& event) -{ - if (g_analog == 0) { - g_analog = 1; - m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(FS/2))); - m_panelWaterfall->setFs(FS); - } - else { - g_analog = 0; - m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(freedv_get_modem_sample_rate(g_pfreedv)/2))); - m_panelWaterfall->setFs(freedv_get_modem_sample_rate(g_pfreedv)); - } - - g_State = g_prev_State = g_interleaverSyncState = 0; - g_stats.snr_est = 0; - - event.Skip(); -} - -void MainFrame::OnCallSignReset(wxCommandEvent& event) -{ - m_pcallsign = m_callsign; - memset(m_callsign, 0, MAX_CALLSIGN); - wxString s; - s.Printf("%s", m_callsign); - m_txtCtrlCallSign->SetValue(s); -} - - -// Force manual resync, just in case demod gets stuck on false sync - -void MainFrame::OnReSync(wxCommandEvent& event) -{ - if (m_RxRunning) { - fprintf(stderr,"OnReSync\n"); - if (g_mode != -1) { - // Resync must be triggered from the TX/RX thread, so pushing the button queues it until - // the next execution of the TX/RX loop. - g_queueResync = true; - } - } -} - - -void MainFrame::OnBerReset(wxCommandEvent& event) -{ - if (m_RxRunning) { - if (g_mode == -1) { -#ifdef __HORUS__ - horus_set_total_payload_bits(g_horus, 0); -#endif - } else { - freedv_set_total_bits(g_pfreedv, 0); - freedv_set_total_bit_errors(g_pfreedv, 0); - g_resyncs = 0; - int i; - for(i=0; i<2*g_Nc; i++) { - g_error_hist[i] = 0; - g_error_histn[i] = 0; - } - // resets variance stats every time it is called - freedv_set_eq(g_pfreedv, wxGetApp().m_700C_EQ); - } - } -} - - //------------------------------------------------------------------------- // OnExit() //------------------------------------------------------------------------- @@ -1977,7 +1621,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) int src_error; g_spec_src = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(g_spec_src != NULL); - g_State = g_prev_State = g_interleaverSyncState = 0; + g_State = g_prev_State = 0; g_snr = 0.0; g_half_duplex = wxGetApp().m_boolHalfDuplex; @@ -3238,7 +2882,6 @@ void per_frame_rx_processing( nin = freedv_nin(g_pfreedv); g_State = freedv_get_sync(g_pfreedv); - g_interleaverSyncState = freedv_get_sync_interleaver(g_pfreedv); //fprintf(g_logfile, "g_State: %d g_stats.sync: %d snr: %f \n", g_State, g_stats.sync, f->snr); diff --git a/src/ongui.cpp b/src/ongui.cpp index ddbd80ec2..3b2fc3e38 100644 --- a/src/ongui.cpp +++ b/src/ongui.cpp @@ -9,6 +9,19 @@ extern int g_mode; extern bool g_modal; +extern int g_SquelchActive; +extern float g_SquelchLevel; +extern int g_analog; +extern int g_split; +extern int g_tx; +extern int g_State, g_prev_State; +extern struct freedv *g_pfreedv; +extern struct MODEM_STATS g_stats; +extern bool g_queueResync; +extern short *g_error_hist, *g_error_histn; +extern int g_resyncs; +extern int g_Nc; + //------------------------------------------------------------------------- // OnExitClick() //------------------------------------------------------------------------- @@ -233,3 +246,302 @@ bool MainFrame::OpenHamlibRig() { return status; } + +//------------------------------------------------------------------------- +// OnCloseFrame() +//------------------------------------------------------------------------- +void MainFrame::OnCloseFrame(wxCloseEvent& event) +{ + //fprintf(stderr, "MainFrame::OnCloseFrame()\n"); + Pa_Terminate(); + Destroy(); +} + +//------------------------------------------------------------------------- +// OnTop() +//------------------------------------------------------------------------- +void MainFrame::OnTop(wxCommandEvent& event) +{ + int style = GetWindowStyle(); + + if (style & wxSTAY_ON_TOP) + { + style &= ~wxSTAY_ON_TOP; + } + else + { + style |= wxSTAY_ON_TOP; + } + SetWindowStyle(style); +} + +//------------------------------------------------------------------------- +// OnDeleteConfig() +//------------------------------------------------------------------------- +void MainFrame::OnDeleteConfig(wxCommandEvent&) +{ + wxConfigBase *pConfig = wxConfigBase::Get(); + if(pConfig->DeleteAll()) + { + wxLogMessage(wxT("Config file/registry key successfully deleted. Please restart FreeDV.")); + + delete wxConfigBase::Set(NULL); + wxConfigBase::DontCreateOnDemand(); + } + else + { + wxLogError(wxT("Deleting config file/registry key failed.")); + } +} + +//------------------------------------------------------------------------- +// Paint() +//------------------------------------------------------------------------- +void MainFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + wxPaintDC dc(this); + + if(GetMenuBar()->IsChecked(ID_PAINT_BG)) + { + dc.Clear(); + } + dc.SetUserScale(m_zoom, m_zoom); +} + +//------------------------------------------------------------------------- +// OnCmdSliderScroll() +//------------------------------------------------------------------------- +void MainFrame::OnCmdSliderScroll(wxScrollEvent& event) +{ + char sqsnr[15]; + g_SquelchLevel = (float)m_sliderSQ->GetValue()/2.0 - 5.0; + sprintf(sqsnr, "%4.1f", g_SquelchLevel); // 0.5 dB steps + wxString sqsnr_string(sqsnr); + m_textSQ->SetLabel(sqsnr_string); + + event.Skip(); +} + +//------------------------------------------------------------------------- +// OnCheckSQClick() +//------------------------------------------------------------------------- +void MainFrame::OnCheckSQClick(wxCommandEvent& event) +{ + if(!g_SquelchActive) + { + g_SquelchActive = true; + } + else + { + g_SquelchActive = false; + } +} + +void MainFrame::setsnrBeta(bool snrSlow) +{ + if(snrSlow) + { + m_snrBeta = 0.95; // make this closer to 1.0 to smooth SNR est further + } + else + { + m_snrBeta = 0.0; // no smoothing of SNR estimate from demodulator + } +} + +//------------------------------------------------------------------------- +// OnCheckSQClick() +//------------------------------------------------------------------------- +void MainFrame::OnCheckSNRClick(wxCommandEvent& event) +{ + wxGetApp().m_snrSlow = m_ckboxSNR->GetValue(); + setsnrBeta(wxGetApp().m_snrSlow); + //printf("m_snrSlow: %d\n", (int)wxGetApp().m_snrSlow); +} + +// check for space bar press (only when running) + +int MainApp::FilterEvent(wxEvent& event) +{ + if ((event.GetEventType() == wxEVT_KEY_DOWN) && + (((wxKeyEvent&)event).GetKeyCode() == WXK_SPACE)) + { + // only use space to toggle PTT if we are running and no modal dialogs (like options) up + //fprintf(stderr,"frame->m_RxRunning: %d g_modal: %d\n", + // frame->m_RxRunning, g_modal); + if (frame->m_RxRunning && !g_modal) { + + // space bar controls rx/rx if keyer not running + if (frame->vk_state == VK_IDLE) { + if (frame->m_btnTogPTT->GetValue()) + frame->m_btnTogPTT->SetValue(false); + else + frame->m_btnTogPTT->SetValue(true); + + frame->togglePTT(); + } + else // space bar stops keyer + frame->VoiceKeyerProcessEvent(VK_SPACE_BAR); + + return true; // absorb space so we don't toggle control with focus (e.g. Start) + + } + } + + return -1; +} + +//------------------------------------------------------------------------- +// OnTogBtnPTT () +//------------------------------------------------------------------------- +void MainFrame::OnTogBtnPTT (wxCommandEvent& event) +{ + if (vk_state == VK_TX) + { + // Disable TX via VK code to prevent state inconsistencies. + VoiceKeyerProcessEvent(VK_SPACE_BAR); + } + else + { + togglePTT(); + } + event.Skip(); +} + +void MainFrame::togglePTT(void) { + + // Change tabbed page in centre panel depending on PTT state + + if (g_tx) + { + // tx-> rx transition, swap to the page we were on for last rx + m_auiNbookCtrl->ChangeSelection(wxGetApp().m_rxNbookCtrl); + + // enable sync text + + m_textSync->Enable(); + + // Reenable On/Off button. + m_togBtnOnOff->Enable(true); + } + else + { + // rx-> tx transition, swap to Mic In page to monitor speech + wxGetApp().m_rxNbookCtrl = m_auiNbookCtrl->GetSelection(); + m_auiNbookCtrl->ChangeSelection(m_auiNbookCtrl->GetPageIndex((wxWindow *)m_panelSpeechIn)); + + // disable sync text + + m_textSync->Disable(); + + // Disable On/Off button. + m_togBtnOnOff->Enable(false); + } + + g_tx = m_btnTogPTT->GetValue(); + + // Hamlib PTT + + if (wxGetApp().m_boolHamlibUseForPTT) { + Hamlib *hamlib = wxGetApp().m_hamlib; + wxString hamlibError; + if (wxGetApp().m_boolHamlibUseForPTT && hamlib != NULL) { + if (hamlib->ptt(g_tx, hamlibError) == false) { + wxMessageBox(wxString("Hamlib PTT Error: ") + hamlibError, wxT("Error"), wxOK | wxICON_ERROR, this); + } + } + } + + // Serial PTT + + if (wxGetApp().m_boolUseSerialPTT && (wxGetApp().m_serialport->isopen())) { + wxGetApp().m_serialport->ptt(g_tx); + } + + // reset level gauge + + m_maxLevel = 0; + m_textLevel->SetLabel(wxT("")); + m_gaugeLevel->SetValue(0); + +} + + +void MainFrame::OnTogBtnSplitClick(wxCommandEvent& event) { + if (g_split) + g_split = 0; + else + g_split = 1; + event.Skip(); +} + +//------------------------------------------------------------------------- +// OnTogBtnAnalogClick() +//------------------------------------------------------------------------- +void MainFrame::OnTogBtnAnalogClick (wxCommandEvent& event) +{ + if (g_analog == 0) { + g_analog = 1; + m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(FS/2))); + m_panelWaterfall->setFs(FS); + } + else { + g_analog = 0; + m_panelSpectrum->setFreqScale(MODEM_STATS_NSPEC*((float)MAX_F_HZ/(freedv_get_modem_sample_rate(g_pfreedv)/2))); + m_panelWaterfall->setFs(freedv_get_modem_sample_rate(g_pfreedv)); + } + + g_State = g_prev_State = 0; + g_stats.snr_est = 0; + + event.Skip(); +} + +void MainFrame::OnCallSignReset(wxCommandEvent& event) +{ + m_pcallsign = m_callsign; + memset(m_callsign, 0, MAX_CALLSIGN); + wxString s; + s.Printf("%s", m_callsign); + m_txtCtrlCallSign->SetValue(s); +} + + +// Force manual resync, just in case demod gets stuck on false sync + +void MainFrame::OnReSync(wxCommandEvent& event) +{ + if (m_RxRunning) { + fprintf(stderr,"OnReSync\n"); + if (g_mode != -1) { + // Resync must be triggered from the TX/RX thread, so pushing the button queues it until + // the next execution of the TX/RX loop. + g_queueResync = true; + } + } +} + + +void MainFrame::OnBerReset(wxCommandEvent& event) +{ + if (m_RxRunning) { + if (g_mode == -1) { +#ifdef __HORUS__ + horus_set_total_payload_bits(g_horus, 0); +#endif + } else { + freedv_set_total_bits(g_pfreedv, 0); + freedv_set_total_bit_errors(g_pfreedv, 0); + g_resyncs = 0; + int i; + for(i=0; i<2*g_Nc; i++) { + g_error_hist[i] = 0; + g_error_histn[i] = 0; + } + // resets variance stats every time it is called + freedv_set_eq(g_pfreedv, wxGetApp().m_700C_EQ); + } + } +} + + diff --git a/src/util.cpp b/src/util.cpp index e1739420d..2c0c1b4b8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,9 +8,11 @@ // Callback from plot_spectrum & plot_waterfall. would be nice to // work out a way to do this without globals. -extern float g_RxFreqOffsetHz; -extern float g_TxFreqOffsetHz; -extern int *g_split; +extern float g_RxFreqOffsetHz; +extern float g_TxFreqOffsetHz; +extern int *g_split; +extern int g_mode; +extern struct freedv *g_pfreedv; void clickTune(float freq) { @@ -229,4 +231,62 @@ void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs) codec2_fifo_write(plotFifo, dec_samples, nSamples); } +// State machine to detect sync and send a UDP message + +void MainFrame::DetectSyncProcessEvent(void) { + int next_state = ds_state; + + switch(ds_state) { + + case DS_IDLE: + if (freedv_get_sync(g_pfreedv) == 1) { + next_state = DS_SYNC_WAIT; + ds_rx_time = 0; + } + break; + + case DS_SYNC_WAIT: + + // In this state we wait fo a few seconds of valid sync, then + // send UDP message + + if (freedv_get_sync(g_pfreedv) == 0) { + next_state = DS_IDLE; + } else { + ds_rx_time += DT; + } + + if (ds_rx_time >= DS_SYNC_WAIT_TIME) { + char s[100]; sprintf(s, "rx sync"); + if (wxGetApp().m_udp_enable) { + UDPSend(wxGetApp().m_udp_port, s, strlen(s)+1); + } + ds_rx_time = 0; + next_state = DS_UNSYNC_WAIT; + } + break; + + case DS_UNSYNC_WAIT: + + // In this state we wait for sync to end + + if (freedv_get_sync(g_pfreedv) == 0) { + ds_rx_time += DT; + if (ds_rx_time >= DS_SYNC_WAIT_TIME) { + next_state = DS_IDLE; + } + } else { + ds_rx_time = 0; + } + break; + + default: + // catch anything we missed + + next_state = DS_IDLE; + } + + ds_state = next_state; +} + From 75e7ed6ec1fe7ec196d9fc0a53e744c0d50bbd94 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:28:01 +1030 Subject: [PATCH 13/18] added g_verbose variable and Tool-Options-Debug checkbox --- src/dlg_options.cpp | 13 +++++++++---- src/dlg_options.h | 1 + src/main.cpp | 3 +-- src/main.h | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dlg_options.cpp b/src/dlg_options.cpp index 029b8f677..bb463f8f4 100644 --- a/src/dlg_options.cpp +++ b/src/dlg_options.cpp @@ -337,13 +337,15 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c wxStaticBox* sb_fifo2 = new wxStaticBox(m_debugTab, wxID_ANY, _("")); wxStaticBoxSizer* sbSizer_fifo2 = new wxStaticBoxSizer(sb_fifo2, wxHORIZONTAL); - m_ckboxTxRxThreadPriority = new wxCheckBox(m_debugTab, wxID_ANY, _(" txRxThreadPriority"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + m_ckboxVerbose = new wxCheckBox(m_debugTab, wxID_ANY, _("Verbose "), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sbSizer_fifo2->Add(m_ckboxVerbose, 0, wxALIGN_LEFT, 0); + m_ckboxTxRxThreadPriority = new wxCheckBox(m_debugTab, wxID_ANY, _("txRxThreadPriority "), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizer_fifo2->Add(m_ckboxTxRxThreadPriority, 0, wxALIGN_LEFT, 0); - m_ckboxTxRxDumpTiming = new wxCheckBox(m_debugTab, wxID_ANY, _(" txRxDumpTiming"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + m_ckboxTxRxDumpTiming = new wxCheckBox(m_debugTab, wxID_ANY, _("txRxDumpTiming "), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizer_fifo2->Add(m_ckboxTxRxDumpTiming, 0, wxALIGN_LEFT, 0); - m_ckboxTxRxDumpFifoState = new wxCheckBox(m_debugTab, wxID_ANY, _(" txRxDumpFifoState"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + m_ckboxTxRxDumpFifoState = new wxCheckBox(m_debugTab, wxID_ANY, _("txRxDumpFifoState "), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizer_fifo2->Add(m_ckboxTxRxDumpFifoState, 0, wxALIGN_LEFT, 0); - m_ckboxFreeDVAPIVerbose = new wxCheckBox(m_debugTab, wxID_ANY, _(" APiVerbose"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + m_ckboxFreeDVAPIVerbose = new wxCheckBox(m_debugTab, wxID_ANY, _("APiVerbose "), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizer_fifo2->Add(m_ckboxFreeDVAPIVerbose, 0, wxALIGN_LEFT, 0); sbSizer_fifo->Add(sbSizer_fifo2, 0, wxALIGN_LEFT, 5); @@ -496,6 +498,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckboxTxRxThreadPriority->SetValue(wxGetApp().m_txRxThreadHighPriority); m_ckboxTxRxDumpTiming->SetValue(g_dump_timing); m_ckboxTxRxDumpFifoState->SetValue(g_dump_fifo_state); + m_ckboxVerbose->SetValue(g_verbose); m_ckboxFreeDVAPIVerbose->SetValue(g_freedv_verbose); m_ckboxFreeDV700txClip->SetValue(wxGetApp().m_FreeDV700txClip); @@ -607,6 +610,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) wxGetApp().m_txRxThreadHighPriority = m_ckboxTxRxThreadPriority->GetValue(); g_dump_timing = m_ckboxTxRxDumpTiming->GetValue(); g_dump_fifo_state = m_ckboxTxRxDumpFifoState->GetValue(); + g_verbose = m_ckboxVerbose->GetValue(); g_freedv_verbose = m_ckboxFreeDVAPIVerbose->GetValue(); wxGetApp().m_udp_enable = m_ckbox_udp_enable->GetValue(); @@ -670,6 +674,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) #ifdef __WXMSW__ pConfig->Write(wxT("/Debug/console"), wxGetApp().m_debug_console); #endif + pConfig->Write(wxT("/Debug/verbose"), g_verbose); pConfig->Write(wxT("/Debug/APIverbose"), g_freedv_verbose); pConfig->Write(wxT("/PSKReporter/Enable"), wxGetApp().m_psk_enable); diff --git a/src/dlg_options.h b/src/dlg_options.h index 659ae5c36..38973fb58 100644 --- a/src/dlg_options.h +++ b/src/dlg_options.h @@ -162,6 +162,7 @@ class OptionsDlg : public wxDialog wxCheckBox *m_ckboxTxRxThreadPriority; wxCheckBox *m_ckboxTxRxDumpTiming; wxCheckBox *m_ckboxTxRxDumpFifoState; + wxCheckBox *m_ckboxVerbose; wxCheckBox *m_ckboxFreeDVAPIVerbose; wxButton* m_sdbSizer5OK; diff --git a/src/main.cpp b/src/main.cpp index 5eaade19d..2ce4431b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,9 +42,8 @@ extern "C" { // back functions // ------------------------------------------------------------------ -int g_in, g_out; - // freedv states +int g_verbose; int g_Nc; int g_mode; struct freedv *g_pfreedv; diff --git a/src/main.h b/src/main.h index 288add072..1a9ca90dd 100644 --- a/src/main.h +++ b/src/main.h @@ -116,7 +116,7 @@ enum { #define EXCHANGE_DATA_IN 0 #define EXCHANGE_DATA_OUT 1 - +extern int g_verbose; extern int g_nSoundCards; extern int g_soundCard1InDeviceNum; extern int g_soundCard1OutDeviceNum; From ef15f6b14896655046032bd5328e093802770c6a Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:33:09 +1030 Subject: [PATCH 14/18] converted printf to fprintf(stderr, --- src/dlg_audiooptions.cpp | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/dlg_audiooptions.cpp b/src/dlg_audiooptions.cpp index 4776ebc3c..72c65d574 100644 --- a/src/dlg_audiooptions.cpp +++ b/src/dlg_audiooptions.cpp @@ -413,7 +413,7 @@ int AudioOptsDialog::setTextCtrlIfDevNumValid(wxTextCtrl *textCtrl, wxListCtrl * if (aDevNum == devNum) { found_devNum = 1; textCtrl->SetValue(listCtrl->GetItemText(i, 0) + " (" + wxString::Format(wxT("%i"),devNum) + ")"); - printf("setting focus of %d\n", i); + fprintf(stderr,"setting focus of %d\n", i); listCtrl->SetItemState(i, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); } } @@ -436,14 +436,14 @@ int AudioOptsDialog::ExchangeData(int inout) // Map sound card device numbers to tx/rx device numbers depending // on number of sound cards in use - printf("EXCHANGE_DATA_IN:\n"); - printf(" g_nSoundCards: %d\n", g_nSoundCards); - printf(" g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); - printf(" g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); - printf(" g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); - printf(" g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); - printf(" g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); - printf(" g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); + fprintf(stderr,"EXCHANGE_DATA_IN:\n"); + fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); + fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); + fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); + fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); + fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); + fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); + fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); if (g_nSoundCards == 0) { m_textCtrlRxIn ->SetValue("none"); rxInAudioDeviceNum = -1; @@ -498,7 +498,7 @@ int AudioOptsDialog::ExchangeData(int inout) m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"),g_soundCard2SampleRate)); } } - printf(" rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", + fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", rxInAudioDeviceNum, rxOutAudioDeviceNum, txInAudioDeviceNum, txOutAudioDeviceNum); } @@ -508,8 +508,8 @@ int AudioOptsDialog::ExchangeData(int inout) int valid_two_card_config = 0; wxString sampleRate1, sampleRate2; - printf("EXCHANGE_DATA_OUT:\n"); - printf(" rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", + fprintf(stderr,"EXCHANGE_DATA_OUT:\n"); + fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", rxInAudioDeviceNum, rxOutAudioDeviceNum, txInAudioDeviceNum, txOutAudioDeviceNum); // --------------------------------------------------------------- @@ -574,7 +574,7 @@ int AudioOptsDialog::ExchangeData(int inout) } - printf(" valid_one_card_config: %d valid_two_card_config: %d\n", valid_one_card_config, valid_two_card_config); + fprintf(stderr," valid_one_card_config: %d valid_two_card_config: %d\n", valid_one_card_config, valid_two_card_config); if (!valid_one_card_config && !valid_two_card_config) { wxMessageBox(wxT("Invalid one or two sound card configuration"), wxT(""), wxOK); @@ -610,13 +610,13 @@ int AudioOptsDialog::ExchangeData(int inout) g_soundCard2SampleRate = wxAtoi(sampleRate2); } - printf(" g_nSoundCards: %d\n", g_nSoundCards); - printf(" g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); - printf(" g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); - printf(" g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); - printf(" g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); - printf(" g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); - printf(" g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); + fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); + fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); + fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); + fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); + fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); + fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); + fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); wxConfigBase *pConfig = wxConfigBase::Get(); if (pConfig != NULL) { @@ -663,7 +663,7 @@ int AudioOptsDialog:: buildListOfSupportedSampleRates(wxComboBox *cbSampleRate, deviceInfo = Pa_GetDeviceInfo(devNum); if (deviceInfo == NULL) { - printf("Pa_GetDeviceInfo(%d) failed!\n", devNum); + fprintf(stderr,"Pa_GetDeviceInfo(%d) failed!\n", devNum); cbSampleRate->Clear(); return 0; } @@ -693,11 +693,11 @@ int AudioOptsDialog:: buildListOfSupportedSampleRates(wxComboBox *cbSampleRate, if( err == paFormatIsSupported ) { str.Printf("%i", (int)standardSampleRates[i]); cbSampleRate->AppendString(str); - printf("%i ", (int)standardSampleRates[i]); + fprintf(stderr,"%i ", (int)standardSampleRates[i]); numSampleRates++; } } - printf("\n"); + fprintf(stderr,"\n"); return numSampleRates; } @@ -958,7 +958,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(int devNum, PlotScalar *plotSca return; if (devNum < 0) return; - printf("devNum %d\n", devNum); + fprintf(stderr,"devNum %d\n", devNum); fifo = codec2_fifo_create((int)(DT*TEST_WAVEFORM_PLOT_FS*2)); assert(fifo != NULL); src = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(src != NULL); @@ -985,7 +985,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(int devNum, PlotScalar *plotSca sampleRate = wxAtoi(m_cbSampleRateRxIn->GetValue()); nBufs = TEST_WAVEFORM_PLOT_TIME*sampleRate/TEST_BUF_SIZE; - printf("inputChannels: %d nBufs %d\n", inputChannels, nBufs); + fprintf(stderr,"inputChannels: %d nBufs %d\n", inputChannels, nBufs); err = Pa_OpenStream( &stream, @@ -1093,7 +1093,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(int devNum, PlotScalar *plotSc else outputChannels = 2; - printf("outputChannels: %d\n", outputChannels); + fprintf(stderr,"outputChannels: %d\n", outputChannels); outputParameters.device = devNum; outputParameters.channelCount = outputChannels; @@ -1274,7 +1274,7 @@ void AudioOptsDialog::OnOkAudioParameters(wxCommandEvent& event) // We only accept OK if config sucessful - printf("status: %d m_isPaInitialized: %d\n", status, m_isPaInitialized); + fprintf(stderr,"status: %d m_isPaInitialized: %d\n", status, m_isPaInitialized); if (status == 0) { if(m_isPaInitialized) { From 113fc1ce37bed378e9fdf7669ee7746cab6ca692 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:38:24 +1030 Subject: [PATCH 15/18] about to make fprintf(stderr... g_verbose --- src/main.cpp | 1 + src/playrec.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2ce4431b1..66b383aee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -501,6 +501,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) wxGetApp().m_noise_snr = (float)pConfig->Read(wxT("/Noise/noise_snr"), 2); wxGetApp().m_debug_console = (float)pConfig->Read(wxT("/Debug/console"), f); + g_verbose = pConfig->Read(wxT("/Debug/verbose"), (long)0); g_freedv_verbose = pConfig->Read(wxT("/Debug/APIverbose"), (long)0); wxGetApp().m_attn_carrier_en = 0; diff --git a/src/playrec.cpp b/src/playrec.cpp index 44d02c5f4..636e78be1 100644 --- a/src/playrec.cpp +++ b/src/playrec.cpp @@ -154,7 +154,7 @@ void MainFrame::OnPlayFileFromRadio(wxCommandEvent& event) { wxUnusedVar(event); - printf("OnPlayFileFromRadio:: %d\n", (int)g_playFileFromRadio); + fprintf(stderr,"OnPlayFileFromRadio:: %d\n", (int)g_playFileFromRadio); if (g_playFileFromRadio) { fprintf(stderr, "OnPlayFileFromRadio:: Stop\n"); From 0ab971faff10a30f59004a6589a38ef014905e2c Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:44:44 +1030 Subject: [PATCH 16/18] part way through g_verbose --- src/main.cpp | 26 +++++++++++++------------- src/ongui.cpp | 2 +- src/playrec.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 66b383aee..00abee77d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1445,7 +1445,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) if (startStop.IsSameAs("Start")) { - fprintf(stderr, "Start .....\n"); + if (g_verbose) fprintf(stderr, "Start .....\n"); g_queueResync = false; // @@ -1591,8 +1591,8 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) // Init Speex pre-processor states // by inspecting Speex source it seems that only denoiser is on by default - fprintf(stderr, "freedv_get_n_speech_samples(g_pfreedv): %d\n", freedv_get_n_speech_samples(g_pfreedv)); - fprintf(stderr, "freedv_get_speech_sample_rate(g_pfreedv): %d\n", freedv_get_speech_sample_rate(g_pfreedv)); + if (g_verbose) fprintf(stderr, "freedv_get_n_speech_samples(g_pfreedv): %d\n", freedv_get_n_speech_samples(g_pfreedv)); + if (g_verbose) fprintf(stderr, "freedv_get_speech_sample_rate(g_pfreedv): %d\n", freedv_get_speech_sample_rate(g_pfreedv)); if (wxGetApp().m_speexpp_enable) g_speex_st = speex_preprocess_state_init(freedv_get_n_speech_samples(g_pfreedv), freedv_get_speech_sample_rate(g_pfreedv)); @@ -1675,7 +1675,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) // Stop was pressed or start up failed if (startStop.IsSameAs("Stop") || !m_RxRunning ) { - fprintf(stderr, "Stop .....\n"); + if (g_verbose) fprintf(stderr, "Stop .....\n"); // // Stop Running ------------------------------------------------- @@ -1892,7 +1892,7 @@ void MainFrame::startRxStream() bool two_rx=false; bool two_tx=false; - fprintf(stderr, "startRxStream .....\n"); + if (g_verbose) fprintf(stderr, "startRxStream .....\n"); if(!m_RxRunning) { m_RxRunning = true; if(Pa_Initialize()) @@ -1906,7 +1906,7 @@ void MainFrame::startRxStream() if(g_soundCard2InDeviceNum != g_soundCard2OutDeviceNum) two_tx=true; - fprintf(stderr, "two_rx: %d two_tx: %d\n", two_rx, two_tx); + if (g_verbose) fprintf(stderr, "two_rx: %d two_tx: %d\n", two_rx, two_tx); if(two_rx) m_rxOutPa = new PortAudioWrap(); else @@ -2093,7 +2093,7 @@ void MainFrame::startRxStream() g_rxUserdata->outfifo2 = codec2_fifo_create(soundCard2FifoSizeSamples); g_rxUserdata->infifo2 = codec2_fifo_create(soundCard2FifoSizeSamples); - fprintf(stderr, "fifoSize_ms: %d infifo1/outfilo1: %d infifo2/outfilo2: %d\n", + if (g_verbose) fprintf(stderr, "fifoSize_ms: %d infifo1/outfilo1: %d infifo2/outfilo2: %d\n", wxGetApp().m_fifoSize_ms, soundCard1FifoSizeSamples, soundCard2FifoSizeSamples); // reset debug stats for FIFOs @@ -2136,7 +2136,7 @@ void MainFrame::startRxStream() g_rxUserdata->rxinfifo = codec2_fifo_create(rxInFifoSizeSamples); g_rxUserdata->rxoutfifo = codec2_fifo_create(rxOutFifoSizeSamples); - fprintf(stderr, "rxInFifoSizeSamples: %d rxOutFifoSizeSamples: %d\n", rxInFifoSizeSamples, rxOutFifoSizeSamples); + if (g_verbose) fprintf(stderr, "rxInFifoSizeSamples: %d rxOutFifoSizeSamples: %d\n", rxInFifoSizeSamples, rxOutFifoSizeSamples); // Init Equaliser Filters ------------------------------------------------------ @@ -2230,7 +2230,7 @@ void MainFrame::startRxStream() } } - fprintf(stderr, "started stream 1\n"); + if (g_verbose) fprintf(stderr, "started stream 1\n"); // Start sound card 2 ---------------------------------------------------------- @@ -2246,7 +2246,7 @@ void MainFrame::startRxStream() m_txErr = m_txInPa->streamOpen(); if(m_txErr != paNoError) { - fprintf(stderr, "Err: %d\n", m_txErr); + if (g_verbose) fprintf(stderr, "Err: %d\n", m_txErr); wxMessageBox(wxT("Sound Card 2 Open/Setup error."), wxT("Error"), wxOK); m_rxInPa->stop(); m_rxInPa->streamClose(); @@ -2347,7 +2347,7 @@ void MainFrame::startRxStream() } } - fprintf(stderr, "starting tx/rx processing thread\n"); + if (g_verbose) fprintf(stderr, "starting tx/rx processing thread\n"); // start tx/rx processing thread @@ -2420,7 +2420,7 @@ void txRxProcessing() if (g_queueResync) { - fprintf(stderr, "Unsyncing per user request.\n"); + if (g_verbose) fprintf(stderr, "Unsyncing per user request.\n"); g_queueResync = false; freedv_set_sync(g_pfreedv, FREEDV_SYNC_UNSYNC); g_resyncs++; @@ -2635,7 +2635,7 @@ void txRxProcessing() if (g_dump_fifo_state) { // If this drops to zero we have a problem as we will run out of output samples // to send to the sound driver via PortAudio - fprintf(stderr, "outfifo1 used: %6d free: %6d nsam_one_modem_frame: %d\n", + if (g_verbose) fprintf(stderr, "outfifo1 used: %6d free: %6d nsam_one_modem_frame: %d\n", codec2_fifo_used(cbData->outfifo1), codec2_fifo_free(cbData->outfifo1), nsam_one_modem_frame); } diff --git a/src/ongui.cpp b/src/ongui.cpp index 3b2fc3e38..e0729cb49 100644 --- a/src/ongui.cpp +++ b/src/ongui.cpp @@ -512,7 +512,7 @@ void MainFrame::OnCallSignReset(wxCommandEvent& event) void MainFrame::OnReSync(wxCommandEvent& event) { if (m_RxRunning) { - fprintf(stderr,"OnReSync\n"); + if (g_verbose) fprintf(stderr,"OnReSync\n"); if (g_mode != -1) { // Resync must be triggered from the TX/RX thread, so pushing the button queues it until // the next execution of the TX/RX loop. diff --git a/src/playrec.cpp b/src/playrec.cpp index 636e78be1..a73e189b0 100644 --- a/src/playrec.cpp +++ b/src/playrec.cpp @@ -154,10 +154,10 @@ void MainFrame::OnPlayFileFromRadio(wxCommandEvent& event) { wxUnusedVar(event); - fprintf(stderr,"OnPlayFileFromRadio:: %d\n", (int)g_playFileFromRadio); + if (g_verbose) fprintf(stderr,"OnPlayFileFromRadio:: %d\n", (int)g_playFileFromRadio); if (g_playFileFromRadio) { - fprintf(stderr, "OnPlayFileFromRadio:: Stop\n"); + if (g_verbose) fprintf(stderr, "OnPlayFileFromRadio:: Stop\n"); StopPlaybackFileFromRadio(); } else @@ -225,7 +225,7 @@ void MainFrame::OnPlayFileFromRadio(wxCommandEvent& event) wxString stringnumber = wxString::Format(wxT("%d"), (int)sfInfo.samplerate); SetStatusText(wxT("raw file assuming Fs=") + stringnumber, 1); } - fprintf(stderr, "OnPlayFileFromRadio:: Playing File Fs = %d\n", (int)sfInfo.samplerate); + if (g_verbose) fprintf(stderr, "OnPlayFileFromRadio:: Playing File Fs = %d\n", (int)sfInfo.samplerate); m_menuItemPlayFileFromRadio->SetItemLabel(wxString(_("Stop Play File - From Radio..."))); g_playFileFromRadio = true; g_blink = 0.0; @@ -256,7 +256,7 @@ void MainFrame::StopRecFileFromRadio() { if (g_recFileFromRadio) { - fprintf(stderr, "Stopping Record....\n"); + if (g_verbose) fprintf(stderr, "Stopping Record....\n"); g_mutexProtectingCallbackData.Lock(); g_recFileFromRadio = false; sf_close(g_sfRecFile); From 1a627efa9cccdf0967d52a1f36d3d0b68b47badb Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Jan 2021 19:57:30 +1030 Subject: [PATCH 17/18] finished first pass of all fprintf(stderr controlled by g_verbose --- src/dlg_audiooptions.cpp | 58 ++++++++++++++++++++-------------------- src/dlg_options.cpp | 2 +- src/dlg_ptt.cpp | 14 +++++----- src/hamlib.cpp | 38 +++++++++++++------------- src/pskreporter.cpp | 8 +++--- src/serialport.cpp | 24 +++++++++-------- src/udp.cpp | 10 +++---- src/voicekeyer.cpp | 2 +- 8 files changed, 81 insertions(+), 75 deletions(-) diff --git a/src/dlg_audiooptions.cpp b/src/dlg_audiooptions.cpp index 72c65d574..f7e815e62 100644 --- a/src/dlg_audiooptions.cpp +++ b/src/dlg_audiooptions.cpp @@ -70,7 +70,7 @@ void AudioOptsDialog::buildTestControls(PlotScalar **plotScalar, wxButton **btnT //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= AudioOptsDialog::AudioOptsDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) { - fprintf(stderr, "pos %d %d\n", pos.x, pos.y); + if (g_verbose) fprintf(stderr, "pos %d %d\n", pos.x, pos.y); Pa_Init(); wxBoxSizer* mainSizer; @@ -413,7 +413,7 @@ int AudioOptsDialog::setTextCtrlIfDevNumValid(wxTextCtrl *textCtrl, wxListCtrl * if (aDevNum == devNum) { found_devNum = 1; textCtrl->SetValue(listCtrl->GetItemText(i, 0) + " (" + wxString::Format(wxT("%i"),devNum) + ")"); - fprintf(stderr,"setting focus of %d\n", i); + if (g_verbose) fprintf(stderr,"setting focus of %d\n", i); listCtrl->SetItemState(i, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); } } @@ -436,14 +436,14 @@ int AudioOptsDialog::ExchangeData(int inout) // Map sound card device numbers to tx/rx device numbers depending // on number of sound cards in use - fprintf(stderr,"EXCHANGE_DATA_IN:\n"); - fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); - fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); - fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); - fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); - fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); - fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); - fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); + if (g_verbose) fprintf(stderr,"EXCHANGE_DATA_IN:\n"); + if (g_verbose) fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); + if (g_verbose) fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); + if (g_verbose) fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); if (g_nSoundCards == 0) { m_textCtrlRxIn ->SetValue("none"); rxInAudioDeviceNum = -1; @@ -498,7 +498,7 @@ int AudioOptsDialog::ExchangeData(int inout) m_cbSampleRateRxOut->SetValue(wxString::Format(wxT("%i"),g_soundCard2SampleRate)); } } - fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", + if (g_verbose) fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", rxInAudioDeviceNum, rxOutAudioDeviceNum, txInAudioDeviceNum, txOutAudioDeviceNum); } @@ -508,8 +508,8 @@ int AudioOptsDialog::ExchangeData(int inout) int valid_two_card_config = 0; wxString sampleRate1, sampleRate2; - fprintf(stderr,"EXCHANGE_DATA_OUT:\n"); - fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", + if (g_verbose) fprintf(stderr,"EXCHANGE_DATA_OUT:\n"); + if (g_verbose) fprintf(stderr," rxInAudioDeviceNum: %d\n rxOutAudioDeviceNum: %d\n txInAudioDeviceNum: %d\n txOutAudioDeviceNum: %d\n", rxInAudioDeviceNum, rxOutAudioDeviceNum, txInAudioDeviceNum, txOutAudioDeviceNum); // --------------------------------------------------------------- @@ -574,7 +574,7 @@ int AudioOptsDialog::ExchangeData(int inout) } - fprintf(stderr," valid_one_card_config: %d valid_two_card_config: %d\n", valid_one_card_config, valid_two_card_config); + if (g_verbose) fprintf(stderr," valid_one_card_config: %d valid_two_card_config: %d\n", valid_one_card_config, valid_two_card_config); if (!valid_one_card_config && !valid_two_card_config) { wxMessageBox(wxT("Invalid one or two sound card configuration"), wxT(""), wxOK); @@ -610,13 +610,13 @@ int AudioOptsDialog::ExchangeData(int inout) g_soundCard2SampleRate = wxAtoi(sampleRate2); } - fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); - fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); - fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); - fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); - fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); - fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); - fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); + if (g_verbose) fprintf(stderr," g_nSoundCards: %d\n", g_nSoundCards); + if (g_verbose) fprintf(stderr," g_soundCard1InDeviceNum: %d\n", g_soundCard1InDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard1OutDeviceNum: %d\n", g_soundCard1OutDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard1SampleRate: %d\n", g_soundCard1SampleRate); + if (g_verbose) fprintf(stderr," g_soundCard2InDeviceNum: %d\n", g_soundCard2InDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard2OutDeviceNum: %d\n", g_soundCard2OutDeviceNum); + if (g_verbose) fprintf(stderr," g_soundCard2SampleRate: %d\n", g_soundCard2SampleRate); wxConfigBase *pConfig = wxConfigBase::Get(); if (pConfig != NULL) { @@ -663,7 +663,7 @@ int AudioOptsDialog:: buildListOfSupportedSampleRates(wxComboBox *cbSampleRate, deviceInfo = Pa_GetDeviceInfo(devNum); if (deviceInfo == NULL) { - fprintf(stderr,"Pa_GetDeviceInfo(%d) failed!\n", devNum); + if (g_verbose) fprintf(stderr,"Pa_GetDeviceInfo(%d) failed!\n", devNum); cbSampleRate->Clear(); return 0; } @@ -693,11 +693,11 @@ int AudioOptsDialog:: buildListOfSupportedSampleRates(wxComboBox *cbSampleRate, if( err == paFormatIsSupported ) { str.Printf("%i", (int)standardSampleRates[i]); cbSampleRate->AppendString(str); - fprintf(stderr,"%i ", (int)standardSampleRates[i]); + if (g_verbose) fprintf(stderr,"%i ", (int)standardSampleRates[i]); numSampleRates++; } } - fprintf(stderr,"\n"); + if (g_verbose) fprintf(stderr,"\n"); return numSampleRates; } @@ -958,7 +958,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(int devNum, PlotScalar *plotSca return; if (devNum < 0) return; - fprintf(stderr,"devNum %d\n", devNum); + if (g_verbose) fprintf(stderr,"devNum %d\n", devNum); fifo = codec2_fifo_create((int)(DT*TEST_WAVEFORM_PLOT_FS*2)); assert(fifo != NULL); src = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(src != NULL); @@ -985,7 +985,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(int devNum, PlotScalar *plotSca sampleRate = wxAtoi(m_cbSampleRateRxIn->GetValue()); nBufs = TEST_WAVEFORM_PLOT_TIME*sampleRate/TEST_BUF_SIZE; - fprintf(stderr,"inputChannels: %d nBufs %d\n", inputChannels, nBufs); + if (g_verbose) fprintf(stderr,"inputChannels: %d nBufs %d\n", inputChannels, nBufs); err = Pa_OpenStream( &stream, @@ -1093,7 +1093,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(int devNum, PlotScalar *plotSc else outputChannels = 2; - fprintf(stderr,"outputChannels: %d\n", outputChannels); + if (g_verbose) fprintf(stderr,"outputChannels: %d\n", outputChannels); outputParameters.device = devNum; outputParameters.channelCount = outputChannels; @@ -1274,13 +1274,13 @@ void AudioOptsDialog::OnOkAudioParameters(wxCommandEvent& event) // We only accept OK if config sucessful - fprintf(stderr,"status: %d m_isPaInitialized: %d\n", status, m_isPaInitialized); + if (g_verbose) fprintf(stderr,"status: %d m_isPaInitialized: %d\n", status, m_isPaInitialized); if (status == 0) { if(m_isPaInitialized) { if((pa_err = Pa_Terminate()) == paNoError) { - printf("terminated OK\n"); + if (g_verbose) fprintf(stderr, "terminated OK\n"); m_isPaInitialized = false; } else diff --git a/src/dlg_options.cpp b/src/dlg_options.cpp index bb463f8f4..b929a0521 100644 --- a/src/dlg_options.cpp +++ b/src/dlg_options.cpp @@ -816,7 +816,7 @@ void OptionsDlg::OnDebugConsole(wxScrollEvent& event) { int ret = AllocConsole(); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); - fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().m_debug_console); + if (g_verbose) fprintf(stderr, "AllocConsole: %d m_debug_console: %d\n", ret, wxGetApp().m_debug_console); } #endif } diff --git a/src/dlg_ptt.cpp b/src/dlg_ptt.cpp index 653903308..9a19a777b 100644 --- a/src/dlg_ptt.cpp +++ b/src/dlg_ptt.cpp @@ -406,7 +406,7 @@ void ComPortsDlg::ExchangeData(int inout) m_cbSerialRate->GetValue().ToLong(&tmp); wxGetApp().m_intHamlibSerialRate = tmp; } - fprintf(stderr, "serial rate: %d\n", wxGetApp().m_intHamlibSerialRate); + if (g_verbose) fprintf(stderr, "serial rate: %d\n", wxGetApp().m_intHamlibSerialRate); pConfig->Write(wxT("/Hamlib/UseForPTT"), wxGetApp().m_boolHamlibUseForPTT); pConfig->Write(wxT("/Hamlib/RigName"), wxGetApp().m_intHamlibRig); @@ -484,7 +484,7 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { // display serial params - fprintf(stderr, "serial rate: %d\n", serial_rate); + if (g_verbose) fprintf(stderr, "serial rate: %d\n", serial_rate); // try to open rig @@ -535,9 +535,9 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { #if defined(__WXGTK__) || defined(__WXOSX__) ctrlport = m_cbCtlDevicePath->GetValue(); #endif - fprintf(stderr, "opening serial port: "); + if (g_verbose) fprintf(stderr, "opening serial port: "); fputs(ctrlport.c_str(), stderr); // don't escape crazy Microsoft bakslash-ified comm port names - fprintf(stderr,"\n"); + if (g_verbose) fprintf(stderr,"\n"); bool success = serialport->openport(ctrlport.c_str(), m_rbUseRTS->GetValue(), @@ -545,7 +545,7 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { m_rbUseDTR->GetValue(), m_ckDTRPos->IsChecked()); - fprintf(stderr, "serial port open\n"); + if (g_verbose) fprintf(stderr, "serial port open\n"); if (!success) { wxMessageBox("Couldn't open serial port", wxT("Error"), wxOK | wxICON_ERROR, this); @@ -557,9 +557,9 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) { wxSleep(1); serialport->ptt(false); - fprintf(stderr, "closing serial port\n"); + if (g_verbose) fprintf(stderr, "closing serial port\n"); serialport->closeport(); - fprintf(stderr, "serial port closed\n"); + if (g_verbose) fprintf(stderr, "serial port closed\n"); } } diff --git a/src/hamlib.cpp b/src/hamlib.cpp index 8b1dc3e1e..290d2d6f9 100644 --- a/src/hamlib.cpp +++ b/src/hamlib.cpp @@ -26,6 +26,8 @@ #define TOK_CIVADDR TOKEN_BACKEND(1) +extern int g_verbose; + using namespace std; typedef std::vector riglist_t; @@ -98,15 +100,15 @@ bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int /* Look up model from index. */ if (rig_index >= m_rigList.size()) { - fprintf(stderr, "rig_index invalid, returning\n"); + if (g_verbose) fprintf(stderr, "rig_index invalid, returning\n"); return false; } - fprintf(stderr, "rig: %s %s (%d)\n", m_rigList[rig_index]->mfg_name, + if (g_verbose) fprintf(stderr, "rig: %s %s (%d)\n", m_rigList[rig_index]->mfg_name, m_rigList[rig_index]->model_name, m_rigList[rig_index]->rig_model); if(m_rig) { - fprintf(stderr, "Closing old hamlib instance!\n"); + if (g_verbose) fprintf(stderr, "Closing old hamlib instance!\n"); close(); } @@ -115,38 +117,38 @@ bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int m_rig = rig_init(m_rigList[rig_index]->rig_model); if (!m_rig) { - fprintf(stderr, "rig_init() failed, returning\n"); + if (g_verbose) fprintf(stderr, "rig_init() failed, returning\n"); return false; } - fprintf(stderr, "rig_init() OK ....\n"); + if (g_verbose) fprintf(stderr, "rig_init() OK ....\n"); /* Set CI-V address if necessary. */ if (!strncmp(m_rigList[rig_index]->mfg_name, "Icom", 4)) { char civ_addr[5]; snprintf(civ_addr, 5, "0x%0X", civ_hex); - fprintf(stderr, "hamlib: setting CI-V address to: %s\n", civ_addr); + if (g_verbose) fprintf(stderr, "hamlib: setting CI-V address to: %s\n", civ_addr); rig_set_conf(m_rig, rig_token_lookup(m_rig, "civaddr"), civ_addr); } else { - fprintf(stderr, "hamlib: ignoring CI-V configuration due to non-Icom radio\r\n"); + if (g_verbose) fprintf(stderr, "hamlib: ignoring CI-V configuration due to non-Icom radio\r\n"); } strncpy(m_rig->state.rigport.pathname, serial_port, FILPATHLEN - 1); if (serial_rate) { - fprintf(stderr, "hamlib: setting serial rate: %d\n", serial_rate); + if (g_verbose) fprintf(stderr, "hamlib: setting serial rate: %d\n", serial_rate); m_rig->state.rigport.parm.serial.rate = serial_rate; } - fprintf(stderr, "hamlib: serial rate: %d\n", m_rig->state.rigport.parm.serial.rate); - fprintf(stderr, "hamlib: data_bits..: %d\n", m_rig->state.rigport.parm.serial.data_bits); - fprintf(stderr, "hamlib: stop_bits..: %d\n", m_rig->state.rigport.parm.serial.stop_bits); + if (g_verbose) fprintf(stderr, "hamlib: serial rate: %d\n", m_rig->state.rigport.parm.serial.rate); + if (g_verbose) fprintf(stderr, "hamlib: data_bits..: %d\n", m_rig->state.rigport.parm.serial.data_bits); + if (g_verbose) fprintf(stderr, "hamlib: stop_bits..: %d\n", m_rig->state.rigport.parm.serial.stop_bits); if (rig_open(m_rig) == RIG_OK) { - fprintf(stderr, "hamlib: rig_open() OK\n"); + if (g_verbose) fprintf(stderr, "hamlib: rig_open() OK\n"); return true; } - fprintf(stderr, "hamlib: rig_open() failed ...\n"); + if (g_verbose) fprintf(stderr, "hamlib: rig_open() failed ...\n"); return false; } @@ -164,7 +166,7 @@ int Hamlib::get_stop_bits(void) { } bool Hamlib::ptt(bool press, wxString &hamlibError) { - fprintf(stderr,"Hamlib::ptt: %d\n", press); + if (g_verbose) fprintf(stderr,"Hamlib::ptt: %d\n", press); hamlibError = ""; if(!m_rig) @@ -177,9 +179,9 @@ bool Hamlib::ptt(bool press, wxString &hamlibError) { /* TODO(Joel): what should the VFO option be? */ int retcode = rig_set_ptt(m_rig, RIG_VFO_CURR, on); - fprintf(stderr,"Hamlib::ptt: rig_set_ptt returned: %d\n", retcode); + if (g_verbose) fprintf(stderr,"Hamlib::ptt: rig_set_ptt returned: %d\n", retcode); if (retcode != RIG_OK ) { - fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(retcode)); + if (g_verbose) fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(retcode)); hamlibError = rigerror(retcode); } @@ -209,7 +211,7 @@ int Hamlib::update_frequency_and_mode(void) int result = rig_get_mode(m_rig, RIG_VFO_CURR, &mode, &passband); if (result != RIG_OK) { - fprintf(stderr, "rig_get_mode: error = %s \n", rigerror(result)); + if (g_verbose) fprintf(stderr, "rig_get_mode: error = %s \n", rigerror(result)); } else { @@ -217,7 +219,7 @@ int Hamlib::update_frequency_and_mode(void) result = rig_get_freq(m_rig, RIG_VFO_CURR, &freq); if (result != RIG_OK) { - fprintf(stderr, "rig_get_freq: error = %s \n", rigerror(result)); + if (g_verbose) fprintf(stderr, "rig_get_freq: error = %s \n", rigerror(result)); } else { diff --git a/src/pskreporter.cpp b/src/pskreporter.cpp index 6186ef831..89170c425 100644 --- a/src/pskreporter.cpp +++ b/src/pskreporter.cpp @@ -30,6 +30,8 @@ #define PSK_REPORTER_PORT "4739" #endif // PSK_REPORTER_TEST +extern int g_verbose; + // RX record: /* For receiverCallsign, receiverLocator, decodingSoftware use */ @@ -180,19 +182,19 @@ bool PskReporter::send() struct addrinfo* res = NULL; int err = getaddrinfo(PSK_REPORTER_HOSTNAME, PSK_REPORTER_PORT, &hints, &res); if (err != 0) { - fprintf(stderr, "cannot resolve %s (err=%d)", PSK_REPORTER_HOSTNAME, err); + if (g_verbose) fprintf(stderr, "cannot resolve %s (err=%d)", PSK_REPORTER_HOSTNAME, err); return false; } int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if(fd < 0){ - fprintf(stderr, "cannot open PSK Reporter socket (err=%d)\n", errno); + if (g_verbose) fprintf(stderr, "cannot open PSK Reporter socket (err=%d)\n", errno); return false; } if (sendto(fd, packet, dgSize, 0, res->ai_addr, res->ai_addrlen) < 0){ delete[] packet; - fprintf(stderr, "cannot send message to PSK Reporter (err=%d)\n", errno); + if (g_verbose) fprintf(stderr, "cannot send message to PSK Reporter (err=%d)\n", errno); close(fd); return false; } diff --git a/src/serialport.cpp b/src/serialport.cpp index c1ecac049..76c948cc0 100644 --- a/src/serialport.cpp +++ b/src/serialport.cpp @@ -8,6 +8,8 @@ #include #endif +extern int g_verbose; + Serialport::Serialport() { com_handle = COM_HANDLE_INVALID; } @@ -22,12 +24,12 @@ Serialport::~Serialport() { bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useDTR, bool DTRPos) { - fprintf(stderr, "starting openport(), name: %s strlen(name): %d useRTS: %d RTSPos: %d useDTR: %d DTRPos: %d\n", + if (g_verbose) fprintf(stderr, "starting openport(), name: %s strlen(name): %d useRTS: %d RTSPos: %d useDTR: %d DTRPos: %d\n", name, (int)strlen(name), useRTS, RTSPos, useDTR, DTRPos); if (com_handle != COM_HANDLE_INVALID) { closeport(); - fprintf(stderr, "comm_handle invalid, closing\n"); + if (g_verbose) fprintf(stderr, "comm_handle invalid, closing\n"); } m_useRTS = useRTS; @@ -60,7 +62,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD StringCchPrintf(nameWithStrangePrefix, 100, "\\\\.\\%s", name); fputs("nameWithStrangePrefix: ", stderr); fputs(nameWithStrangePrefix, stderr); - fprintf(stderr,"\n"); + if (g_verbose) fprintf(stderr,"\n"); #ifdef NOT_USED @@ -75,7 +77,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD needed as I can't see anything similar in Hamlib */ if(GetDefaultCommConfigA(nameWithStrangePrefix, &CC, &CCsize)) { - fprintf(stderr, "GetDefaultCommConfigA OK\n"); + if (g_verbose) fprintf(stderr, "GetDefaultCommConfigA OK\n"); CC.dcb.fOutxCtsFlow = FALSE; CC.dcb.fOutxDsrFlow = FALSE; CC.dcb.fDtrControl = DTR_CONTROL_DISABLE; @@ -85,7 +87,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD StringCchPrintf(lpszFunction, 100, "%s", "SetDefaultCommConfigA"); goto error; } - fprintf(stderr, "SetDefaultCommConfigA OK\n"); + if (g_verbose) fprintf(stderr, "SetDefaultCommConfigA OK\n"); } else { StringCchPrintf(lpszFunction, 100, "%s", "GetDefaultCommConfigA"); goto error; @@ -103,10 +105,10 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD StringCchPrintf(lpszFunction, 100, "%s", "CreateFileA"); goto error; } - fprintf(stderr, "CreateFileA OK\n"); + if (g_verbose) fprintf(stderr, "CreateFileA OK\n"); if(GetCommTimeouts(com_handle, &timeouts)) { - fprintf(stderr, "GetCommTimeouts OK\n"); + if (g_verbose) fprintf(stderr, "GetCommTimeouts OK\n"); timeouts.ReadIntervalTimeout=MAXDWORD; timeouts.ReadTotalTimeoutMultiplier=0; timeouts.ReadTotalTimeoutConstant=0; // No-wait read timeout @@ -116,7 +118,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD StringCchPrintf(lpszFunction, 100, "%s", "SetCommTimeouts"); goto error; } - fprintf(stderr, "SetCommTimeouts OK\n"); + if (g_verbose) fprintf(stderr, "SetCommTimeouts OK\n"); } else { StringCchPrintf(lpszFunction, 100, "%s", "GetCommTimeouts"); goto error; @@ -124,7 +126,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD /* Force N-8-1 mode: */ if(GetCommState(com_handle, &dcb)==TRUE) { - fprintf(stderr, "GetCommState OK\n"); + if (g_verbose) fprintf(stderr, "GetCommState OK\n"); dcb.ByteSize = 8; dcb.Parity = NOPARITY; @@ -144,7 +146,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD StringCchPrintf(lpszFunction, 100, "%s", "SetCommState"); goto error; } - fprintf(stderr, "SetCommState OK\n"); + if (g_verbose) fprintf(stderr, "SetCommState OK\n"); } else { StringCchPrintf(lpszFunction, 100, "%s", "GetCommState"); goto error; @@ -153,7 +155,7 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD return true; error: - fprintf(stderr, "%s failed\n", lpszFunction); + if (g_verbose) fprintf(stderr, "%s failed\n", lpszFunction); // Retrieve the system error message for the last-error code diff --git a/src/udp.cpp b/src/udp.cpp index 217633c8c..2b320e7c1 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -20,28 +20,28 @@ void UDPInit(void) { // We use IsOk() here to see if the server is really listening if (!g_sock->IsOk()) { - fprintf(stderr, "UDPInit: Could not listen at the specified port !\n"); + if (g_verbose) fprintf(stderr, "UDPInit: Could not listen at the specified port !\n"); return; } wxIPV4address addrReal; if (!g_sock->GetLocal(addrReal)){ - fprintf(stderr, "UDPInit: Couldn't get the address we bound to\n"); + if (g_verbose) fprintf(stderr, "UDPInit: Couldn't get the address we bound to\n"); } else { - fprintf(stderr, "Server listening at %s:%u \n", (const char*)addrReal.IPAddress().c_str(), addrReal.Service()); + if (g_verbose) fprintf(stderr, "Server listening at %s:%u \n", (const char*)addrReal.IPAddress().c_str(), addrReal.Service()); } } void UDPSend(int port, char *buf, unsigned int n) { - fprintf(stderr, "UDPSend buf: %s n: %d\n", buf, n); + if (g_verbose) fprintf(stderr, "UDPSend buf: %s n: %d\n", buf, n); wxIPV4address addr_tx; addr_tx.Hostname("localhost"); addr_tx.Service(port); if ( g_sock->SendTo(addr_tx, (const void*)buf, n).LastCount() != n ) { - fprintf(stderr, "UDPSend: failed to send data"); + if (g_verbose) fprintf(stderr, "UDPSend: failed to send data"); return; } } diff --git a/src/voicekeyer.cpp b/src/voicekeyer.cpp index 6bfa7c354..8044fae61 100644 --- a/src/voicekeyer.cpp +++ b/src/voicekeyer.cpp @@ -59,7 +59,7 @@ void MainFrame::VoiceKeyerProcessEvent(int vk_event) { // sample these puppies at start just in case they are changed while VK running vk_rx_pause = wxGetApp().m_intVoiceKeyerRxPause; vk_repeats = wxGetApp().m_intVoiceKeyerRepeats; - fprintf(stderr, "vk_rx_pause: %d vk_repeats: %d\n", vk_rx_pause, vk_repeats); + if (g_verbose) fprintf(stderr, "vk_rx_pause: %d vk_repeats: %d\n", vk_rx_pause, vk_repeats); vk_repeat_counter = 0; next_state = VoiceKeyerStartTx(); From ceaee068ccbbf093732a9e432f2538a75c706437 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 16 Jan 2021 16:40:40 +1030 Subject: [PATCH 18/18] removed commented out disconnect line --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 00abee77d..14a6dd88d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -791,8 +791,7 @@ MainFrame::~MainFrame() m_togBtnOnOff->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnOnOffUI), NULL, this); m_togBtnSplit->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this); m_togBtnAnalog->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this); - //m_btnTogPTT->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnPTT_UI), NULL, this); - + sox_biquad_finish(); if (m_RxRunning)