CubicSDR/src/demod/DemodulatorThread.h

109 lines
2.2 KiB
C
Raw Normal View History

2014-11-16 16:51:45 -05:00
#pragma once
#include <queue>
#include <vector>
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/thread.h"
#include "liquid/liquid.h"
#include "CubicSDRDefs.h"
2014-11-30 23:33:55 -05:00
#include "DemodulatorWorkerThread.h"
2014-12-11 19:07:21 -05:00
#include "DemodDefs.h"
class DemodulatorThreadParameters {
public:
2014-12-11 19:07:21 -05:00
unsigned int frequency;
unsigned int inputRate;
unsigned int bandwidth; // set equal to disable second stage re-sampling?
unsigned int audioSampleRate;
2014-12-11 19:07:21 -05:00
DemodulatorType demodType;
2014-12-11 19:07:21 -05:00
DemodulatorThreadParameters() :
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
2014-12-11 19:07:21 -05:00
}
2014-12-11 19:07:21 -05:00
~DemodulatorThreadParameters() {
2014-12-11 19:07:21 -05:00
}
};
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
class DemodulatorThread {
2014-11-16 16:51:45 -05:00
public:
2014-12-11 19:07:21 -05:00
DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify);
~DemodulatorThread();
#ifdef __APPLE__
void *threadMain();
#else
void threadMain();
#endif
2014-11-16 16:51:45 -05:00
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
visOutQueue = tQueue;
}
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
commandQueue = tQueue;
}
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
audioInputQueue = tQueue;
}
DemodulatorThreadParameters &getParams() {
return params;
}
void initialize();
void terminate();
#ifdef __APPLE__
static void *pthread_helper(void *context) {
return ((DemodulatorThread *) context)->threadMain();
}
#endif
2014-11-16 16:51:45 -05:00
protected:
DemodulatorThreadInputQueue* inputQueue;
DemodulatorThreadOutputQueue* visOutQueue;
DemodulatorThreadCommandQueue* commandQueue;
AudioThreadInputQueue *audioInputQueue;
2014-11-16 16:51:45 -05:00
firfilt_crcf fir_filter;
2014-11-16 16:51:45 -05:00
msresamp_crcf resampler;
float resample_ratio;
2014-11-16 16:51:45 -05:00
msresamp_crcf audio_resampler;
float audio_resample_ratio;
2014-11-16 16:51:45 -05:00
DemodulatorThreadParameters params;
DemodulatorThreadParameters last_params;
freqdem fdem;
nco_crcf nco_shift;
int shift_freq;
std::atomic<bool> terminated;
std::atomic<bool> initialized;
2014-11-30 23:33:55 -05:00
DemodulatorWorkerThread *workerThread;
std::thread *t_Worker;
2014-11-30 23:33:55 -05:00
DemodulatorThreadWorkerCommandQueue *workerQueue;
DemodulatorThreadWorkerResultQueue *workerResults;
2014-12-11 19:07:21 -05:00
DemodulatorThreadCommandQueue* threadQueueNotify;
2014-11-16 16:51:45 -05:00
};