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"
|
2014-11-22 22:17:33 -05:00
|
|
|
#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"
|
2014-11-22 22:17:33 -05:00
|
|
|
|
|
|
|
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-11-22 22:17:33 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
DemodulatorType demodType;
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
DemodulatorThreadParameters() :
|
|
|
|
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
|
|
|
|
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
}
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
~DemodulatorThreadParameters() {
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
}
|
2014-11-22 22:17:33 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
|
|
|
|
|
|
|
class DemodulatorThread {
|
2014-11-16 16:51:45 -05:00
|
|
|
public:
|
2014-11-17 22:58:56 -05:00
|
|
|
|
2014-12-11 19:07:21 -05:00
|
|
|
DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify);
|
2014-12-01 18:59:07 -05:00
|
|
|
~DemodulatorThread();
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
void *threadMain();
|
|
|
|
#else
|
|
|
|
void threadMain();
|
|
|
|
#endif
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
|
|
|
visOutQueue = tQueue;
|
|
|
|
}
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
|
|
|
commandQueue = tQueue;
|
|
|
|
}
|
2014-11-22 22:17:33 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
|
|
|
audioInputQueue = tQueue;
|
|
|
|
}
|
2014-11-26 21:05:19 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
DemodulatorThreadParameters &getParams() {
|
|
|
|
return params;
|
|
|
|
}
|
2014-11-30 17:11:29 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
void initialize();
|
2014-11-26 21:05:19 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
void terminate();
|
2014-11-26 21:05:19 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
#ifdef __APPLE__
|
|
|
|
static void *pthread_helper(void *context) {
|
|
|
|
return ((DemodulatorThread *) context)->threadMain();
|
|
|
|
}
|
|
|
|
#endif
|
2014-11-23 19:39:27 -05:00
|
|
|
|
2014-11-16 16:51:45 -05:00
|
|
|
protected:
|
2014-12-01 18:59:07 -05:00
|
|
|
DemodulatorThreadInputQueue* inputQueue;
|
|
|
|
DemodulatorThreadOutputQueue* visOutQueue;
|
|
|
|
DemodulatorThreadCommandQueue* commandQueue;
|
|
|
|
AudioThreadInputQueue *audioInputQueue;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
firfilt_crcf fir_filter;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
msresamp_crcf resampler;
|
|
|
|
float resample_ratio;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
msresamp_crcf audio_resampler;
|
|
|
|
float audio_resample_ratio;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
DemodulatorThreadParameters params;
|
|
|
|
DemodulatorThreadParameters last_params;
|
2014-11-26 22:29:23 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
freqdem fdem;
|
|
|
|
nco_crcf nco_shift;
|
|
|
|
int shift_freq;
|
2014-11-27 22:13:21 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
std::atomic<bool> terminated;
|
|
|
|
std::atomic<bool> initialized;
|
2014-11-30 23:33:55 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
DemodulatorWorkerThread *workerThread;
|
|
|
|
std::thread *t_Worker;
|
2014-11-30 23:33:55 -05:00
|
|
|
|
2014-12-01 18:59:07 -05:00
|
|
|
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
|
|
|
DemodulatorThreadWorkerResultQueue *workerResults;
|
2014-12-11 19:07:21 -05:00
|
|
|
DemodulatorThreadCommandQueue* threadQueueNotify;
|
2014-11-16 16:51:45 -05:00
|
|
|
};
|