mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-26 21:43:11 -04:00
Cleanup, reformat
This commit is contained in:
+15
-16
@@ -8,29 +8,28 @@ enum DemodulatorType {
|
||||
DEMOD_TYPE_NULL,
|
||||
DEMOD_TYPE_AM,
|
||||
DEMOD_TYPE_FM,
|
||||
DEMOD_TYPE_LSB,
|
||||
DEMOD_TYPE_USB
|
||||
DEMOD_TYPE_LSB, DEMOD_TYPE_USB
|
||||
};
|
||||
|
||||
class DemodulatorThread;
|
||||
class DemodulatorThreadCommand {
|
||||
public:
|
||||
enum DemodulatorThreadCommandEnum {
|
||||
DEMOD_THREAD_CMD_NULL,
|
||||
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
||||
DEMOD_THREAD_CMD_SET_FREQUENCY,
|
||||
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
||||
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
||||
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
||||
};
|
||||
enum DemodulatorThreadCommandEnum {
|
||||
DEMOD_THREAD_CMD_NULL,
|
||||
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
||||
DEMOD_THREAD_CMD_SET_FREQUENCY,
|
||||
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
||||
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
||||
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
||||
};
|
||||
|
||||
DemodulatorThreadCommand() :
|
||||
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
|
||||
DemodulatorThreadCommand() :
|
||||
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||
cmd(cmd), int_value(0), context(NULL) {
|
||||
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||
cmd(cmd), int_value(0), context(NULL) {
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +68,7 @@ public:
|
||||
float resample_ratio;
|
||||
msresamp_crcf resampler;
|
||||
|
||||
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL) {
|
||||
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,139 +1,139 @@
|
||||
#include "DemodulatorInstance.h"
|
||||
|
||||
DemodulatorInstance::DemodulatorInstance() :
|
||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false), preDemodTerminated(false) {
|
||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false), preDemodTerminated(false) {
|
||||
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
threadQueuePostDemod = new DemodulatorThreadPostInputQueue;
|
||||
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
||||
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
threadQueuePostDemod = new DemodulatorThreadPostInputQueue;
|
||||
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
||||
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
||||
|
||||
demodulatorPreThread = new DemodulatorPreThread(threadQueueDemod, threadQueuePostDemod, threadQueueNotify);
|
||||
demodulatorPreThread->setCommandQueue(threadQueueCommand);
|
||||
demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueNotify);
|
||||
demodulatorPreThread = new DemodulatorPreThread(threadQueueDemod, threadQueuePostDemod, threadQueueNotify);
|
||||
demodulatorPreThread->setCommandQueue(threadQueueCommand);
|
||||
demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueNotify);
|
||||
|
||||
audioInputQueue = new AudioThreadInputQueue;
|
||||
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
||||
audioInputQueue = new AudioThreadInputQueue;
|
||||
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
||||
|
||||
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
||||
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
||||
}
|
||||
|
||||
DemodulatorInstance::~DemodulatorInstance() {
|
||||
delete audioThread;
|
||||
delete demodulatorThread;
|
||||
delete audioThread;
|
||||
delete demodulatorThread;
|
||||
|
||||
delete audioInputQueue;
|
||||
delete threadQueueDemod;
|
||||
delete audioInputQueue;
|
||||
delete threadQueueDemod;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
demodulatorThread->setVisualOutputQueue(tQueue);
|
||||
demodulatorThread->setVisualOutputQueue(tQueue);
|
||||
}
|
||||
|
||||
void DemodulatorInstance::run() {
|
||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||
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_t attr;
|
||||
size_t size;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||
|
||||
#else
|
||||
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
|
||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
|
||||
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());
|
||||
std::stringstream newLabel;
|
||||
newLabel.precision(3);
|
||||
newLabel << std::fixed << ((float) freq / 1000000.0);
|
||||
setLabel(newLabel.str());
|
||||
}
|
||||
|
||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
||||
return threadQueueCommand;
|
||||
return threadQueueCommand;
|
||||
}
|
||||
|
||||
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
||||
return demodulatorPreThread->getParams();
|
||||
return demodulatorPreThread->getParams();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::terminate() {
|
||||
std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
|
||||
demodulatorPreThread->terminate();
|
||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||
demodulatorThread->terminate();
|
||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||
audioThread->terminate();
|
||||
std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
|
||||
demodulatorPreThread->terminate();
|
||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||
demodulatorThread->terminate();
|
||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||
audioThread->terminate();
|
||||
}
|
||||
|
||||
std::string DemodulatorInstance::getLabel() {
|
||||
return *(label.load());
|
||||
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;
|
||||
std::string *newLabel = new std::string;
|
||||
newLabel->append(labelStr);
|
||||
std::string *oldLabel;
|
||||
oldLabel = label;
|
||||
label = newLabel;
|
||||
delete oldLabel;
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isTerminated() {
|
||||
while (!threadQueueNotify->empty()) {
|
||||
DemodulatorThreadCommand cmd;
|
||||
threadQueueNotify->pop(cmd);
|
||||
while (!threadQueueNotify->empty()) {
|
||||
DemodulatorThreadCommand cmd;
|
||||
threadQueueNotify->pop(cmd);
|
||||
|
||||
switch (cmd.cmd) {
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
||||
audioThread = NULL;
|
||||
t_Audio->join();
|
||||
audioTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
|
||||
demodulatorThread = NULL;
|
||||
switch (cmd.cmd) {
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
||||
audioThread = NULL;
|
||||
t_Audio->join();
|
||||
audioTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
|
||||
demodulatorThread = NULL;
|
||||
#ifdef __APPLE__
|
||||
pthread_join(t_Demod, NULL);
|
||||
pthread_join(t_Demod, NULL);
|
||||
#else
|
||||
t_Demod->join();
|
||||
t_Demod->join();
|
||||
#endif
|
||||
demodTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
||||
demodulatorPreThread = NULL;
|
||||
demodTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
||||
demodulatorPreThread = NULL;
|
||||
#ifdef __APPLE__
|
||||
pthread_join(t_PreDemod, NULL);
|
||||
pthread_join(t_PreDemod, NULL);
|
||||
#else
|
||||
t_PreDemod->join();
|
||||
t_PreDemod->join();
|
||||
#endif
|
||||
preDemodTerminated = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
preDemodTerminated = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
||||
terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
||||
|
||||
return terminated;
|
||||
return terminated;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,6 @@ public:
|
||||
void updateLabel(int freq);
|
||||
|
||||
private:
|
||||
std::atomic<std::string *> label;
|
||||
bool terminated;
|
||||
bool demodTerminated;
|
||||
bool audioTerminated;
|
||||
bool preDemodTerminated;
|
||||
std::atomic<std::string *> label;bool terminated;bool demodTerminated;bool audioTerminated;bool preDemodTerminated;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -6,137 +6,137 @@
|
||||
#include <sstream>
|
||||
|
||||
DemodulatorMgr::DemodulatorMgr() :
|
||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorMgr::~DemodulatorMgr() {
|
||||
terminateAll();
|
||||
terminateAll();
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::newThread() {
|
||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||
|
||||
demods.push_back(newDemod);
|
||||
demods.push_back(newDemod);
|
||||
|
||||
std::stringstream label;
|
||||
label << demods.size();
|
||||
newDemod->setLabel(label.str());
|
||||
std::stringstream label;
|
||||
label << demods.size();
|
||||
newDemod->setLabel(label.str());
|
||||
|
||||
return newDemod;
|
||||
return newDemod;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::terminateAll() {
|
||||
while (demods.size()) {
|
||||
DemodulatorInstance *d = demods.back();
|
||||
deleteThread(d);
|
||||
}
|
||||
while (demods.size()) {
|
||||
DemodulatorInstance *d = demods.back();
|
||||
deleteThread(d);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||
return demods;
|
||||
return demods;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
|
||||
i = std::find(demods.begin(), demods.end(), demod);
|
||||
i = std::find(demods.begin(), demods.end(), demod);
|
||||
|
||||
if (activeDemodulator == demod) {
|
||||
activeDemodulator = NULL;
|
||||
}
|
||||
if (lastActiveDemodulator == demod) {
|
||||
lastActiveDemodulator = NULL;
|
||||
}
|
||||
if (activeVisualDemodulator == demod) {
|
||||
activeVisualDemodulator = NULL;
|
||||
}
|
||||
if (activeDemodulator == demod) {
|
||||
activeDemodulator = NULL;
|
||||
}
|
||||
if (lastActiveDemodulator == demod) {
|
||||
lastActiveDemodulator = NULL;
|
||||
}
|
||||
if (activeVisualDemodulator == demod) {
|
||||
activeVisualDemodulator = NULL;
|
||||
}
|
||||
|
||||
if (i != demods.end()) {
|
||||
demods.erase(i);
|
||||
demod->terminate();
|
||||
}
|
||||
if (i != demods.end()) {
|
||||
demods.erase(i);
|
||||
demod->terminate();
|
||||
}
|
||||
|
||||
demods_deleted.push_back(demod);
|
||||
demods_deleted.push_back(demod);
|
||||
|
||||
garbageCollect();
|
||||
garbageCollect();
|
||||
}
|
||||
|
||||
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
|
||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstance *testDemod = demods[i];
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstance *testDemod = demods[i];
|
||||
|
||||
int freqTest = testDemod->getParams().frequency;
|
||||
int bandwidthTest = testDemod->getParams().bandwidth;
|
||||
int halfBandwidthTest = bandwidthTest / 2;
|
||||
int freqTest = testDemod->getParams().frequency;
|
||||
int bandwidthTest = testDemod->getParams().bandwidth;
|
||||
int halfBandwidthTest = bandwidthTest / 2;
|
||||
|
||||
int halfBuffer = bandwidth / 2;
|
||||
int halfBuffer = bandwidth / 2;
|
||||
|
||||
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
||||
foundDemods->push_back(testDemod);
|
||||
}
|
||||
}
|
||||
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
||||
foundDemods->push_back(testDemod);
|
||||
}
|
||||
}
|
||||
|
||||
return foundDemods;
|
||||
return foundDemods;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool temporary) {
|
||||
if (!temporary) {
|
||||
if (activeDemodulator != NULL) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
} else {
|
||||
lastActiveDemodulator = demod;
|
||||
}
|
||||
}
|
||||
if (!temporary) {
|
||||
if (activeDemodulator != NULL) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
} else {
|
||||
lastActiveDemodulator = demod;
|
||||
}
|
||||
}
|
||||
|
||||
if (activeVisualDemodulator) {
|
||||
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
||||
}
|
||||
if (demod) {
|
||||
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
activeVisualDemodulator = demod;
|
||||
} else {
|
||||
DemodulatorInstance *last = getLastActiveDemodulator();
|
||||
if (last) {
|
||||
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
}
|
||||
activeVisualDemodulator = last;
|
||||
}
|
||||
if (activeVisualDemodulator) {
|
||||
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
||||
}
|
||||
if (demod) {
|
||||
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
activeVisualDemodulator = demod;
|
||||
} else {
|
||||
DemodulatorInstance *last = getLastActiveDemodulator();
|
||||
if (last) {
|
||||
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
}
|
||||
activeVisualDemodulator = last;
|
||||
}
|
||||
|
||||
activeDemodulator = demod;
|
||||
activeDemodulator = demod;
|
||||
|
||||
garbageCollect();
|
||||
garbageCollect();
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
||||
return activeDemodulator;
|
||||
return activeDemodulator;
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
||||
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
}
|
||||
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
}
|
||||
|
||||
return lastActiveDemodulator;
|
||||
return lastActiveDemodulator;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::garbageCollect() {
|
||||
if (demods_deleted.size()) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
if (demods_deleted.size()) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
|
||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||
if ((*i)->isTerminated()) {
|
||||
DemodulatorInstance *deleted = (*i);
|
||||
demods_deleted.erase(i);
|
||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||
if ((*i)->isTerminated()) {
|
||||
DemodulatorInstance *deleted = (*i);
|
||||
demods_deleted.erase(i);
|
||||
|
||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||
|
||||
delete deleted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete deleted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "CubicSDRDefs.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -8,7 +7,8 @@
|
||||
|
||||
#include "DemodulatorPreThread.h"
|
||||
|
||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut,
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||
inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
|
||||
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||
|
||||
@@ -88,17 +88,16 @@ void *DemodulatorPreThread::threadMain() {
|
||||
void DemodulatorPreThread::threadMain() {
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = { priority }; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = {priority}; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
#endif
|
||||
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Demodulator preprocessor thread started.." << std::endl;
|
||||
while (!terminated) {
|
||||
DemodulatorThreadIQData inp;
|
||||
@@ -160,7 +159,7 @@ void DemodulatorPreThread::threadMain() {
|
||||
|
||||
std::vector<signed char> *data = &inp.data;
|
||||
if (data->size()) {
|
||||
int bufSize = data->size() / 2;
|
||||
int bufSize = data->size() / 2;
|
||||
|
||||
liquid_float_complex in_buf_data[bufSize];
|
||||
liquid_float_complex out_buf_data[bufSize];
|
||||
|
||||
@@ -10,64 +10,65 @@
|
||||
class DemodulatorPreThread {
|
||||
public:
|
||||
|
||||
DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||
~DemodulatorPreThread();
|
||||
DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut,
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||
~DemodulatorPreThread();
|
||||
|
||||
#ifdef __APPLE__
|
||||
void *threadMain();
|
||||
void *threadMain();
|
||||
#else
|
||||
void threadMain();
|
||||
void threadMain();
|
||||
#endif
|
||||
|
||||
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
||||
commandQueue = tQueue;
|
||||
}
|
||||
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
||||
commandQueue = tQueue;
|
||||
}
|
||||
|
||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||
audioInputQueue = tQueue;
|
||||
}
|
||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||
audioInputQueue = tQueue;
|
||||
}
|
||||
|
||||
DemodulatorThreadParameters &getParams() {
|
||||
return params;
|
||||
}
|
||||
DemodulatorThreadParameters &getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
void initialize();
|
||||
void initialize();
|
||||
|
||||
void terminate();
|
||||
void terminate();
|
||||
|
||||
#ifdef __APPLE__
|
||||
static void *pthread_helper(void *context) {
|
||||
return ((DemodulatorPreThread *) context)->threadMain();
|
||||
}
|
||||
static void *pthread_helper(void *context) {
|
||||
return ((DemodulatorPreThread *) context)->threadMain();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DemodulatorThreadInputQueue* inputQueue;
|
||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||
DemodulatorThreadCommandQueue* commandQueue;
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
DemodulatorThreadInputQueue* inputQueue;
|
||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||
DemodulatorThreadCommandQueue* commandQueue;
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
|
||||
firfilt_crcf fir_filter;
|
||||
msresamp_crcf resampler;
|
||||
float resample_ratio;
|
||||
firfilt_crcf fir_filter;
|
||||
msresamp_crcf resampler;
|
||||
float resample_ratio;
|
||||
|
||||
msresamp_crcf audio_resampler;
|
||||
float audio_resample_ratio;
|
||||
msresamp_crcf audio_resampler;
|
||||
float audio_resample_ratio;
|
||||
|
||||
DemodulatorThreadParameters params;
|
||||
DemodulatorThreadParameters last_params;
|
||||
DemodulatorThreadParameters params;
|
||||
DemodulatorThreadParameters last_params;
|
||||
|
||||
freqdem fdem;
|
||||
nco_crcf nco_shift;
|
||||
int shift_freq;
|
||||
freqdem fdem;
|
||||
nco_crcf nco_shift;
|
||||
int shift_freq;
|
||||
|
||||
std::atomic<bool> terminated;
|
||||
std::atomic<bool> initialized;
|
||||
std::atomic<bool> terminated;
|
||||
std::atomic<bool> initialized;
|
||||
|
||||
DemodulatorWorkerThread *workerThread;
|
||||
std::thread *t_Worker;
|
||||
DemodulatorWorkerThread *workerThread;
|
||||
std::thread *t_Worker;
|
||||
|
||||
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
||||
DemodulatorThreadWorkerResultQueue *workerResults;
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
||||
DemodulatorThreadWorkerResultQueue *workerResults;
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
};
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#endif
|
||||
|
||||
DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||
|
||||
float kf = 0.5; // modulation factor
|
||||
fdem = freqdem_create(kf);
|
||||
float kf = 0.5; // modulation factor
|
||||
fdem = freqdem_create(kf);
|
||||
// freqdem_print(fdem);
|
||||
}
|
||||
DemodulatorThread::~DemodulatorThread() {
|
||||
@@ -19,100 +19,100 @@ DemodulatorThread::~DemodulatorThread() {
|
||||
#ifdef __APPLE__
|
||||
void *DemodulatorThread::threadMain() {
|
||||
#else
|
||||
void DemodulatorThread::threadMain() {
|
||||
void DemodulatorThread::threadMain() {
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = { priority }; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = {priority}; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
#endif
|
||||
|
||||
msresamp_crcf audio_resampler = NULL;
|
||||
msresamp_crcf resampler = NULL;
|
||||
msresamp_crcf audio_resampler = NULL;
|
||||
msresamp_crcf resampler = NULL;
|
||||
|
||||
std::cout << "Demodulator thread started.." << std::endl;
|
||||
while (!terminated) {
|
||||
DemodulatorThreadPostIQData inp;
|
||||
postInputQueue->pop(inp);
|
||||
std::cout << "Demodulator thread started.." << std::endl;
|
||||
while (!terminated) {
|
||||
DemodulatorThreadPostIQData inp;
|
||||
postInputQueue->pop(inp);
|
||||
|
||||
int bufSize = inp.data.size();
|
||||
int bufSize = inp.data.size();
|
||||
|
||||
if (!bufSize) {
|
||||
continue;
|
||||
}
|
||||
if (!bufSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resampler == NULL) {
|
||||
resampler = inp.resampler;
|
||||
audio_resampler = inp.audio_resampler;
|
||||
} else if (resampler != inp.resampler) {
|
||||
msresamp_crcf_destroy(resampler);
|
||||
msresamp_crcf_destroy(audio_resampler);
|
||||
resampler = inp.resampler;
|
||||
audio_resampler = inp.audio_resampler;
|
||||
}
|
||||
if (resampler == NULL) {
|
||||
resampler = inp.resampler;
|
||||
audio_resampler = inp.audio_resampler;
|
||||
} else if (resampler != inp.resampler) {
|
||||
msresamp_crcf_destroy(resampler);
|
||||
msresamp_crcf_destroy(audio_resampler);
|
||||
resampler = inp.resampler;
|
||||
audio_resampler = inp.audio_resampler;
|
||||
}
|
||||
|
||||
int out_size = ceil((float) (bufSize) * inp.resample_ratio);
|
||||
liquid_float_complex resampled_data[out_size];
|
||||
|
||||
|
||||
unsigned int num_written;
|
||||
msresamp_crcf_execute(resampler, &inp.data[0], bufSize, resampled_data, &num_written);
|
||||
|
||||
float audio_resample_ratio = inp.audio_resample_ratio;
|
||||
|
||||
float demod_output[num_written];
|
||||
float audio_resample_ratio = inp.audio_resample_ratio;
|
||||
|
||||
freqdem_demodulate_block(fdem, resampled_data, num_written, demod_output);
|
||||
float demod_output[num_written];
|
||||
|
||||
liquid_float_complex demod_audio_data[num_written];
|
||||
freqdem_demodulate_block(fdem, resampled_data, num_written, demod_output);
|
||||
|
||||
for (int i = 0; i < num_written; i++) {
|
||||
demod_audio_data[i].real = demod_output[i];
|
||||
demod_audio_data[i].imag = 0;
|
||||
}
|
||||
liquid_float_complex demod_audio_data[num_written];
|
||||
|
||||
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
|
||||
liquid_float_complex resampled_audio_output[audio_out_size];
|
||||
for (int i = 0; i < num_written; i++) {
|
||||
demod_audio_data[i].real = demod_output[i];
|
||||
demod_audio_data[i].imag = 0;
|
||||
}
|
||||
|
||||
unsigned int num_audio_written;
|
||||
msresamp_crcf_execute(audio_resampler, demod_audio_data, num_written, resampled_audio_output, &num_audio_written);
|
||||
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
|
||||
liquid_float_complex resampled_audio_output[audio_out_size];
|
||||
|
||||
std::vector<float> newBuffer;
|
||||
newBuffer.resize(num_audio_written * 2);
|
||||
for (int i = 0; i < num_audio_written; i++) {
|
||||
liquid_float_complex y = resampled_audio_output[i];
|
||||
unsigned int num_audio_written;
|
||||
msresamp_crcf_execute(audio_resampler, demod_audio_data, num_written, resampled_audio_output, &num_audio_written);
|
||||
|
||||
newBuffer[i * 2] = y.real;
|
||||
newBuffer[i * 2 + 1] = y.real;
|
||||
}
|
||||
std::vector<float> newBuffer;
|
||||
newBuffer.resize(num_audio_written * 2);
|
||||
for (int i = 0; i < num_audio_written; i++) {
|
||||
liquid_float_complex y = resampled_audio_output[i];
|
||||
|
||||
AudioThreadInput ati;
|
||||
ati.data = newBuffer;
|
||||
newBuffer[i * 2] = y.real;
|
||||
newBuffer[i * 2 + 1] = y.real;
|
||||
}
|
||||
|
||||
if (audioInputQueue != NULL) {
|
||||
audioInputQueue->push(ati);
|
||||
}
|
||||
AudioThreadInput ati;
|
||||
ati.data = newBuffer;
|
||||
|
||||
if (visOutQueue != NULL) {
|
||||
visOutQueue->push(ati);
|
||||
}
|
||||
}
|
||||
if (audioInputQueue != NULL) {
|
||||
audioInputQueue->push(ati);
|
||||
}
|
||||
|
||||
if (resampler != NULL) {
|
||||
msresamp_crcf_destroy(resampler);
|
||||
}
|
||||
if (audio_resampler != NULL) {
|
||||
msresamp_crcf_destroy(audio_resampler);
|
||||
}
|
||||
if (visOutQueue != NULL) {
|
||||
visOutQueue->push(ati);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Demodulator thread done." << std::endl;
|
||||
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
||||
tCmd.context = this;
|
||||
threadQueueNotify->push(tCmd);
|
||||
if (resampler != NULL) {
|
||||
msresamp_crcf_destroy(resampler);
|
||||
}
|
||||
if (audio_resampler != NULL) {
|
||||
msresamp_crcf_destroy(audio_resampler);
|
||||
}
|
||||
|
||||
std::cout << "Demodulator thread done." << std::endl;
|
||||
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
||||
tCmd.context = this;
|
||||
threadQueueNotify->push(tCmd);
|
||||
}
|
||||
|
||||
void DemodulatorThread::terminate() {
|
||||
terminated = true;
|
||||
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
|
||||
postInputQueue->push(inp);
|
||||
terminated = true;
|
||||
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
|
||||
postInputQueue->push(inp);
|
||||
}
|
||||
|
||||
@@ -11,41 +11,41 @@ typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
||||
class DemodulatorThread {
|
||||
public:
|
||||
|
||||
DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||
~DemodulatorThread();
|
||||
DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||
~DemodulatorThread();
|
||||
|
||||
#ifdef __APPLE__
|
||||
void *threadMain();
|
||||
void *threadMain();
|
||||
#else
|
||||
void threadMain();
|
||||
void threadMain();
|
||||
#endif
|
||||
|
||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
visOutQueue = tQueue;
|
||||
}
|
||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
visOutQueue = tQueue;
|
||||
}
|
||||
|
||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||
audioInputQueue = tQueue;
|
||||
}
|
||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||
audioInputQueue = tQueue;
|
||||
}
|
||||
|
||||
void initialize();
|
||||
void initialize();
|
||||
|
||||
void terminate();
|
||||
void terminate();
|
||||
|
||||
#ifdef __APPLE__
|
||||
static void *pthread_helper(void *context) {
|
||||
return ((DemodulatorThread *) context)->threadMain();
|
||||
}
|
||||
static void *pthread_helper(void *context) {
|
||||
return ((DemodulatorThread *) context)->threadMain();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||
DemodulatorThreadOutputQueue* visOutQueue;
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||
DemodulatorThreadOutputQueue* visOutQueue;
|
||||
AudioThreadInputQueue *audioInputQueue;
|
||||
|
||||
freqdem fdem;
|
||||
freqdem fdem;
|
||||
|
||||
std::atomic<bool> terminated;
|
||||
std::atomic<bool> terminated;
|
||||
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user