mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 21:58:37 -05:00
Clean up some early prototype garbage..
This commit is contained in:
parent
c0eca0b2f3
commit
7b301fadc1
@ -14,9 +14,6 @@ class DemodulatorThreadCommand {
|
|||||||
public:
|
public:
|
||||||
enum DemodulatorThreadCommandEnum {
|
enum DemodulatorThreadCommandEnum {
|
||||||
DEMOD_THREAD_CMD_NULL,
|
DEMOD_THREAD_CMD_NULL,
|
||||||
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
|
||||||
DEMOD_THREAD_CMD_SET_FREQUENCY,
|
|
||||||
DEMOD_THREAD_CMD_SET_AUDIO_RATE,
|
|
||||||
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
||||||
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
||||||
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
||||||
@ -124,23 +121,3 @@ typedef ThreadQueue<DemodulatorThreadIQData *> DemodulatorThreadInputQueue;
|
|||||||
typedef ThreadQueue<DemodulatorThreadPostIQData *> DemodulatorThreadPostInputQueue;
|
typedef ThreadQueue<DemodulatorThreadPostIQData *> DemodulatorThreadPostInputQueue;
|
||||||
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
|
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
|
||||||
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;
|
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;
|
||||||
|
|
||||||
class DemodulatorThreadParameters {
|
|
||||||
public:
|
|
||||||
long long frequency;
|
|
||||||
long long sampleRate;
|
|
||||||
unsigned int bandwidth; // set equal to disable second stage re-sampling?
|
|
||||||
unsigned int audioSampleRate;
|
|
||||||
|
|
||||||
std::string demodType;
|
|
||||||
|
|
||||||
DemodulatorThreadParameters() :
|
|
||||||
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate(0),
|
|
||||||
demodType("FM") {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
~DemodulatorThreadParameters() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -12,22 +12,18 @@ DemodulatorInstance::DemodulatorInstance() :
|
|||||||
muted.store(false);
|
muted.store(false);
|
||||||
tracking.store(false);
|
tracking.store(false);
|
||||||
follow.store(false);
|
follow.store(false);
|
||||||
currentAudioSampleRate.store(0);
|
|
||||||
currentFrequency.store(0);
|
|
||||||
currentOutputDevice.store(-1);
|
currentOutputDevice.store(-1);
|
||||||
currentAudioGain.store(1.0);
|
currentAudioGain.store(1.0);
|
||||||
|
|
||||||
label = new std::string("Unnamed");
|
label = new std::string("Unnamed");
|
||||||
pipeIQInputData = new DemodulatorThreadInputQueue;
|
pipeIQInputData = new DemodulatorThreadInputQueue;
|
||||||
pipeIQDemodData = new DemodulatorThreadPostInputQueue;
|
pipeIQDemodData = new DemodulatorThreadPostInputQueue;
|
||||||
pipeDemodCommand = new DemodulatorThreadCommandQueue;
|
|
||||||
pipeDemodNotify = new DemodulatorThreadCommandQueue;
|
pipeDemodNotify = new DemodulatorThreadCommandQueue;
|
||||||
|
|
||||||
demodulatorPreThread = new DemodulatorPreThread(this);
|
demodulatorPreThread = new DemodulatorPreThread(this);
|
||||||
demodulatorPreThread->setInputQueue("IQDataInput",pipeIQInputData);
|
demodulatorPreThread->setInputQueue("IQDataInput",pipeIQInputData);
|
||||||
demodulatorPreThread->setOutputQueue("IQDataOutput",pipeIQDemodData);
|
demodulatorPreThread->setOutputQueue("IQDataOutput",pipeIQDemodData);
|
||||||
demodulatorPreThread->setOutputQueue("NotifyQueue",pipeDemodNotify);
|
demodulatorPreThread->setOutputQueue("NotifyQueue",pipeDemodNotify);
|
||||||
demodulatorPreThread->setInputQueue("CommandQueue",pipeDemodCommand);
|
|
||||||
|
|
||||||
pipeAudioData = new AudioThreadInputQueue;
|
pipeAudioData = new AudioThreadInputQueue;
|
||||||
threadQueueControl = new DemodulatorThreadControlCommandQueue;
|
threadQueueControl = new DemodulatorThreadControlCommandQueue;
|
||||||
@ -41,8 +37,6 @@ DemodulatorInstance::DemodulatorInstance() :
|
|||||||
audioThread = new AudioThread();
|
audioThread = new AudioThread();
|
||||||
audioThread->setInputQueue("AudioDataInput", pipeAudioData);
|
audioThread->setInputQueue("AudioDataInput", pipeAudioData);
|
||||||
audioThread->setOutputQueue("NotifyQueue", pipeDemodNotify);
|
audioThread->setOutputQueue("NotifyQueue", pipeDemodNotify);
|
||||||
|
|
||||||
currentDemodType = demodulatorPreThread->getParams().demodType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance::~DemodulatorInstance() {
|
DemodulatorInstance::~DemodulatorInstance() {
|
||||||
@ -51,7 +45,6 @@ DemodulatorInstance::~DemodulatorInstance() {
|
|||||||
delete demodulatorPreThread;
|
delete demodulatorPreThread;
|
||||||
delete pipeIQInputData;
|
delete pipeIQInputData;
|
||||||
delete pipeIQDemodData;
|
delete pipeIQDemodData;
|
||||||
delete pipeDemodCommand;
|
|
||||||
delete pipeDemodNotify;
|
delete pipeDemodNotify;
|
||||||
delete threadQueueControl;
|
delete threadQueueControl;
|
||||||
delete pipeAudioData;
|
delete pipeAudioData;
|
||||||
@ -66,17 +59,8 @@ void DemodulatorInstance::run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// while (!isTerminated()) {
|
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
||||||
// }
|
|
||||||
|
|
||||||
currentFrequency = demodulatorPreThread->getParams().frequency;
|
|
||||||
currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()];
|
|
||||||
demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate;
|
|
||||||
setDemodulatorType(demodulatorPreThread->getParams().demodType);
|
|
||||||
|
|
||||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||||
|
|
||||||
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -112,10 +96,6 @@ void DemodulatorInstance::updateLabel(long long freq) {
|
|||||||
setLabel(newLabel.str());
|
setLabel(newLabel.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
|
||||||
return pipeDemodCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DemodulatorInstance::terminate() {
|
void DemodulatorInstance::terminate() {
|
||||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||||
audioThread->terminate();
|
audioThread->terminate();
|
||||||
@ -254,27 +234,14 @@ int DemodulatorInstance::getOutputDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
|
void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
|
||||||
currentDemodType = demod_type_in;
|
|
||||||
|
|
||||||
if (currentDemodType == "I/Q") {
|
|
||||||
if (currentAudioSampleRate) {
|
|
||||||
setBandwidth(currentAudioSampleRate);
|
|
||||||
} else {
|
|
||||||
setBandwidth(AudioThread::deviceSampleRate[getOutputDevice()]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setGain(getGain());
|
setGain(getGain());
|
||||||
|
if (demodulatorPreThread) {
|
||||||
demodulatorPreThread->getParams().demodType = currentDemodType;
|
demodulatorPreThread->setDemodType(demod_type_in);
|
||||||
if (!active) {
|
|
||||||
demodulatorPreThread->setDemodType(currentDemodType);
|
|
||||||
} else if (demodulatorThread && threadQueueControl) {
|
|
||||||
demodulatorPreThread->setDemodType(currentDemodType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DemodulatorInstance::getDemodulatorType() {
|
std::string DemodulatorInstance::getDemodulatorType() {
|
||||||
return currentDemodType;
|
return demodulatorPreThread->getDemodType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setDemodulatorLock(bool demod_lock_in) {
|
void DemodulatorInstance::setDemodulatorLock(bool demod_lock_in) {
|
||||||
@ -310,65 +277,34 @@ int DemodulatorInstance::getDemodulatorCons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setBandwidth(int bw) {
|
void DemodulatorInstance::setBandwidth(int bw) {
|
||||||
if (!active && demodulatorPreThread != NULL) {
|
demodulatorPreThread->setBandwidth(bw);
|
||||||
demodulatorPreThread->getParams().bandwidth = bw;
|
|
||||||
} else if (demodulatorPreThread && pipeDemodCommand) {
|
|
||||||
DemodulatorThreadCommand command;
|
|
||||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH;
|
|
||||||
command.llong_value = bw;
|
|
||||||
pipeDemodCommand->push(command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DemodulatorInstance::getBandwidth() {
|
int DemodulatorInstance::getBandwidth() {
|
||||||
return demodulatorPreThread->getParams().bandwidth;
|
return demodulatorPreThread->getBandwidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setFrequency(long long freq) {
|
void DemodulatorInstance::setFrequency(long long freq) {
|
||||||
if ((freq - getBandwidth() / 2) <= 0) {
|
if ((freq - getBandwidth() / 2) <= 0) {
|
||||||
freq = getBandwidth() / 2;
|
freq = getBandwidth() / 2;
|
||||||
}
|
}
|
||||||
if (!active) {
|
|
||||||
currentFrequency = freq;
|
demodulatorPreThread->setFrequency(freq);
|
||||||
demodulatorPreThread->getParams().frequency = currentFrequency;
|
|
||||||
} else if (demodulatorPreThread && pipeDemodCommand) {
|
|
||||||
DemodulatorThreadCommand command;
|
|
||||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY;
|
|
||||||
currentFrequency = freq;
|
|
||||||
command.llong_value = freq;
|
|
||||||
pipeDemodCommand->push(command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long long DemodulatorInstance::getFrequency() {
|
long long DemodulatorInstance::getFrequency() {
|
||||||
if (!currentFrequency) {
|
return demodulatorPreThread->getFrequency();
|
||||||
currentFrequency = demodulatorPreThread->getParams().frequency;
|
|
||||||
}
|
|
||||||
return currentFrequency;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DemodulatorInstance::setAudioSampleRate(int sampleRate) {
|
void DemodulatorInstance::setAudioSampleRate(int sampleRate) {
|
||||||
if (terminated) {
|
demodulatorPreThread->setSampleRate(sampleRate);
|
||||||
currentAudioSampleRate = sampleRate;
|
|
||||||
demodulatorPreThread->getParams().audioSampleRate = sampleRate;
|
|
||||||
} else if (demodulatorPreThread && pipeDemodCommand) {
|
|
||||||
DemodulatorThreadCommand command;
|
|
||||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_AUDIO_RATE;
|
|
||||||
currentAudioSampleRate = sampleRate;
|
|
||||||
command.llong_value = sampleRate;
|
|
||||||
pipeDemodCommand->push(command);
|
|
||||||
}
|
|
||||||
if (currentDemodType == "I/Q") {
|
|
||||||
setBandwidth(currentAudioSampleRate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DemodulatorInstance::getAudioSampleRate() {
|
int DemodulatorInstance::getAudioSampleRate() {
|
||||||
currentAudioSampleRate = audioThread->getSampleRate();
|
if (!audioThread) {
|
||||||
demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate;
|
return 0;
|
||||||
|
}
|
||||||
return currentAudioSampleRate;
|
return audioThread->getSampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
|
|
||||||
void setAudioSampleRate(int sampleRate);
|
void setAudioSampleRate(int sampleRate);
|
||||||
int getAudioSampleRate();
|
int getAudioSampleRate();
|
||||||
|
|
||||||
bool isFollow();
|
bool isFollow();
|
||||||
void setFollow(bool follow);
|
void setFollow(bool follow);
|
||||||
|
|
||||||
@ -89,7 +89,6 @@ protected:
|
|||||||
DemodulatorThreadInputQueue* pipeIQInputData;
|
DemodulatorThreadInputQueue* pipeIQInputData;
|
||||||
DemodulatorThreadPostInputQueue* pipeIQDemodData;
|
DemodulatorThreadPostInputQueue* pipeIQDemodData;
|
||||||
AudioThreadInputQueue *pipeAudioData;
|
AudioThreadInputQueue *pipeAudioData;
|
||||||
DemodulatorThreadCommandQueue* pipeDemodCommand;
|
|
||||||
DemodulatorThreadCommandQueue* pipeDemodNotify;
|
DemodulatorThreadCommandQueue* pipeDemodNotify;
|
||||||
DemodulatorPreThread *demodulatorPreThread;
|
DemodulatorPreThread *demodulatorPreThread;
|
||||||
DemodulatorThread *demodulatorThread;
|
DemodulatorThread *demodulatorThread;
|
||||||
@ -106,10 +105,7 @@ private:
|
|||||||
std::atomic_bool squelch;
|
std::atomic_bool squelch;
|
||||||
std::atomic_bool muted;
|
std::atomic_bool muted;
|
||||||
|
|
||||||
std::atomic_llong currentFrequency;
|
|
||||||
std::string currentDemodType;
|
|
||||||
std::atomic_int currentOutputDevice;
|
std::atomic_int currentOutputDevice;
|
||||||
std::atomic_int currentAudioSampleRate;
|
|
||||||
std::atomic<float> currentAudioGain;
|
std::atomic<float> currentAudioGain;
|
||||||
std::atomic_bool follow, tracking;
|
std::atomic_bool follow, tracking;
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "CubicSDR.h"
|
#include "CubicSDR.h"
|
||||||
#include "DemodulatorInstance.h"
|
#include "DemodulatorInstance.h"
|
||||||
|
|
||||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance *parent) : IOThread(), iqResampler(NULL), iqResampleRatio(1), cModem(nullptr), cModemKit(nullptr), iqInputQueue(NULL), iqOutputQueue(NULL), threadQueueNotify(NULL), commandQueue(NULL)
|
DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance *parent) : IOThread(), iqResampler(NULL), iqResampleRatio(1), cModem(nullptr), cModemKit(nullptr), iqInputQueue(NULL), iqOutputQueue(NULL), threadQueueNotify(NULL)
|
||||||
{
|
{
|
||||||
initialized.store(false);
|
initialized.store(false);
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
@ -23,18 +23,20 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance *parent) : IOThre
|
|||||||
workerThread = new DemodulatorWorkerThread();
|
workerThread = new DemodulatorWorkerThread();
|
||||||
workerThread->setInputQueue("WorkerCommandQueue",workerQueue);
|
workerThread->setInputQueue("WorkerCommandQueue",workerQueue);
|
||||||
workerThread->setOutputQueue("WorkerResultQueue",workerResults);
|
workerThread->setOutputQueue("WorkerResultQueue",workerResults);
|
||||||
|
|
||||||
|
newSampleRate = currentSampleRate = 0;
|
||||||
|
newBandwidth = currentBandwidth = 0;
|
||||||
|
newAudioSampleRate = currentAudioSampleRate = 0;
|
||||||
|
newFrequency = currentFrequency = 0;
|
||||||
|
|
||||||
|
sampleRateChanged.store(false);
|
||||||
|
frequencyChanged.store(false);
|
||||||
|
bandwidthChanged.store(false);
|
||||||
|
audioSampleRateChanged.store(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorPreThread::initialize() {
|
void DemodulatorPreThread::initialize() {
|
||||||
iqResampleRatio = (double) (params.bandwidth) / (double) params.sampleRate;
|
|
||||||
|
|
||||||
float As = 60.0f; // stop-band attenuation [dB]
|
|
||||||
|
|
||||||
iqResampler = msresamp_crcf_create(iqResampleRatio, As);
|
|
||||||
|
|
||||||
initialized.store(true);
|
initialized.store(true);
|
||||||
|
|
||||||
lastParams = params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorPreThread::~DemodulatorPreThread() {
|
DemodulatorPreThread::~DemodulatorPreThread() {
|
||||||
@ -59,83 +61,86 @@ void DemodulatorPreThread::run() {
|
|||||||
iqInputQueue = (DemodulatorThreadInputQueue*)getInputQueue("IQDataInput");
|
iqInputQueue = (DemodulatorThreadInputQueue*)getInputQueue("IQDataInput");
|
||||||
iqOutputQueue = (DemodulatorThreadPostInputQueue*)getOutputQueue("IQDataOutput");
|
iqOutputQueue = (DemodulatorThreadPostInputQueue*)getOutputQueue("IQDataOutput");
|
||||||
threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue");
|
threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue");
|
||||||
commandQueue = ( DemodulatorThreadCommandQueue*)getInputQueue("CommandQueue");
|
|
||||||
|
|
||||||
std::vector<liquid_float_complex> in_buf_data;
|
std::vector<liquid_float_complex> in_buf_data;
|
||||||
std::vector<liquid_float_complex> out_buf_data;
|
std::vector<liquid_float_complex> out_buf_data;
|
||||||
|
|
||||||
setDemodType(params.demodType);
|
|
||||||
t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread);
|
t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread);
|
||||||
|
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
DemodulatorThreadIQData *inp;
|
DemodulatorThreadIQData *inp;
|
||||||
iqInputQueue->pop(inp);
|
iqInputQueue->pop(inp);
|
||||||
|
|
||||||
bool bandwidthChanged = false;
|
if (frequencyChanged.load()) {
|
||||||
bool rateChanged = false;
|
currentFrequency = newFrequency;
|
||||||
DemodulatorThreadParameters tempParams = params;
|
frequencyChanged.store(false);
|
||||||
|
}
|
||||||
if (!commandQueue->empty()) {
|
|
||||||
while (!commandQueue->empty()) {
|
if (inp->sampleRate != currentSampleRate) {
|
||||||
DemodulatorThreadCommand command;
|
newSampleRate = inp->sampleRate;
|
||||||
commandQueue->pop(command);
|
if (newSampleRate) {
|
||||||
switch (command.cmd) {
|
sampleRateChanged.store(true);
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH:
|
|
||||||
if (command.llong_value < 1500) {
|
|
||||||
command.llong_value = 1500;
|
|
||||||
}
|
|
||||||
tempParams.bandwidth = command.llong_value;
|
|
||||||
bandwidthChanged = true;
|
|
||||||
break;
|
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY:
|
|
||||||
params.frequency = tempParams.frequency = command.llong_value;
|
|
||||||
break;
|
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_AUDIO_RATE:
|
|
||||||
tempParams.audioSampleRate = (int)command.llong_value;
|
|
||||||
rateChanged = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inp->sampleRate != tempParams.sampleRate && inp->sampleRate) {
|
if (!newAudioSampleRate) {
|
||||||
tempParams.sampleRate = inp->sampleRate;
|
newAudioSampleRate = parent->getAudioSampleRate();
|
||||||
rateChanged = true;
|
if (newAudioSampleRate) {
|
||||||
|
audioSampleRateChanged.store(true);
|
||||||
|
}
|
||||||
|
} else if (parent->getAudioSampleRate() != newAudioSampleRate) {
|
||||||
|
int newRate;
|
||||||
|
if ((newRate = parent->getAudioSampleRate())) {
|
||||||
|
newAudioSampleRate = parent->getAudioSampleRate();
|
||||||
|
audioSampleRateChanged.store(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bandwidthChanged || rateChanged) {
|
if (demodTypeChanged.load() && (newSampleRate && newAudioSampleRate && newBandwidth)) {
|
||||||
|
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD);
|
||||||
|
command.frequency = newFrequency;
|
||||||
|
command.sampleRate = newSampleRate;
|
||||||
|
command.demodType = newDemodType;
|
||||||
|
command.bandwidth = newBandwidth;
|
||||||
|
command.audioSampleRate = newAudioSampleRate;
|
||||||
|
workerQueue->push(command);
|
||||||
|
demodType = newDemodType;
|
||||||
|
sampleRateChanged.store(false);
|
||||||
|
audioSampleRateChanged.store(false);
|
||||||
|
demodTypeChanged.store(false);
|
||||||
|
} else if (cModemKit && cModem && (bandwidthChanged.load() || sampleRateChanged.load() || audioSampleRateChanged.load()) && (newSampleRate && newAudioSampleRate && newBandwidth)) {
|
||||||
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
|
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
|
||||||
command.sampleRate = tempParams.sampleRate;
|
command.frequency = newFrequency;
|
||||||
command.audioSampleRate = tempParams.audioSampleRate;
|
command.sampleRate = newSampleRate;
|
||||||
command.bandwidth = tempParams.bandwidth;
|
command.bandwidth = newBandwidth;
|
||||||
command.frequency = tempParams.frequency;
|
command.audioSampleRate = newAudioSampleRate;
|
||||||
|
bandwidthChanged.store(false);
|
||||||
|
sampleRateChanged.store(false);
|
||||||
|
audioSampleRateChanged.store(false);
|
||||||
workerQueue->push(command);
|
workerQueue->push(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
inp->decRefCount();
|
inp->decRefCount();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requested frequency is not center, shift it into the center!
|
// Requested frequency is not center, shift it into the center!
|
||||||
if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) {
|
if ((currentFrequency - inp->frequency) != shiftFrequency) {
|
||||||
shiftFrequency = params.frequency - inp->frequency;
|
shiftFrequency = currentFrequency - inp->frequency;
|
||||||
if (abs(shiftFrequency) <= (int) ((double) (inp->sampleRate / 2) * 1.5)) {
|
if (abs(shiftFrequency) <= (int) ((double) (inp->sampleRate / 2) * 1.5)) {
|
||||||
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) inp->sampleRate)));
|
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) inp->sampleRate)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abs(shiftFrequency) > (int) ((double) (inp->sampleRate / 2) * 1.5)) {
|
if (cModem && cModemKit && abs(shiftFrequency) > (int) ((double) (inp->sampleRate / 2) * 1.5)) {
|
||||||
inp->decRefCount();
|
inp->decRefCount();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||||
std::vector<liquid_float_complex> *data = &inp->data;
|
std::vector<liquid_float_complex> *data = &inp->data;
|
||||||
if (data->size() && (inp->sampleRate == params.sampleRate)) {
|
if (data->size() && (inp->sampleRate == currentSampleRate) && cModem && cModemKit) {
|
||||||
int bufSize = data->size();
|
int bufSize = data->size();
|
||||||
|
|
||||||
if (in_buf_data.size() != bufSize) {
|
if (in_buf_data.size() != bufSize) {
|
||||||
@ -184,7 +189,7 @@ void DemodulatorPreThread::run() {
|
|||||||
resamp->modemType = demodType;
|
resamp->modemType = demodType;
|
||||||
resamp->modem = cModem;
|
resamp->modem = cModem;
|
||||||
resamp->modemKit = cModemKit;
|
resamp->modemKit = cModemKit;
|
||||||
resamp->sampleRate = params.bandwidth;
|
resamp->sampleRate = currentBandwidth;
|
||||||
|
|
||||||
iqOutputQueue->push(resamp);
|
iqOutputQueue->push(resamp);
|
||||||
}
|
}
|
||||||
@ -198,7 +203,6 @@ void DemodulatorPreThread::run() {
|
|||||||
|
|
||||||
switch (result.cmd) {
|
switch (result.cmd) {
|
||||||
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
|
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
|
||||||
|
|
||||||
if (result.iqResampler) {
|
if (result.iqResampler) {
|
||||||
if (iqResampler) {
|
if (iqResampler) {
|
||||||
msresamp_crcf_destroy(iqResampler);
|
msresamp_crcf_destroy(iqResampler);
|
||||||
@ -213,21 +217,23 @@ void DemodulatorPreThread::run() {
|
|||||||
|
|
||||||
if (result.modemKit != nullptr) {
|
if (result.modemKit != nullptr) {
|
||||||
cModemKit = result.modemKit;
|
cModemKit = result.modemKit;
|
||||||
|
currentAudioSampleRate = cModemKit->audioSampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.bandwidth) {
|
if (result.bandwidth) {
|
||||||
params.bandwidth = result.bandwidth;
|
currentBandwidth = result.bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.sampleRate) {
|
if (result.sampleRate) {
|
||||||
params.sampleRate = result.sampleRate;
|
currentSampleRate = result.sampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.modemType != "") {
|
if (result.modemType != "") {
|
||||||
demodType = result.modemType;
|
demodType = result.modemType;
|
||||||
params.demodType = result.modemType;
|
|
||||||
demodTypeChanged.store(false);
|
demodTypeChanged.store(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shiftFrequency = inp->frequency-1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -244,22 +250,8 @@ void DemodulatorPreThread::run() {
|
|||||||
std::cout << "Demodulator preprocessor thread done." << std::endl;
|
std::cout << "Demodulator preprocessor thread done." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadParameters &DemodulatorPreThread::getParams() {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DemodulatorPreThread::setParams(DemodulatorThreadParameters ¶ms_in) {
|
|
||||||
params = params_in;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DemodulatorPreThread::setDemodType(std::string demodType) {
|
void DemodulatorPreThread::setDemodType(std::string demodType) {
|
||||||
this->newDemodType = demodType;
|
newDemodType = demodType;
|
||||||
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD);
|
|
||||||
command.sampleRate = params.sampleRate;
|
|
||||||
command.demodType = demodType;
|
|
||||||
command.bandwidth = params.bandwidth;
|
|
||||||
command.audioSampleRate = params.audioSampleRate;
|
|
||||||
workerQueue->push(command);
|
|
||||||
demodTypeChanged.store(true);
|
demodTypeChanged.store(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +262,55 @@ std::string DemodulatorPreThread::getDemodType() {
|
|||||||
return demodType;
|
return demodType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DemodulatorPreThread::setFrequency(long long freq) {
|
||||||
|
frequencyChanged.store(true);
|
||||||
|
newFrequency = freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long DemodulatorPreThread::getFrequency() {
|
||||||
|
if (frequencyChanged.load()) {
|
||||||
|
return newFrequency;
|
||||||
|
}
|
||||||
|
return currentFrequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemodulatorPreThread::setSampleRate(long long sampleRate) {
|
||||||
|
sampleRateChanged.store(true);
|
||||||
|
newSampleRate = sampleRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long DemodulatorPreThread::getSampleRate() {
|
||||||
|
if (sampleRateChanged.load()) {
|
||||||
|
return newSampleRate;
|
||||||
|
}
|
||||||
|
return currentSampleRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemodulatorPreThread::setBandwidth(int bandwidth) {
|
||||||
|
bandwidthChanged.store(true);
|
||||||
|
newBandwidth = bandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DemodulatorPreThread::getBandwidth() {
|
||||||
|
// if (bandwidthChanged.load()) {
|
||||||
|
// return newBandwidth;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return currentBandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemodulatorPreThread::setAudioSampleRate(int rate) {
|
||||||
|
audioSampleRateChanged.store(true);
|
||||||
|
newAudioSampleRate = rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DemodulatorPreThread::getAudioSampleRate() {
|
||||||
|
if (audioSampleRateChanged.load()) {
|
||||||
|
return newAudioSampleRate;
|
||||||
|
}
|
||||||
|
return currentAudioSampleRate;
|
||||||
|
}
|
||||||
|
|
||||||
void DemodulatorPreThread::terminate() {
|
void DemodulatorPreThread::terminate() {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
|
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
|
||||||
@ -284,7 +325,6 @@ void DemodulatorPreThread::terminate() {
|
|||||||
delete workerQueue;
|
delete workerQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Modem *DemodulatorPreThread::getModem() {
|
Modem *DemodulatorPreThread::getModem() {
|
||||||
return cModem;
|
return cModem;
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,22 @@ public:
|
|||||||
~DemodulatorPreThread();
|
~DemodulatorPreThread();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
DemodulatorThreadParameters &getParams();
|
|
||||||
void setParams(DemodulatorThreadParameters ¶ms_in);
|
|
||||||
|
|
||||||
void setDemodType(std::string demodType);
|
void setDemodType(std::string demodType);
|
||||||
std::string getDemodType();
|
std::string getDemodType();
|
||||||
|
|
||||||
|
void setFrequency(long long sampleRate);
|
||||||
|
long long getFrequency();
|
||||||
|
|
||||||
|
void setSampleRate(long long sampleRate);
|
||||||
|
long long getSampleRate();
|
||||||
|
|
||||||
|
void setBandwidth(int bandwidth);
|
||||||
|
int getBandwidth();
|
||||||
|
|
||||||
|
void setAudioSampleRate(int rate);
|
||||||
|
int getAudioSampleRate();
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
@ -37,10 +46,14 @@ protected:
|
|||||||
|
|
||||||
Modem *cModem;
|
Modem *cModem;
|
||||||
ModemKit *cModemKit;
|
ModemKit *cModemKit;
|
||||||
|
|
||||||
|
long long currentSampleRate, newSampleRate;
|
||||||
|
long long currentFrequency, newFrequency;
|
||||||
|
int currentBandwidth, newBandwidth;
|
||||||
|
int currentAudioSampleRate, newAudioSampleRate;
|
||||||
|
|
||||||
DemodulatorThreadParameters params;
|
std::atomic_bool sampleRateChanged, frequencyChanged, bandwidthChanged, audioSampleRateChanged;
|
||||||
DemodulatorThreadParameters lastParams;
|
|
||||||
|
|
||||||
nco_crcf freqShifter;
|
nco_crcf freqShifter;
|
||||||
int shiftFrequency;
|
int shiftFrequency;
|
||||||
|
|
||||||
@ -58,5 +71,4 @@ protected:
|
|||||||
DemodulatorThreadInputQueue* iqInputQueue;
|
DemodulatorThreadInputQueue* iqInputQueue;
|
||||||
DemodulatorThreadPostInputQueue* iqOutputQueue;
|
DemodulatorThreadPostInputQueue* iqOutputQueue;
|
||||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||||
DemodulatorThreadCommandQueue* commandQueue;
|
|
||||||
};
|
};
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(), audioSampleRate(0), squelchLevel(-100), signalLevel(-100), squelchEnabled(false), cModem(nullptr), cModemKit(nullptr), iqInputQueue(NULL), audioOutputQueue(NULL), audioVisOutputQueue(NULL), threadQueueControl(NULL), threadQueueNotify(NULL) {
|
DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(), squelchLevel(-100), signalLevel(-100), squelchEnabled(false), cModem(nullptr), cModemKit(nullptr), iqInputQueue(NULL), audioOutputQueue(NULL), audioVisOutputQueue(NULL), threadQueueControl(NULL), threadQueueNotify(NULL) {
|
||||||
|
|
||||||
demodInstance = parent;
|
demodInstance = parent;
|
||||||
muted.store(false);
|
muted.store(false);
|
||||||
@ -73,8 +73,6 @@ void DemodulatorThread::run() {
|
|||||||
iqInputQueue->pop(inp);
|
iqInputQueue->pop(inp);
|
||||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||||
|
|
||||||
audioSampleRate = demodInstance->getAudioSampleRate();
|
|
||||||
|
|
||||||
int bufSize = inp->data.size();
|
int bufSize = inp->data.size();
|
||||||
|
|
||||||
if (!bufSize) {
|
if (!bufSize) {
|
||||||
@ -127,7 +125,7 @@ void DemodulatorThread::run() {
|
|||||||
if (modemAnalog != nullptr) {
|
if (modemAnalog != nullptr) {
|
||||||
ati = outputBuffers.getBuffer();
|
ati = outputBuffers.getBuffer();
|
||||||
|
|
||||||
ati->sampleRate = audioSampleRate;
|
ati->sampleRate = cModemKit->audioSampleRate;
|
||||||
ati->inputRate = inp->sampleRate;
|
ati->inputRate = inp->sampleRate;
|
||||||
ati->setRefCount(1);
|
ati->setRefCount(1);
|
||||||
}
|
}
|
||||||
@ -178,7 +176,7 @@ void DemodulatorThread::run() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < stereoSize / 2; i++) {
|
for (int i = 0; i < stereoSize / 2; i++) {
|
||||||
ati_vis->inputRate = audioSampleRate;
|
ati_vis->inputRate = cModemKit->audioSampleRate;
|
||||||
ati_vis->sampleRate = 36000;
|
ati_vis->sampleRate = 36000;
|
||||||
ati_vis->data[i] = ati->data[i * 2];
|
ati_vis->data[i] = ati->data[i * 2];
|
||||||
ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1];
|
ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1];
|
||||||
@ -189,7 +187,7 @@ void DemodulatorThread::run() {
|
|||||||
ati_vis->channels = 1;
|
ati_vis->channels = 1;
|
||||||
std::vector<float> *demodOutData = (modemAnalog != nullptr)?modemAnalog->getDemodOutputData():nullptr;
|
std::vector<float> *demodOutData = (modemAnalog != nullptr)?modemAnalog->getDemodOutputData():nullptr;
|
||||||
if ((numAudioWritten > bufSize) || (demodOutData == nullptr)) {
|
if ((numAudioWritten > bufSize) || (demodOutData == nullptr)) {
|
||||||
ati_vis->inputRate = audioSampleRate;
|
ati_vis->inputRate = cModemKit->audioSampleRate;
|
||||||
if (num_vis > numAudioWritten) {
|
if (num_vis > numAudioWritten) {
|
||||||
num_vis = numAudioWritten;
|
num_vis = numAudioWritten;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ protected:
|
|||||||
ReBuffer<AudioThreadInput> outputBuffers;
|
ReBuffer<AudioThreadInput> outputBuffers;
|
||||||
|
|
||||||
std::atomic_bool muted;
|
std::atomic_bool muted;
|
||||||
int audioSampleRate;
|
|
||||||
|
|
||||||
std::atomic<float> squelchLevel;
|
std::atomic<float> squelchLevel;
|
||||||
std::atomic<float> signalLevel;
|
std::atomic<float> signalLevel;
|
||||||
|
@ -42,7 +42,9 @@ ModemKit *ModemFMStereo::buildKit(long long sampleRate, int audioSampleRate) {
|
|||||||
ModemKitFMStereo *kit = new ModemKitFMStereo;
|
ModemKitFMStereo *kit = new ModemKitFMStereo;
|
||||||
|
|
||||||
kit->audioResampleRatio = double(audioSampleRate) / double(sampleRate);
|
kit->audioResampleRatio = double(audioSampleRate) / double(sampleRate);
|
||||||
|
kit->sampleRate = sampleRate;
|
||||||
|
kit->audioSampleRate = audioSampleRate;
|
||||||
|
|
||||||
float As = 60.0f; // stop-band attenuation [dB]
|
float As = 60.0f; // stop-band attenuation [dB]
|
||||||
|
|
||||||
kit->audioResampler = msresamp_rrrf_create(kit->audioResampleRatio, As);
|
kit->audioResampler = msresamp_rrrf_create(kit->audioResampleRatio, As);
|
||||||
|
@ -29,6 +29,5 @@ public:
|
|||||||
void setHoverAlpha(float hoverAlpha);
|
void setHoverAlpha(float hoverAlpha);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DemodulatorThreadParameters defaultDemodParams;
|
|
||||||
float hoverAlpha;
|
float hoverAlpha;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user