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"));
menu = new wxMenu;
menu->Append(wxID_THEME_DEFAULT, "Default");
@ -171,6 +170,16 @@ AppFrame::AppFrame() :
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);
@ -262,6 +271,27 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
waterfallCanvas->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)) {
@ -307,8 +337,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
}
unsigned int demodBw = (unsigned int) ceil((float) demod->getParams().bandwidth * 2.5);
if (demodBw > SRATE / 2) {
demodBw = SRATE / 2;
if (demodBw > wxGetApp().getSampleRate() / 2) {
demodBw = wxGetApp().getSampleRate() / 2;
}
if (demodBw < 80000) {
demodBw = 80000;
@ -399,9 +429,8 @@ void AppFrame::saveSession(std::string fileName) {
s.SaveToFileXML(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()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));
}
@ -494,7 +523,7 @@ bool AppFrame::loadSession(std::string 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()));
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_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
class AppFrame: public wxFrame {
public:
@ -59,6 +66,9 @@ private:
std::map<int,RtAudio::DeviceInfo> outputDevices;
std::map<int,wxMenuItem *> outputDeviceMenuItems;
std::map<int,wxMenuItem *> sampleRateMenuItems;
std::string currentSessionFile;
wxDECLARE_EVENT_TABLE();

View File

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

View File

@ -20,7 +20,7 @@
class CubicSDR: public wxApp {
public:
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);
long long getOffset();
void setSampleRate(long long rate_in);
long long getSampleRate();
DemodulatorThreadOutputQueue* getAudioVisualQueue();
DemodulatorThreadInputQueue* getIQVisualQueue();
DemodulatorMgr &getDemodMgr();
@ -49,6 +52,7 @@ private:
long long frequency;
long long offset;
long long sampleRate;
SDRThread *sdrThread;
SDRPostThread *sdrPostThread;

View File

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

View File

@ -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) {
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
};

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@
class SDRThreadCommand {
public:
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() :
@ -37,16 +37,16 @@ public:
class SDRThreadIQData: public ReferenceCounter {
public:
long long frequency;
unsigned int bandwidth;
long long sampleRate;
std::vector<signed char> data;
SDRThreadIQData() :
frequency(0), bandwidth(0) {
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE) {
}
SDRThreadIQData(unsigned int bandwidth, long long frequency, std::vector<signed char> *data) :
frequency(frequency), bandwidth(bandwidth) {
SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> *data) :
frequency(frequency), sampleRate(bandwidth) {
}

View File

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

View File

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

View File

@ -23,9 +23,9 @@ public:
void BeginDraw();
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 DrawDemod(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 = 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 = 0);
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);

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 freqEdge = centerFreq + bwOfs;
if (abs(freq - freqEdge) > (SRATE / 2)) {
freqChange = -((centerFreq > freq) ? (freqEdge - freq - (SRATE / 2)) : (freqEdge - freq + (SRATE / 2)));
if (abs(freq - freqEdge) > (wxGetApp().getSampleRate() / 2)) {
freqChange = -((centerFreq > freq) ? (freqEdge - freq - (wxGetApp().getSampleRate() / 2)) : (freqEdge - freq + (wxGetApp().getSampleRate() / 2)));
} else {
freqChange = 0;
}
}
if (freqChange) {
if (freq - freqChange < SRATE/2) {
freq = SRATE/2;
if (freq - freqChange < wxGetApp().getSampleRate()/2) {
freq = wxGetApp().getSampleRate()/2;
} else {
freq -= freqChange;
}

View File

@ -67,7 +67,7 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) {
dragAccum += mouseTracker.getMouseX() - mouseTracker.getOriginMouseX();
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) {

View File

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