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-18 18:00:06 -05:00
|
|
|
#include "AudioThread.h"
|
2014-11-22 22:17:33 -05:00
|
|
|
#include "ThreadQueue.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
2014-11-16 16:51:45 -05:00
|
|
|
|
2014-11-22 22:17:33 -05:00
|
|
|
enum DemodulatorType {
|
|
|
|
DEMOD_TYPE_NULL, DEMOD_TYPE_AM, DEMOD_TYPE_FM, DEMOD_TYPE_LSB, DEMOD_TYPE_USB, DEMOD_TYPE_WFM
|
|
|
|
};
|
|
|
|
|
|
|
|
class DemodulatorThreadIQData {
|
|
|
|
public:
|
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int bandwidth;
|
|
|
|
std::vector<signed char> data;
|
|
|
|
|
|
|
|
DemodulatorThreadIQData() :
|
|
|
|
frequency(0), bandwidth(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> data) :
|
|
|
|
data(data), frequency(frequency), bandwidth(bandwidth) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadIQData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DemodulatorThreadAudioData {
|
|
|
|
public:
|
|
|
|
unsigned int frequency;
|
|
|
|
unsigned int sampleRate;
|
|
|
|
unsigned char channels;
|
|
|
|
|
|
|
|
std::vector<float> data;
|
|
|
|
|
|
|
|
DemodulatorThreadAudioData() :
|
|
|
|
sampleRate(0), frequency(0), channels(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector<float> data) :
|
|
|
|
data(data), sampleRate(sampleRate), frequency(frequency), channels(1) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadAudioData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DemodulatorThreadParameters {
|
|
|
|
public:
|
|
|
|
unsigned int inputRate;
|
|
|
|
unsigned int inputResampleRate; // set equal to disable second stage re-sampling?
|
|
|
|
unsigned int demodResampleRate;
|
|
|
|
unsigned int filterFrequency;
|
|
|
|
unsigned int audioSampleRate;
|
|
|
|
AudioThreadInputQueue *audioInputQueue;
|
|
|
|
|
|
|
|
DemodulatorType demodType;
|
|
|
|
|
|
|
|
DemodulatorThreadParameters() :
|
|
|
|
audioInputQueue(NULL), inputRate(SRATE), inputResampleRate(200000), demodResampleRate(100000), audioSampleRate(48000), filterFrequency(
|
|
|
|
32000), demodType(DEMOD_TYPE_WFM) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemodulatorThreadParameters() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
|
|
|
|
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
|
|
|
|
|
|
|
class DemodulatorThread {
|
2014-11-16 16:51:45 -05:00
|
|
|
public:
|
2014-11-17 22:58:56 -05:00
|
|
|
|
2014-11-22 22:17:33 -05:00
|
|
|
DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params);
|
2014-11-16 16:51:45 -05:00
|
|
|
~DemodulatorThread();
|
|
|
|
|
2014-11-22 22:17:33 -05:00
|
|
|
void threadMain();
|
|
|
|
|
|
|
|
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
|
|
|
visOutQueue = tQueue;
|
|
|
|
visOutQueue->set_max_num_items(1);
|
|
|
|
}
|
|
|
|
|
2014-11-16 16:51:45 -05:00
|
|
|
protected:
|
2014-11-22 22:17:33 -05:00
|
|
|
DemodulatorThreadInputQueue* m_pQueue;
|
|
|
|
DemodulatorThreadOutputQueue* visOutQueue;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
|
|
|
firfilt_crcf fir_filter;
|
|
|
|
firfilt_crcf fir_audio_filter;
|
|
|
|
|
|
|
|
msresamp_crcf resampler;
|
|
|
|
float resample_ratio;
|
|
|
|
|
2014-11-17 22:58:56 -05:00
|
|
|
msresamp_crcf second_resampler;
|
|
|
|
float second_resampler_ratio;
|
2014-11-16 16:51:45 -05:00
|
|
|
|
|
|
|
msresamp_crcf audio_resampler;
|
|
|
|
float audio_resample_ratio;
|
|
|
|
|
2014-11-17 22:58:56 -05:00
|
|
|
DemodulatorThreadParameters params;
|
2014-11-16 16:51:45 -05:00
|
|
|
freqdem fdem;
|
|
|
|
};
|