diff --git a/CMakeLists.txt b/CMakeLists.txt index 796e6aa..ddceaf5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,7 @@ include_directories ( ${PROJECT_SOURCE_DIR}/src/sdr ADD_DEFINITIONS( -std=c++0x # or -std=c++11 + -pthread ) #configure_files(${PROJECT_SOURCE_DIR}/shaders ${PROJECT_BINARY_DIR}/shaders COPYONLY) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 3cc586a..b64db4b 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -16,6 +16,8 @@ #include "AudioThread.h" #include "CubicSDR.h" +#include + wxBEGIN_EVENT_TABLE(AppFrame, wxFrame) //EVT_MENU(wxID_NEW, AppFrame::OnNewWindow) EVT_MENU(wxID_CLOSE, AppFrame::OnClose) @@ -26,6 +28,11 @@ wxEND_EVENT_TABLE() AppFrame::AppFrame() : wxFrame(NULL, wxID_ANY, wxT("CubicSDR")), frequency(DEFAULT_FREQ) { + audioThreadQueue = new ThreadQueue; + audioThread = new AudioThreadNew(audioThreadQueue); + + t1 = new std::thread(&AudioThreadNew::threadMain, audioThread); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); scopeCanvas = new ScopeCanvas(this, NULL); @@ -119,6 +126,7 @@ void AppFrame::OnThread(wxCommandEvent& event) { std::vector *new_uc_buffer; std::vector *new_float_buffer; + std::string asdf("beep"); switch (event.GetId()) { @@ -133,7 +141,7 @@ void AppFrame::OnThread(wxCommandEvent& event) { std::cout << "Incoming IQ data empty?" << std::endl; } delete iqData; - + // audioThreadQueue->push(asdf); break; // thread wants to exit: disable controls and destroy main window // Demodulator -> Audio diff --git a/src/AppFrame.h b/src/AppFrame.h index 6f41c5f..10937e2 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -9,7 +9,7 @@ #include "ScopeCanvas.h" #include "SpectrumCanvas.h" #include "WaterfallCanvas.h" - +#include "ThreadQueue.h" // Define a new frame type class AppFrame: public wxFrame { @@ -43,6 +43,9 @@ private: DemodulatorInstance *demodulatorTest; + ThreadQueue *audioThreadQueue; + AudioThreadNew *audioThread; + std::thread *t1; // event table wxDECLARE_EVENT_TABLE(); }; diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index b1bd0ba..91f8362 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -2,6 +2,7 @@ #include #include +#include #include "wx/wxprec.h" #ifndef WX_PRECOMP @@ -11,9 +12,9 @@ #include "wx/thread.h" #include "AudioThreadQueue.h" +#include "ThreadQueue.h" #include "portaudio.h" - static int audioCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData); @@ -33,3 +34,23 @@ protected: PaStreamParameters outputParameters; PaStream *stream; }; + +class AudioThreadNew { +private: + ThreadQueue *threadQueue; +public: + AudioThreadNew(ThreadQueue *tq_in) { + threadQueue = tq_in; + } + + void threadMain() { + while (1) { + while (!threadQueue->empty()) { + std::string str; + if (threadQueue->try_pop(str)) { + std::cout << str << std::endl; + } + } + } + } +};