Can now change input device bandwidth

This commit is contained in:
Charles J. Cliffe 2015-01-11 17:08:16 -05:00
parent 19b569f072
commit ea2627ace6
20 changed files with 189 additions and 112 deletions

View File

@ -158,7 +158,6 @@ AppFrame::AppFrame() :
menuBar->Append(menu, wxT("Active Demodulator &Output")); menuBar->Append(menu, wxT("Active Demodulator &Output"));
menu = new wxMenu; menu = new wxMenu;
menu->Append(wxID_THEME_DEFAULT, "Default"); menu->Append(wxID_THEME_DEFAULT, "Default");
@ -171,6 +170,16 @@ AppFrame::AppFrame() :
menuBar->Append(menu, wxT("&Color Scheme")); menuBar->Append(menu, wxT("&Color Scheme"));
menu = new wxMenu;
menu->Append(wxID_BANDWIDTH_1000M, "1.0M");
menu->Append(wxID_BANDWIDTH_1500M, "1.5M");
menu->Append(wxID_BANDWIDTH_2000M, "2.0M");
menu->Append(wxID_BANDWIDTH_2500M, "2.5M");
menu->Append(wxID_BANDWIDTH_2880M, "2.88M");
menu->Append(wxID_BANDWIDTH_3200M, "3.2M");
menuBar->Append(menu, wxT("&Input Bandwidth"));
SetMenuBar(menuBar); SetMenuBar(menuBar);
@ -262,6 +271,27 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
waterfallCanvas->setTheme(COLOR_THEME_RADAR); waterfallCanvas->setTheme(COLOR_THEME_RADAR);
demodWaterfallCanvas->setTheme(COLOR_THEME_RADAR); demodWaterfallCanvas->setTheme(COLOR_THEME_RADAR);
} }
switch (event.GetId()) {
case wxID_BANDWIDTH_1000M:
wxGetApp().setSampleRate(1000000);
break;
case wxID_BANDWIDTH_1500M:
wxGetApp().setSampleRate(1500000);
break;
case wxID_BANDWIDTH_2000M:
wxGetApp().setSampleRate(2000000);
break;
case wxID_BANDWIDTH_2500M:
wxGetApp().setSampleRate(2500000);
break;
case wxID_BANDWIDTH_2880M:
wxGetApp().setSampleRate(2880000);
break;
case wxID_BANDWIDTH_3200M:
wxGetApp().setSampleRate(3200000);
break;
}
} }
void AppFrame::OnClose(wxCommandEvent& WXUNUSED(event)) { void AppFrame::OnClose(wxCommandEvent& WXUNUSED(event)) {
@ -307,8 +337,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
} }
unsigned int demodBw = (unsigned int) ceil((float) demod->getParams().bandwidth * 2.5); unsigned int demodBw = (unsigned int) ceil((float) demod->getParams().bandwidth * 2.5);
if (demodBw > SRATE / 2) { if (demodBw > wxGetApp().getSampleRate() / 2) {
demodBw = SRATE / 2; demodBw = wxGetApp().getSampleRate() / 2;
} }
if (demodBw < 80000) { if (demodBw < 80000) {
demodBw = 80000; demodBw = 80000;
@ -399,9 +429,8 @@ void AppFrame::saveSession(std::string fileName) {
s.SaveToFileXML(fileName); s.SaveToFileXML(fileName);
currentSessionFile = fileName; currentSessionFile = fileName;
std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator)+1); std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1);
GetStatusBar()->SetStatusText(wxString::Format(wxT("Saved session: %s"), currentSessionFile.c_str())); GetStatusBar()->SetStatusText(wxString::Format(wxT("Saved session: %s"), currentSessionFile.c_str()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str())); SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));
} }
@ -494,7 +523,7 @@ bool AppFrame::loadSession(std::string fileName) {
currentSessionFile = fileName; currentSessionFile = fileName;
std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator)+1); std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1);
GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str())); GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str())); SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));

View File

@ -24,6 +24,13 @@
#define wxID_THEME_HD 2105 #define wxID_THEME_HD 2105
#define wxID_THEME_RADAR 2106 #define wxID_THEME_RADAR 2106
#define wxID_BANDWIDTH_1000M 2152
#define wxID_BANDWIDTH_1500M 2153
#define wxID_BANDWIDTH_2000M 2154
#define wxID_BANDWIDTH_2500M 2155
#define wxID_BANDWIDTH_2880M 2156
#define wxID_BANDWIDTH_3200M 2158
// Define a new frame type // Define a new frame type
class AppFrame: public wxFrame { class AppFrame: public wxFrame {
public: public:
@ -59,6 +66,9 @@ private:
std::map<int,RtAudio::DeviceInfo> outputDevices; std::map<int,RtAudio::DeviceInfo> outputDevices;
std::map<int,wxMenuItem *> outputDeviceMenuItems; std::map<int,wxMenuItem *> outputDeviceMenuItems;
std::map<int,wxMenuItem *> sampleRateMenuItems;
std::string currentSessionFile; std::string currentSessionFile;
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@ -82,7 +82,6 @@ int CubicSDR::OnExit() {
delete m_glContext; delete m_glContext;
#ifdef __APPLE__ #ifdef __APPLE__
AudioThread::deviceCleanup(); AudioThread::deviceCleanup();
#endif #endif
@ -103,8 +102,8 @@ PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) {
} }
void CubicSDR::setFrequency(long long freq) { void CubicSDR::setFrequency(long long freq) {
if (freq < SRATE/2) { if (freq < sampleRate / 2) {
freq = SRATE/2; freq = sampleRate / 2;
} }
frequency = freq; frequency = freq;
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE); SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE);
@ -146,6 +145,18 @@ void CubicSDR::bindDemodulator(DemodulatorInstance *demod) {
sdrPostThread->bindDemodulator(demod); sdrPostThread->bindDemodulator(demod);
} }
void CubicSDR::setSampleRate(long long rate_in) {
sampleRate = rate_in;
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_SAMPLERATE);
command.llong_value = rate_in;
threadCmdQueueSDR->push(command);
setFrequency(frequency);
}
long long CubicSDR::getSampleRate() {
return sampleRate;
}
void CubicSDR::removeDemodulator(DemodulatorInstance *demod) { void CubicSDR::removeDemodulator(DemodulatorInstance *demod) {
if (!demod) { if (!demod) {
return; return;

View File

@ -20,7 +20,7 @@
class CubicSDR: public wxApp { class CubicSDR: public wxApp {
public: public:
CubicSDR() : CubicSDR() :
m_glContext(NULL), frequency(DEFAULT_FREQ), sdrThread(NULL), sdrPostThread(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), iqPostDataQueue(NULL), audioVisualQueue(NULL), t_SDR(NULL), t_PostSDR(NULL) { m_glContext(NULL), frequency(DEFAULT_FREQ), sdrThread(NULL), sdrPostThread(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), iqPostDataQueue(NULL), audioVisualQueue(NULL), t_SDR(NULL), t_PostSDR(NULL), sampleRate(DEFAULT_SAMPLE_RATE) {
} }
@ -35,6 +35,9 @@ public:
void setOffset(long long ofs); void setOffset(long long ofs);
long long getOffset(); long long getOffset();
void setSampleRate(long long rate_in);
long long getSampleRate();
DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadOutputQueue* getAudioVisualQueue();
DemodulatorThreadInputQueue* getIQVisualQueue(); DemodulatorThreadInputQueue* getIQVisualQueue();
DemodulatorMgr &getDemodMgr(); DemodulatorMgr &getDemodMgr();
@ -49,6 +52,7 @@ private:
long long frequency; long long frequency;
long long offset; long long offset;
long long sampleRate;
SDRThread *sdrThread; SDRThread *sdrThread;
SDRPostThread *sdrPostThread; SDRPostThread *sdrPostThread;

View File

@ -12,10 +12,10 @@ const char filePathSeparator =
#ifdef __APPLE__ #ifdef __APPLE__
#define BUF_SIZE (16384*2) #define BUF_SIZE (16384*2)
#define SRATE 2000000 #define DEFAULT_SAMPLE_RATE 2000000
#else #else
#define BUF_SIZE (16384*5) #define BUF_SIZE (16384*5)
#define SRATE 2500000 #define DEFAULT_SAMPLE_RATE 2500000
#endif #endif
#define DEFAULT_FFT_SIZE 2048 #define DEFAULT_FFT_SIZE 2048

View File

@ -14,7 +14,6 @@
#define DEMOD_TYPE_USB 4 #define DEMOD_TYPE_USB 4
#define DEMOD_TYPE_DSB 5 #define DEMOD_TYPE_DSB 5
class DemodulatorThread; class DemodulatorThread;
class DemodulatorThreadCommand { class DemodulatorThreadCommand {
public: public:
@ -59,11 +58,11 @@ public:
class DemodulatorThreadIQData: public ReferenceCounter { class DemodulatorThreadIQData: public ReferenceCounter {
public: public:
long long frequency; long long frequency;
unsigned int bandwidth; long long sampleRate;
std::vector<liquid_float_complex> data; std::vector<liquid_float_complex> data;
DemodulatorThreadIQData() : DemodulatorThreadIQData() :
frequency(0), bandwidth(0) { frequency(0), sampleRate(0) {
} }
@ -75,13 +74,13 @@ public:
class DemodulatorThreadPostIQData: public ReferenceCounter { class DemodulatorThreadPostIQData: public ReferenceCounter {
public: public:
std::vector<liquid_float_complex> data; std::vector<liquid_float_complex> data;
int bandwidth; long long sampleRate;
msresamp_rrrf audioResampler; msresamp_rrrf audioResampler;
msresamp_rrrf stereoResampler; msresamp_rrrf stereoResampler;
double audioResampleRatio; double audioResampleRatio;
DemodulatorThreadPostIQData() : 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 { class DemodulatorThreadParameters {
public: public:
long long frequency; long long frequency;
unsigned int inputRate; long long sampleRate;
unsigned int bandwidth; // set equal to disable second stage re-sampling? unsigned int bandwidth; // set equal to disable second stage re-sampling?
unsigned int audioSampleRate; unsigned int audioSampleRate;
int demodType; int demodType;
DemodulatorThreadParameters() : DemodulatorThreadParameters() :
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate( frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate(
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) { AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
} }

View File

@ -6,6 +6,7 @@
#endif #endif
#include "DemodulatorPreThread.h" #include "DemodulatorPreThread.h"
#include "CubicSDR.h"
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQueue, DemodulatorThreadPostInputQueue* iqOutputQueue, DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQueue, DemodulatorThreadPostInputQueue* iqOutputQueue,
DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) :
@ -26,7 +27,7 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQ
void DemodulatorPreThread::initialize() { void DemodulatorPreThread::initialize() {
initialized = false; initialized = false;
iqResampleRatio = (double) (params.bandwidth) / (double) params.inputRate; iqResampleRatio = (double) (params.bandwidth) / (double) params.sampleRate;
audioResampleRatio = (double) (params.audioSampleRate) / (double) params.bandwidth; audioResampleRatio = (double) (params.audioSampleRate) / (double) params.bandwidth;
float As = 120.0f; // stop-band attenuation [dB] float As = 120.0f; // stop-band attenuation [dB]
@ -77,10 +78,10 @@ void DemodulatorPreThread::threadMain() {
iqInputQueue->pop(inp); iqInputQueue->pop(inp);
bool bandwidthChanged = false; bool bandwidthChanged = false;
DemodulatorThreadParameters bandwidthParams = params; bool rateChanged = false;
DemodulatorThreadParameters tempParams = params;
if (!commandQueue->empty()) { if (!commandQueue->empty()) {
bool paramsChanged = false;
while (!commandQueue->empty()) { while (!commandQueue->empty()) {
DemodulatorThreadCommand command; DemodulatorThreadCommand command;
commandQueue->pop(command); commandQueue->pop(command);
@ -89,10 +90,11 @@ void DemodulatorPreThread::threadMain() {
if (command.llong_value < 1500) { if (command.llong_value < 1500) {
command.llong_value = 1500; command.llong_value = 1500;
} }
if (command.llong_value > SRATE) { if (command.llong_value > params.sampleRate) {
command.llong_value = SRATE; tempParams.bandwidth = params.sampleRate;
} else {
tempParams.bandwidth = command.llong_value;
} }
bandwidthParams.bandwidth = command.llong_value;
bandwidthChanged = true; bandwidthChanged = true;
break; break;
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY: case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY:
@ -100,16 +102,21 @@ void DemodulatorPreThread::threadMain() {
break; break;
} }
} }
}
if (bandwidthChanged) { if (inp->sampleRate != tempParams.sampleRate) {
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS); tempParams.sampleRate = inp->sampleRate;
command.audioSampleRate = bandwidthParams.audioSampleRate; rateChanged = true;
command.bandwidth = bandwidthParams.bandwidth; }
command.frequency = bandwidthParams.frequency;
command.inputRate = bandwidthParams.inputRate;
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) { if (!initialized) {
@ -118,21 +125,21 @@ void DemodulatorPreThread::threadMain() {
// Requested frequency is not center, shift it into the center! // Requested frequency is not center, shift it into the center!
if (inp->frequency != params.frequency) { if (inp->frequency != params.frequency) {
if ((params.frequency - inp->frequency) != shiftFrequency) { if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) {
shiftFrequency = params.frequency - inp->frequency; shiftFrequency = params.frequency - inp->frequency;
if (abs(shiftFrequency) <= (int) ((double) (SRATE / 2) * 1.5)) { if (abs(shiftFrequency) <= (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) {
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) SRATE))); 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; 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()) { if (data->size() && (inp->sampleRate == params.sampleRate)) {
int bufSize = data->size(); int bufSize = data->size();
if (in_buf_data.size() != bufSize) { if (in_buf_data.size() != bufSize) {
@ -193,7 +200,7 @@ void DemodulatorPreThread::threadMain() {
resamp->audioResampleRatio = audioResampleRatio; resamp->audioResampleRatio = audioResampleRatio;
resamp->audioResampler = audioResampler; resamp->audioResampler = audioResampler;
resamp->stereoResampler = stereoResampler; resamp->stereoResampler = stereoResampler;
resamp->bandwidth = params.bandwidth; resamp->sampleRate = params.bandwidth;
iqOutputQueue->push(resamp); iqOutputQueue->push(resamp);
} }
@ -209,16 +216,16 @@ void DemodulatorPreThread::threadMain() {
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS: case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
msresamp_crcf_destroy(iqResampler); msresamp_crcf_destroy(iqResampler);
iqResampler = result.resampler; iqResampler = result.iqResampler;
audioResampler = result.audioResampler; audioResampler = result.audioResampler;
stereoResampler = result.stereoResampler; stereoResampler = result.stereoResampler;
iqResampleRatio = result.resamplerRatio; iqResampleRatio = result.iqResampleRatio;
audioResampleRatio = result.audioResamplerRatio; audioResampleRatio = result.audioResamplerRatio;
params.audioSampleRate = result.audioSampleRate; params.audioSampleRate = result.audioSampleRate;
params.bandwidth = result.bandwidth; params.bandwidth = result.bandwidth;
params.inputRate = result.inputRate; params.sampleRate = result.sampleRate;
break; break;
} }

View File

@ -217,7 +217,7 @@ void DemodulatorThread::threadMain() {
demodStereoData.resize(bufSize); 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) { if (stereoShiftFrequency != freq) {
nco_crcf_set_frequency(stereoShifter, freq); nco_crcf_set_frequency(stereoShifter, freq);

View File

@ -34,18 +34,18 @@ void DemodulatorWorkerThread::threadMain() {
if (filterChanged) { if (filterChanged) {
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS); 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; result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth;
float As = 60.0f; // stop-band attenuation [dB] 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.audioResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As); result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As);
result.audioSampleRate = filterCommand.audioSampleRate; result.audioSampleRate = filterCommand.audioSampleRate;
result.bandwidth = filterCommand.bandwidth; result.bandwidth = filterCommand.bandwidth;
result.inputRate = filterCommand.inputRate; result.sampleRate = filterCommand.sampleRate;
resultQueue->push(result); resultQueue->push(result);
} }

View File

@ -22,26 +22,26 @@ public:
}; };
DemodulatorWorkerThreadResult() : DemodulatorWorkerThreadResult() :
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), resampler(NULL), resamplerRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio( cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(NULL), iqResampleRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResamplerRatio(
0), inputRate(0), bandwidth(0), audioSampleRate(0) { 0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
} }
DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) : 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) { 0), audioSampleRate(0) {
} }
DemodulatorThreadResultEnum cmd; DemodulatorThreadResultEnum cmd;
msresamp_crcf resampler; msresamp_crcf iqResampler;
double resamplerRatio; double iqResampleRatio;
msresamp_rrrf audioResampler; msresamp_rrrf audioResampler;
msresamp_rrrf stereoResampler; msresamp_rrrf stereoResampler;
double audioResamplerRatio; double audioResamplerRatio;
unsigned int inputRate; long long sampleRate;
unsigned int bandwidth; unsigned int bandwidth;
unsigned int audioSampleRate; unsigned int audioSampleRate;
@ -54,19 +54,19 @@ public:
}; };
DemodulatorWorkerThreadCommand() : 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) : 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; DemodulatorThreadCommandEnum cmd;
long long frequency; long long frequency;
unsigned int inputRate; long long sampleRate;
unsigned int bandwidth; unsigned int bandwidth;
unsigned int audioSampleRate; unsigned int audioSampleRate;
}; };

View File

@ -6,7 +6,7 @@
#include <deque> #include <deque>
SDRPostThread::SDRPostThread() : SDRPostThread::SDRPostThread() :
sample_rate(SRATE), iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL), num_vis_samples(2048) { iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL), num_vis_samples(2048) {
} }
SDRPostThread::~SDRPostThread() { SDRPostThread::~SDRPostThread() {
@ -90,7 +90,7 @@ void SDRPostThread::threadMain() {
DemodulatorThreadIQData *pipeDataOut = new DemodulatorThreadIQData; DemodulatorThreadIQData *pipeDataOut = new DemodulatorThreadIQData;
pipeDataOut->frequency = data_in->frequency; pipeDataOut->frequency = data_in->frequency;
pipeDataOut->bandwidth = data_in->bandwidth; pipeDataOut->sampleRate = data_in->sampleRate;
pipeDataOut->data.assign(dataOut.begin(), dataOut.end()); pipeDataOut->data.assign(dataOut.begin(), dataOut.end());
iqDataOutQueue.load()->push(pipeDataOut); iqDataOutQueue.load()->push(pipeDataOut);
} }
@ -98,7 +98,7 @@ void SDRPostThread::threadMain() {
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) { if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
DemodulatorThreadIQData *visualDataOut = new DemodulatorThreadIQData; DemodulatorThreadIQData *visualDataOut = new DemodulatorThreadIQData;
visualDataOut->frequency = data_in->frequency; visualDataOut->frequency = data_in->frequency;
visualDataOut->bandwidth = data_in->bandwidth; visualDataOut->sampleRate = data_in->sampleRate;
visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + num_vis_samples); visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + num_vis_samples);
iqVisualQueue.load()->push(visualDataOut); iqVisualQueue.load()->push(visualDataOut);
} }
@ -131,7 +131,7 @@ void SDRPostThread::threadMain() {
for (i = demodulators.begin(); i != demodulators.end(); i++) { for (i = demodulators.begin(); i != demodulators.end(); i++) {
DemodulatorInstance *demod = *i; DemodulatorInstance *demod = *i;
if (demod->getFrequency() != data_in->frequency if (demod->getFrequency() != data_in->frequency
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) { && abs(data_in->frequency - demod->getFrequency()) > (wxGetApp().getSampleRate() / 2)) {
continue; continue;
} }
activeDemods++; activeDemods++;
@ -155,7 +155,7 @@ void SDRPostThread::threadMain() {
// std::lock_guard < std::mutex > lock(demodDataOut->m_mutex); // std::lock_guard < std::mutex > lock(demodDataOut->m_mutex);
demodDataOut->frequency = data_in->frequency; demodDataOut->frequency = data_in->frequency;
demodDataOut->bandwidth = data_in->bandwidth; demodDataOut->sampleRate = data_in->sampleRate;
demodDataOut->setRefCount(activeDemods); demodDataOut->setRefCount(activeDemods);
demodDataOut->data.assign(dataOut.begin(), dataOut.end()); demodDataOut->data.assign(dataOut.begin(), dataOut.end());
@ -165,12 +165,12 @@ void SDRPostThread::threadMain() {
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod; DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
if (demod->getFrequency() != data_in->frequency if (demod->getFrequency() != data_in->frequency
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) { && abs(data_in->frequency - demod->getFrequency()) > (wxGetApp().getSampleRate() / 2)) {
if (demod->isActive()) { if (demod->isActive()) {
demod->setActive(false); demod->setActive(false);
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData; DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
dummyDataOut->frequency = data_in->frequency; dummyDataOut->frequency = data_in->frequency;
dummyDataOut->bandwidth = data_in->bandwidth; dummyDataOut->sampleRate = data_in->sampleRate;
demodQueue->push(dummyDataOut); demodQueue->push(dummyDataOut);
} }
} else if (!demod->isActive()) { } else if (!demod->isActive()) {

View File

@ -22,8 +22,6 @@ public:
void terminate(); void terminate();
protected: protected:
uint32_t sample_rate;
std::atomic<SDRThreadIQDataQueue *> iqDataInQueue; std::atomic<SDRThreadIQDataQueue *> iqDataInQueue;
std::atomic<DemodulatorThreadInputQueue *> iqDataOutQueue; std::atomic<DemodulatorThreadInputQueue *> iqDataOutQueue;
std::atomic<DemodulatorThreadInputQueue *> iqVisualQueue; std::atomic<DemodulatorThreadInputQueue *> iqVisualQueue;

View File

@ -6,7 +6,7 @@
SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) : SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) :
commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0) { commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0) {
dev = NULL; dev = NULL;
sampleRate = SRATE; sampleRate = DEFAULT_SAMPLE_RATE;
} }
SDRThread::~SDRThread() { SDRThread::~SDRThread() {
@ -111,16 +111,15 @@ void SDRThread::threadMain() {
signed char buf[BUF_SIZE]; signed char buf[BUF_SIZE];
long long frequency = DEFAULT_FREQ; long long frequency = DEFAULT_FREQ;
unsigned int bandwidth = SRATE;
rtlsdr_open(&dev, firstDevAvailable); rtlsdr_open(&dev, firstDevAvailable);
rtlsdr_set_sample_rate(dev, bandwidth); rtlsdr_set_sample_rate(dev, sampleRate);
rtlsdr_set_center_freq(dev, frequency); rtlsdr_set_center_freq(dev, frequency - offset);
rtlsdr_set_agc_mode(dev, 1); rtlsdr_set_agc_mode(dev, 1);
rtlsdr_set_offset_tuning(dev, 0); rtlsdr_set_offset_tuning(dev, 0);
rtlsdr_reset_buffer(dev); rtlsdr_reset_buffer(dev);
sampleRate = rtlsdr_get_sample_rate(dev); // sampleRate = rtlsdr_get_sample_rate(dev);
std::cout << "Sample Rate is: " << sampleRate << std::endl; std::cout << "Sample Rate is: " << sampleRate << std::endl;
@ -138,8 +137,10 @@ void SDRThread::threadMain() {
if (!cmdQueue->empty()) { if (!cmdQueue->empty()) {
bool freq_changed = false; bool freq_changed = false;
bool offset_changed = false; bool offset_changed = false;
bool rate_changed = false;
long long new_freq; long long new_freq;
long long new_offset; long long new_offset;
long long new_rate;
while (!cmdQueue->empty()) { while (!cmdQueue->empty()) {
SDRThreadCommand command; SDRThreadCommand command;
@ -149,8 +150,8 @@ void SDRThread::threadMain() {
case SDRThreadCommand::SDR_THREAD_CMD_TUNE: case SDRThreadCommand::SDR_THREAD_CMD_TUNE:
freq_changed = true; freq_changed = true;
new_freq = command.llong_value; new_freq = command.llong_value;
if (new_freq < SRATE / 2) { if (new_freq < sampleRate / 2) {
new_freq = SRATE / 2; new_freq = sampleRate / 2;
} }
std::cout << "Set frequency: " << new_freq << std::endl; std::cout << "Set frequency: " << new_freq << std::endl;
break; break;
@ -159,6 +160,11 @@ void SDRThread::threadMain() {
new_offset = command.llong_value; new_offset = command.llong_value;
std::cout << "Set offset: " << new_offset << std::endl; std::cout << "Set offset: " << new_offset << std::endl;
break; break;
case SDRThreadCommand::SDR_THREAD_CMD_SET_SAMPLERATE:
rate_changed = true;
new_rate = command.llong_value;
std::cout << "Set sample rate: " << new_rate << std::endl;
break;
default: default:
break; break;
} }
@ -169,9 +175,12 @@ void SDRThread::threadMain() {
freq_changed = true; freq_changed = true;
offset = new_offset; offset = new_offset;
} }
if (freq_changed) { if (rate_changed) {
sampleRate = new_rate;
rtlsdr_set_sample_rate(dev, new_rate);
} else if (freq_changed) {
frequency = new_freq; frequency = new_freq;
rtlsdr_set_center_freq(dev, frequency-offset); rtlsdr_set_center_freq(dev, frequency - offset);
} }
} }
@ -194,7 +203,7 @@ void SDRThread::threadMain() {
// std::lock_guard < std::mutex > lock(dataOut->m_mutex); // std::lock_guard < std::mutex > lock(dataOut->m_mutex);
dataOut->setRefCount(1); dataOut->setRefCount(1);
dataOut->frequency = frequency; dataOut->frequency = frequency;
dataOut->bandwidth = bandwidth; dataOut->sampleRate = sampleRate;
if (dataOut->data.capacity() < n_read) { if (dataOut->data.capacity() < n_read) {
dataOut->data.reserve(n_read); dataOut->data.reserve(n_read);

View File

@ -17,7 +17,7 @@
class SDRThreadCommand { class SDRThreadCommand {
public: public:
enum SDRThreadCommandEnum { enum SDRThreadCommandEnum {
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE
}; };
SDRThreadCommand() : SDRThreadCommand() :
@ -37,16 +37,16 @@ public:
class SDRThreadIQData: public ReferenceCounter { class SDRThreadIQData: public ReferenceCounter {
public: public:
long long frequency; long long frequency;
unsigned int bandwidth; long long sampleRate;
std::vector<signed char> data; std::vector<signed char> data;
SDRThreadIQData() : SDRThreadIQData() :
frequency(0), bandwidth(0) { frequency(0), sampleRate(DEFAULT_SAMPLE_RATE) {
} }
SDRThreadIQData(unsigned int bandwidth, long long frequency, std::vector<signed char> *data) : SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> *data) :
frequency(frequency), bandwidth(bandwidth) { frequency(frequency), sampleRate(bandwidth) {
} }

View File

@ -37,7 +37,7 @@ void InteractiveCanvas::setView(long long center_freq_in, int bandwidth_in) {
void InteractiveCanvas::disableView() { void InteractiveCanvas::disableView() {
isView = false; isView = false;
centerFreq = wxGetApp().getFrequency(); centerFreq = wxGetApp().getFrequency();
bandwidth = SRATE; bandwidth = wxGetApp().getSampleRate();
lastBandwidth = 0; lastBandwidth = 0;
} }
@ -69,7 +69,7 @@ unsigned int InteractiveCanvas::getBandwidth() {
if (isView) { if (isView) {
return bandwidth; return bandwidth;
} else { } else {
return SRATE; return wxGetApp().getSampleRate();
} }
} }

View File

@ -96,6 +96,9 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
if (!demod) { if (!demod) {
return; return;
} }
if (!srate) {
srate = wxGetApp().getSampleRate();
}
GLint vp[4]; GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp); glGetIntegerv( GL_VIEWPORT, vp);
@ -171,6 +174,9 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
if (!demod) { if (!demod) {
return; return;
} }
if (!srate) {
srate = wxGetApp().getSampleRate();
}
if (center_freq == -1) { if (center_freq == -1) {
center_freq = wxGetApp().getFrequency(); center_freq = wxGetApp().getFrequency();
@ -271,6 +277,10 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
bw = demod->getBandwidth(); bw = demod->getBandwidth();
} }
if (!srate) {
srate = wxGetApp().getSampleRate();
}
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);

View File

@ -23,9 +23,9 @@ public:
void BeginDraw(); void BeginDraw();
void EndDraw(); void EndDraw();
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0, long long center_freq = -1, long long srate = SRATE); void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0, long long center_freq = -1, long long srate = 0);
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = SRATE); void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = 0);
void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = SRATE); void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = 0);
static GLFont &getFont(GLFontSize esize); static GLFont &getFont(GLFontSize esize);

View File

@ -196,16 +196,16 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) {
long long bwOfs = (centerFreq > freq) ? ((long long) bandwidth / 2) : (-(long long) bandwidth / 2); long long bwOfs = (centerFreq > freq) ? ((long long) bandwidth / 2) : (-(long long) bandwidth / 2);
long long freqEdge = centerFreq + bwOfs; long long freqEdge = centerFreq + bwOfs;
if (abs(freq - freqEdge) > (SRATE / 2)) { if (abs(freq - freqEdge) > (wxGetApp().getSampleRate() / 2)) {
freqChange = -((centerFreq > freq) ? (freqEdge - freq - (SRATE / 2)) : (freqEdge - freq + (SRATE / 2))); freqChange = -((centerFreq > freq) ? (freqEdge - freq - (wxGetApp().getSampleRate() / 2)) : (freqEdge - freq + (wxGetApp().getSampleRate() / 2)));
} else { } else {
freqChange = 0; freqChange = 0;
} }
} }
if (freqChange) { if (freqChange) {
if (freq - freqChange < SRATE/2) { if (freq - freqChange < wxGetApp().getSampleRate()/2) {
freq = SRATE/2; freq = wxGetApp().getSampleRate()/2;
} else { } else {
freq -= freqChange; freq -= freqChange;
} }

View File

@ -67,7 +67,7 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) {
dragAccum += mouseTracker.getMouseX() - mouseTracker.getOriginMouseX(); dragAccum += mouseTracker.getMouseX() - mouseTracker.getOriginMouseX();
if (uxDown > 0.275) { if (uxDown > 0.275) {
wxGetApp().setFrequency(wxGetApp().getFrequency() + (int) (mouseTracker.getOriginDeltaMouseX() * SRATE * 15.0)); wxGetApp().setFrequency(wxGetApp().getFrequency() + (int) (mouseTracker.getOriginDeltaMouseX() * (float)wxGetApp().getSampleRate() * 15.0));
} }
if (abs(dragAccum * 10.0) >= 1) { if (abs(dragAccum * 10.0) >= 1) {

View File

@ -214,7 +214,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
freq = wxGetApp().getFrequency(); freq = wxGetApp().getFrequency();
originalFreq = freq; originalFreq = freq;
if (shiftDown) { if (shiftDown) {
freq += SRATE * 10; freq += wxGetApp().getSampleRate() * 10;
if (isView) { if (isView) {
setView(centerFreq + (freq - originalFreq), getBandwidth()); setView(centerFreq + (freq - originalFreq), getBandwidth());
if (spectrumCanvas) { if (spectrumCanvas) {
@ -222,7 +222,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
} }
} }
} else { } else {
freq += SRATE / 2; freq += wxGetApp().getSampleRate() / 2;
if (isView) { if (isView) {
setView(centerFreq + (freq - originalFreq), getBandwidth()); setView(centerFreq + (freq - originalFreq), getBandwidth());
if (spectrumCanvas) { if (spectrumCanvas) {
@ -237,10 +237,10 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
freq = wxGetApp().getFrequency(); freq = wxGetApp().getFrequency();
originalFreq = freq; originalFreq = freq;
if (shiftDown) { if (shiftDown) {
if ((freq - SRATE * 10) < SRATE / 2) { if ((freq - wxGetApp().getSampleRate() * 10) < wxGetApp().getSampleRate() / 2) {
freq = SRATE / 2; freq = wxGetApp().getSampleRate() / 2;
} else { } else {
freq -= SRATE * 10; freq -= wxGetApp().getSampleRate() * 10;
} }
if (isView) { if (isView) {
setView(centerFreq + (freq - originalFreq), getBandwidth()); setView(centerFreq + (freq - originalFreq), getBandwidth());
@ -249,10 +249,10 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
} }
} }
} else { } else {
if ((freq - SRATE / 2) < SRATE / 2) { if ((freq - wxGetApp().getSampleRate() / 2) < wxGetApp().getSampleRate() / 2) {
freq = SRATE / 2; freq = wxGetApp().getSampleRate() / 2;
} else { } else {
freq -= SRATE / 2; freq -= wxGetApp().getSampleRate() / 2;
} }
if (isView) { if (isView) {
setView(centerFreq + (freq - originalFreq), getBandwidth()); setView(centerFreq + (freq - originalFreq), getBandwidth());
@ -339,8 +339,8 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
if (isView) { if (isView) {
bw = getBandwidth(); bw = getBandwidth();
bw = (long long) ceil((long double) bw * currentZoom); bw = (long long) ceil((long double) bw * currentZoom);
if (bw >= SRATE) { if (bw >= wxGetApp().getSampleRate()) {
bw = SRATE; bw = wxGetApp().getSampleRate();
disableView(); disableView();
if (spectrumCanvas) { if (spectrumCanvas) {
spectrumCanvas->disableView(); spectrumCanvas->disableView();
@ -361,11 +361,11 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
} }
} }
} }
if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - SRATE / 2)) { if (centerFreq < freq && (centerFreq - bandwidth / 2) < (freq - wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq - SRATE / 2) + bandwidth / 2; centerFreq = (freq - wxGetApp().getSampleRate() / 2) + bandwidth / 2;
} }
if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + SRATE / 2)) { if (centerFreq > freq && (centerFreq + bandwidth / 2) > (freq + wxGetApp().getSampleRate() / 2)) {
centerFreq = (freq + SRATE / 2) - bandwidth / 2; centerFreq = (freq + wxGetApp().getSampleRate() / 2) - bandwidth / 2;
} }
} }
@ -385,16 +385,16 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
} }
if (isView) { if (isView) {
if (!input->frequency || !input->bandwidth) { if (!input->frequency || !input->sampleRate) {
return; return;
} }
if (centerFreq != input->frequency) { if (centerFreq != input->frequency) {
if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->bandwidth) { if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->sampleRate) {
if (abs(input->frequency - centerFreq) < (SRATE / 2)) { if (abs(input->frequency - centerFreq) < (wxGetApp().getSampleRate() / 2)) {
shiftFrequency = centerFreq - input->frequency; shiftFrequency = centerFreq - input->frequency;
nco_crcf_reset(freqShifter); nco_crcf_reset(freqShifter);
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->bandwidth))); nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->sampleRate)));
} }
} }
@ -414,8 +414,8 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
shiftBuffer.assign(input->data.begin(), input->data.end()); shiftBuffer.assign(input->data.begin(), input->data.end());
} }
if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != input->bandwidth) { if (!resampler || bandwidth != lastBandwidth || lastInputBandwidth != input->sampleRate) {
resamplerRatio = (double) (bandwidth) / (double) input->bandwidth; resamplerRatio = (double) (bandwidth) / (double) input->sampleRate;
float As = 120.0f; float As = 120.0f;
@ -425,7 +425,7 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
resampler = msresamp_crcf_create(resamplerRatio, As); resampler = msresamp_crcf_create(resamplerRatio, As);
lastBandwidth = bandwidth; lastBandwidth = bandwidth;
lastInputBandwidth = input->bandwidth; lastInputBandwidth = input->sampleRate;
} }
int out_size = ceil((double) (input->data.size()) * resamplerRatio) + 512; int out_size = ceil((double) (input->data.size()) * resamplerRatio) + 512;
@ -562,8 +562,8 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) {
int currentBW = demod->getBandwidth(); int currentBW = demod->getBandwidth();
currentBW = currentBW + bwDiff; currentBW = currentBW + bwDiff;
if (currentBW > SRATE) { if (currentBW > wxGetApp().getSampleRate()) {
currentBW = SRATE; currentBW = wxGetApp().getSampleRate();
} }
if (currentBW < MIN_BANDWIDTH) { if (currentBW < MIN_BANDWIDTH) {
currentBW = MIN_BANDWIDTH; currentBW = MIN_BANDWIDTH;