new thread queue testing

This commit is contained in:
Charles J. Cliffe 2014-11-21 21:50:14 -05:00
parent 99aa87df63
commit 35830afed0
4 changed files with 36 additions and 3 deletions

View File

@ -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)

View File

@ -16,6 +16,8 @@
#include "AudioThread.h"
#include "CubicSDR.h"
#include <thread>
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<std::string>;
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<signed char> *new_uc_buffer;
std::vector<float> *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

View File

@ -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<std::string> *audioThreadQueue;
AudioThreadNew *audioThread;
std::thread *t1;
// event table
wxDECLARE_EVENT_TABLE();
};

View File

@ -2,6 +2,7 @@
#include <queue>
#include <vector>
#include <string>
#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<std::string> *threadQueue;
public:
AudioThreadNew(ThreadQueue<std::string> *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;
}
}
}
}
};