2014-11-30 23:33:55 -05:00
|
|
|
#include "DemodulatorWorkerThread.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
DemodulatorWorkerThread::DemodulatorWorkerThread(DemodulatorThreadWorkerCommandQueue* in, DemodulatorThreadWorkerResultQueue* out) :
|
|
|
|
terminated(false), commandQueue(in), resultQueue(out) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorWorkerThread::~DemodulatorWorkerThread() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodulatorWorkerThread::threadMain() {
|
|
|
|
|
|
|
|
std::cout << "Demodulator worker thread started.." << std::endl;
|
|
|
|
|
|
|
|
while (!terminated) {
|
|
|
|
bool filterChanged = false;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
done = commandQueue->empty();
|
|
|
|
}
|
|
|
|
|
2015-01-11 20:26:51 -05:00
|
|
|
if (filterChanged && !terminated) {
|
2014-12-01 02:10:36 -05:00
|
|
|
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
|
2014-11-30 23:33:55 -05:00
|
|
|
|
2015-01-11 17:08:16 -05:00
|
|
|
result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate;
|
2015-01-03 17:07:39 -05:00
|
|
|
result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth;
|
2014-11-30 23:33:55 -05:00
|
|
|
|
|
|
|
float As = 60.0f; // stop-band attenuation [dB]
|
|
|
|
|
2015-01-11 17:08:16 -05:00
|
|
|
result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As);
|
2015-01-03 17:07:39 -05:00
|
|
|
result.audioResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
|
|
|
|
result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
|
2014-12-01 02:10:36 -05:00
|
|
|
|
|
|
|
result.audioSampleRate = filterCommand.audioSampleRate;
|
|
|
|
result.bandwidth = filterCommand.bandwidth;
|
2015-01-11 17:08:16 -05:00
|
|
|
result.sampleRate = filterCommand.sampleRate;
|
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);
|
|
|
|
}
|