mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-05 06:37:52 -04:00
Demodulator split
This commit is contained in:
parent
c7a167a1d0
commit
62c5ab38e5
87
src/demod/DemodulatorThread.cpp
Normal file
87
src/demod/DemodulatorThread.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "DemodulatorThread.h"
|
||||||
|
#include "CubicSDRDefs.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadCommandQueue* threadQueueNotify) :
|
||||||
|
postInputQueue(pQueue), visOutQueue(NULL), terminated(false), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify) {
|
||||||
|
|
||||||
|
float kf = 0.5; // modulation factor
|
||||||
|
fdem = freqdem_create(kf);
|
||||||
|
// freqdem_print(fdem);
|
||||||
|
}
|
||||||
|
DemodulatorThread::~DemodulatorThread() {
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
void *DemodulatorThread::threadMain() {
|
||||||
|
#else
|
||||||
|
void DemodulatorThread::threadMain() {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::cout << "Demodulator thread started.." << std::endl;
|
||||||
|
while (!terminated) {
|
||||||
|
DemodulatorThreadPostIQData inp;
|
||||||
|
postInputQueue->pop(inp);
|
||||||
|
|
||||||
|
int out_size = inp.data.size();
|
||||||
|
|
||||||
|
if (!out_size) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
msresamp_crcf audio_resampler = inp.audio_resampler;
|
||||||
|
float audio_resample_ratio = inp.audio_resample_ratio;
|
||||||
|
|
||||||
|
float demod_output[out_size];
|
||||||
|
|
||||||
|
freqdem_demodulate_block(fdem, &inp.data[0], out_size, demod_output);
|
||||||
|
|
||||||
|
liquid_float_complex demod_audio_data[out_size];
|
||||||
|
|
||||||
|
for (int i = 0; i < out_size; i++) {
|
||||||
|
demod_audio_data[i].real = demod_output[i];
|
||||||
|
demod_audio_data[i].imag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int audio_out_size = ceil((float) (out_size) * audio_resample_ratio);
|
||||||
|
liquid_float_complex resampled_audio_output[audio_out_size];
|
||||||
|
|
||||||
|
unsigned int num_audio_written;
|
||||||
|
msresamp_crcf_execute(audio_resampler, demod_audio_data, out_size, resampled_audio_output, &num_audio_written);
|
||||||
|
|
||||||
|
std::vector<float> newBuffer;
|
||||||
|
newBuffer.resize(num_audio_written * 2);
|
||||||
|
for (int i = 0; i < num_audio_written; i++) {
|
||||||
|
liquid_float_complex y = resampled_audio_output[i];
|
||||||
|
|
||||||
|
newBuffer[i * 2] = y.real;
|
||||||
|
newBuffer[i * 2 + 1] = y.real;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioThreadInput ati;
|
||||||
|
ati.data = newBuffer;
|
||||||
|
|
||||||
|
if (audioInputQueue != NULL) {
|
||||||
|
audioInputQueue->push(ati);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visOutQueue != NULL) {
|
||||||
|
visOutQueue->push(ati);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Demodulator thread done." << std::endl;
|
||||||
|
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
||||||
|
tCmd.context = this;
|
||||||
|
threadQueueNotify->push(tCmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemodulatorThread::terminate() {
|
||||||
|
terminated = true;
|
||||||
|
DemodulatorThreadPostIQData inp; // push dummy to nudge queue
|
||||||
|
postInputQueue->push(inp);
|
||||||
|
}
|
51
src/demod/DemodulatorThread.h
Normal file
51
src/demod/DemodulatorThread.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "DemodDefs.h"
|
||||||
|
#include "AudioThread.h"
|
||||||
|
|
||||||
|
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
||||||
|
|
||||||
|
class DemodulatorThread {
|
||||||
|
public:
|
||||||
|
|
||||||
|
DemodulatorThread(DemodulatorThreadPostInputQueue* pQueueIn, DemodulatorThreadCommandQueue* threadQueueNotify);
|
||||||
|
~DemodulatorThread();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
void *threadMain();
|
||||||
|
#else
|
||||||
|
void threadMain();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||||
|
visOutQueue = tQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||||
|
audioInputQueue = tQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize();
|
||||||
|
|
||||||
|
void terminate();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
static void *pthread_helper(void *context) {
|
||||||
|
return ((DemodulatorThread *) context)->threadMain();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
DemodulatorThreadPostInputQueue* postInputQueue;
|
||||||
|
DemodulatorThreadOutputQueue* visOutQueue;
|
||||||
|
AudioThreadInputQueue *audioInputQueue;
|
||||||
|
|
||||||
|
freqdem fdem;
|
||||||
|
|
||||||
|
std::atomic<bool> terminated;
|
||||||
|
|
||||||
|
DemodulatorThreadCommandQueue* threadQueueNotify;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user