CubicSDR/src/demod/DemodulatorWorkerThread.cpp

90 lines
3.0 KiB
C++
Raw Normal View History

2014-11-30 23:33:55 -05:00
#include "DemodulatorWorkerThread.h"
#include "CubicSDRDefs.h"
#include <vector>
DemodulatorWorkerThread::DemodulatorWorkerThread() : IOThread(),
commandQueue(NULL), resultQueue(NULL), cModem(nullptr), cModemKit(nullptr) {
2014-11-30 23:33:55 -05:00
}
DemodulatorWorkerThread::~DemodulatorWorkerThread() {
}
2015-07-29 20:57:02 -04:00
void DemodulatorWorkerThread::run() {
2014-11-30 23:33:55 -05:00
std::cout << "Demodulator worker thread started.." << std::endl;
commandQueue = (DemodulatorThreadWorkerCommandQueue *)getInputQueue("WorkerCommandQueue");
resultQueue = (DemodulatorThreadWorkerResultQueue *)getOutputQueue("WorkerResultQueue");
2014-11-30 23:33:55 -05:00
while (!terminated) {
bool filterChanged = false;
bool makeDemod = false;
2014-11-30 23:33:55 -05:00
DemodulatorWorkerThreadCommand filterCommand;
DemodulatorWorkerThreadCommand command;
bool done = false;
while (!done) {
commandQueue->pop(command);
switch (command.cmd) {
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS:
filterChanged = true;
filterCommand = command;
break;
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD:
makeDemod = true;
filterCommand = command;
break;
default:
break;
2014-11-30 23:33:55 -05:00
}
done = commandQueue->empty();
}
2015-01-22 23:41:33 -05:00
2014-11-30 23:33:55 -05:00
if ((makeDemod || filterChanged) && !terminated) {
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
2014-11-30 23:33:55 -05:00
float As = 60.0f; // stop-band attenuation [dB]
2015-01-23 02:09:37 -05:00
if (filterCommand.sampleRate && filterCommand.bandwidth) {
result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate;
result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As);
}
if (makeDemod) {
cModem = Modem::makeModem(filterCommand.demodType);
cModemType = filterCommand.demodType;
}
result.modem = cModem;
2015-01-23 02:09:37 -05:00
if (filterCommand.bandwidth && filterCommand.audioSampleRate) {
if (cModem != nullptr) {
cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate);
}
2015-01-23 02:09:37 -05:00
}
result.modemKit = cModemKit;
2015-01-23 02:09:37 -05:00
if (filterCommand.bandwidth) {
result.bandwidth = filterCommand.bandwidth;
}
if (filterCommand.sampleRate) {
result.sampleRate = filterCommand.sampleRate;
}
result.modemType = cModemType;
2014-11-30 23:33:55 -05:00
resultQueue->push(result);
}
}
std::cout << "Demodulator worker thread done." << std::endl;
}
void DemodulatorWorkerThread::terminate() {
terminated = true;
DemodulatorWorkerThreadCommand inp; // push dummy to nudge queue
commandQueue->push(inp);
}