mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-20 06:38:43 -04:00
Can now change input device bandwidth
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#define DEMOD_TYPE_USB 4
|
||||
#define DEMOD_TYPE_DSB 5
|
||||
|
||||
|
||||
class DemodulatorThread;
|
||||
class DemodulatorThreadCommand {
|
||||
public:
|
||||
@@ -59,11 +58,11 @@ public:
|
||||
class DemodulatorThreadIQData: public ReferenceCounter {
|
||||
public:
|
||||
long long frequency;
|
||||
unsigned int bandwidth;
|
||||
long long sampleRate;
|
||||
std::vector<liquid_float_complex> data;
|
||||
|
||||
DemodulatorThreadIQData() :
|
||||
frequency(0), bandwidth(0) {
|
||||
frequency(0), sampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -75,13 +74,13 @@ public:
|
||||
class DemodulatorThreadPostIQData: public ReferenceCounter {
|
||||
public:
|
||||
std::vector<liquid_float_complex> data;
|
||||
int bandwidth;
|
||||
long long sampleRate;
|
||||
msresamp_rrrf audioResampler;
|
||||
msresamp_rrrf stereoResampler;
|
||||
double audioResampleRatio;
|
||||
|
||||
DemodulatorThreadPostIQData() :
|
||||
bandwidth(0), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(0) {
|
||||
sampleRate(0), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -121,14 +120,14 @@ typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCom
|
||||
class DemodulatorThreadParameters {
|
||||
public:
|
||||
long long frequency;
|
||||
unsigned int inputRate;
|
||||
long long sampleRate;
|
||||
unsigned int bandwidth; // set equal to disable second stage re-sampling?
|
||||
unsigned int audioSampleRate;
|
||||
|
||||
int demodType;
|
||||
|
||||
DemodulatorThreadParameters() :
|
||||
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
|
||||
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate(
|
||||
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#include "DemodulatorPreThread.h"
|
||||
#include "CubicSDR.h"
|
||||
|
||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQueue, DemodulatorThreadPostInputQueue* iqOutputQueue,
|
||||
DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||
@@ -26,7 +27,7 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQ
|
||||
void DemodulatorPreThread::initialize() {
|
||||
initialized = false;
|
||||
|
||||
iqResampleRatio = (double) (params.bandwidth) / (double) params.inputRate;
|
||||
iqResampleRatio = (double) (params.bandwidth) / (double) params.sampleRate;
|
||||
audioResampleRatio = (double) (params.audioSampleRate) / (double) params.bandwidth;
|
||||
|
||||
float As = 120.0f; // stop-band attenuation [dB]
|
||||
@@ -77,10 +78,10 @@ void DemodulatorPreThread::threadMain() {
|
||||
iqInputQueue->pop(inp);
|
||||
|
||||
bool bandwidthChanged = false;
|
||||
DemodulatorThreadParameters bandwidthParams = params;
|
||||
bool rateChanged = false;
|
||||
DemodulatorThreadParameters tempParams = params;
|
||||
|
||||
if (!commandQueue->empty()) {
|
||||
bool paramsChanged = false;
|
||||
while (!commandQueue->empty()) {
|
||||
DemodulatorThreadCommand command;
|
||||
commandQueue->pop(command);
|
||||
@@ -89,10 +90,11 @@ void DemodulatorPreThread::threadMain() {
|
||||
if (command.llong_value < 1500) {
|
||||
command.llong_value = 1500;
|
||||
}
|
||||
if (command.llong_value > SRATE) {
|
||||
command.llong_value = SRATE;
|
||||
if (command.llong_value > params.sampleRate) {
|
||||
tempParams.bandwidth = params.sampleRate;
|
||||
} else {
|
||||
tempParams.bandwidth = command.llong_value;
|
||||
}
|
||||
bandwidthParams.bandwidth = command.llong_value;
|
||||
bandwidthChanged = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY:
|
||||
@@ -100,16 +102,21 @@ void DemodulatorPreThread::threadMain() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bandwidthChanged) {
|
||||
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
|
||||
command.audioSampleRate = bandwidthParams.audioSampleRate;
|
||||
command.bandwidth = bandwidthParams.bandwidth;
|
||||
command.frequency = bandwidthParams.frequency;
|
||||
command.inputRate = bandwidthParams.inputRate;
|
||||
if (inp->sampleRate != tempParams.sampleRate) {
|
||||
tempParams.sampleRate = inp->sampleRate;
|
||||
rateChanged = true;
|
||||
}
|
||||
|
||||
workerQueue->push(command);
|
||||
}
|
||||
if (bandwidthChanged || rateChanged) {
|
||||
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
|
||||
command.sampleRate = tempParams.sampleRate;
|
||||
command.audioSampleRate = tempParams.audioSampleRate;
|
||||
command.bandwidth = tempParams.bandwidth;
|
||||
command.frequency = tempParams.frequency;
|
||||
|
||||
workerQueue->push(command);
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
@@ -118,21 +125,21 @@ void DemodulatorPreThread::threadMain() {
|
||||
|
||||
// Requested frequency is not center, shift it into the center!
|
||||
if (inp->frequency != params.frequency) {
|
||||
if ((params.frequency - inp->frequency) != shiftFrequency) {
|
||||
if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) {
|
||||
shiftFrequency = params.frequency - inp->frequency;
|
||||
if (abs(shiftFrequency) <= (int) ((double) (SRATE / 2) * 1.5)) {
|
||||
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) SRATE)));
|
||||
if (abs(shiftFrequency) <= (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) {
|
||||
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) wxGetApp().getSampleRate())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (abs(shiftFrequency) > (int) ((double) (SRATE / 2) * 1.5)) {
|
||||
if (abs(shiftFrequency) > (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||
std::vector<liquid_float_complex> *data = &inp->data;
|
||||
if (data->size()) {
|
||||
if (data->size() && (inp->sampleRate == params.sampleRate)) {
|
||||
int bufSize = data->size();
|
||||
|
||||
if (in_buf_data.size() != bufSize) {
|
||||
@@ -193,7 +200,7 @@ void DemodulatorPreThread::threadMain() {
|
||||
resamp->audioResampleRatio = audioResampleRatio;
|
||||
resamp->audioResampler = audioResampler;
|
||||
resamp->stereoResampler = stereoResampler;
|
||||
resamp->bandwidth = params.bandwidth;
|
||||
resamp->sampleRate = params.bandwidth;
|
||||
|
||||
iqOutputQueue->push(resamp);
|
||||
}
|
||||
@@ -209,16 +216,16 @@ void DemodulatorPreThread::threadMain() {
|
||||
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
|
||||
msresamp_crcf_destroy(iqResampler);
|
||||
|
||||
iqResampler = result.resampler;
|
||||
iqResampler = result.iqResampler;
|
||||
audioResampler = result.audioResampler;
|
||||
stereoResampler = result.stereoResampler;
|
||||
|
||||
iqResampleRatio = result.resamplerRatio;
|
||||
iqResampleRatio = result.iqResampleRatio;
|
||||
audioResampleRatio = result.audioResamplerRatio;
|
||||
|
||||
params.audioSampleRate = result.audioSampleRate;
|
||||
params.bandwidth = result.bandwidth;
|
||||
params.inputRate = result.inputRate;
|
||||
params.sampleRate = result.sampleRate;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ void DemodulatorThread::threadMain() {
|
||||
demodStereoData.resize(bufSize);
|
||||
}
|
||||
|
||||
double freq = (2.0 * M_PI) * (((double) abs(38000)) / ((double) inp->bandwidth));
|
||||
double freq = (2.0 * M_PI) * (((double) abs(38000)) / ((double) inp->sampleRate));
|
||||
|
||||
if (stereoShiftFrequency != freq) {
|
||||
nco_crcf_set_frequency(stereoShifter, freq);
|
||||
|
||||
@@ -34,18 +34,18 @@ void DemodulatorWorkerThread::threadMain() {
|
||||
if (filterChanged) {
|
||||
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
|
||||
|
||||
result.resamplerRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.inputRate;
|
||||
result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate;
|
||||
result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth;
|
||||
|
||||
float As = 60.0f; // stop-band attenuation [dB]
|
||||
|
||||
result.resampler = msresamp_crcf_create(result.resamplerRatio, As);
|
||||
result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As);
|
||||
result.audioResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
|
||||
result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
|
||||
|
||||
result.audioSampleRate = filterCommand.audioSampleRate;
|
||||
result.bandwidth = filterCommand.bandwidth;
|
||||
result.inputRate = filterCommand.inputRate;
|
||||
result.sampleRate = filterCommand.sampleRate;
|
||||
resultQueue->push(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,26 +22,26 @@ public:
|
||||
};
|
||||
|
||||
DemodulatorWorkerThreadResult() :
|
||||
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), resampler(NULL), resamplerRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio(
|
||||
0), inputRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(NULL), iqResampleRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio(
|
||||
0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) :
|
||||
cmd(cmd), resampler(NULL), resamplerRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio(0), inputRate(0), bandwidth(
|
||||
cmd(cmd), iqResampler(NULL), iqResampleRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio(0), sampleRate(0), bandwidth(
|
||||
0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorThreadResultEnum cmd;
|
||||
|
||||
msresamp_crcf resampler;
|
||||
double resamplerRatio;
|
||||
msresamp_crcf iqResampler;
|
||||
double iqResampleRatio;
|
||||
msresamp_rrrf audioResampler;
|
||||
msresamp_rrrf stereoResampler;
|
||||
double audioResamplerRatio;
|
||||
|
||||
unsigned int inputRate;
|
||||
long long sampleRate;
|
||||
unsigned int bandwidth;
|
||||
unsigned int audioSampleRate;
|
||||
|
||||
@@ -54,19 +54,19 @@ public:
|
||||
};
|
||||
|
||||
DemodulatorWorkerThreadCommand() :
|
||||
cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), inputRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||
cmd(cmd), frequency(0), inputRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorThreadCommandEnum cmd;
|
||||
|
||||
long long frequency;
|
||||
unsigned int inputRate;
|
||||
long long sampleRate;
|
||||
unsigned int bandwidth;
|
||||
unsigned int audioSampleRate;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user