Merge branch 'thread-data-optimization' of https://github.com/cjcliffe/CubicSDR into thread-data-optimization

This commit is contained in:
Charles J. Cliffe 2014-12-23 02:01:46 -05:00
commit 3f00148de8
17 changed files with 212 additions and 217 deletions

View File

@ -96,14 +96,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
// std::this_thread::yield();
//#endif
if (!wxGetApp().getIQVisualQueue()->empty()) {
SDRThreadIQData iqData;
SDRThreadIQData *iqData;
wxGetApp().getIQVisualQueue()->pop(iqData);
if (iqData.data && iqData.data->size()) {
spectrumCanvas->setData(iqData.data);
waterfallCanvas->setData(iqData.data);
if (iqData && iqData->data.size()) {
spectrumCanvas->setData(&iqData->data);
waterfallCanvas->setData(&iqData->data);
delete iqData.data;
delete iqData;
} else {
std::cout << "Incoming IQ data empty?" << std::endl;
}
@ -111,20 +111,19 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
}
if (!wxGetApp().getAudioVisualQueue()->empty()) {
AudioThreadInput demodAudioData;
AudioThreadInput *demodAudioData;
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
if (demodAudioData.data && demodAudioData.data->size()) {
if (scopeCanvas->waveform_points.size() != demodAudioData.data->size()*2) {
scopeCanvas->waveform_points.resize(demodAudioData.data->size()*2);
if (demodAudioData && demodAudioData->data.size()) {
if (scopeCanvas->waveform_points.size() != demodAudioData->data.size()*2) {
scopeCanvas->waveform_points.resize(demodAudioData->data.size()*2);
}
for (int i = 0, iMax = demodAudioData.data->size(); i < iMax; i++) {
scopeCanvas->waveform_points[i * 2 + 1] = (*demodAudioData.data)[i] * 0.5f;
for (int i = 0, iMax = demodAudioData->data.size(); i < iMax; i++) {
scopeCanvas->waveform_points[i * 2 + 1] = demodAudioData->data[i] * 0.5f;
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
}
delete demodAudioData.data;
delete demodAudioData;
} else {
std::cout << "Incoming Demodulator data empty?" << std::endl;
}

View File

@ -20,8 +20,7 @@
class CubicSDR: public wxApp {
public:
CubicSDR() :
m_glContext(NULL), t_PostSDR(NULL), t_SDR(NULL), audioVisualQueue(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), frequency(
DEFAULT_FREQ), sdrPostThread(NULL), iqPostDataQueue(NULL), sdrThread(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) {
}

View File

@ -10,8 +10,7 @@ std::map<int, std::thread *> AudioThread::deviceThread;
#endif
AudioThread::AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify) :
inputQueue(inputQueue), terminated(false), audio_queue_ptr(0), underflow_count(0), threadQueueNotify(threadQueueNotify), gain(1.0), active(
false) {
inputQueue(inputQueue), audio_queue_ptr(0), underflow_count(0), terminated(false), active(false), gain(1.0), threadQueueNotify(threadQueueNotify) {
#ifdef __APPLE__
boundThreads = new std::vector<AudioThread *>;
#endif
@ -65,44 +64,65 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
continue;
}
if (srcmix->currentInput.channels == 0 || !srcmix->currentInput.data) {
if (!srcmix->currentInput) {
if (srcmix->terminated) {
continue;
}
srcmix->inputQueue->pop(srcmix->currentInput);
srcmix->audio_queue_ptr = 0;
continue;
}
if (srcmix->currentInput->channels == 0 || !srcmix->currentInput->data.size()) {
if (!srcmix->inputQueue->empty()) {
if (srcmix->currentInput.data) {
delete srcmix->currentInput.data;
if (srcmix->currentInput) {
delete srcmix->currentInput;
srcmix->currentInput = NULL;
}
if (srcmix->terminated) {
continue;
}
srcmix->inputQueue->pop(srcmix->currentInput);
srcmix->audio_queue_ptr = 0;
}
return 0;
continue;
}
if (srcmix->currentInput.channels == 1) {
if (srcmix->currentInput->channels == 1) {
for (int i = 0; i < nBufferFrames; i++) {
if (srcmix->audio_queue_ptr >= srcmix->currentInput.data->size()) {
if (srcmix->currentInput.data) {
delete srcmix->currentInput.data;
if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) {
if (srcmix->currentInput) {
delete srcmix->currentInput;
srcmix->currentInput = NULL;
}
if (srcmix->terminated) {
continue;
}
srcmix->inputQueue->pop(srcmix->currentInput);
srcmix->audio_queue_ptr = 0;
}
if (srcmix->currentInput.data && srcmix->currentInput.data->size()) {
float v = (*srcmix->currentInput.data)[srcmix->audio_queue_ptr] * src->gain;
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
float v = srcmix->currentInput->data[srcmix->audio_queue_ptr] * src->gain;
out[i * 2] += v;
out[i * 2 + 1] += v;
}
srcmix->audio_queue_ptr++;
}
} else {
for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) {
if (srcmix->audio_queue_ptr >= srcmix->currentInput.data.size()) {
if (srcmix->currentInput.data) {
delete srcmix->currentInput.data;
for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) {
if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) {
if (srcmix->currentInput) {
delete srcmix->currentInput;
srcmix->currentInput = NULL;
}
if (srcmix->terminated) {
continue;
}
srcmix->inputQueue->pop(srcmix->currentInput);
srcmix->audio_queue_ptr = 0;
}
if (srcmix->currentInput.data && srcmix->currentInput.data->size()) {
out[i] = out[i] + (*srcmix->currentInput.data)[srcmix->audio_queue_ptr] * src->gain;
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
out[i] = out[i] + srcmix->currentInput->data[srcmix->audio_queue_ptr] * src->gain;
}
srcmix->audio_queue_ptr++;
}
@ -123,11 +143,21 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
if (status) {
std::cout << "Audio buffer underflow.." << (src->underflow_count++) << std::endl;
}
if (!src->currentInput) {
src->inputQueue->pop(src->currentInput);
src->audio_queue_ptr = 0;
return 0;
}
if (src->currentInput.channels == 0 || !src->currentInput.data) {
if (src->currentInput->channels == 0 || !src->currentInput->data.size()) {
if (!src->inputQueue->empty()) {
if (src->currentInput.data) {
delete src->currentInput.data;
if (src->currentInput) {
delete src->currentInput;
src->currentInput = NULL;
}
if (src->terminated) {
return 1;
}
src->inputQueue->pop(src->currentInput);
src->audio_queue_ptr = 0;
@ -135,34 +165,35 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
return 0;
}
if (src->currentInput.channels == 1) {
if (src->currentInput->channels == 1) {
for (int i = 0; i < nBufferFrames; i++) {
if (src->audio_queue_ptr >= src->currentInput.data->size()) {
if (src->currentInput.data) {
delete src->currentInput.data;
if (src->audio_queue_ptr >= src->currentInput->data.size()) {
if (src->currentInput) {
delete src->currentInput;
src->currentInput = NULL;
}
if (src->terminated) {
break;
return 1;
}
src->inputQueue->pop(src->currentInput);
src->audio_queue_ptr = 0;
}
if (src->currentInput.data && src->currentInput.data->size()) {
out[i * 2] = out[i * 2 + 1] = (*src->currentInput.data)[src->audio_queue_ptr] * src->gain;
if (src->currentInput && src->currentInput->data.size()) {
out[i * 2] = out[i * 2 + 1] = src->currentInput->data[src->audio_queue_ptr] * src->gain;
}
src->audio_queue_ptr++;
}
} else {
for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) {
if (src->audio_queue_ptr >= src->currentInput.data->size()) {
for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) {
if (src->audio_queue_ptr >= src->currentInput->data.size()) {
if (src->terminated) {
break;
return 1;
}
src->inputQueue->pop(src->currentInput);
src->audio_queue_ptr = 0;
}
if (src->currentInput.data && src->currentInput.data->size()) {
out[i] = (*src->currentInput.data)[src->audio_queue_ptr] * src->gain;
if (src->currentInput && src->currentInput->data.size()) {
out[i] = src->currentInput->data[src->audio_queue_ptr] * src->gain;
}
src->audio_queue_ptr++;
}
@ -322,12 +353,12 @@ bool AudioThread::isActive() {
void AudioThread::setActive(bool state) {
#ifdef __APPLE__
AudioThreadInput dummy;
AudioThreadInput *dummy;
if (state && !active) {
while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy);
if (dummy.data) {
delete dummy.data;
if (dummy) {
delete dummy;
}
}
deviceController[parameters.deviceId]->bindThread(this);
@ -335,8 +366,8 @@ void AudioThread::setActive(bool state) {
deviceController[parameters.deviceId]->removeThread(this);
while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy);
if (dummy.data) {
delete dummy.data;
if (dummy) {
delete dummy;
}
}
}

View File

@ -24,7 +24,7 @@ public:
int sampleRate;
int channels;
AudioThreadInput(): frequency(0), sampleRate(0), channels(0), data(NULL) {
AudioThreadInput(): frequency(0), sampleRate(0), channels(0) {
}
@ -32,7 +32,7 @@ public:
}
std::vector<float> *data;
std::vector<float> data;
};
class AudioThreadCommand {
@ -49,13 +49,13 @@ public:
int int_value;
};
typedef ThreadQueue<AudioThreadInput> AudioThreadInputQueue;
typedef ThreadQueue<AudioThreadInput *> AudioThreadInputQueue;
typedef ThreadQueue<AudioThreadCommand> AudioThreadCommandQueue;
class AudioThread {
public:
AudioThreadInput currentInput;
AudioThreadInput *currentInput;
AudioThreadInputQueue *inputQueue;
std::atomic<unsigned int> audio_queue_ptr;
std::atomic<unsigned int> underflow_count;

View File

@ -26,12 +26,12 @@ public:
};
DemodulatorThreadCommand() :
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
cmd(DEMOD_THREAD_CMD_NULL), context(NULL), int_value(0) {
}
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
cmd(cmd), int_value(0), context(NULL) {
cmd(cmd), context(NULL), int_value(0) {
}
@ -59,62 +59,45 @@ class DemodulatorThreadIQData {
public:
unsigned int frequency;
unsigned int bandwidth;
std::vector<signed char> *data;
std::atomic<int> *refCount;
std::vector<signed char> data;
DemodulatorThreadIQData() :
frequency(0), bandwidth(0), data(NULL), refCount(NULL) {
frequency(0), bandwidth(0), refCount(0) {
}
DemodulatorThreadIQData(const DemodulatorThreadIQData& o) {
frequency = o.frequency;
bandwidth = o.bandwidth;
data = o.data;
refCount = o.refCount;
}
void setRefCount(std::atomic<int> *rc) {
refCount = rc;
void setRefCount(int rc) {
refCount.store(rc);
}
void cleanup() {
if (refCount) {
refCount->store(refCount->load()-1);
if (refCount->load() == 0) {
delete data;
data = NULL;
delete refCount;
refCount = NULL;
}
}
void decRefCount() {
refCount.store(refCount.load()-1);
}
int getRefCount() {
return refCount.load();
}
~DemodulatorThreadIQData() {
}
private:
std::atomic<int> refCount;
};
class DemodulatorThreadPostIQData {
public:
std::vector<liquid_float_complex> *data;
std::vector<liquid_float_complex> data;
float audio_resample_ratio;
msresamp_rrrf audio_resampler;
float resample_ratio;
msresamp_crcf resampler;
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL), data(NULL) {
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) {
}
DemodulatorThreadPostIQData(const DemodulatorThreadPostIQData &o) {
audio_resample_ratio = o.audio_resample_ratio;
audio_resampler = o.audio_resampler;
resample_ratio = o.resample_ratio;
resampler = o.resampler;
data = o.data;
}
~DemodulatorThreadPostIQData() {
}
@ -130,14 +113,13 @@ public:
std::vector<float> *data;
DemodulatorThreadAudioData() :
sampleRate(0), frequency(0), channels(0), data(NULL) {
frequency(0), sampleRate(0), channels(0), data(NULL) {
}
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate,
std::vector<float> *data) :
data(data), sampleRate(sampleRate), frequency(frequency), channels(
1) {
frequency(frequency), sampleRate(sampleRate), channels(1), data(data) {
}
@ -146,8 +128,8 @@ public:
}
};
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
typedef ThreadQueue<DemodulatorThreadPostIQData> DemodulatorThreadPostInputQueue;
typedef ThreadQueue<DemodulatorThreadIQData *> DemodulatorThreadInputQueue;
typedef ThreadQueue<DemodulatorThreadPostIQData *> DemodulatorThreadPostInputQueue;
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;

View File

@ -100,7 +100,7 @@ void DemodulatorPreThread::threadMain() {
std::cout << "Demodulator preprocessor thread started.." << std::endl;
while (!terminated) {
DemodulatorThreadIQData inp;
DemodulatorThreadIQData *inp;
inputQueue->pop(inp);
bool bandwidthChanged = false;
@ -144,9 +144,9 @@ void DemodulatorPreThread::threadMain() {
}
// Requested frequency is not center, shift it into the center!
if (inp.frequency != params.frequency) {
if ((params.frequency - inp.frequency) != shift_freq) {
shift_freq = params.frequency - inp.frequency;
if (inp->frequency != params.frequency) {
if ((params.frequency - inp->frequency) != shift_freq) {
shift_freq = params.frequency - inp->frequency;
if (abs(shift_freq) <= (int) ((float) (SRATE / 2) * 1.5)) {
nco_crcf_set_frequency(nco_shift, (2.0 * M_PI) * (((float) abs(shift_freq)) / ((float) SRATE)));
}
@ -157,8 +157,8 @@ void DemodulatorPreThread::threadMain() {
continue;
}
std::vector<signed char> *data = inp.data;
if (data && data->size()) {
std::vector<signed char> *data = &inp->data;
if (data->size()) {
int bufSize = data->size() / 2;
liquid_float_complex in_buf_data[bufSize];
@ -184,20 +184,21 @@ void DemodulatorPreThread::threadMain() {
out_buf = temp_buf;
}
DemodulatorThreadPostIQData resamp;
resamp.data = new std::vector<liquid_float_complex>;
// resamp.data->resize(bufSize);
resamp.data->assign(in_buf,in_buf+bufSize);
DemodulatorThreadPostIQData *resamp = new DemodulatorThreadPostIQData;
resamp->data.assign(in_buf,in_buf+bufSize);
// firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, &((*resamp.data)[0]));
resamp.audio_resample_ratio = audio_resample_ratio;
resamp.audio_resampler = audio_resampler;
resamp.resample_ratio = resample_ratio;
resamp.resampler = resampler;
resamp->audio_resample_ratio = audio_resample_ratio;
resamp->audio_resampler = audio_resampler;
resamp->resample_ratio = resample_ratio;
resamp->resampler = resampler;
postInputQueue->push(resamp);
inp.cleanup();
inp->decRefCount();
if (inp->getRefCount()<=0) {
delete inp;
}
}
if (!workerResults->empty()) {
@ -236,7 +237,7 @@ void DemodulatorPreThread::threadMain() {
void DemodulatorPreThread::terminate() {
terminated = true;
DemodulatorThreadIQData inp; // push dummy to nudge queue
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
inputQueue->push(inp);
workerThread->terminate();
}

View File

@ -7,7 +7,7 @@
#endif
DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) :
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), agc(NULL), squelch_enabled(false), squelch_level(0), squelch_tolerance(0) {
postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) {
float kf = 0.5; // modulation factor
fdem = freqdem_create(kf);
@ -36,40 +36,36 @@ void DemodulatorThread::threadMain() {
std::cout << "Demodulator thread started.." << std::endl;
while (!terminated) {
DemodulatorThreadPostIQData inp;
DemodulatorThreadPostIQData *inp;
postInputQueue->pop(inp);
if (!inp.data) {
continue;
}
int bufSize = inp.data->size();
int bufSize = inp->data.size();
if (!bufSize) {
delete inp.data;
delete inp;
continue;
}
if (resampler == NULL) {
resampler = inp.resampler;
audio_resampler = inp.audio_resampler;
} else if (resampler != inp.resampler) {
resampler = inp->resampler;
audio_resampler = inp->audio_resampler;
} else if (resampler != inp->resampler) {
msresamp_crcf_destroy(resampler);
msresamp_rrrf_destroy(audio_resampler);
resampler = inp.resampler;
audio_resampler = inp.audio_resampler;
resampler = inp->resampler;
audio_resampler = inp->audio_resampler;
}
int out_size = ceil((float) (bufSize) * inp.resample_ratio);
int out_size = ceil((float) (bufSize) * inp->resample_ratio);
liquid_float_complex resampled_data[out_size];
liquid_float_complex agc_data[out_size];
unsigned int num_written;
msresamp_crcf_execute(resampler, &((*inp.data)[0]), bufSize, resampled_data, &num_written);
msresamp_crcf_execute(resampler, &(inp->data[0]), bufSize, resampled_data, &num_written);
agc_crcf_execute_block(agc, resampled_data, num_written, agc_data);
float audio_resample_ratio = inp.audio_resample_ratio;
float audio_resample_ratio = inp->audio_resample_ratio;
float demod_output[num_written];
freqdem_demodulate_block(fdem, agc_data, num_written, demod_output);
@ -80,10 +76,9 @@ void DemodulatorThread::threadMain() {
unsigned int num_audio_written;
msresamp_rrrf_execute(audio_resampler, demod_output, num_written, resampled_audio_output, &num_audio_written);
AudioThreadInput ati;
ati.channels = 1;
ati.data = new std::vector<float>;
ati.data->assign(resampled_audio_output,resampled_audio_output+num_audio_written);
AudioThreadInput *ati = new AudioThreadInput;
ati->channels = 1;
ati->data.assign(resampled_audio_output,resampled_audio_output+num_audio_written);
if (audioInputQueue != NULL) {
if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) {
@ -92,22 +87,20 @@ void DemodulatorThread::threadMain() {
}
if (visOutQueue != NULL && visOutQueue->empty()) {
AudioThreadInput ati_vis;
ati_vis.channels = ati.channels;
AudioThreadInput *ati_vis = new AudioThreadInput;
ati_vis->channels = ati->channels;
int num_vis = DEMOD_VIS_SIZE;
if (num_audio_written > num_written) {
if (num_vis > num_audio_written) {
num_vis = num_audio_written;
}
ati_vis.data = new std::vector<float>;
ati_vis.data->assign(ati.data->begin(), ati.data->begin()+num_vis);
ati_vis->data.assign(ati->data.begin(), ati->data.begin()+num_vis);
} else {
if (num_vis > num_written) {
num_vis = num_written;
}
ati_vis.data = new std::vector<float>;
ati_vis.data->assign(demod_output, demod_output + num_vis);
ati_vis->data.assign(demod_output, demod_output + num_vis);
}
visOutQueue->push(ati_vis);
@ -136,7 +129,7 @@ void DemodulatorThread::threadMain() {
}
}
delete inp.data;
delete inp;
}
if (resampler != NULL) {
@ -156,6 +149,6 @@ void DemodulatorThread::threadMain() {
void DemodulatorThread::terminate() {
terminated = true;
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue
postInputQueue->push(inp);
}

View File

@ -6,7 +6,7 @@
#include "DemodDefs.h"
#include "AudioThread.h"
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
typedef ThreadQueue<AudioThreadInput *> DemodulatorThreadOutputQueue;
#define DEMOD_VIS_SIZE 2048

View File

@ -22,17 +22,19 @@ public:
};
DemodulatorWorkerThreadResult() :
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), audioSampleRate(0), bandwidth(0), inputRate(0), fir_filter(NULL), resampler(NULL), resample_ratio(
0), audio_resampler(NULL), audio_resample_ratio(0) {
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio(
0), audio_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth(0), audioSampleRate(0) {
}
DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) :
cmd(cmd), audioSampleRate(0), bandwidth(0), inputRate(0), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(
0) {
cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(
0), inputRate(0), bandwidth(0), audioSampleRate(0) {
}
DemodulatorThreadResultEnum cmd;
firfilt_crcf fir_filter;
msresamp_crcf resampler;
float resample_ratio;
@ -43,7 +45,6 @@ public:
unsigned int bandwidth;
unsigned int audioSampleRate;
DemodulatorThreadResultEnum cmd;
};
class DemodulatorWorkerThreadCommand {
@ -62,12 +63,12 @@ public:
}
DemodulatorThreadCommandEnum cmd;
unsigned int frequency;
unsigned int inputRate;
unsigned int bandwidth;
unsigned int audioSampleRate;
DemodulatorThreadCommandEnum cmd;
};
typedef ThreadQueue<DemodulatorWorkerThreadCommand> DemodulatorThreadWorkerCommandQueue;

View File

@ -4,7 +4,7 @@
#include "CubicSDR.h"
SDRPostThread::SDRPostThread() :
iqDataInQueue(NULL), iqDataOutQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL), sample_rate(SRATE) {
sample_rate(SRATE), iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL) {
}
SDRPostThread::~SDRPostThread() {
@ -39,7 +39,7 @@ void SDRPostThread::threadMain() {
#ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread
int priority = sched_get_priority_max( SCHED_FIFO) - 1;
sched_param prio = {priority}; // scheduling priority of thread
sched_param prio = { priority }; // scheduling priority of thread
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
@ -50,25 +50,25 @@ void SDRPostThread::threadMain() {
std::cout << "SDR post-processing thread started.." << std::endl;
while (!terminated) {
SDRThreadIQData data_in;
SDRThreadIQData *data_in;
iqDataInQueue.load()->pop(data_in);
if (data_in.data && data_in.data->size()) {
SDRThreadIQData dataOut;
if (data_in && data_in->data.size()) {
SDRThreadIQData *dataOut = new SDRThreadIQData;
dataOut.frequency = data_in.frequency;
dataOut.bandwidth = data_in.bandwidth;
dataOut.data = data_in.data;
dataOut->frequency = data_in->frequency;
dataOut->bandwidth = data_in->bandwidth;
dataOut->data.assign(data_in->data.begin(), data_in->data.end());
for (int i = 0, iMax = dataOut.data->size() / 2; i < iMax; i++) {
x.real = (float) (*dataOut.data)[i * 2] / 127.0;
x.imag = (float) (*dataOut.data)[i * 2 + 1] / 127.0;
for (int i = 0, iMax = dataOut->data.size() / 2; i < iMax; i++) {
x.real = (float) dataOut->data[i * 2] / 127.0;
x.imag = (float) dataOut->data[i * 2 + 1] / 127.0;
iirfilt_crcf_execute(dcFilter, x, &y);
(*dataOut.data)[i * 2] = (signed char) floor(y.real * 127.0);
(*dataOut.data)[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
dataOut->data[i * 2] = (signed char) floor(y.real * 127.0);
dataOut->data[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
}
if (iqDataOutQueue != NULL) {
@ -76,13 +76,11 @@ void SDRPostThread::threadMain() {
}
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
SDRThreadIQData visualDataOut;
visualDataOut.data = new std::vector<signed char>;
visualDataOut.data->assign(dataOut.data->begin(), dataOut.data->begin() + (FFT_SIZE * 2));
SDRThreadIQData *visualDataOut = new SDRThreadIQData;
visualDataOut->data.assign(dataOut->data.begin(), dataOut->data.begin() + (FFT_SIZE * 2));
iqVisualQueue.load()->push(visualDataOut);
}
if (demodulators_add.size()) {
while (!demodulators_add.empty()) {
demodulators.push_back(demodulators_add.back());
@ -104,7 +102,6 @@ void SDRPostThread::threadMain() {
int activeDemods = 0;
bool pushedData = false;
std::atomic<int> *c = new std::atomic<int>;
if (demodulators.size()) {
@ -112,37 +109,32 @@ void SDRPostThread::threadMain() {
for (i = demodulators.begin(); i != demodulators.end(); i++) {
DemodulatorInstance *demod = *i;
if (demod->getParams().frequency != data_in.frequency
&& abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
if (demod->getParams().frequency != data_in->frequency
&& abs(data_in->frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
continue;
}
activeDemods++;
}
c->store(activeDemods);
bool demodActive = false;
if (demodulators.size()) {
DemodulatorThreadIQData dummyDataOut;
dummyDataOut.frequency = data_in.frequency;
dummyDataOut.bandwidth = data_in.bandwidth;
dummyDataOut.data = NULL;
DemodulatorThreadIQData demodDataOut;
demodDataOut.frequency = data_in.frequency;
demodDataOut.bandwidth = data_in.bandwidth;
demodDataOut.setRefCount(c);
demodDataOut.data = data_in.data;
DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
demodDataOut->frequency = data_in->frequency;
demodDataOut->bandwidth = data_in->bandwidth;
demodDataOut->setRefCount(activeDemods);
demodDataOut->data.assign(dataOut->data.begin(), dataOut->data.begin() + dataOut->data.size());
std::vector<DemodulatorInstance *>::iterator i;
for (i = demodulators.begin(); i != demodulators.end(); i++) {
DemodulatorInstance *demod = *i;
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
if (demod->getParams().frequency != data_in.frequency
&& abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
if (demod->getParams().frequency != data_in->frequency
&& abs(data_in->frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
if (demod->isActive()) {
demod->setActive(false);
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
dummyDataOut->frequency = data_in->frequency;
dummyDataOut->bandwidth = data_in->bandwidth;
demodQueue->push(dummyDataOut);
}
} else if (!demod->isActive()) {
@ -156,22 +148,23 @@ void SDRPostThread::threadMain() {
demodQueue->push(demodDataOut);
pushedData = true;
}
if (!pushedData) {
delete demodDataOut;
}
}
}
if (!pushedData) {
delete dataOut.data;
delete c;
}
delete dataOut;
}
if (data_in) {
delete data_in;
}
}
std::cout << "SDR post-processing thread done." << std::endl;
}
void SDRPostThread::terminate() {
terminated = true;
SDRThreadIQData dummy;
SDRThreadIQData *dummy = new SDRThreadIQData;
iqDataInQueue.load()->push(dummy);
}

View File

@ -13,7 +13,7 @@ public:
void setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue);
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue);
void setIQVisualQueue(SDRThreadIQDataQueue *iqVisQueue);
void setIQVisualQueue(SDRThreadIQDataQueue* iqVisQueue);
void threadMain();
void terminate();
@ -21,9 +21,9 @@ public:
protected:
uint32_t sample_rate;
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
std::atomic<SDRThreadIQDataQueue*> iqDataInQueue;
std::atomic<SDRThreadIQDataQueue*> iqVisualQueue;
std::atomic<SDRThreadIQDataQueue *> iqDataOutQueue;
std::atomic<SDRThreadIQDataQueue *> iqDataInQueue;
std::atomic<SDRThreadIQDataQueue *> iqVisualQueue;
std::vector<DemodulatorInstance *> demodulators;
std::vector<DemodulatorInstance *> demodulators_add;

View File

@ -145,6 +145,8 @@ void SDRThread::threadMain() {
freq_changed = true;
new_freq = command.int_value;
break;
default:
break;
}
}
@ -156,20 +158,17 @@ void SDRThread::threadMain() {
rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read);
std::vector<signed char> *new_buffer = new std::vector<signed char>;
SDRThreadIQData *dataOut = new SDRThreadIQData;
dataOut->frequency = frequency;
dataOut->bandwidth = bandwidth;
for (int i = 0; i < n_read; i++) {
new_buffer->push_back(buf[i] - 127);
dataOut->data.push_back(buf[i] - 127);
}
double time_slice = (double) n_read / (double) sample_rate;
seconds += time_slice;
SDRThreadIQData dataOut;
dataOut.frequency = frequency;
dataOut.bandwidth = bandwidth;
dataOut.data = new_buffer;
if (iqDataOutQueue != NULL) {
iqDataOutQueue.load()->push(dataOut);
}

View File

@ -38,7 +38,7 @@ class SDRThreadIQData {
public:
unsigned int frequency;
unsigned int bandwidth;
std::vector<signed char> *data;
std::vector<signed char> data;
SDRThreadIQData() :
frequency(0), bandwidth(0), data(NULL) {
@ -46,7 +46,7 @@ public:
}
SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> *data) :
data(data), frequency(frequency), bandwidth(bandwidth) {
frequency(frequency), bandwidth(bandwidth) {
}
@ -56,7 +56,7 @@ public:
};
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
typedef ThreadQueue<SDRThreadIQData> SDRThreadIQDataQueue;
typedef ThreadQueue<SDRThreadIQData *> SDRThreadIQDataQueue;
class SDRThread {
public:

View File

@ -5,7 +5,7 @@
#include <algorithm>
GLFontChar::GLFontChar() :
id(0), x(0), y(0), width(0), height(0), xadvance(0), xoffset(0), yoffset(0), index(0), aspect(1) {
id(0), x(0), y(0), width(0), height(0), xoffset(0), yoffset(0), xadvance(0), aspect(1), index(0) {
}
@ -96,7 +96,7 @@ int GLFontChar::getIndex() {
}
GLFont::GLFont() :
numCharacters(0), imageHeight(0), imageWidth(0), base(0), lineHeight(0), texId(0), loaded(false) {
numCharacters(0), lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0) {
}
@ -289,7 +289,7 @@ void GLFont::loadFont(std::string fontFile) {
unsigned int ofs = 0;
for (char_i = characters.begin(); char_i != characters.end(); char_i++) {
int charId = (*char_i).first;
// int charId = (*char_i).first;
GLFontChar *fchar = (*char_i).second;
float faspect = fchar->getAspect();

View File

@ -5,14 +5,12 @@
class MouseTracker {
public:
MouseTracker(wxWindow *target) :
target(target), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown(
false), vertDragLock(false), horizDragLock(false), isMouseInView(false) {
mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), vertDragLock(false), horizDragLock(false), isMouseDown(false), isMouseInView(false), target(target) {
}
MouseTracker() :
target(NULL), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown(
false), vertDragLock(false), horizDragLock(false), isMouseInView(false) {
mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), vertDragLock(false), horizDragLock(false), isMouseDown(false), isMouseInView(false), target(NULL) {
}
@ -43,10 +41,10 @@ public:
private:
float mouseX, mouseY;
float lastMouseX, lastMouseY;
float deltaMouseX, deltaMouseY;
float originMouseX, originMouseY;
float deltaMouseX, deltaMouseY;
bool isMouseDown, isMouseInView;
bool vertDragLock, horizDragLock;
bool isMouseDown, isMouseInView;
wxWindow *target;
};

View File

@ -5,7 +5,7 @@
#include <mmsystem.h>
#endif
Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), paused_time(0), offset(0), paused_state(false), num_updates(0), lock_state(0), lock_rate(0)
Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), num_updates(0), paused_time(0), offset(0), paused_state(false), lock_state(0), lock_rate(0)
{
}

View File

@ -30,8 +30,7 @@ wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), shiftDown(
false), altDown(false), ctrlDown(false), activeDemodulatorBandwidth(0), activeDemodulatorFrequency(0) {
wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), activeDemodulatorBandwidth(0), activeDemodulatorFrequency(0), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), shiftDown(false), altDown(false), ctrlDown(false) {
int in_block_size = FFT_SIZE;
int out_block_size = FFT_SIZE;