mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 13:48:38 -05:00
refactor remaining transaction objects
This commit is contained in:
parent
8ce3065bce
commit
a7913e3290
@ -96,14 +96,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
|||||||
// std::this_thread::yield();
|
// std::this_thread::yield();
|
||||||
//#endif
|
//#endif
|
||||||
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
||||||
SDRThreadIQData iqData;
|
SDRThreadIQData *iqData;
|
||||||
wxGetApp().getIQVisualQueue()->pop(iqData);
|
wxGetApp().getIQVisualQueue()->pop(iqData);
|
||||||
|
|
||||||
if (iqData.data && iqData.data->size()) {
|
if (iqData && iqData->data.size()) {
|
||||||
spectrumCanvas->setData(iqData.data);
|
spectrumCanvas->setData(&iqData->data);
|
||||||
waterfallCanvas->setData(iqData.data);
|
waterfallCanvas->setData(&iqData->data);
|
||||||
|
|
||||||
delete iqData.data;
|
delete iqData;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Incoming IQ data empty?" << std::endl;
|
std::cout << "Incoming IQ data empty?" << std::endl;
|
||||||
}
|
}
|
||||||
@ -111,20 +111,19 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!wxGetApp().getAudioVisualQueue()->empty()) {
|
if (!wxGetApp().getAudioVisualQueue()->empty()) {
|
||||||
AudioThreadInput demodAudioData;
|
AudioThreadInput *demodAudioData;
|
||||||
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
|
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
|
||||||
if (demodAudioData.data && demodAudioData.data->size()) {
|
if (demodAudioData && demodAudioData->data.size()) {
|
||||||
|
if (scopeCanvas->waveform_points.size() != demodAudioData->data.size()*2) {
|
||||||
if (scopeCanvas->waveform_points.size() != demodAudioData.data->size()*2) {
|
scopeCanvas->waveform_points.resize(demodAudioData->data.size()*2);
|
||||||
scopeCanvas->waveform_points.resize(demodAudioData.data->size()*2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, iMax = demodAudioData.data->size(); i < iMax; i++) {
|
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 + 1] = demodAudioData->data[i] * 0.5f;
|
||||||
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete demodAudioData.data;
|
delete demodAudioData;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Incoming Demodulator data empty?" << std::endl;
|
std::cout << "Incoming Demodulator data empty?" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -64,44 +64,65 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcmix->currentInput.channels == 0 || !srcmix->currentInput.data) {
|
if (!srcmix->currentInput) {
|
||||||
if (!srcmix->inputQueue->empty()) {
|
if (srcmix->terminated) {
|
||||||
if (srcmix->currentInput.data) {
|
continue;
|
||||||
delete srcmix->currentInput.data;
|
|
||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
srcmix->audio_queue_ptr = 0;
|
srcmix->audio_queue_ptr = 0;
|
||||||
}
|
continue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcmix->currentInput.channels == 1) {
|
if (srcmix->currentInput->channels == 0 || !srcmix->currentInput->data.size()) {
|
||||||
for (int i = 0; i < nBufferFrames; i++) {
|
if (!srcmix->inputQueue->empty()) {
|
||||||
if (srcmix->audio_queue_ptr >= srcmix->currentInput.data->size()) {
|
if (srcmix->currentInput) {
|
||||||
if (srcmix->currentInput.data) {
|
delete srcmix->currentInput;
|
||||||
delete srcmix->currentInput.data;
|
srcmix->currentInput = NULL;
|
||||||
|
}
|
||||||
|
if (srcmix->terminated) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
srcmix->audio_queue_ptr = 0;
|
srcmix->audio_queue_ptr = 0;
|
||||||
}
|
}
|
||||||
if (srcmix->currentInput.data && srcmix->currentInput.data->size()) {
|
continue;
|
||||||
float v = (*srcmix->currentInput.data)[srcmix->audio_queue_ptr] * src->gain;
|
}
|
||||||
|
|
||||||
|
if (srcmix->currentInput->channels == 1) {
|
||||||
|
for (int i = 0; i < nBufferFrames; 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 && srcmix->currentInput->data.size()) {
|
||||||
|
float v = srcmix->currentInput->data[srcmix->audio_queue_ptr] * src->gain;
|
||||||
out[i * 2] += v;
|
out[i * 2] += v;
|
||||||
out[i * 2 + 1] += v;
|
out[i * 2 + 1] += v;
|
||||||
}
|
}
|
||||||
srcmix->audio_queue_ptr++;
|
srcmix->audio_queue_ptr++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) {
|
for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) {
|
||||||
if (srcmix->audio_queue_ptr >= srcmix->currentInput.data->size()) {
|
if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) {
|
||||||
if (srcmix->currentInput.data) {
|
if (srcmix->currentInput) {
|
||||||
delete srcmix->currentInput.data;
|
delete srcmix->currentInput;
|
||||||
|
srcmix->currentInput = NULL;
|
||||||
|
}
|
||||||
|
if (srcmix->terminated) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||||
srcmix->audio_queue_ptr = 0;
|
srcmix->audio_queue_ptr = 0;
|
||||||
}
|
}
|
||||||
if (srcmix->currentInput.data && srcmix->currentInput.data->size()) {
|
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
|
||||||
out[i] = out[i] + (*srcmix->currentInput.data)[srcmix->audio_queue_ptr] * src->gain;
|
out[i] = out[i] + srcmix->currentInput->data[srcmix->audio_queue_ptr] * src->gain;
|
||||||
}
|
}
|
||||||
srcmix->audio_queue_ptr++;
|
srcmix->audio_queue_ptr++;
|
||||||
}
|
}
|
||||||
@ -123,10 +144,20 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
|||||||
std::cout << "Audio buffer underflow.." << (src->underflow_count++) << std::endl;
|
std::cout << "Audio buffer underflow.." << (src->underflow_count++) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->currentInput.channels == 0 || !src->currentInput.data) {
|
if (!src->currentInput) {
|
||||||
|
src->inputQueue->pop(src->currentInput);
|
||||||
|
src->audio_queue_ptr = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src->currentInput->channels == 0 || !src->currentInput->data.size()) {
|
||||||
if (!src->inputQueue->empty()) {
|
if (!src->inputQueue->empty()) {
|
||||||
if (src->currentInput.data) {
|
if (src->currentInput) {
|
||||||
delete src->currentInput.data;
|
delete src->currentInput;
|
||||||
|
src->currentInput = NULL;
|
||||||
|
}
|
||||||
|
if (src->terminated) {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
src->inputQueue->pop(src->currentInput);
|
src->inputQueue->pop(src->currentInput);
|
||||||
src->audio_queue_ptr = 0;
|
src->audio_queue_ptr = 0;
|
||||||
@ -134,34 +165,35 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->currentInput.channels == 1) {
|
if (src->currentInput->channels == 1) {
|
||||||
for (int i = 0; i < nBufferFrames; i++) {
|
for (int i = 0; i < nBufferFrames; i++) {
|
||||||
if (src->audio_queue_ptr >= src->currentInput.data->size()) {
|
if (src->audio_queue_ptr >= src->currentInput->data.size()) {
|
||||||
if (src->currentInput.data) {
|
if (src->currentInput) {
|
||||||
delete src->currentInput.data;
|
delete src->currentInput;
|
||||||
|
src->currentInput = NULL;
|
||||||
}
|
}
|
||||||
if (src->terminated) {
|
if (src->terminated) {
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
src->inputQueue->pop(src->currentInput);
|
src->inputQueue->pop(src->currentInput);
|
||||||
src->audio_queue_ptr = 0;
|
src->audio_queue_ptr = 0;
|
||||||
}
|
}
|
||||||
if (src->currentInput.data && src->currentInput.data->size()) {
|
if (src->currentInput && src->currentInput->data.size()) {
|
||||||
out[i * 2] = out[i * 2 + 1] = (*src->currentInput.data)[src->audio_queue_ptr] * src->gain;
|
out[i * 2] = out[i * 2 + 1] = src->currentInput->data[src->audio_queue_ptr] * src->gain;
|
||||||
}
|
}
|
||||||
src->audio_queue_ptr++;
|
src->audio_queue_ptr++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) {
|
for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) {
|
||||||
if (src->audio_queue_ptr >= src->currentInput.data->size()) {
|
if (src->audio_queue_ptr >= src->currentInput->data.size()) {
|
||||||
if (src->terminated) {
|
if (src->terminated) {
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
src->inputQueue->pop(src->currentInput);
|
src->inputQueue->pop(src->currentInput);
|
||||||
src->audio_queue_ptr = 0;
|
src->audio_queue_ptr = 0;
|
||||||
}
|
}
|
||||||
if (src->currentInput.data && src->currentInput.data->size()) {
|
if (src->currentInput && src->currentInput->data.size()) {
|
||||||
out[i] = (*src->currentInput.data)[src->audio_queue_ptr] * src->gain;
|
out[i] = src->currentInput->data[src->audio_queue_ptr] * src->gain;
|
||||||
}
|
}
|
||||||
src->audio_queue_ptr++;
|
src->audio_queue_ptr++;
|
||||||
}
|
}
|
||||||
@ -321,12 +353,12 @@ bool AudioThread::isActive() {
|
|||||||
|
|
||||||
void AudioThread::setActive(bool state) {
|
void AudioThread::setActive(bool state) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
AudioThreadInput dummy;
|
AudioThreadInput *dummy;
|
||||||
if (state && !active) {
|
if (state && !active) {
|
||||||
while (!inputQueue->empty()) { // flush queue
|
while (!inputQueue->empty()) { // flush queue
|
||||||
inputQueue->pop(dummy);
|
inputQueue->pop(dummy);
|
||||||
if (dummy.data) {
|
if (dummy) {
|
||||||
delete dummy.data;
|
delete dummy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceController[parameters.deviceId]->bindThread(this);
|
deviceController[parameters.deviceId]->bindThread(this);
|
||||||
@ -334,8 +366,8 @@ void AudioThread::setActive(bool state) {
|
|||||||
deviceController[parameters.deviceId]->removeThread(this);
|
deviceController[parameters.deviceId]->removeThread(this);
|
||||||
while (!inputQueue->empty()) { // flush queue
|
while (!inputQueue->empty()) { // flush queue
|
||||||
inputQueue->pop(dummy);
|
inputQueue->pop(dummy);
|
||||||
if (dummy.data) {
|
if (dummy) {
|
||||||
delete dummy.data;
|
delete dummy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
int sampleRate;
|
int sampleRate;
|
||||||
int channels;
|
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 {
|
class AudioThreadCommand {
|
||||||
@ -49,13 +49,13 @@ public:
|
|||||||
int int_value;
|
int int_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ThreadQueue<AudioThreadInput> AudioThreadInputQueue;
|
typedef ThreadQueue<AudioThreadInput *> AudioThreadInputQueue;
|
||||||
typedef ThreadQueue<AudioThreadCommand> AudioThreadCommandQueue;
|
typedef ThreadQueue<AudioThreadCommand> AudioThreadCommandQueue;
|
||||||
|
|
||||||
class AudioThread {
|
class AudioThread {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AudioThreadInput currentInput;
|
AudioThreadInput *currentInput;
|
||||||
AudioThreadInputQueue *inputQueue;
|
AudioThreadInputQueue *inputQueue;
|
||||||
std::atomic<unsigned int> audio_queue_ptr;
|
std::atomic<unsigned int> audio_queue_ptr;
|
||||||
std::atomic<unsigned int> underflow_count;
|
std::atomic<unsigned int> underflow_count;
|
||||||
|
@ -76,10 +76,9 @@ void DemodulatorThread::threadMain() {
|
|||||||
unsigned int num_audio_written;
|
unsigned int num_audio_written;
|
||||||
msresamp_rrrf_execute(audio_resampler, demod_output, num_written, resampled_audio_output, &num_audio_written);
|
msresamp_rrrf_execute(audio_resampler, demod_output, num_written, resampled_audio_output, &num_audio_written);
|
||||||
|
|
||||||
AudioThreadInput ati;
|
AudioThreadInput *ati = new AudioThreadInput;
|
||||||
ati.channels = 1;
|
ati->channels = 1;
|
||||||
ati.data = new std::vector<float>;
|
ati->data.assign(resampled_audio_output,resampled_audio_output+num_audio_written);
|
||||||
ati.data->assign(resampled_audio_output,resampled_audio_output+num_audio_written);
|
|
||||||
|
|
||||||
if (audioInputQueue != NULL) {
|
if (audioInputQueue != NULL) {
|
||||||
if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) {
|
if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) {
|
||||||
@ -88,22 +87,20 @@ void DemodulatorThread::threadMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (visOutQueue != NULL && visOutQueue->empty()) {
|
if (visOutQueue != NULL && visOutQueue->empty()) {
|
||||||
AudioThreadInput ati_vis;
|
AudioThreadInput *ati_vis = new AudioThreadInput;
|
||||||
ati_vis.channels = ati.channels;
|
ati_vis->channels = ati->channels;
|
||||||
|
|
||||||
int num_vis = DEMOD_VIS_SIZE;
|
int num_vis = DEMOD_VIS_SIZE;
|
||||||
if (num_audio_written > num_written) {
|
if (num_audio_written > num_written) {
|
||||||
if (num_vis > num_audio_written) {
|
if (num_vis > num_audio_written) {
|
||||||
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 {
|
} else {
|
||||||
if (num_vis > num_written) {
|
if (num_vis > num_written) {
|
||||||
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);
|
visOutQueue->push(ati_vis);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "DemodDefs.h"
|
#include "DemodDefs.h"
|
||||||
#include "AudioThread.h"
|
#include "AudioThread.h"
|
||||||
|
|
||||||
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
typedef ThreadQueue<AudioThreadInput *> DemodulatorThreadOutputQueue;
|
||||||
|
|
||||||
#define DEMOD_VIS_SIZE 2048
|
#define DEMOD_VIS_SIZE 2048
|
||||||
|
|
||||||
|
@ -50,25 +50,25 @@ void SDRPostThread::threadMain() {
|
|||||||
std::cout << "SDR post-processing thread started.." << std::endl;
|
std::cout << "SDR post-processing thread started.." << std::endl;
|
||||||
|
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
SDRThreadIQData data_in;
|
SDRThreadIQData *data_in;
|
||||||
|
|
||||||
iqDataInQueue.load()->pop(data_in);
|
iqDataInQueue.load()->pop(data_in);
|
||||||
|
|
||||||
if (data_in.data && data_in.data->size()) {
|
if (data_in && data_in->data.size()) {
|
||||||
SDRThreadIQData dataOut;
|
SDRThreadIQData *dataOut = new SDRThreadIQData;
|
||||||
|
|
||||||
dataOut.frequency = data_in.frequency;
|
dataOut->frequency = data_in->frequency;
|
||||||
dataOut.bandwidth = data_in.bandwidth;
|
dataOut->bandwidth = data_in->bandwidth;
|
||||||
dataOut.data = data_in.data;
|
dataOut->data.assign(data_in->data.begin(), data_in->data.end());
|
||||||
|
|
||||||
for (int i = 0, iMax = dataOut.data->size() / 2; i < iMax; i++) {
|
for (int i = 0, iMax = dataOut->data.size() / 2; i < iMax; i++) {
|
||||||
x.real = (float) (*dataOut.data)[i * 2] / 127.0;
|
x.real = (float) dataOut->data[i * 2] / 127.0;
|
||||||
x.imag = (float) (*dataOut.data)[i * 2 + 1] / 127.0;
|
x.imag = (float) dataOut->data[i * 2 + 1] / 127.0;
|
||||||
|
|
||||||
iirfilt_crcf_execute(dcFilter, x, &y);
|
iirfilt_crcf_execute(dcFilter, x, &y);
|
||||||
|
|
||||||
(*dataOut.data)[i * 2] = (signed char) floor(y.real * 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);
|
dataOut->data[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iqDataOutQueue != NULL) {
|
if (iqDataOutQueue != NULL) {
|
||||||
@ -76,9 +76,8 @@ void SDRPostThread::threadMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
|
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
|
||||||
SDRThreadIQData visualDataOut;
|
SDRThreadIQData *visualDataOut = new SDRThreadIQData;
|
||||||
visualDataOut.data = new std::vector<signed char>;
|
visualDataOut->data.assign(dataOut->data.begin(), dataOut->data.begin() + (FFT_SIZE * 2));
|
||||||
visualDataOut.data->assign(dataOut.data->begin(), dataOut.data->begin() + (FFT_SIZE * 2));
|
|
||||||
iqVisualQueue.load()->push(visualDataOut);
|
iqVisualQueue.load()->push(visualDataOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,34 +109,32 @@ void SDRPostThread::threadMain() {
|
|||||||
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
||||||
DemodulatorInstance *demod = *i;
|
DemodulatorInstance *demod = *i;
|
||||||
|
|
||||||
if (demod->getParams().frequency != data_in.frequency
|
if (demod->getParams().frequency != data_in->frequency
|
||||||
&& abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
|
&& abs(data_in->frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
activeDemods++;
|
activeDemods++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool demodActive = false;
|
|
||||||
|
|
||||||
if (demodulators.size()) {
|
if (demodulators.size()) {
|
||||||
DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
|
DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
|
||||||
demodDataOut->frequency = data_in.frequency;
|
demodDataOut->frequency = data_in->frequency;
|
||||||
demodDataOut->bandwidth = data_in.bandwidth;
|
demodDataOut->bandwidth = data_in->bandwidth;
|
||||||
demodDataOut->setRefCount(activeDemods);
|
demodDataOut->setRefCount(activeDemods);
|
||||||
demodDataOut->data.assign(dataOut.data->begin(), dataOut.data->begin() + dataOut.data->size());
|
demodDataOut->data.assign(dataOut->data.begin(), dataOut->data.begin() + dataOut->data.size());
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
||||||
DemodulatorInstance *demod = *i;
|
DemodulatorInstance *demod = *i;
|
||||||
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
|
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
|
||||||
|
|
||||||
if (demod->getParams().frequency != data_in.frequency
|
if (demod->getParams().frequency != data_in->frequency
|
||||||
&& abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
|
&& abs(data_in->frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
|
||||||
if (demod->isActive()) {
|
if (demod->isActive()) {
|
||||||
demod->setActive(false);
|
demod->setActive(false);
|
||||||
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
|
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
|
||||||
dummyDataOut->frequency = data_in.frequency;
|
dummyDataOut->frequency = data_in->frequency;
|
||||||
dummyDataOut->bandwidth = data_in.bandwidth;
|
dummyDataOut->bandwidth = data_in->bandwidth;
|
||||||
demodQueue->push(dummyDataOut);
|
demodQueue->push(dummyDataOut);
|
||||||
}
|
}
|
||||||
} else if (!demod->isActive()) {
|
} else if (!demod->isActive()) {
|
||||||
@ -157,7 +154,10 @@ void SDRPostThread::threadMain() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete dataOut.data;
|
delete dataOut;
|
||||||
|
}
|
||||||
|
if (data_in) {
|
||||||
|
delete data_in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "SDR post-processing thread done." << std::endl;
|
std::cout << "SDR post-processing thread done." << std::endl;
|
||||||
@ -165,6 +165,6 @@ void SDRPostThread::threadMain() {
|
|||||||
|
|
||||||
void SDRPostThread::terminate() {
|
void SDRPostThread::terminate() {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
SDRThreadIQData dummy;
|
SDRThreadIQData *dummy = new SDRThreadIQData;
|
||||||
iqDataInQueue.load()->push(dummy);
|
iqDataInQueue.load()->push(dummy);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
|
|
||||||
void setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue);
|
void setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue);
|
||||||
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue);
|
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue);
|
||||||
void setIQVisualQueue(SDRThreadIQDataQueue *iqVisQueue);
|
void setIQVisualQueue(SDRThreadIQDataQueue* iqVisQueue);
|
||||||
|
|
||||||
void threadMain();
|
void threadMain();
|
||||||
void terminate();
|
void terminate();
|
||||||
@ -21,9 +21,9 @@ public:
|
|||||||
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;
|
||||||
std::atomic<SDRThreadIQDataQueue*> iqVisualQueue;
|
std::atomic<SDRThreadIQDataQueue *> iqVisualQueue;
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> demodulators;
|
std::vector<DemodulatorInstance *> demodulators;
|
||||||
std::vector<DemodulatorInstance *> demodulators_add;
|
std::vector<DemodulatorInstance *> demodulators_add;
|
||||||
|
@ -158,20 +158,17 @@ void SDRThread::threadMain() {
|
|||||||
|
|
||||||
rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read);
|
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++) {
|
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;
|
double time_slice = (double) n_read / (double) sample_rate;
|
||||||
seconds += time_slice;
|
seconds += time_slice;
|
||||||
|
|
||||||
SDRThreadIQData dataOut;
|
|
||||||
dataOut.frequency = frequency;
|
|
||||||
dataOut.bandwidth = bandwidth;
|
|
||||||
dataOut.data = new_buffer;
|
|
||||||
|
|
||||||
if (iqDataOutQueue != NULL) {
|
if (iqDataOutQueue != NULL) {
|
||||||
iqDataOutQueue.load()->push(dataOut);
|
iqDataOutQueue.load()->push(dataOut);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class SDRThreadIQData {
|
|||||||
public:
|
public:
|
||||||
unsigned int frequency;
|
unsigned int frequency;
|
||||||
unsigned int bandwidth;
|
unsigned int bandwidth;
|
||||||
std::vector<signed char> *data;
|
std::vector<signed char> data;
|
||||||
|
|
||||||
SDRThreadIQData() :
|
SDRThreadIQData() :
|
||||||
frequency(0), bandwidth(0), data(NULL) {
|
frequency(0), bandwidth(0), data(NULL) {
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> *data) :
|
SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> *data) :
|
||||||
frequency(frequency), bandwidth(bandwidth), data(data) {
|
frequency(frequency), bandwidth(bandwidth) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
|
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
|
||||||
typedef ThreadQueue<SDRThreadIQData> SDRThreadIQDataQueue;
|
typedef ThreadQueue<SDRThreadIQData *> SDRThreadIQDataQueue;
|
||||||
|
|
||||||
class SDRThread {
|
class SDRThread {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user