2014-11-30 23:33:55 -05:00
|
|
|
#include "DemodulatorWorkerThread.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
2015-11-23 22:03:14 -05:00
|
|
|
#include "CubicSDR.h"
|
2014-11-30 23:33:55 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2015-07-30 19:30:46 -04:00
|
|
|
DemodulatorWorkerThread::DemodulatorWorkerThread() : IOThread(),
|
2015-11-17 23:23:23 -05:00
|
|
|
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;
|
2015-07-30 19:30:46 -04:00
|
|
|
|
|
|
|
commandQueue = (DemodulatorThreadWorkerCommandQueue *)getInputQueue("WorkerCommandQueue");
|
|
|
|
resultQueue = (DemodulatorThreadWorkerResultQueue *)getOutputQueue("WorkerResultQueue");
|
|
|
|
|
2014-11-30 23:33:55 -05:00
|
|
|
while (!terminated) {
|
|
|
|
bool filterChanged = false;
|
2015-11-17 20:20:12 -05:00
|
|
|
bool makeDemod = false;
|
2015-11-20 21:41:57 -05:00
|
|
|
DemodulatorWorkerThreadCommand filterCommand, demodCommand;
|
2014-11-30 23:33:55 -05:00
|
|
|
DemodulatorWorkerThreadCommand command;
|
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
while (!done) {
|
|
|
|
commandQueue->pop(command);
|
|
|
|
switch (command.cmd) {
|
2015-11-22 19:56:25 -05:00
|
|
|
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS:
|
|
|
|
filterChanged = true;
|
|
|
|
filterCommand = command;
|
|
|
|
break;
|
|
|
|
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD:
|
|
|
|
makeDemod = true;
|
|
|
|
demodCommand = command;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-11-30 23:33:55 -05:00
|
|
|
}
|
|
|
|
done = commandQueue->empty();
|
|
|
|
}
|
|
|
|
|
2015-11-17 23:23:23 -05:00
|
|
|
if ((makeDemod || filterChanged) && !terminated) {
|
2014-12-01 02:10:36 -05:00
|
|
|
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
|
2015-11-22 19:56:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
if (filterCommand.sampleRate) {
|
|
|
|
result.sampleRate = filterCommand.sampleRate;
|
2015-01-23 02:09:37 -05:00
|
|
|
}
|
2015-11-22 19:56:25 -05:00
|
|
|
|
2015-11-17 20:20:12 -05:00
|
|
|
if (makeDemod) {
|
2015-11-20 21:41:57 -05:00
|
|
|
cModem = Modem::makeModem(demodCommand.demodType);
|
|
|
|
cModemType = demodCommand.demodType;
|
2015-11-22 19:56:25 -05:00
|
|
|
result.sampleRate = demodCommand.sampleRate;
|
2015-11-23 22:03:14 -05:00
|
|
|
wxGetApp().getAppFrame()->updateModemProperties(cModem->getSettings());
|
2015-11-17 20:20:12 -05:00
|
|
|
}
|
2015-11-17 23:23:23 -05:00
|
|
|
result.modem = cModem;
|
|
|
|
|
2015-11-20 21:41:57 -05:00
|
|
|
if (makeDemod && demodCommand.bandwidth && demodCommand.audioSampleRate) {
|
2015-11-17 20:20:12 -05:00
|
|
|
if (cModem != nullptr) {
|
2015-11-22 19:56:25 -05:00
|
|
|
result.bandwidth = cModem->checkSampleRate(demodCommand.bandwidth, demodCommand.audioSampleRate);
|
|
|
|
cModemKit = cModem->buildKit(result.bandwidth, demodCommand.audioSampleRate);
|
2015-11-20 21:41:57 -05:00
|
|
|
} else {
|
|
|
|
cModemKit = nullptr;
|
2015-06-06 20:47:14 -04:00
|
|
|
}
|
2015-11-21 02:13:33 -05:00
|
|
|
} else if (filterChanged && filterCommand.bandwidth && filterCommand.audioSampleRate) {
|
|
|
|
if (cModem != nullptr) {
|
2015-11-22 19:56:25 -05:00
|
|
|
result.bandwidth = cModem->checkSampleRate(filterCommand.bandwidth, filterCommand.audioSampleRate);
|
|
|
|
cModemKit = cModem->buildKit(result.bandwidth, filterCommand.audioSampleRate);
|
2015-11-21 02:13:33 -05:00
|
|
|
} else {
|
|
|
|
cModemKit = nullptr;
|
|
|
|
}
|
2015-11-20 21:41:57 -05:00
|
|
|
} else if (makeDemod) {
|
|
|
|
cModemKit = nullptr;
|
2015-01-23 02:09:37 -05:00
|
|
|
}
|
2015-11-23 20:44:48 -05:00
|
|
|
if (cModem != nullptr) {
|
|
|
|
cModem->clearRebuildKit();
|
|
|
|
}
|
2015-11-22 19:56:25 -05:00
|
|
|
|
|
|
|
float As = 60.0f; // stop-band attenuation [dB]
|
|
|
|
|
|
|
|
if (result.sampleRate && result.bandwidth) {
|
|
|
|
result.bandwidth = cModem->checkSampleRate(result.bandwidth, makeDemod?demodCommand.audioSampleRate:filterCommand.audioSampleRate);
|
|
|
|
result.iqResampleRatio = (double) (result.bandwidth) / (double) result.sampleRate;
|
|
|
|
result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As);
|
2015-01-23 02:09:37 -05:00
|
|
|
}
|
2014-12-01 02:10:36 -05:00
|
|
|
|
2015-11-22 19:56:25 -05:00
|
|
|
result.modemKit = cModemKit;
|
2015-11-17 21:49:02 -05:00
|
|
|
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);
|
|
|
|
}
|