mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-06 07:07:48 -04:00
Increase demodulator stack size on OSX
Using pthreads as a drop-in, should work since underlying is already pthreads?
This commit is contained in:
parent
86ac0c59a8
commit
e668fa2b5d
@ -50,7 +50,22 @@ void DemodulatorInstance::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||||
|
|
||||||
|
#ifdef __APPLE__ // Already using pthreads, might as well do some custom init..
|
||||||
|
pthread_attr_t attr;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
pthread_attr_init(&attr);
|
||||||
|
pthread_attr_setstacksize(&attr, 2048000);
|
||||||
|
pthread_attr_getstacksize(&attr, &size);
|
||||||
|
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
|
std::cout << "Initialized demodulator stack size of " << size << std::endl;
|
||||||
|
|
||||||
|
#else
|
||||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
|
||||||
@ -64,8 +79,11 @@ DemodulatorThreadParameters &DemodulatorInstance::getParams() {
|
|||||||
void DemodulatorInstance::terminate() {
|
void DemodulatorInstance::terminate() {
|
||||||
std::cout << "Terminating demodulator thread.." << std::endl;
|
std::cout << "Terminating demodulator thread.." << std::endl;
|
||||||
demodulatorThread->terminate();
|
demodulatorThread->terminate();
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_join(t_Demod,NULL);
|
||||||
|
#else
|
||||||
t_Demod->join();
|
t_Demod->join();
|
||||||
|
#endif
|
||||||
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
std::cout << "Terminating demodulator audio thread.." << std::endl;
|
||||||
audioThread->terminate();
|
audioThread->terminate();
|
||||||
t_Audio->join();
|
t_Audio->join();
|
||||||
|
@ -12,7 +12,11 @@ public:
|
|||||||
DemodulatorThreadInputQueue* threadQueueDemod;
|
DemodulatorThreadInputQueue* threadQueueDemod;
|
||||||
DemodulatorThreadCommandQueue* threadQueueCommand;
|
DemodulatorThreadCommandQueue* threadQueueCommand;
|
||||||
DemodulatorThread *demodulatorThread;
|
DemodulatorThread *demodulatorThread;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_t t_Demod;
|
||||||
|
#else
|
||||||
std::thread *t_Demod;
|
std::thread *t_Demod;
|
||||||
|
#endif
|
||||||
|
|
||||||
AudioThreadInputQueue *audioInputQueue;
|
AudioThreadInputQueue *audioInputQueue;
|
||||||
AudioThread *audioThread;
|
AudioThread *audioThread;
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
#include "CubicSDRDefs.h"
|
#include "CubicSDRDefs.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue) :
|
DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue) :
|
||||||
inputQueue(pQueue), visOutQueue(NULL), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
|
inputQueue(pQueue), visOutQueue(NULL), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio(
|
||||||
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL) {
|
1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL) {
|
||||||
@ -76,7 +80,11 @@ DemodulatorThread::~DemodulatorThread() {
|
|||||||
delete workerResults;
|
delete workerResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
void *DemodulatorThread::threadMain() {
|
||||||
|
#else
|
||||||
void DemodulatorThread::threadMain() {
|
void DemodulatorThread::threadMain() {
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialize();
|
initialize();
|
||||||
|
@ -17,153 +17,172 @@
|
|||||||
#include "DemodulatorWorkerThread.h"
|
#include "DemodulatorWorkerThread.h"
|
||||||
|
|
||||||
enum DemodulatorType {
|
enum DemodulatorType {
|
||||||
DEMOD_TYPE_NULL, DEMOD_TYPE_AM, DEMOD_TYPE_FM, DEMOD_TYPE_LSB, DEMOD_TYPE_USB
|
DEMOD_TYPE_NULL,
|
||||||
|
DEMOD_TYPE_AM,
|
||||||
|
DEMOD_TYPE_FM,
|
||||||
|
DEMOD_TYPE_LSB,
|
||||||
|
DEMOD_TYPE_USB
|
||||||
};
|
};
|
||||||
|
|
||||||
class DemodulatorThreadCommand {
|
class DemodulatorThreadCommand {
|
||||||
public:
|
public:
|
||||||
enum DemodulatorThreadCommandEnum {
|
enum DemodulatorThreadCommandEnum {
|
||||||
DEMOD_THREAD_CMD_NULL, DEMOD_THREAD_CMD_SET_BANDWIDTH, DEMOD_THREAD_CMD_SET_FREQUENCY
|
DEMOD_THREAD_CMD_NULL,
|
||||||
};
|
DEMOD_THREAD_CMD_SET_BANDWIDTH,
|
||||||
|
DEMOD_THREAD_CMD_SET_FREQUENCY
|
||||||
|
};
|
||||||
|
|
||||||
DemodulatorThreadCommand() :
|
DemodulatorThreadCommand() :
|
||||||
cmd(DEMOD_THREAD_CMD_NULL), int_value(0) {
|
cmd(DEMOD_THREAD_CMD_NULL), int_value(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||||
cmd(cmd), int_value(0) {
|
cmd(cmd), int_value(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadCommandEnum cmd;
|
DemodulatorThreadCommandEnum cmd;
|
||||||
int int_value;
|
int int_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DemodulatorThreadIQData {
|
class DemodulatorThreadIQData {
|
||||||
public:
|
public:
|
||||||
unsigned int frequency;
|
unsigned int frequency;
|
||||||
unsigned int bandwidth;
|
unsigned int bandwidth;
|
||||||
std::vector<signed char> data;
|
std::vector<signed char> data;
|
||||||
|
|
||||||
DemodulatorThreadIQData() :
|
DemodulatorThreadIQData() :
|
||||||
frequency(0), bandwidth(0) {
|
frequency(0), bandwidth(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> data) :
|
DemodulatorThreadIQData(unsigned int bandwidth, unsigned int frequency,
|
||||||
data(data), frequency(frequency), bandwidth(bandwidth) {
|
std::vector<signed char> data) :
|
||||||
|
data(data), frequency(frequency), bandwidth(bandwidth) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~DemodulatorThreadIQData() {
|
~DemodulatorThreadIQData() {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DemodulatorThreadAudioData {
|
class DemodulatorThreadAudioData {
|
||||||
public:
|
public:
|
||||||
unsigned int frequency;
|
unsigned int frequency;
|
||||||
unsigned int sampleRate;
|
unsigned int sampleRate;
|
||||||
unsigned char channels;
|
unsigned char channels;
|
||||||
|
|
||||||
std::vector<float> data;
|
std::vector<float> data;
|
||||||
|
|
||||||
DemodulatorThreadAudioData() :
|
DemodulatorThreadAudioData() :
|
||||||
sampleRate(0), frequency(0), channels(0) {
|
sampleRate(0), frequency(0), channels(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector<float> data) :
|
DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate,
|
||||||
data(data), sampleRate(sampleRate), frequency(frequency), channels(1) {
|
std::vector<float> data) :
|
||||||
|
data(data), sampleRate(sampleRate), frequency(frequency), channels(
|
||||||
|
1) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~DemodulatorThreadAudioData() {
|
~DemodulatorThreadAudioData() {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DemodulatorThreadParameters {
|
class DemodulatorThreadParameters {
|
||||||
public:
|
public:
|
||||||
unsigned int frequency;
|
unsigned int frequency;
|
||||||
unsigned int inputRate;
|
unsigned int inputRate;
|
||||||
unsigned int bandwidth; // set equal to disable second stage re-sampling?
|
unsigned int bandwidth; // set equal to disable second stage re-sampling?
|
||||||
unsigned int audioSampleRate;
|
unsigned int audioSampleRate;
|
||||||
|
|
||||||
DemodulatorType demodType;
|
DemodulatorType demodType;
|
||||||
|
|
||||||
DemodulatorThreadParameters() :
|
DemodulatorThreadParameters() :
|
||||||
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
frequency(0), inputRate(SRATE), bandwidth(200000), audioSampleRate(
|
||||||
|
AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~DemodulatorThreadParameters() {
|
~DemodulatorThreadParameters() {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
|
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
|
||||||
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
|
||||||
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
|
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
|
||||||
|
|
||||||
|
|
||||||
class DemodulatorThread {
|
class DemodulatorThread {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DemodulatorThread(DemodulatorThreadInputQueue* pQueue);
|
DemodulatorThread(DemodulatorThreadInputQueue* pQueue);
|
||||||
~DemodulatorThread();
|
~DemodulatorThread();
|
||||||
|
|
||||||
void threadMain();
|
#ifdef __APPLE__
|
||||||
|
void *threadMain();
|
||||||
|
#else
|
||||||
|
void threadMain();
|
||||||
|
#endif
|
||||||
|
|
||||||
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||||
visOutQueue = tQueue;
|
visOutQueue = tQueue;
|
||||||
visOutQueue->set_max_num_items(1);
|
visOutQueue->set_max_num_items(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
|
||||||
commandQueue = tQueue;
|
commandQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
void setAudioInputQueue(AudioThreadInputQueue *tQueue) {
|
||||||
audioInputQueue = tQueue;
|
audioInputQueue = tQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorThreadParameters &getParams() {
|
DemodulatorThreadParameters &getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
static void *pthread_helper(void *context) {
|
||||||
|
return ((DemodulatorThread *) context)->threadMain();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DemodulatorThreadInputQueue* inputQueue;
|
DemodulatorThreadInputQueue* inputQueue;
|
||||||
DemodulatorThreadOutputQueue* visOutQueue;
|
DemodulatorThreadOutputQueue* visOutQueue;
|
||||||
DemodulatorThreadCommandQueue* commandQueue;
|
DemodulatorThreadCommandQueue* commandQueue;
|
||||||
AudioThreadInputQueue *audioInputQueue;
|
AudioThreadInputQueue *audioInputQueue;
|
||||||
|
|
||||||
firfilt_crcf fir_filter;
|
firfilt_crcf fir_filter;
|
||||||
|
|
||||||
msresamp_crcf resampler;
|
msresamp_crcf resampler;
|
||||||
float resample_ratio;
|
float resample_ratio;
|
||||||
|
|
||||||
msresamp_crcf audio_resampler;
|
msresamp_crcf audio_resampler;
|
||||||
float audio_resample_ratio;
|
float audio_resample_ratio;
|
||||||
|
|
||||||
DemodulatorThreadParameters params;
|
DemodulatorThreadParameters params;
|
||||||
DemodulatorThreadParameters last_params;
|
DemodulatorThreadParameters last_params;
|
||||||
|
|
||||||
freqdem fdem;
|
freqdem fdem;
|
||||||
nco_crcf nco_shift;
|
nco_crcf nco_shift;
|
||||||
int shift_freq;
|
int shift_freq;
|
||||||
|
|
||||||
std::atomic<bool> terminated;
|
std::atomic<bool> terminated;
|
||||||
std::atomic<bool> initialized;
|
std::atomic<bool> initialized;
|
||||||
|
|
||||||
DemodulatorWorkerThread *workerThread;
|
DemodulatorWorkerThread *workerThread;
|
||||||
std::thread *t_Worker;
|
std::thread *t_Worker;
|
||||||
|
|
||||||
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
DemodulatorThreadWorkerCommandQueue *workerQueue;
|
||||||
DemodulatorThreadWorkerResultQueue *workerResults;
|
DemodulatorThreadWorkerResultQueue *workerResults;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user