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-11 19:07:21 -05:00
|
|
|
enum DemodulatorType {
|
|
|
|
DEMOD_TYPE_NULL,
|
|
|
|
DEMOD_TYPE_AM,
|
|
|
|
DEMOD_TYPE_FM,
|
2014-12-16 21:30:03 -05:00
|
|
|
DEMOD_TYPE_LSB, DEMOD_TYPE_USB
|
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() :
|
|
|
|
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
|
|
|
|
|
|
|
|
}
|
2014-12-11 19:07:21 -05:00
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
|
|
|
cmd(cmd), int_value(0), context(NULL) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadCommandEnum cmd;
|
|
|
|
void *context;
|
|
|
|
int int_value;
|
|
|
|
};
|
|
|
|
|
2014-12-21 16:08:32 -05:00
|
|
|
class DemodulatorThreadControlCommand {
|
|
|
|
public:
|
|
|
|
enum DemodulatorThreadControlCommandEnum {
|
|
|
|
DEMOD_THREAD_CMD_CTL_NULL,
|
|
|
|
DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO,
|
|
|
|
DEMOD_THREAD_CMD_CTL_SQUELCH_OFF
|
|
|
|
};
|
|
|
|
|
|
|
|
DemodulatorThreadControlCommand() :
|
|
|
|
cmd(DEMOD_THREAD_CMD_CTL_NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadControlCommandEnum cmd;
|
|
|
|
};
|
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
class DemodulatorThreadIQData {
|
|
|
|
public:
|
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int bandwidth;
|
2014-12-22 19:43:56 -05:00
|
|
|
std::vector<signed char> *data;
|
|
|
|
std::atomic<int> *refCount;
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
DemodulatorThreadIQData() :
|
2014-12-22 19:43:56 -05:00
|
|
|
frequency(0), bandwidth(0), data(NULL), refCount(0) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
DemodulatorThreadIQData(const DemodulatorThreadIQData& o) {
|
|
|
|
frequency = o.frequency;
|
|
|
|
bandwidth = o.bandwidth;
|
|
|
|
data = o.data;
|
|
|
|
refCount = o.refCount;
|
2014-12-11 19:07:21 -05:00
|
|
|
}
|
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
void setRefCount(std::atomic<int> *rc) {
|
|
|
|
refCount = rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup() {
|
|
|
|
if (refCount) {
|
|
|
|
(*refCount)--;
|
|
|
|
if ((*refCount) <= 0) {
|
|
|
|
delete data;
|
|
|
|
data = NULL;
|
|
|
|
delete refCount;
|
|
|
|
refCount = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
~DemodulatorThreadIQData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-16 18:27:02 -05:00
|
|
|
class DemodulatorThreadPostIQData {
|
|
|
|
public:
|
2014-12-22 19:43:56 -05:00
|
|
|
std::vector<liquid_float_complex> *data;
|
2014-12-16 18:27:02 -05:00
|
|
|
float audio_resample_ratio;
|
2014-12-21 17:37:41 -05:00
|
|
|
msresamp_rrrf audio_resampler;
|
2014-12-16 20:33:44 -05:00
|
|
|
float resample_ratio;
|
|
|
|
msresamp_crcf resampler;
|
2014-12-16 18:27:02 -05:00
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL), data(NULL) {
|
2014-12-16 18:27:02 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
DemodulatorThreadPostIQData(const DemodulatorThreadPostIQData &o) {
|
|
|
|
audio_resample_ratio = o.audio_resample_ratio;
|
|
|
|
audio_resampler = o.audio_resampler;
|
|
|
|
resample_ratio = o.resample_ratio;
|
|
|
|
resampler = o.resampler;
|
|
|
|
data = o.data;
|
|
|
|
}
|
|
|
|
|
2014-12-16 18:27:02 -05:00
|
|
|
~DemodulatorThreadPostIQData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
class DemodulatorThreadAudioData {
|
|
|
|
public:
|
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int sampleRate;
|
|
|
|
unsigned char channels;
|
|
|
|
|
2014-12-22 19:43:56 -05:00
|
|
|
std::vector<float> *data;
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
DemodulatorThreadAudioData() :
|
2014-12-22 19:43:56 -05:00
|
|
|
sampleRate(0), frequency(0), channels(0), data(NULL) {
|
2014-12-11 19:07:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate,
|
2014-12-22 19:43:56 -05:00
|
|
|
std::vector<float> *data) :
|
2014-12-11 19:07:21 -05:00
|
|
|
data(data), sampleRate(sampleRate), frequency(frequency), channels(
|
|
|
|
1) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadAudioData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
|
2014-12-16 18:27:02 -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;
|
|
|
|
|
|
|
|
DemodulatorType demodType;
|
|
|
|
|
|
|
|
DemodulatorThreadParameters() :
|
|
|
|
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
|
|
|
|
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadParameters() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|