mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-22 11:49:38 -05:00
Split DemodulatorMgr and DemodulatorInstance
This commit is contained in:
parent
5a396d234f
commit
24cd93d1ae
@ -127,6 +127,7 @@ SET (cubicsdr_sources
|
||||
src/sdr/SDRPostThread.cpp
|
||||
src/demod/DemodulatorThread.cpp
|
||||
src/demod/DemodulatorWorkerThread.cpp
|
||||
src/demod/DemodulatorInstance.cpp
|
||||
src/demod/DemodulatorMgr.cpp
|
||||
src/audio/AudioThread.cpp
|
||||
src/util/Gradient.cpp
|
||||
@ -152,6 +153,7 @@ SET (cubicsdr_headers
|
||||
src/sdr/SDRPostThread.h
|
||||
src/demod/DemodulatorThread.h
|
||||
src/demod/DemodulatorWorkerThread.h
|
||||
src/demod/DemodulatorInstance.h
|
||||
src/demod/DemodulatorMgr.h
|
||||
src/demod/DemodDefs.h
|
||||
src/audio/AudioThread.h
|
||||
|
87
src/demod/DemodulatorInstance.cpp
Normal file
87
src/demod/DemodulatorInstance.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "DemodulatorInstance.h"
|
||||
|
||||
DemodulatorInstance::DemodulatorInstance() :
|
||||
t_Demod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false) {
|
||||
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
||||
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
||||
demodulatorThread = new DemodulatorThread(threadQueueDemod, threadQueueNotify);
|
||||
demodulatorThread->setCommandQueue(threadQueueCommand);
|
||||
audioInputQueue = new AudioThreadInputQueue;
|
||||
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
||||
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
||||
}
|
||||
|
||||
DemodulatorInstance::~DemodulatorInstance() {
|
||||
delete audioThread;
|
||||
delete demodulatorThread;
|
||||
|
||||
delete audioInputQueue;
|
||||
delete threadQueueDemod;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
demodulatorThread->setVisualOutputQueue(tQueue);
|
||||
}
|
||||
|
||||
void DemodulatorInstance::run() {
|
||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||
|
||||
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
||||
pthread_attr_t attr;
|
||||
size_t size;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||
|
||||
#else
|
||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DemodulatorInstance::updateLabel(int freq) {
|
||||
std::stringstream newLabel;
|
||||
newLabel.precision(3);
|
||||
newLabel << std::fixed << ((float) freq / 1000000.0);
|
||||
setLabel(newLabel.str());
|
||||
}
|
||||
|
||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
||||
return threadQueueCommand;
|
||||
}
|
||||
|
||||
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
||||
return demodulatorThread->getParams();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::terminate() {
|
||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||
demodulatorThread->terminate();
|
||||
//#ifdef __APPLE__
|
||||
// pthread_join(t_Demod,NULL);
|
||||
//#else
|
||||
//#endif
|
||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||
audioThread->terminate();
|
||||
}
|
||||
|
||||
std::string DemodulatorInstance::getLabel() {
|
||||
return *(label.load());
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setLabel(std::string labelStr) {
|
||||
std::string *newLabel = new std::string;
|
||||
newLabel->append(labelStr);
|
||||
std::string *oldLabel;
|
||||
oldLabel = label;
|
||||
label = newLabel;
|
||||
delete oldLabel;
|
||||
}
|
49
src/demod/DemodulatorInstance.h
Normal file
49
src/demod/DemodulatorInstance.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include "DemodulatorThread.h"
|
||||
|
||||
class DemodulatorInstance {
|
||||
public:
|
||||
|
||||
DemodulatorThreadInputQueue* threadQueueDemod;
|
||||
DemodulatorThreadCommandQueue* threadQueueCommand;
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
DemodulatorThread *demodulatorThread;
|
||||
#ifdef __APPLE__
|
||||
pthread_t t_Demod;
|
||||
#else
|
||||
std::thread *t_Demod;
|
||||
#endif
|
||||
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
AudioThread *audioThread;
|
||||
std::thread *t_Audio;
|
||||
|
||||
DemodulatorInstance();
|
||||
~DemodulatorInstance();
|
||||
|
||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue);
|
||||
|
||||
DemodulatorThreadCommandQueue *getCommandQueue();
|
||||
DemodulatorThreadParameters &getParams();
|
||||
|
||||
void run();
|
||||
void terminate();
|
||||
std::string getLabel();
|
||||
void setLabel(std::string labelStr);
|
||||
|
||||
bool isTerminated();
|
||||
void updateLabel(int freq);
|
||||
|
||||
private:
|
||||
std::atomic<std::string *> label;
|
||||
bool terminated;
|
||||
bool demodTerminated;
|
||||
bool audioTerminated;
|
||||
};
|
||||
|
||||
|
@ -5,91 +5,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
DemodulatorInstance::DemodulatorInstance() :
|
||||
t_Demod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false) {
|
||||
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
||||
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
||||
demodulatorThread = new DemodulatorThread(threadQueueDemod, threadQueueNotify);
|
||||
demodulatorThread->setCommandQueue(threadQueueCommand);
|
||||
audioInputQueue = new AudioThreadInputQueue;
|
||||
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
||||
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
||||
}
|
||||
|
||||
DemodulatorInstance::~DemodulatorInstance() {
|
||||
delete audioThread;
|
||||
delete demodulatorThread;
|
||||
|
||||
delete audioInputQueue;
|
||||
delete threadQueueDemod;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
demodulatorThread->setVisualOutputQueue(tQueue);
|
||||
}
|
||||
|
||||
void DemodulatorInstance::run() {
|
||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||
|
||||
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
||||
pthread_attr_t attr;
|
||||
size_t size;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||
|
||||
#else
|
||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DemodulatorInstance::updateLabel(int freq) {
|
||||
std::stringstream newLabel;
|
||||
newLabel.precision(3);
|
||||
newLabel << std::fixed << ((float) freq / 1000000.0);
|
||||
setLabel(newLabel.str());
|
||||
}
|
||||
|
||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
||||
return threadQueueCommand;
|
||||
}
|
||||
|
||||
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
||||
return demodulatorThread->getParams();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::terminate() {
|
||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||
demodulatorThread->terminate();
|
||||
//#ifdef __APPLE__
|
||||
// pthread_join(t_Demod,NULL);
|
||||
//#else
|
||||
//#endif
|
||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||
audioThread->terminate();
|
||||
}
|
||||
|
||||
std::string DemodulatorInstance::getLabel() {
|
||||
return *(label.load());
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setLabel(std::string labelStr) {
|
||||
std::string *newLabel = new std::string;
|
||||
newLabel->append(labelStr);
|
||||
std::string *oldLabel;
|
||||
oldLabel = label;
|
||||
label = newLabel;
|
||||
delete oldLabel;
|
||||
}
|
||||
|
||||
DemodulatorMgr::DemodulatorMgr() :
|
||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||
|
@ -4,47 +4,7 @@
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include "DemodulatorThread.h"
|
||||
|
||||
class DemodulatorInstance {
|
||||
public:
|
||||
|
||||
DemodulatorThreadInputQueue* threadQueueDemod;
|
||||
DemodulatorThreadCommandQueue* threadQueueCommand;
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
DemodulatorThread *demodulatorThread;
|
||||
#ifdef __APPLE__
|
||||
pthread_t t_Demod;
|
||||
#else
|
||||
std::thread *t_Demod;
|
||||
#endif
|
||||
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
AudioThread *audioThread;
|
||||
std::thread *t_Audio;
|
||||
|
||||
DemodulatorInstance();
|
||||
~DemodulatorInstance();
|
||||
|
||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue);
|
||||
|
||||
DemodulatorThreadCommandQueue *getCommandQueue();
|
||||
DemodulatorThreadParameters &getParams();
|
||||
|
||||
void run();
|
||||
void terminate();
|
||||
std::string getLabel();
|
||||
void setLabel(std::string labelStr);
|
||||
|
||||
bool isTerminated();
|
||||
void updateLabel(int freq);
|
||||
|
||||
private:
|
||||
std::atomic<std::string *> label;
|
||||
bool terminated;
|
||||
bool demodTerminated;
|
||||
bool audioTerminated;
|
||||
};
|
||||
#include "DemodulatorInstance.h"
|
||||
|
||||
class DemodulatorMgr {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user