2014-12-11 19:07:21 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ThreadQueue.h"
|
2014-12-16 18:27:02 -05:00
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include "liquid/liquid.h"
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
#include <atomic>
|
2014-12-23 23:37:18 -05:00
|
|
|
#include <mutex>
|
2014-12-22 19:43:56 -05:00
|
|
|
|
2015-01-01 18:08:54 -05:00
|
|
|
#define DEMOD_TYPE_NULL 0
|
|
|
|
#define DEMOD_TYPE_FM 1
|
|
|
|
#define DEMOD_TYPE_AM 2
|
|
|
|
#define DEMOD_TYPE_LSB 3
|
|
|
|
#define DEMOD_TYPE_USB 4
|
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
class DemodulatorThread;
|
|
|
|
class DemodulatorThreadCommand {
|
|
|
|
public:
|
2014-12-16 21:30:03 -05:00
|
|
|
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
|
|
|
|
};
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
DemodulatorThreadCommand() :
|
2014-12-23 01:12:14 -05:00
|
|
|
cmd(DEMOD_THREAD_CMD_NULL), context(NULL), int_value(0) {
|
2014-12-16 21:30:03 -05:00
|
|
|
|
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
2014-12-23 01:12:14 -05:00
|
|
|
cmd(cmd), context(NULL), int_value(0) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
DemodulatorThreadCommandEnum cmd;
|
|
|
|
void *context;
|
|
|
|
int int_value;
|
2014-12-11 19:07:21 -05:00
|
|
|
};
|
|
|
|
|
2014-12-21 16:08:32 -05:00
|
|
|
class DemodulatorThreadControlCommand {
|
|
|
|
public:
|
|
|
|
enum DemodulatorThreadControlCommandEnum {
|
2015-01-03 17:07:39 -05:00
|
|
|
DEMOD_THREAD_CMD_CTL_NULL, DEMOD_THREAD_CMD_CTL_SQUELCH_ON, DEMOD_THREAD_CMD_CTL_SQUELCH_OFF, DEMOD_THREAD_CMD_CTL_TYPE
|
2014-12-21 16:08:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
DemodulatorThreadControlCommand() :
|
2015-01-01 18:08:54 -05:00
|
|
|
cmd(DEMOD_THREAD_CMD_CTL_NULL), demodType(DEMOD_TYPE_NULL) {
|
2014-12-21 16:08:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadControlCommandEnum cmd;
|
2015-01-01 18:08:54 -05:00
|
|
|
int demodType;
|
2014-12-21 16:08:32 -05:00
|
|
|
};
|
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
class DemodulatorThreadIQData: public ReferenceCounter {
|
2014-12-11 19:07:21 -05:00
|
|
|
public:
|
2014-12-24 01:28:33 -05:00
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int bandwidth;
|
2014-12-26 16:15:35 -05:00
|
|
|
std::vector<liquid_float_complex> data;
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
DemodulatorThreadIQData() :
|
|
|
|
frequency(0), bandwidth(0) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
~DemodulatorThreadIQData() {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
};
|
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
class DemodulatorThreadPostIQData: public ReferenceCounter {
|
2014-12-16 18:27:02 -05:00
|
|
|
public:
|
2014-12-24 01:28:33 -05:00
|
|
|
std::vector<liquid_float_complex> data;
|
2014-12-26 20:58:42 -05:00
|
|
|
int bandwidth;
|
2014-12-16 20:33:44 -05:00
|
|
|
msresamp_crcf resampler;
|
2015-01-03 17:07:39 -05:00
|
|
|
double resamplerRatio;
|
|
|
|
msresamp_rrrf audioResampler;
|
|
|
|
msresamp_rrrf stereoResampler;
|
|
|
|
double audioResampleRatio;
|
2014-12-16 18:27:02 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
DemodulatorThreadPostIQData() :
|
2015-01-03 17:07:39 -05:00
|
|
|
bandwidth(0), resampler(NULL), resamplerRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(0) {
|
2014-12-16 18:27:02 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-16 18:27:02 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
~DemodulatorThreadPostIQData() {
|
2014-12-27 15:04:43 -05:00
|
|
|
std::lock_guard < std::mutex > lock(m_mutex);
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-16 18:27:02 -05:00
|
|
|
};
|
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
class DemodulatorThreadAudioData: public ReferenceCounter {
|
2014-12-11 19:07:21 -05:00
|
|
|
public:
|
2014-12-24 01:28:33 -05:00
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int sampleRate;
|
|
|
|
unsigned char channels;
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
std::vector<float> *data;
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
DemodulatorThreadAudioData() :
|
|
|
|
frequency(0), sampleRate(0), channels(0), data(NULL) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector<float> *data) :
|
|
|
|
frequency(frequency), sampleRate(sampleRate), channels(1), data(data) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
~DemodulatorThreadAudioData() {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-24 01:28:33 -05:00
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
};
|
|
|
|
|
2014-12-22 23:27:52 -05:00
|
|
|
typedef ThreadQueue<DemodulatorThreadIQData *> DemodulatorThreadInputQueue;
|
2014-12-23 01:12:14 -05:00
|
|
|
typedef ThreadQueue<DemodulatorThreadPostIQData *> DemodulatorThreadPostInputQueue;
|
2014-12-11 19:07:21 -05:00
|
|
|
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
|
2014-12-21 16:08:32 -05:00
|
|
|
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;
|
2014-12-16 18:27:02 -05:00
|
|
|
|
|
|
|
class DemodulatorThreadParameters {
|
|
|
|
public:
|
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int inputRate;
|
|
|
|
unsigned int bandwidth; // set equal to disable second stage re-sampling?
|
|
|
|
unsigned int audioSampleRate;
|
|
|
|
|
2015-01-01 18:08:54 -05:00
|
|
|
int demodType;
|
2014-12-16 18:27:02 -05:00
|
|
|
|
|
|
|
DemodulatorThreadParameters() :
|
|
|
|
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
|
2014-12-24 01:28:33 -05:00
|
|
|
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
2014-12-16 18:27:02 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadParameters() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|