Worker thread demod spawn, abstract Modem

This commit is contained in:
Charles J. Cliffe 2015-11-17 20:20:12 -05:00
parent 39c42c2b82
commit 31bf65259d
5 changed files with 30 additions and 56 deletions

View File

@ -82,6 +82,7 @@ class DemodulatorThreadPostIQData: public ReferenceCounter {
public: public:
std::vector<liquid_float_complex> data; std::vector<liquid_float_complex> data;
long long sampleRate; long long sampleRate;
std::string modemType;
Modem *modem; Modem *modem;
ModemKit *modemKit; ModemKit *modemKit;

View File

@ -18,6 +18,7 @@ void DemodulatorWorkerThread::run() {
while (!terminated) { while (!terminated) {
bool filterChanged = false; bool filterChanged = false;
bool makeDemod = false;
DemodulatorWorkerThreadCommand filterCommand; DemodulatorWorkerThreadCommand filterCommand;
DemodulatorWorkerThreadCommand command; DemodulatorWorkerThreadCommand command;
@ -29,6 +30,10 @@ void DemodulatorWorkerThread::run() {
filterChanged = true; filterChanged = true;
filterCommand = command; filterCommand = command;
break; break;
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD:
makeDemod = true;
filterCommand = command;
break;
default: default:
break; break;
} }
@ -46,44 +51,16 @@ void DemodulatorWorkerThread::run() {
result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As); result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As);
} }
if (makeDemod) {
cModem = Modem::makeModem(filterCommand.demodType);
}
if (filterCommand.bandwidth && filterCommand.audioSampleRate) { if (filterCommand.bandwidth && filterCommand.audioSampleRate) {
// result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth; result.modem = cModem;
// result.audioResampler = msresamp_rrrf_create(result.audioResamplerRatio, As); if (cModem != nullptr) {
// result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As); cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate);
// result.audioSampleRate = filterCommand.audioSampleRate;
/* // Stereo filters / shifters
double firStereoCutoff = ((double) 16000 / (double) filterCommand.audioSampleRate);
float ft = ((double) 1000 / (double) filterCommand.audioSampleRate); // filter transition
float mu = 0.0f; // fractional timing offset
if (firStereoCutoff < 0) {
firStereoCutoff = 0;
} }
result.modemKit = cModemKit;
if (firStereoCutoff > 0.5) {
firStereoCutoff = 0.5;
}
unsigned int h_len = estimate_req_filter_len(ft, As);
float *h = new float[h_len];
liquid_firdes_kaiser(h_len, firStereoCutoff, As, mu, h);
result.firStereoLeft = firfilt_rrrf_create(h, h_len);
result.firStereoRight = firfilt_rrrf_create(h, h_len);
float bw = filterCommand.bandwidth;
if (bw < 100000.0) {
bw = 100000.0;
}
// stereo pilot filter
unsigned int order = 5; // filter order
float f0 = ((double) 19000 / bw);
float fc = ((double) 19500 / bw);
float Ap = 1.0f;
As = 60.0f;
result.iirStereoPilot = iirfilt_crcf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_BANDPASS, LIQUID_IIRDES_SOS, order, fc, f0, Ap, As); */
} }
if (filterCommand.bandwidth) { if (filterCommand.bandwidth) {

View File

@ -41,16 +41,16 @@ public:
class DemodulatorWorkerThreadCommand { class DemodulatorWorkerThreadCommand {
public: public:
enum DemodulatorThreadCommandEnum { enum DemodulatorThreadCommandEnum {
DEMOD_WORKER_THREAD_CMD_NULL, DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS DEMOD_WORKER_THREAD_CMD_NULL, DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS, DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD
}; };
DemodulatorWorkerThreadCommand() : DemodulatorWorkerThreadCommand() :
cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) { cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") {
} }
DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) : DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) :
cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) { cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") {
} }
@ -60,6 +60,7 @@ public:
long long sampleRate; long long sampleRate;
unsigned int bandwidth; unsigned int bandwidth;
unsigned int audioSampleRate; unsigned int audioSampleRate;
std::string demodType;
}; };
typedef ThreadQueue<DemodulatorWorkerThreadCommand> DemodulatorThreadWorkerCommandQueue; typedef ThreadQueue<DemodulatorWorkerThreadCommand> DemodulatorThreadWorkerCommandQueue;
@ -87,4 +88,6 @@ protected:
DemodulatorThreadWorkerCommandQueue *commandQueue; DemodulatorThreadWorkerCommandQueue *commandQueue;
DemodulatorThreadWorkerResultQueue *resultQueue; DemodulatorThreadWorkerResultQueue *resultQueue;
Modem *cModem;
ModemKit *cModemKit;
}; };

View File

@ -10,18 +10,10 @@ ModemFactoryList Modem::getFactories() {
return modemFactories; return modemFactories;
} }
Modem *Modem::factory() { Modem *Modem::makeModem(std::string modemType) {
if (modemFactories.find(modemType) != modemFactories.end()) {
return modemFactories[modemType]->factory();
}
return nullptr; return nullptr;
} }
ModemKit *Modem::buildKit(long long sampleRate, int audioSampleRate) {
return nullptr;
}
void Modem::disposeKit(ModemKit *kit) {
return;
}
void Modem::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) {
return;
}

View File

@ -36,12 +36,13 @@ class Modem {
public: public:
static void addModemFactory(std::string modemName, Modem *factorySingle); static void addModemFactory(std::string modemName, Modem *factorySingle);
static ModemFactoryList getFactories(); static ModemFactoryList getFactories();
static Modem *makeModem(std::string modemType);
virtual Modem *factory(); virtual Modem *factory() = 0;
virtual ModemKit *buildKit(long long sampleRate, int audioSampleRate); virtual ModemKit *buildKit(long long sampleRate, int audioSampleRate) = 0;
virtual void disposeKit(ModemKit *kit); virtual void disposeKit(ModemKit *kit) = 0;
virtual void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); virtual void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) = 0;
private: private:
static ModemFactoryList modemFactories; static ModemFactoryList modemFactories;
}; };