cleanup / refactor / profiled

This commit is contained in:
Charles J. Cliffe 2014-12-23 01:12:14 -05:00
parent 703501f32d
commit 8ce3065bce
13 changed files with 50 additions and 74 deletions

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

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) {
}
@ -66,13 +66,6 @@ public:
}
DemodulatorThreadIQData(const DemodulatorThreadIQData& o) {
frequency = o.frequency;
bandwidth = o.bandwidth;
data = o.data;
refCount.store(o.refCount.load());
}
void setRefCount(int rc) {
refCount.store(rc);
}
@ -95,24 +88,16 @@ private:
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() {
}
@ -128,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) {
}
@ -145,7 +129,7 @@ public:
};
typedef ThreadQueue<DemodulatorThreadIQData *> DemodulatorThreadInputQueue;
typedef ThreadQueue<DemodulatorThreadPostIQData> DemodulatorThreadPostInputQueue;
typedef ThreadQueue<DemodulatorThreadPostIQData *> DemodulatorThreadPostInputQueue;
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;

View File

@ -184,17 +184,15 @@ 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->decRefCount();

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);
@ -136,7 +132,7 @@ void DemodulatorThread::threadMain() {
}
}
delete inp.data;
delete inp;
}
if (resampler != NULL) {
@ -156,6 +152,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

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

View File

@ -145,6 +145,8 @@ void SDRThread::threadMain() {
freq_changed = true;
new_freq = command.int_value;
break;
default:
break;
}
}

View File

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

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;