From a9d46b7624929e32d3c397de97b37c806da2e6b4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 19 Nov 2014 17:41:49 -0500 Subject: [PATCH] Preparing to change threading model --- src/AppFrame.cpp | 2 -- src/AppFrame.h | 1 + src/audio/AudioThread.cpp | 48 ++++++++++++++++++++++++++++++++------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 1f01055..3cc586a 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -164,8 +164,6 @@ void AppFrame::OnThread(wxCommandEvent& event) { void AppFrame::OnIdle(wxIdleEvent& event) { - Sleep(10); - event.Skip(); } diff --git a/src/AppFrame.h b/src/AppFrame.h index 60db1a9..6f41c5f 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -10,6 +10,7 @@ #include "SpectrumCanvas.h" #include "WaterfallCanvas.h" + // Define a new frame type class AppFrame: public wxFrame { public: diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 22f5c41..b5a6f4b 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -2,6 +2,31 @@ #include "CubicSDRDefs.h" #include +#ifdef WIN32 + #include + #include + #include + #include + #include + + // trim from start + static inline std::wstring &wltrim(std::wstring &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + return s; + } + + // trim from end + static inline std::wstring &wrtrim(std::wstring &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + return s; + } + + // trim from both ends + static inline std::wstring &wtrim(std::wstring &s) { + return wltrim(wrtrim(s)); + } +#endif + //wxDEFINE_EVENT(wxEVT_COMMAND_AudioThread_INPUT, wxThreadEvent); AudioThread::AudioThread(AudioThreadQueue* pQueue, int id) : @@ -74,16 +99,23 @@ wxThread::ExitCode AudioThread::Entry() { wchar_t dev_str[255]; memset(dev_str, 0, sizeof(wchar_t) * 255); std::wstring env_name(L"PA_RECOMMENDED_OUTPUT_DEVICE"); - GetEnvironmentVariable(env_name.c_str(), dev_str, 255); - std::wstring env_result(dev_str); + GetEnvironmentVariable(wtrim(env_name).c_str(), dev_str, 255); + std::wistringstream env_result(dev_str); - int env_dev = _wtoi(env_result.c_str()); + if (!env_result.eof()) { + int env_dev = -1; + env_result >> env_dev; - if (env_dev || env_result.length()) { - std::cout << "Using preferred PortAudio device PA_RECOMMENDED_OUTPUT_DEVICE=" << env_result.c_str() << std::endl; - preferred_device = env_dev; - } else { - std::cout << "Environment variable PA_RECOMMENDED_OUTPUT_DEVICE not set, using PortAudio defaults." << std::endl; + if (env_result.eof()) { // read everything, was all a number + if (env_dev >= 0) { + std::cout << "Using preferred PortAudio device PA_RECOMMENDED_OUTPUT_DEVICE=" << env_dev << std::endl; + preferred_device = env_dev; + } else { + std::cout << "Environment variable PA_RECOMMENDED_OUTPUT_DEVICE not set, using PortAudio defaults." << std::endl; + } + } else { + std::cout << "Environment variable PA_RECOMMENDED_OUTPUT_DEVICE didn't evaluate to a number, using PortAudio defaults." << std::endl; + } } #endif