mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-02-03 09:44:26 -05:00
Cleanup, reformat
This commit is contained in:
parent
a78651687a
commit
9e32ef478d
@ -61,9 +61,7 @@ AppFrame::AppFrame() :
|
|||||||
Centre();
|
Centre();
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
|
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), DEFAULT_FREQ));
|
||||||
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"),DEFAULT_FREQ));
|
|
||||||
|
|
||||||
|
|
||||||
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
||||||
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
||||||
@ -119,8 +117,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
|||||||
scopeCanvas->waveform_points.resize(demodAudioData.data.size());
|
scopeCanvas->waveform_points.resize(demodAudioData.data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, iMax = demodAudioData.data.size()/2; i < iMax; i++) {
|
for (int i = 0, iMax = demodAudioData.data.size() / 2; i < iMax; i++) {
|
||||||
scopeCanvas->waveform_points[i * 2 + 1] = demodAudioData.data[i*2] * 0.5f;
|
scopeCanvas->waveform_points[i * 2 + 1] = demodAudioData.data[i * 2] * 0.5f;
|
||||||
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +129,6 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!work_done) {
|
if (!work_done) {
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
#include "PrimaryGLContext.h"
|
#include "PrimaryGLContext.h"
|
||||||
|
|
||||||
|
|
||||||
#include "ScopeCanvas.h"
|
#include "ScopeCanvas.h"
|
||||||
#include "SpectrumCanvas.h"
|
#include "SpectrumCanvas.h"
|
||||||
#include "WaterfallCanvas.h"
|
#include "WaterfallCanvas.h"
|
||||||
@ -16,7 +15,6 @@ public:
|
|||||||
void OnThread(wxCommandEvent& event);
|
void OnThread(wxCommandEvent& event);
|
||||||
void OnEventInput(wxThreadEvent& event);
|
void OnEventInput(wxThreadEvent& event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnClose(wxCommandEvent& event);
|
void OnClose(wxCommandEvent& event);
|
||||||
void OnNewWindow(wxCommandEvent& event);
|
void OnNewWindow(wxCommandEvent& event);
|
||||||
@ -26,7 +24,6 @@ private:
|
|||||||
SpectrumCanvas *spectrumCanvas;
|
SpectrumCanvas *spectrumCanvas;
|
||||||
WaterfallCanvas *waterfallCanvas;
|
WaterfallCanvas *waterfallCanvas;
|
||||||
|
|
||||||
|
|
||||||
// event table
|
// event table
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
@ -24,9 +24,6 @@ bool CubicSDR::OnInit() {
|
|||||||
audioVisualQueue = new DemodulatorThreadOutputQueue();
|
audioVisualQueue = new DemodulatorThreadOutputQueue();
|
||||||
audioVisualQueue->set_max_num_items(1);
|
audioVisualQueue->set_max_num_items(1);
|
||||||
|
|
||||||
// demodulatorTest[0]->setVisualOutputQueue(audioVisualQueue);
|
|
||||||
// demodMgr.setActiveDemodulator(demodulatorTest[0]);
|
|
||||||
|
|
||||||
threadCmdQueueSDR = new SDRThreadCommandQueue;
|
threadCmdQueueSDR = new SDRThreadCommandQueue;
|
||||||
sdrThread = new SDRThread(threadCmdQueueSDR);
|
sdrThread = new SDRThread(threadCmdQueueSDR);
|
||||||
|
|
||||||
|
@ -45,13 +45,13 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
|||||||
|
|
||||||
void AudioThread::threadMain() {
|
void AudioThread::threadMain() {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pthread_t tID = pthread_self(); // ID of this thread
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
int priority = sched_get_priority_min( SCHED_RR );
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
sched_param prio = { priority }; // scheduling priority of thread
|
sched_param prio = {priority}; // scheduling priority of thread
|
||||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::cout << "Audio thread initializing.." << std::endl;
|
std::cout << "Audio thread initializing.." << std::endl;
|
||||||
|
|
||||||
if (dac.getDeviceCount() < 1) {
|
if (dac.getDeviceCount() < 1) {
|
||||||
std::cout << "No audio devices found!" << std::endl;
|
std::cout << "No audio devices found!" << std::endl;
|
||||||
@ -66,7 +66,7 @@ void AudioThread::threadMain() {
|
|||||||
unsigned int bufferFrames = 256;
|
unsigned int bufferFrames = 256;
|
||||||
|
|
||||||
RtAudio::StreamOptions opts;
|
RtAudio::StreamOptions opts;
|
||||||
opts.flags = RTAUDIO_SCHEDULE_REALTIME;
|
opts.flags = RTAUDIO_SCHEDULE_REALTIME;
|
||||||
// | RTAUDIO_MINIMIZE_LATENCY;
|
// | RTAUDIO_MINIMIZE_LATENCY;
|
||||||
// opts.flags = RTAUDIO_MINIMIZE_LATENCY;
|
// opts.flags = RTAUDIO_MINIMIZE_LATENCY;
|
||||||
opts.streamName = "CubicSDR Audio Output";
|
opts.streamName = "CubicSDR Audio Output";
|
||||||
|
@ -28,8 +28,7 @@ public:
|
|||||||
class AudioThreadCommand {
|
class AudioThreadCommand {
|
||||||
public:
|
public:
|
||||||
enum AudioThreadCommandEnum {
|
enum AudioThreadCommandEnum {
|
||||||
AUTIO_THREAD_CMD_NULL,
|
AUTIO_THREAD_CMD_NULL, AUTIO_THREAD_CMD_SET_DEVICE,
|
||||||
AUTIO_THREAD_CMD_SET_DEVICE,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioThreadCommand() :
|
AudioThreadCommand() :
|
||||||
|
@ -8,29 +8,28 @@ enum DemodulatorType {
|
|||||||
DEMOD_TYPE_NULL,
|
DEMOD_TYPE_NULL,
|
||||||
DEMOD_TYPE_AM,
|
DEMOD_TYPE_AM,
|
||||||
DEMOD_TYPE_FM,
|
DEMOD_TYPE_FM,
|
||||||
DEMOD_TYPE_LSB,
|
DEMOD_TYPE_LSB, DEMOD_TYPE_USB
|
||||||
DEMOD_TYPE_USB
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DemodulatorThread;
|
class DemodulatorThread;
|
||||||
class DemodulatorThreadCommand {
|
class DemodulatorThreadCommand {
|
||||||
public:
|
public:
|
||||||
enum DemodulatorThreadCommandEnum {
|
enum DemodulatorThreadCommandEnum {
|
||||||
DEMOD_THREAD_CMD_NULL,
|
DEMOD_THREAD_CMD_NULL,
|
||||||
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
||||||
DEMOD_THREAD_CMD_SET_FREQUENCY,
|
DEMOD_THREAD_CMD_SET_FREQUENCY,
|
||||||
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED,
|
||||||
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
DEMOD_THREAD_CMD_DEMOD_TERMINATED,
|
||||||
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
DEMOD_THREAD_CMD_AUDIO_TERMINATED
|
||||||
};
|
};
|
||||||
|
|
||||||
DemodulatorThreadCommand() :
|
DemodulatorThreadCommand() :
|
||||||
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
|
cmd(DEMOD_THREAD_CMD_NULL), int_value(0), context(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||||
cmd(cmd), int_value(0), context(NULL) {
|
cmd(cmd), int_value(0), context(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ public:
|
|||||||
float resample_ratio;
|
float resample_ratio;
|
||||||
msresamp_crcf resampler;
|
msresamp_crcf resampler;
|
||||||
|
|
||||||
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL) {
|
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,139 +1,139 @@
|
|||||||
#include "DemodulatorInstance.h"
|
#include "DemodulatorInstance.h"
|
||||||
|
|
||||||
DemodulatorInstance::DemodulatorInstance() :
|
DemodulatorInstance::DemodulatorInstance() :
|
||||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||||
false), preDemodTerminated(false) {
|
false), preDemodTerminated(false) {
|
||||||
|
|
||||||
label = new std::string("Unnamed");
|
label = new std::string("Unnamed");
|
||||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||||
threadQueuePostDemod = new DemodulatorThreadPostInputQueue;
|
threadQueuePostDemod = new DemodulatorThreadPostInputQueue;
|
||||||
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
threadQueueCommand = new DemodulatorThreadCommandQueue;
|
||||||
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
threadQueueNotify = new DemodulatorThreadCommandQueue;
|
||||||
|
|
||||||
demodulatorPreThread = new DemodulatorPreThread(threadQueueDemod, threadQueuePostDemod, threadQueueNotify);
|
demodulatorPreThread = new DemodulatorPreThread(threadQueueDemod, threadQueuePostDemod, threadQueueNotify);
|
||||||
demodulatorPreThread->setCommandQueue(threadQueueCommand);
|
demodulatorPreThread->setCommandQueue(threadQueueCommand);
|
||||||
demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueNotify);
|
demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueNotify);
|
||||||
|
|
||||||
audioInputQueue = new AudioThreadInputQueue;
|
audioInputQueue = new AudioThreadInputQueue;
|
||||||
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
audioThread = new AudioThread(audioInputQueue, threadQueueNotify);
|
||||||
|
|
||||||
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
demodulatorThread->setAudioInputQueue(audioInputQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance::~DemodulatorInstance() {
|
DemodulatorInstance::~DemodulatorInstance() {
|
||||||
delete audioThread;
|
delete audioThread;
|
||||||
delete demodulatorThread;
|
delete demodulatorThread;
|
||||||
|
|
||||||
delete audioInputQueue;
|
delete audioInputQueue;
|
||||||
delete threadQueueDemod;
|
delete threadQueueDemod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||||
demodulatorThread->setVisualOutputQueue(tQueue);
|
demodulatorThread->setVisualOutputQueue(tQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::run() {
|
void DemodulatorInstance::run() {
|
||||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||||
|
|
||||||
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setstacksize(&attr, 2048000);
|
pthread_attr_setstacksize(&attr, 2048000);
|
||||||
pthread_attr_getstacksize(&attr, &size);
|
pthread_attr_getstacksize(&attr, &size);
|
||||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||||
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setstacksize(&attr, 2048000);
|
pthread_attr_setstacksize(&attr, 2048000);
|
||||||
pthread_attr_getstacksize(&attr, &size);
|
pthread_attr_getstacksize(&attr, &size);
|
||||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
|
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
|
||||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::updateLabel(int freq) {
|
void DemodulatorInstance::updateLabel(int freq) {
|
||||||
std::stringstream newLabel;
|
std::stringstream newLabel;
|
||||||
newLabel.precision(3);
|
newLabel.precision(3);
|
||||||
newLabel << std::fixed << ((float) freq / 1000000.0);
|
newLabel << std::fixed << ((float) freq / 1000000.0);
|
||||||
setLabel(newLabel.str());
|
setLabel(newLabel.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
||||||
return threadQueueCommand;
|
return threadQueueCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
||||||
return demodulatorPreThread->getParams();
|
return demodulatorPreThread->getParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::terminate() {
|
void DemodulatorInstance::terminate() {
|
||||||
std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
|
std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
|
||||||
demodulatorPreThread->terminate();
|
demodulatorPreThread->terminate();
|
||||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||||
demodulatorThread->terminate();
|
demodulatorThread->terminate();
|
||||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||||
audioThread->terminate();
|
audioThread->terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DemodulatorInstance::getLabel() {
|
std::string DemodulatorInstance::getLabel() {
|
||||||
return *(label.load());
|
return *(label.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setLabel(std::string labelStr) {
|
void DemodulatorInstance::setLabel(std::string labelStr) {
|
||||||
std::string *newLabel = new std::string;
|
std::string *newLabel = new std::string;
|
||||||
newLabel->append(labelStr);
|
newLabel->append(labelStr);
|
||||||
std::string *oldLabel;
|
std::string *oldLabel;
|
||||||
oldLabel = label;
|
oldLabel = label;
|
||||||
label = newLabel;
|
label = newLabel;
|
||||||
delete oldLabel;
|
delete oldLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DemodulatorInstance::isTerminated() {
|
bool DemodulatorInstance::isTerminated() {
|
||||||
while (!threadQueueNotify->empty()) {
|
while (!threadQueueNotify->empty()) {
|
||||||
DemodulatorThreadCommand cmd;
|
DemodulatorThreadCommand cmd;
|
||||||
threadQueueNotify->pop(cmd);
|
threadQueueNotify->pop(cmd);
|
||||||
|
|
||||||
switch (cmd.cmd) {
|
switch (cmd.cmd) {
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
||||||
audioThread = NULL;
|
audioThread = NULL;
|
||||||
t_Audio->join();
|
t_Audio->join();
|
||||||
audioTerminated = true;
|
audioTerminated = true;
|
||||||
break;
|
break;
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
|
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
|
||||||
demodulatorThread = NULL;
|
demodulatorThread = NULL;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pthread_join(t_Demod, NULL);
|
pthread_join(t_Demod, NULL);
|
||||||
#else
|
#else
|
||||||
t_Demod->join();
|
t_Demod->join();
|
||||||
#endif
|
#endif
|
||||||
demodTerminated = true;
|
demodTerminated = true;
|
||||||
break;
|
break;
|
||||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
||||||
demodulatorPreThread = NULL;
|
demodulatorPreThread = NULL;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pthread_join(t_PreDemod, NULL);
|
pthread_join(t_PreDemod, NULL);
|
||||||
#else
|
#else
|
||||||
t_PreDemod->join();
|
t_PreDemod->join();
|
||||||
#endif
|
#endif
|
||||||
preDemodTerminated = true;
|
preDemodTerminated = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
||||||
|
|
||||||
return terminated;
|
return terminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,6 @@ public:
|
|||||||
void updateLabel(int freq);
|
void updateLabel(int freq);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<std::string *> label;
|
std::atomic<std::string *> label;bool terminated;bool demodTerminated;bool audioTerminated;bool preDemodTerminated;
|
||||||
bool terminated;
|
|
||||||
bool demodTerminated;
|
|
||||||
bool audioTerminated;
|
|
||||||
bool preDemodTerminated;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,137 +6,137 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
DemodulatorMgr::DemodulatorMgr() :
|
DemodulatorMgr::DemodulatorMgr() :
|
||||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorMgr::~DemodulatorMgr() {
|
DemodulatorMgr::~DemodulatorMgr() {
|
||||||
terminateAll();
|
terminateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::newThread() {
|
DemodulatorInstance *DemodulatorMgr::newThread() {
|
||||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||||
|
|
||||||
demods.push_back(newDemod);
|
demods.push_back(newDemod);
|
||||||
|
|
||||||
std::stringstream label;
|
std::stringstream label;
|
||||||
label << demods.size();
|
label << demods.size();
|
||||||
newDemod->setLabel(label.str());
|
newDemod->setLabel(label.str());
|
||||||
|
|
||||||
return newDemod;
|
return newDemod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::terminateAll() {
|
void DemodulatorMgr::terminateAll() {
|
||||||
while (demods.size()) {
|
while (demods.size()) {
|
||||||
DemodulatorInstance *d = demods.back();
|
DemodulatorInstance *d = demods.back();
|
||||||
deleteThread(d);
|
deleteThread(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||||
return demods;
|
return demods;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
i = std::find(demods.begin(), demods.end(), demod);
|
i = std::find(demods.begin(), demods.end(), demod);
|
||||||
|
|
||||||
if (activeDemodulator == demod) {
|
if (activeDemodulator == demod) {
|
||||||
activeDemodulator = NULL;
|
activeDemodulator = NULL;
|
||||||
}
|
}
|
||||||
if (lastActiveDemodulator == demod) {
|
if (lastActiveDemodulator == demod) {
|
||||||
lastActiveDemodulator = NULL;
|
lastActiveDemodulator = NULL;
|
||||||
}
|
}
|
||||||
if (activeVisualDemodulator == demod) {
|
if (activeVisualDemodulator == demod) {
|
||||||
activeVisualDemodulator = NULL;
|
activeVisualDemodulator = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != demods.end()) {
|
if (i != demods.end()) {
|
||||||
demods.erase(i);
|
demods.erase(i);
|
||||||
demod->terminate();
|
demod->terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
demods_deleted.push_back(demod);
|
demods_deleted.push_back(demod);
|
||||||
|
|
||||||
garbageCollect();
|
garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
|
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
|
||||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||||
|
|
||||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
DemodulatorInstance *testDemod = demods[i];
|
DemodulatorInstance *testDemod = demods[i];
|
||||||
|
|
||||||
int freqTest = testDemod->getParams().frequency;
|
int freqTest = testDemod->getParams().frequency;
|
||||||
int bandwidthTest = testDemod->getParams().bandwidth;
|
int bandwidthTest = testDemod->getParams().bandwidth;
|
||||||
int halfBandwidthTest = bandwidthTest / 2;
|
int halfBandwidthTest = bandwidthTest / 2;
|
||||||
|
|
||||||
int halfBuffer = bandwidth / 2;
|
int halfBuffer = bandwidth / 2;
|
||||||
|
|
||||||
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
||||||
foundDemods->push_back(testDemod);
|
foundDemods->push_back(testDemod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundDemods;
|
return foundDemods;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool temporary) {
|
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool temporary) {
|
||||||
if (!temporary) {
|
if (!temporary) {
|
||||||
if (activeDemodulator != NULL) {
|
if (activeDemodulator != NULL) {
|
||||||
lastActiveDemodulator = activeDemodulator;
|
lastActiveDemodulator = activeDemodulator;
|
||||||
} else {
|
} else {
|
||||||
lastActiveDemodulator = demod;
|
lastActiveDemodulator = demod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeVisualDemodulator) {
|
if (activeVisualDemodulator) {
|
||||||
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
||||||
}
|
}
|
||||||
if (demod) {
|
if (demod) {
|
||||||
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||||
activeVisualDemodulator = demod;
|
activeVisualDemodulator = demod;
|
||||||
} else {
|
} else {
|
||||||
DemodulatorInstance *last = getLastActiveDemodulator();
|
DemodulatorInstance *last = getLastActiveDemodulator();
|
||||||
if (last) {
|
if (last) {
|
||||||
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||||
}
|
}
|
||||||
activeVisualDemodulator = last;
|
activeVisualDemodulator = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
activeDemodulator = demod;
|
activeDemodulator = demod;
|
||||||
|
|
||||||
garbageCollect();
|
garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
||||||
return activeDemodulator;
|
return activeDemodulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
||||||
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
||||||
lastActiveDemodulator = activeDemodulator;
|
lastActiveDemodulator = activeDemodulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastActiveDemodulator;
|
return lastActiveDemodulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::garbageCollect() {
|
void DemodulatorMgr::garbageCollect() {
|
||||||
if (demods_deleted.size()) {
|
if (demods_deleted.size()) {
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||||
if ((*i)->isTerminated()) {
|
if ((*i)->isTerminated()) {
|
||||||
DemodulatorInstance *deleted = (*i);
|
DemodulatorInstance *deleted = (*i);
|
||||||
demods_deleted.erase(i);
|
demods_deleted.erase(i);
|
||||||
|
|
||||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||||
|
|
||||||
delete deleted;
|
delete deleted;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#include "CubicSDRDefs.h"
|
#include "CubicSDRDefs.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -8,7 +7,8 @@
|
|||||||
|
|
||||||
#include "DemodulatorPreThread.h"
|
#include "DemodulatorPreThread.h"
|
||||||
|
|
||||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut,
|
||||||
|
DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||||
inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
|
inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
|
||||||
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||||
|
|
||||||
@ -88,17 +88,16 @@ void *DemodulatorPreThread::threadMain() {
|
|||||||
void DemodulatorPreThread::threadMain() {
|
void DemodulatorPreThread::threadMain() {
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pthread_t tID = pthread_self(); // ID of this thread
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
int priority = sched_get_priority_min( SCHED_RR );
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
sched_param prio = { priority }; // scheduling priority of thread
|
sched_param prio = {priority}; // scheduling priority of thread
|
||||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Demodulator preprocessor thread started.." << std::endl;
|
std::cout << "Demodulator preprocessor thread started.." << std::endl;
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
DemodulatorThreadIQData inp;
|
DemodulatorThreadIQData inp;
|
||||||
@ -160,7 +159,7 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
|
|
||||||
std::vector<signed char> *data = &inp.data;
|
std::vector<signed char> *data = &inp.data;
|
||||||
if (data->size()) {
|
if (data->size()) {
|
||||||
int bufSize = data->size() / 2;
|
int bufSize = data->size() / 2;
|
||||||
|
|
||||||
liquid_float_complex in_buf_data[bufSize];
|
liquid_float_complex in_buf_data[bufSize];
|
||||||
liquid_float_complex out_buf_data[bufSize];
|
liquid_float_complex out_buf_data[bufSize];
|
||||||
|
@ -10,64 +10,65 @@
|
|||||||
class DemodulatorPreThread {
|
class DemodulatorPreThread {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadCommandQueue* threadQueueNotify);
|
DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut,
|
||||||
~DemodulatorPreThread();
|
DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||||
|
~DemodulatorPreThread();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void *threadMain();
|
void *threadMain();
|
||||||
#else
|
#else
|
||||||
void threadMain();
|
void threadMain();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
||||||
commandQueue = tQueue;
|
commandQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||||
audioInputQueue = tQueue;
|
audioInputQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadParameters &getParams() {
|
DemodulatorThreadParameters &getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static void *pthread_helper(void *context) {
|
static void *pthread_helper(void *context) {
|
||||||
return ((DemodulatorPreThread *) context)->threadMain();
|
return ((DemodulatorPreThread *) context)->threadMain();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DemodulatorThreadInputQueue* inputQueue;
|
DemodulatorThreadInputQueue* inputQueue;
|
||||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||||
DemodulatorThreadCommandQueue* commandQueue;
|
DemodulatorThreadCommandQueue* commandQueue;
|
||||||
AudioThreadInputQueue *audioInputQueue;
|
AudioThreadInputQueue *audioInputQueue;
|
||||||
|
|
||||||
firfilt_crcf fir_filter;
|
firfilt_crcf fir_filter;
|
||||||
msresamp_crcf resampler;
|
msresamp_crcf resampler;
|
||||||
float resample_ratio;
|
float resample_ratio;
|
||||||
|
|
||||||
msresamp_crcf audio_resampler;
|
msresamp_crcf audio_resampler;
|
||||||
float audio_resample_ratio;
|
float audio_resample_ratio;
|
||||||
|
|
||||||
DemodulatorThreadParameters params;
|
DemodulatorThreadParameters params;
|
||||||
DemodulatorThreadParameters last_params;
|
DemodulatorThreadParameters last_params;
|
||||||
|
|
||||||
freqdem fdem;
|
freqdem fdem;
|
||||||
nco_crcf nco_shift;
|
nco_crcf nco_shift;
|
||||||
int shift_freq;
|
int shift_freq;
|
||||||
|
|
||||||
std::atomic<bool> terminated;
|
std::atomic<bool> terminated;
|
||||||
std::atomic<bool> initialized;
|
std::atomic<bool> initialized;
|
||||||
|
|
||||||
DemodulatorWorkerThread *workerThread;
|
DemodulatorWorkerThread *workerThread;
|
||||||
std::thread *t_Worker;
|
std::thread *t_Worker;
|
||||||
|
|
||||||
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
||||||
DemodulatorThreadWorkerResultQueue *workerResults;
|
DemodulatorThreadWorkerResultQueue *workerResults;
|
||||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||||
};
|
};
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||||
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||||
|
|
||||||
float kf = 0.5; // modulation factor
|
float kf = 0.5; // modulation factor
|
||||||
fdem = freqdem_create(kf);
|
fdem = freqdem_create(kf);
|
||||||
// freqdem_print(fdem);
|
// freqdem_print(fdem);
|
||||||
}
|
}
|
||||||
DemodulatorThread::~DemodulatorThread() {
|
DemodulatorThread::~DemodulatorThread() {
|
||||||
@ -19,38 +19,38 @@ DemodulatorThread::~DemodulatorThread() {
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void *DemodulatorThread::threadMain() {
|
void *DemodulatorThread::threadMain() {
|
||||||
#else
|
#else
|
||||||
void DemodulatorThread::threadMain() {
|
void DemodulatorThread::threadMain() {
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pthread_t tID = pthread_self(); // ID of this thread
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
int priority = sched_get_priority_min( SCHED_RR );
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
sched_param prio = { priority }; // scheduling priority of thread
|
sched_param prio = {priority}; // scheduling priority of thread
|
||||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
msresamp_crcf audio_resampler = NULL;
|
msresamp_crcf audio_resampler = NULL;
|
||||||
msresamp_crcf resampler = NULL;
|
msresamp_crcf resampler = NULL;
|
||||||
|
|
||||||
std::cout << "Demodulator thread started.." << std::endl;
|
std::cout << "Demodulator thread started.." << std::endl;
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
DemodulatorThreadPostIQData inp;
|
DemodulatorThreadPostIQData inp;
|
||||||
postInputQueue->pop(inp);
|
postInputQueue->pop(inp);
|
||||||
|
|
||||||
int bufSize = inp.data.size();
|
int bufSize = inp.data.size();
|
||||||
|
|
||||||
if (!bufSize) {
|
if (!bufSize) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resampler == NULL) {
|
if (resampler == NULL) {
|
||||||
resampler = inp.resampler;
|
resampler = inp.resampler;
|
||||||
audio_resampler = inp.audio_resampler;
|
audio_resampler = inp.audio_resampler;
|
||||||
} else if (resampler != inp.resampler) {
|
} else if (resampler != inp.resampler) {
|
||||||
msresamp_crcf_destroy(resampler);
|
msresamp_crcf_destroy(resampler);
|
||||||
msresamp_crcf_destroy(audio_resampler);
|
msresamp_crcf_destroy(audio_resampler);
|
||||||
resampler = inp.resampler;
|
resampler = inp.resampler;
|
||||||
audio_resampler = inp.audio_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 resampled_data[out_size];
|
||||||
@ -58,61 +58,61 @@ void *DemodulatorThread::threadMain() {
|
|||||||
unsigned int num_written;
|
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);
|
||||||
|
|
||||||
float audio_resample_ratio = inp.audio_resample_ratio;
|
float audio_resample_ratio = inp.audio_resample_ratio;
|
||||||
|
|
||||||
float demod_output[num_written];
|
float demod_output[num_written];
|
||||||
|
|
||||||
freqdem_demodulate_block(fdem, resampled_data, num_written, demod_output);
|
freqdem_demodulate_block(fdem, resampled_data, num_written, demod_output);
|
||||||
|
|
||||||
liquid_float_complex demod_audio_data[num_written];
|
liquid_float_complex demod_audio_data[num_written];
|
||||||
|
|
||||||
for (int i = 0; i < num_written; i++) {
|
for (int i = 0; i < num_written; i++) {
|
||||||
demod_audio_data[i].real = demod_output[i];
|
demod_audio_data[i].real = demod_output[i];
|
||||||
demod_audio_data[i].imag = 0;
|
demod_audio_data[i].imag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
|
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
|
||||||
liquid_float_complex resampled_audio_output[audio_out_size];
|
liquid_float_complex resampled_audio_output[audio_out_size];
|
||||||
|
|
||||||
unsigned int num_audio_written;
|
unsigned int num_audio_written;
|
||||||
msresamp_crcf_execute(audio_resampler, demod_audio_data, num_written, resampled_audio_output, &num_audio_written);
|
msresamp_crcf_execute(audio_resampler, demod_audio_data, num_written, resampled_audio_output, &num_audio_written);
|
||||||
|
|
||||||
std::vector<float> newBuffer;
|
std::vector<float> newBuffer;
|
||||||
newBuffer.resize(num_audio_written * 2);
|
newBuffer.resize(num_audio_written * 2);
|
||||||
for (int i = 0; i < num_audio_written; i++) {
|
for (int i = 0; i < num_audio_written; i++) {
|
||||||
liquid_float_complex y = resampled_audio_output[i];
|
liquid_float_complex y = resampled_audio_output[i];
|
||||||
|
|
||||||
newBuffer[i * 2] = y.real;
|
newBuffer[i * 2] = y.real;
|
||||||
newBuffer[i * 2 + 1] = y.real;
|
newBuffer[i * 2 + 1] = y.real;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioThreadInput ati;
|
AudioThreadInput ati;
|
||||||
ati.data = newBuffer;
|
ati.data = newBuffer;
|
||||||
|
|
||||||
if (audioInputQueue != NULL) {
|
if (audioInputQueue != NULL) {
|
||||||
audioInputQueue->push(ati);
|
audioInputQueue->push(ati);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visOutQueue != NULL) {
|
if (visOutQueue != NULL) {
|
||||||
visOutQueue->push(ati);
|
visOutQueue->push(ati);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resampler != NULL) {
|
if (resampler != NULL) {
|
||||||
msresamp_crcf_destroy(resampler);
|
msresamp_crcf_destroy(resampler);
|
||||||
}
|
}
|
||||||
if (audio_resampler != NULL) {
|
if (audio_resampler != NULL) {
|
||||||
msresamp_crcf_destroy(audio_resampler);
|
msresamp_crcf_destroy(audio_resampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Demodulator thread done." << std::endl;
|
std::cout << "Demodulator thread done." << std::endl;
|
||||||
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
||||||
tCmd.context = this;
|
tCmd.context = this;
|
||||||
threadQueueNotify->push(tCmd);
|
threadQueueNotify->push(tCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorThread::terminate() {
|
void DemodulatorThread::terminate() {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
|
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
|
||||||
postInputQueue->push(inp);
|
postInputQueue->push(inp);
|
||||||
}
|
}
|
||||||
|
@ -11,41 +11,41 @@ typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
|||||||
class DemodulatorThread {
|
class DemodulatorThread {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadCommandQueue* threadQueueNotify);
|
DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||||
~DemodulatorThread();
|
~DemodulatorThread();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void *threadMain();
|
void *threadMain();
|
||||||
#else
|
#else
|
||||||
void threadMain();
|
void threadMain();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||||
visOutQueue = tQueue;
|
visOutQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||||
audioInputQueue = tQueue;
|
audioInputQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static void *pthread_helper(void *context) {
|
static void *pthread_helper(void *context) {
|
||||||
return ((DemodulatorThread *) context)->threadMain();
|
return ((DemodulatorThread *) context)->threadMain();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DemodulatorThreadPostInputQueue* postInputQueue;
|
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||||
DemodulatorThreadOutputQueue* visOutQueue;
|
DemodulatorThreadOutputQueue* visOutQueue;
|
||||||
AudioThreadInputQueue *audioInputQueue;
|
AudioThreadInputQueue *audioInputQueue;
|
||||||
|
|
||||||
freqdem fdem;
|
freqdem fdem;
|
||||||
|
|
||||||
std::atomic<bool> terminated;
|
std::atomic<bool> terminated;
|
||||||
|
|
||||||
DemodulatorThreadCommandQueue* threadQueueNotify;
|
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t sample_rate;
|
uint32_t sample_rate;
|
||||||
|
|
||||||
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
|
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
|
||||||
std::atomic<SDRThreadIQDataQueue*> iqDataInQueue;
|
std::atomic<SDRThreadIQDataQueue*> iqDataInQueue;
|
||||||
|
@ -17,15 +17,16 @@
|
|||||||
class SDRThreadCommand {
|
class SDRThreadCommand {
|
||||||
public:
|
public:
|
||||||
enum SDRThreadCommandEnum {
|
enum SDRThreadCommandEnum {
|
||||||
SDR_THREAD_CMD_NULL,
|
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE
|
||||||
SDR_THREAD_CMD_TUNE
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SDRThreadCommand() : cmd(SDR_THREAD_CMD_NULL), int_value(0) {
|
SDRThreadCommand() :
|
||||||
|
cmd(SDR_THREAD_CMD_NULL), int_value(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDRThreadCommand(SDRThreadCommandEnum cmd) : cmd(cmd), int_value(0) {
|
SDRThreadCommand(SDRThreadCommandEnum cmd) :
|
||||||
|
cmd(cmd), int_value(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +40,8 @@ public:
|
|||||||
unsigned int bandwidth;
|
unsigned int bandwidth;
|
||||||
std::vector<signed char> data;
|
std::vector<signed char> data;
|
||||||
|
|
||||||
SDRThreadIQData(): frequency(0), bandwidth(0) {
|
SDRThreadIQData() :
|
||||||
|
frequency(0), bandwidth(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +55,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
|
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
|
||||||
typedef ThreadQueue<SDRThreadIQData> SDRThreadIQDataQueue;
|
typedef ThreadQueue<SDRThreadIQData> SDRThreadIQDataQueue;
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "lodepng.h"
|
#include "lodepng.h"
|
||||||
#include "wx/glcanvas.h"
|
#include "wx/glcanvas.h"
|
||||||
|
|
||||||
|
|
||||||
class GLFontChar {
|
class GLFontChar {
|
||||||
public:
|
public:
|
||||||
GLFontChar();
|
GLFontChar();
|
||||||
@ -53,11 +52,7 @@ private:
|
|||||||
class GLFont {
|
class GLFont {
|
||||||
public:
|
public:
|
||||||
enum Align {
|
enum Align {
|
||||||
GLFONT_ALIGN_LEFT,
|
GLFONT_ALIGN_LEFT, GLFONT_ALIGN_RIGHT, GLFONT_ALIGN_CENTER, GLFONT_ALIGN_TOP, GLFONT_ALIGN_BOTTOM
|
||||||
GLFONT_ALIGN_RIGHT,
|
|
||||||
GLFONT_ALIGN_CENTER,
|
|
||||||
GLFONT_ALIGN_TOP,
|
|
||||||
GLFONT_ALIGN_BOTTOM
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GLFont();
|
GLFont();
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
void addColor(GradientColor c);
|
void addColor(GradientColor c);
|
||||||
|
|
||||||
std::vector<float> &getRed();;
|
std::vector<float> &getRed();
|
||||||
std::vector<float> &getGreen();
|
std::vector<float> &getGreen();
|
||||||
std::vector<float> &getBlue();
|
std::vector<float> &getBlue();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContex
|
|||||||
SetCurrent(*canvas);
|
SetCurrent(*canvas);
|
||||||
// Pre-load fonts
|
// Pre-load fonts
|
||||||
for (int i = 0; i < GLFONT_MAX; i++) {
|
for (int i = 0; i < GLFONT_MAX; i++) {
|
||||||
getFont((GLFontSize)i);
|
getFont((GLFontSize) i);
|
||||||
}
|
}
|
||||||
CheckGLError();
|
CheckGLError();
|
||||||
}
|
}
|
||||||
@ -202,7 +202,6 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
|
|||||||
bw = demod->getParams().bandwidth;
|
bw = demod->getParams().bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
|
|
||||||
class PrimaryGLContext: public wxGLContext {
|
class PrimaryGLContext: public wxGLContext {
|
||||||
public:
|
public:
|
||||||
enum GLFontSize { GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX };
|
enum GLFontSize {
|
||||||
|
GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX
|
||||||
|
};
|
||||||
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
|
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
|
||||||
|
|
||||||
static wxString glGetwxString(GLenum name);
|
static wxString glGetwxString(GLenum name);
|
||||||
@ -21,7 +23,7 @@ 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);
|
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0);
|
||||||
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
||||||
void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
|
|||||||
demod->run();
|
demod->run();
|
||||||
|
|
||||||
wxGetApp().bindDemodulator(demod);
|
wxGetApp().bindDemodulator(demod);
|
||||||
wxGetApp().getDemodMgr().setActiveDemodulator(demod,false);
|
wxGetApp().getDemodMgr().setActiveDemodulator(demod, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (demod == NULL) {
|
if (demod == NULL) {
|
||||||
@ -482,7 +482,7 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
|
|||||||
|
|
||||||
int center_freq = wxGetApp().getFrequency();
|
int center_freq = wxGetApp().getFrequency();
|
||||||
int freq = center_freq - (int) (0.5 * (float) SRATE) + (int) ((float) pos * (float) SRATE);
|
int freq = center_freq - (int) (0.5 * (float) SRATE) + (int) ((float) pos * (float) SRATE);
|
||||||
int bandwidth = (int)(fabs(width) * (float)SRATE);
|
int bandwidth = (int) (fabs(width) * (float) SRATE);
|
||||||
|
|
||||||
if (bandwidth < 1000) {
|
if (bandwidth < 1000) {
|
||||||
bandwidth = 1000;
|
bandwidth = 1000;
|
||||||
@ -503,7 +503,7 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
|
|||||||
demod->run();
|
demod->run();
|
||||||
|
|
||||||
wxGetApp().bindDemodulator(demod);
|
wxGetApp().bindDemodulator(demod);
|
||||||
wxGetApp().getDemodMgr().setActiveDemodulator(demod,false);
|
wxGetApp().getDemodMgr().setActiveDemodulator(demod, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (demod == NULL) {
|
if (demod == NULL) {
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
class WaterfallCanvas: public wxGLCanvas {
|
class WaterfallCanvas: public wxGLCanvas {
|
||||||
public:
|
public:
|
||||||
enum DragState { WF_DRAG_NONE, WF_DRAG_BANDWIDTH_LEFT, WF_DRAG_BANDWIDTH_RIGHT, WF_DRAG_FREQUENCY, WF_DRAG_RANGE };
|
enum DragState {
|
||||||
|
WF_DRAG_NONE, WF_DRAG_BANDWIDTH_LEFT, WF_DRAG_BANDWIDTH_RIGHT, WF_DRAG_FREQUENCY, WF_DRAG_RANGE
|
||||||
|
};
|
||||||
|
|
||||||
WaterfallCanvas(wxWindow *parent, int *attribList = NULL);
|
WaterfallCanvas(wxWindow *parent, int *attribList = NULL);
|
||||||
~WaterfallCanvas();
|
~WaterfallCanvas();
|
||||||
@ -60,9 +62,7 @@ private:
|
|||||||
DragState dragState;
|
DragState dragState;
|
||||||
DragState nextDragState;
|
DragState nextDragState;
|
||||||
|
|
||||||
bool shiftDown;
|
bool shiftDown;bool altDown;bool ctrlDown;
|
||||||
bool altDown;
|
|
||||||
bool ctrlDown;
|
|
||||||
// event table
|
// event table
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
@ -37,7 +37,6 @@ WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedC
|
|||||||
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]);
|
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(grad.getBlue())[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WaterfallContext::Draw(std::vector<float> &points) {
|
void WaterfallContext::Draw(std::vector<float> &points) {
|
||||||
|
|
||||||
if (points.size()) {
|
if (points.size()) {
|
||||||
|
@ -11,7 +11,6 @@ class WaterfallContext: public PrimaryGLContext {
|
|||||||
public:
|
public:
|
||||||
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
|
WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext);
|
||||||
|
|
||||||
|
|
||||||
void Draw(std::vector<float> &points);
|
void Draw(std::vector<float> &points);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user