mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 13:48:38 -05:00
Rebalance demodulator threads, tweak priorities
This commit is contained in:
parent
62c5ab38e5
commit
02cf2099a9
@ -93,6 +93,10 @@ void AppFrame::OnThread(wxCommandEvent& event) {
|
|||||||
void AppFrame::OnIdle(wxIdleEvent& event) {
|
void AppFrame::OnIdle(wxIdleEvent& event) {
|
||||||
bool work_done = false;
|
bool work_done = false;
|
||||||
|
|
||||||
|
//#ifdef __APPLE__
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||||
|
// std::this_thread::yield();
|
||||||
|
//#endif
|
||||||
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
||||||
SDRThreadIQData iqData;
|
SDRThreadIQData iqData;
|
||||||
wxGetApp().getIQVisualQueue()->pop(iqData);
|
wxGetApp().getIQVisualQueue()->pop(iqData);
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define BUF_SIZE (16384*3)
|
#define BUF_SIZE (16384*3)
|
||||||
#else
|
#define SRATE 1500000
|
||||||
#define BUF_SIZE (16384*4)
|
|
||||||
#endif
|
|
||||||
#define SRATE 2000000
|
|
||||||
#define FFT_SIZE 2048
|
#define FFT_SIZE 2048
|
||||||
|
|
||||||
#define DEFAULT_FREQ 98900000
|
#define DEFAULT_FREQ 98900000
|
||||||
#define AUDIO_FREQUENCY 48000
|
#define AUDIO_FREQUENCY 44100
|
||||||
|
@ -44,6 +44,13 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudioThread::threadMain() {
|
void AudioThread::threadMain() {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
|
sched_param prio = { priority }; // scheduling priority of thread
|
||||||
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
|
#endif
|
||||||
|
|
||||||
std::cout << "Audio thread initializing.." << std::endl;
|
std::cout << "Audio thread initializing.." << std::endl;
|
||||||
|
|
||||||
if (dac.getDeviceCount() < 1) {
|
if (dac.getDeviceCount() < 1) {
|
||||||
@ -59,7 +66,8 @@ void AudioThread::threadMain() {
|
|||||||
unsigned int bufferFrames = 256;
|
unsigned int bufferFrames = 256;
|
||||||
|
|
||||||
RtAudio::StreamOptions opts;
|
RtAudio::StreamOptions opts;
|
||||||
// opts.flags = RTAUDIO_SCHEDULE_REALTIME | RTAUDIO_MINIMIZE_LATENCY;
|
opts.flags = RTAUDIO_SCHEDULE_REALTIME;
|
||||||
|
// | RTAUDIO_MINIMIZE_LATENCY;
|
||||||
// opts.flags = RTAUDIO_MINIMIZE_LATENCY;
|
// opts.flags = RTAUDIO_MINIMIZE_LATENCY;
|
||||||
opts.streamName = "CubicSDR Audio Output";
|
opts.streamName = "CubicSDR Audio Output";
|
||||||
// opts.priority = sched_get_priority_max(SCHED_FIFO);
|
// opts.priority = sched_get_priority_max(SCHED_FIFO);
|
||||||
|
@ -66,6 +66,8 @@ public:
|
|||||||
std::vector<liquid_float_complex> data;
|
std::vector<liquid_float_complex> data;
|
||||||
float audio_resample_ratio;
|
float audio_resample_ratio;
|
||||||
msresamp_crcf audio_resampler;
|
msresamp_crcf audio_resampler;
|
||||||
|
float resample_ratio;
|
||||||
|
msresamp_crcf resampler;
|
||||||
|
|
||||||
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL) {
|
DemodulatorThreadPostIQData(): audio_resample_ratio(0), audio_resampler(NULL) {
|
||||||
|
|
||||||
|
@ -42,12 +42,14 @@ void DemodulatorInstance::run() {
|
|||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setstacksize(&attr, 2048000);
|
pthread_attr_setstacksize(&attr, 2048000);
|
||||||
pthread_attr_getstacksize(&attr, &size);
|
pthread_attr_getstacksize(&attr, &size);
|
||||||
|
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||||
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setstacksize(&attr, 2048000);
|
pthread_attr_setstacksize(&attr, 2048000);
|
||||||
pthread_attr_getstacksize(&attr, &size);
|
pthread_attr_getstacksize(&attr, &size);
|
||||||
|
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
|
@ -86,6 +86,12 @@ DemodulatorPreThread::~DemodulatorPreThread() {
|
|||||||
void *DemodulatorPreThread::threadMain() {
|
void *DemodulatorPreThread::threadMain() {
|
||||||
#else
|
#else
|
||||||
void DemodulatorPreThread::threadMain() {
|
void DemodulatorPreThread::threadMain() {
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
|
sched_param prio = { priority }; // scheduling priority of thread
|
||||||
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
@ -179,20 +185,15 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
out_buf = temp_buf;
|
out_buf = temp_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, out_buf);
|
|
||||||
|
|
||||||
int out_size = ceil((float) (bufSize) * resample_ratio);
|
|
||||||
|
|
||||||
DemodulatorThreadPostIQData resamp;
|
DemodulatorThreadPostIQData resamp;
|
||||||
|
resamp.data.resize(bufSize);
|
||||||
|
|
||||||
|
firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, &resamp.data[0]);
|
||||||
|
|
||||||
resamp.audio_resample_ratio = audio_resample_ratio;
|
resamp.audio_resample_ratio = audio_resample_ratio;
|
||||||
resamp.audio_resampler = audio_resampler;
|
resamp.audio_resampler = audio_resampler;
|
||||||
resamp.data.resize(out_size);
|
resamp.resample_ratio = resample_ratio;
|
||||||
|
resamp.resampler = resampler;
|
||||||
unsigned int num_written; // number of values written to buffer
|
|
||||||
msresamp_crcf_execute(resampler, out_buf, (bufSize), &resamp.data[0], &num_written);
|
|
||||||
|
|
||||||
resamp.data.resize(num_written);
|
|
||||||
|
|
||||||
postInputQueue->push(resamp);
|
postInputQueue->push(resamp);
|
||||||
}
|
}
|
||||||
@ -205,8 +206,8 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
switch (result.cmd) {
|
switch (result.cmd) {
|
||||||
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
|
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
|
||||||
firfilt_crcf_destroy(fir_filter);
|
firfilt_crcf_destroy(fir_filter);
|
||||||
msresamp_crcf_destroy(resampler);
|
// msresamp_crcf_destroy(resampler);
|
||||||
msresamp_crcf_destroy(audio_resampler);
|
// msresamp_crcf_destroy(audio_resampler);
|
||||||
|
|
||||||
fir_filter = result.fir_filter;
|
fir_filter = result.fir_filter;
|
||||||
resampler = result.resampler;
|
resampler = result.resampler;
|
||||||
|
@ -21,37 +21,61 @@ void *DemodulatorThread::threadMain() {
|
|||||||
#else
|
#else
|
||||||
void DemodulatorThread::threadMain() {
|
void DemodulatorThread::threadMain() {
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
|
int priority = sched_get_priority_min( SCHED_RR );
|
||||||
|
sched_param prio = { priority }; // scheduling priority of thread
|
||||||
|
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
msresamp_crcf audio_resampler = NULL;
|
||||||
|
msresamp_crcf resampler = NULL;
|
||||||
|
|
||||||
std::cout << "Demodulator thread started.." << std::endl;
|
std::cout << "Demodulator thread started.." << std::endl;
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
DemodulatorThreadPostIQData inp;
|
DemodulatorThreadPostIQData inp;
|
||||||
postInputQueue->pop(inp);
|
postInputQueue->pop(inp);
|
||||||
|
|
||||||
int out_size = inp.data.size();
|
int bufSize = inp.data.size();
|
||||||
|
|
||||||
if (!out_size) {
|
if (!bufSize) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
msresamp_crcf audio_resampler = inp.audio_resampler;
|
if (resampler == NULL) {
|
||||||
|
resampler = inp.resampler;
|
||||||
|
audio_resampler = inp.audio_resampler;
|
||||||
|
} else if (resampler != inp.resampler) {
|
||||||
|
msresamp_crcf_destroy(resampler);
|
||||||
|
msresamp_crcf_destroy(audio_resampler);
|
||||||
|
resampler = inp.resampler;
|
||||||
|
audio_resampler = inp.audio_resampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
int out_size = ceil((float) (bufSize) * inp.resample_ratio);
|
||||||
|
liquid_float_complex resampled_data[out_size];
|
||||||
|
|
||||||
|
unsigned int num_written;
|
||||||
|
msresamp_crcf_execute(resampler, &inp.data[0], bufSize, resampled_data, &num_written);
|
||||||
|
|
||||||
float audio_resample_ratio = inp.audio_resample_ratio;
|
float audio_resample_ratio = inp.audio_resample_ratio;
|
||||||
|
|
||||||
float demod_output[out_size];
|
float demod_output[num_written];
|
||||||
|
|
||||||
freqdem_demodulate_block(fdem, &inp.data[0], out_size, demod_output);
|
freqdem_demodulate_block(fdem, resampled_data, num_written, demod_output);
|
||||||
|
|
||||||
liquid_float_complex demod_audio_data[out_size];
|
liquid_float_complex demod_audio_data[num_written];
|
||||||
|
|
||||||
for (int i = 0; i < out_size; i++) {
|
for (int i = 0; i < num_written; i++) {
|
||||||
demod_audio_data[i].real = demod_output[i];
|
demod_audio_data[i].real = demod_output[i];
|
||||||
demod_audio_data[i].imag = 0;
|
demod_audio_data[i].imag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_out_size = ceil((float) (out_size) * audio_resample_ratio);
|
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
|
||||||
liquid_float_complex resampled_audio_output[audio_out_size];
|
liquid_float_complex resampled_audio_output[audio_out_size];
|
||||||
|
|
||||||
unsigned int num_audio_written;
|
unsigned int num_audio_written;
|
||||||
msresamp_crcf_execute(audio_resampler, demod_audio_data, out_size, resampled_audio_output, &num_audio_written);
|
msresamp_crcf_execute(audio_resampler, demod_audio_data, num_written, resampled_audio_output, &num_audio_written);
|
||||||
|
|
||||||
std::vector<float> newBuffer;
|
std::vector<float> newBuffer;
|
||||||
newBuffer.resize(num_audio_written * 2);
|
newBuffer.resize(num_audio_written * 2);
|
||||||
@ -74,6 +98,13 @@ void *DemodulatorThread::threadMain() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resampler != NULL) {
|
||||||
|
msresamp_crcf_destroy(resampler);
|
||||||
|
}
|
||||||
|
if (audio_resampler != NULL) {
|
||||||
|
msresamp_crcf_destroy(audio_resampler);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Demodulator thread done." << std::endl;
|
std::cout << "Demodulator thread done." << std::endl;
|
||||||
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
|
||||||
tCmd.context = this;
|
tCmd.context = this;
|
||||||
|
@ -42,6 +42,13 @@ void SDRPostThread::threadMain() {
|
|||||||
int n_read;
|
int n_read;
|
||||||
double seconds = 0.0;
|
double seconds = 0.0;
|
||||||
|
|
||||||
|
//#ifdef __APPLE__
|
||||||
|
// pthread_t tID = pthread_self(); // ID of this thread
|
||||||
|
// int priority = sched_get_priority_min( SCHED_RR );
|
||||||
|
// sched_param prio = { priority }; // scheduling priority of thread
|
||||||
|
// pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
|
//#endif
|
||||||
|
|
||||||
dcFilter = iirfilt_crcf_create_dc_blocker(0.0005);
|
dcFilter = iirfilt_crcf_create_dc_blocker(0.0005);
|
||||||
|
|
||||||
liquid_float_complex x, y;
|
liquid_float_complex x, y;
|
||||||
|
@ -89,6 +89,12 @@ int SDRThread::enumerate_rtl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SDRThread::threadMain() {
|
void SDRThread::threadMain() {
|
||||||
|
//#ifdef __APPLE__
|
||||||
|
// pthread_t tID = pthread_self(); // ID of this thread
|
||||||
|
// int priority = sched_get_priority_min( SCHED_RR );
|
||||||
|
// sched_param prio = { priority }; // scheduling priority of thread
|
||||||
|
// pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||||
|
//#endif
|
||||||
|
|
||||||
std::cout << "SDR thread initializing.." << std::endl;
|
std::cout << "SDR thread initializing.." << std::endl;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user