mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-22 11:49:38 -05:00
eliminate fp/int IQ data conversions
This commit is contained in:
parent
b487cf9901
commit
45b223aed9
@ -96,7 +96,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
|
||||
// std::this_thread::yield();
|
||||
//#endif
|
||||
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
||||
SDRThreadIQData *iqData;
|
||||
DemodulatorThreadIQData *iqData;
|
||||
wxGetApp().getIQVisualQueue()->pop(iqData);
|
||||
|
||||
if (iqData && iqData->data.size()) {
|
||||
|
@ -30,7 +30,7 @@ bool CubicSDR::OnInit() {
|
||||
sdrPostThread = new SDRPostThread();
|
||||
|
||||
iqPostDataQueue = new SDRThreadIQDataQueue;
|
||||
iqVisualQueue = new SDRThreadIQDataQueue;
|
||||
iqVisualQueue = new DemodulatorThreadInputQueue;
|
||||
iqVisualQueue->set_max_num_items(1);
|
||||
|
||||
sdrThread->setIQDataOutQueue(iqPostDataQueue);
|
||||
@ -115,7 +115,7 @@ DemodulatorThreadOutputQueue* CubicSDR::getAudioVisualQueue() {
|
||||
return audioVisualQueue;
|
||||
}
|
||||
|
||||
SDRThreadIQDataQueue* CubicSDR::getIQVisualQueue() {
|
||||
DemodulatorThreadInputQueue* CubicSDR::getIQVisualQueue() {
|
||||
return iqVisualQueue;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
int getFrequency();
|
||||
|
||||
DemodulatorThreadOutputQueue* getAudioVisualQueue();
|
||||
SDRThreadIQDataQueue* getIQVisualQueue();
|
||||
DemodulatorThreadInputQueue* getIQVisualQueue();
|
||||
DemodulatorMgr &getDemodMgr();
|
||||
|
||||
void bindDemodulator(DemodulatorInstance *demod);
|
||||
@ -50,8 +50,8 @@ private:
|
||||
SDRPostThread *sdrPostThread;
|
||||
|
||||
SDRThreadCommandQueue* threadCmdQueueSDR;
|
||||
SDRThreadIQDataQueue* iqVisualQueue;
|
||||
SDRThreadIQDataQueue* iqPostDataQueue;
|
||||
DemodulatorThreadInputQueue* iqVisualQueue;
|
||||
DemodulatorThreadOutputQueue* audioVisualQueue;
|
||||
|
||||
std::thread *t_SDR;
|
||||
|
@ -55,7 +55,7 @@ class DemodulatorThreadIQData: public ReferenceCounter {
|
||||
public:
|
||||
unsigned int frequency;
|
||||
unsigned int bandwidth;
|
||||
std::vector<signed char> data;
|
||||
std::vector<liquid_float_complex> data;
|
||||
|
||||
DemodulatorThreadIQData() :
|
||||
frequency(0), bandwidth(0) {
|
||||
|
@ -166,9 +166,9 @@ void DemodulatorPreThread::threadMain() {
|
||||
}
|
||||
|
||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||
std::vector<signed char> *data = &inp->data;
|
||||
std::vector<liquid_float_complex> *data = &inp->data;
|
||||
if (data->size()) {
|
||||
int bufSize = data->size() / 2;
|
||||
int bufSize = data->size();
|
||||
|
||||
if (in_buf_data.size() != bufSize) {
|
||||
if (in_buf_data.capacity() < bufSize) {
|
||||
@ -179,15 +179,12 @@ void DemodulatorPreThread::threadMain() {
|
||||
out_buf_data.resize(bufSize);
|
||||
}
|
||||
|
||||
in_buf_data.assign(inp->data.begin(),inp->data.end());
|
||||
|
||||
liquid_float_complex *in_buf = &in_buf_data[0];
|
||||
liquid_float_complex *out_buf = &out_buf_data[0];
|
||||
liquid_float_complex *temp_buf = NULL;
|
||||
|
||||
for (int i = 0; i < bufSize; i++) {
|
||||
in_buf[i].real = (float) (*data)[i * 2] / 127.0f;
|
||||
in_buf[i].imag = (float) (*data)[i * 2 + 1] / 127.0f;
|
||||
}
|
||||
|
||||
if (shift_freq != 0) {
|
||||
if (shift_freq < 0) {
|
||||
nco_crcf_mix_block_up(nco_shift, in_buf, out_buf, bufSize);
|
||||
|
@ -27,10 +27,10 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||
void SDRPostThread::setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue) {
|
||||
iqDataInQueue = iqDataQueue;
|
||||
}
|
||||
void SDRPostThread::setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue) {
|
||||
void SDRPostThread::setIQDataOutQueue(DemodulatorThreadInputQueue* iqDataQueue) {
|
||||
iqDataOutQueue = iqDataQueue;
|
||||
}
|
||||
void SDRPostThread::setIQVisualQueue(SDRThreadIQDataQueue *iqVisQueue) {
|
||||
void SDRPostThread::setIQVisualQueue(DemodulatorThreadInputQueue *iqVisQueue) {
|
||||
iqVisualQueue = iqVisQueue;
|
||||
}
|
||||
|
||||
@ -47,13 +47,12 @@ void SDRPostThread::threadMain() {
|
||||
|
||||
dcFilter = iirfilt_crcf_create_dc_blocker(0.0005);
|
||||
|
||||
liquid_float_complex x, y;
|
||||
|
||||
std::cout << "SDR post-processing thread started.." << std::endl;
|
||||
|
||||
std::deque<DemodulatorThreadIQData *> buffers;
|
||||
std::deque<DemodulatorThreadIQData *>::iterator buffers_i;
|
||||
std::vector<signed char> dataOut;
|
||||
std::vector<liquid_float_complex> fpData;
|
||||
std::vector<liquid_float_complex> dataOut;
|
||||
|
||||
while (!terminated) {
|
||||
SDRThreadIQData *data_in;
|
||||
@ -62,34 +61,35 @@ void SDRPostThread::threadMain() {
|
||||
// std::lock_guard < std::mutex > lock(data_in->m_mutex);
|
||||
|
||||
if (data_in && data_in->data.size()) {
|
||||
if (data_in->data.size() > dataOut.capacity()) {
|
||||
dataOut.reserve(data_in->data.size());
|
||||
int dataSize = data_in->data.size()/2;
|
||||
if (dataSize > fpData.capacity()) {
|
||||
fpData.reserve(dataSize);
|
||||
dataOut.reserve(dataSize);
|
||||
}
|
||||
if (dataSize != fpData.size()) {
|
||||
fpData.resize(dataSize);
|
||||
dataOut.resize(dataSize);
|
||||
}
|
||||
|
||||
dataOut.assign(data_in->data.begin(), data_in->data.end());
|
||||
|
||||
for (int i = 0, iMax = dataOut.size() / 2; i < iMax; i++) {
|
||||
x.real = (float) dataOut[i * 2] / 127.0;
|
||||
x.imag = (float) dataOut[i * 2 + 1] / 127.0;
|
||||
|
||||
iirfilt_crcf_execute(dcFilter, x, &y);
|
||||
|
||||
dataOut[i * 2] = (signed char) floor(y.real * 127.0);
|
||||
dataOut[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
|
||||
for (int i = 0, iMax = dataSize; i < iMax; i++) {
|
||||
fpData[i].real = (float) data_in->data[i * 2] / 127.0;
|
||||
fpData[i].imag = (float) data_in->data[i * 2 + 1] / 127.0;
|
||||
}
|
||||
|
||||
iirfilt_crcf_execute_block(dcFilter, &fpData[0], dataSize, &dataOut[0]);
|
||||
|
||||
if (iqDataOutQueue != NULL) {
|
||||
SDRThreadIQData *visDataOut = new SDRThreadIQData;
|
||||
DemodulatorThreadIQData *pipeDataOut = new DemodulatorThreadIQData;
|
||||
|
||||
visDataOut->frequency = data_in->frequency;
|
||||
visDataOut->bandwidth = data_in->bandwidth;
|
||||
visDataOut->data.assign(dataOut.begin(), dataOut.end());
|
||||
iqDataOutQueue.load()->push(visDataOut);
|
||||
pipeDataOut->frequency = data_in->frequency;
|
||||
pipeDataOut->bandwidth = data_in->bandwidth;
|
||||
pipeDataOut->data.assign(dataOut.begin(), dataOut.end());
|
||||
iqDataOutQueue.load()->push(pipeDataOut);
|
||||
}
|
||||
|
||||
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
|
||||
SDRThreadIQData *visualDataOut = new SDRThreadIQData;
|
||||
visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + (FFT_SIZE * 2));
|
||||
DemodulatorThreadIQData *visualDataOut = new DemodulatorThreadIQData;
|
||||
visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + FFT_SIZE);
|
||||
iqVisualQueue.load()->push(visualDataOut);
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ void SDRPostThread::threadMain() {
|
||||
demodDataOut->frequency = data_in->frequency;
|
||||
demodDataOut->bandwidth = data_in->bandwidth;
|
||||
demodDataOut->setRefCount(activeDemods);
|
||||
demodDataOut->data.assign(dataOut.begin(), dataOut.begin() + dataOut.size());
|
||||
demodDataOut->data.assign(dataOut.begin(), dataOut.end());
|
||||
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
||||
|
@ -12,8 +12,8 @@ public:
|
||||
void removeDemodulator(DemodulatorInstance *demod);
|
||||
|
||||
void setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue);
|
||||
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue);
|
||||
void setIQVisualQueue(SDRThreadIQDataQueue* iqVisQueue);
|
||||
void setIQDataOutQueue(DemodulatorThreadInputQueue* iqDataQueue);
|
||||
void setIQVisualQueue(DemodulatorThreadInputQueue* 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<DemodulatorThreadInputQueue *> iqDataOutQueue;
|
||||
std::atomic<DemodulatorThreadInputQueue *> iqVisualQueue;
|
||||
|
||||
std::vector<DemodulatorInstance *> demodulators;
|
||||
std::vector<DemodulatorInstance *> demodulators_add;
|
||||
|
@ -73,7 +73,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
void SpectrumCanvas::setData(std::vector<signed char> *data) {
|
||||
void SpectrumCanvas::setData(std::vector<liquid_float_complex> *data) {
|
||||
|
||||
if (data && data->size()) {
|
||||
if (spectrum_points.size() < FFT_SIZE * 2) {
|
||||
@ -81,8 +81,8 @@ void SpectrumCanvas::setData(std::vector<signed char> *data) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < FFT_SIZE; i++) {
|
||||
in[i][0] = (float) (*data)[i * 2] / 127.0f;
|
||||
in[i][1] = (float) (*data)[i * 2 + 1] / 127.0f;
|
||||
in[i][0] = (*data)[i].real;
|
||||
in[i][1] = (*data)[i].imag;
|
||||
}
|
||||
|
||||
fftw_execute(plan);
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
SpectrumCanvas(wxWindow *parent, int *attribList = NULL);
|
||||
~SpectrumCanvas();
|
||||
|
||||
void setData(std::vector<signed char> *data);
|
||||
void setData(std::vector<liquid_float_complex> *data);
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
|
||||
|
@ -206,7 +206,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallCanvas::setData(std::vector<signed char> *data) {
|
||||
void WaterfallCanvas::setData(std::vector<liquid_float_complex> *data) {
|
||||
|
||||
if (data && data->size()) {
|
||||
if (spectrum_points.size() < FFT_SIZE * 2) {
|
||||
@ -214,8 +214,8 @@ void WaterfallCanvas::setData(std::vector<signed char> *data) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < FFT_SIZE; i++) {
|
||||
in[i][0] = (float) (*data)[i * 2] / 127.0f;
|
||||
in[i][1] = (float) (*data)[i * 2 + 1] / 127.0f;
|
||||
in[i][0] = (*data)[i].real;
|
||||
in[i][1] = (*data)[i].imag;
|
||||
}
|
||||
|
||||
fftw_execute(plan);
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
WaterfallCanvas(wxWindow *parent, int *attribList = NULL);
|
||||
~WaterfallCanvas();
|
||||
|
||||
void setData(std::vector<signed char> *data);
|
||||
void setData(std::vector<liquid_float_complex> *data);
|
||||
int GetFrequencyAt(float x);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user