Fix demodulator init race

This commit is contained in:
Charles J. Cliffe 2015-11-20 21:41:57 -05:00
parent 7e856988a2
commit 703e281d76
2 changed files with 12 additions and 7 deletions

View File

@ -75,6 +75,7 @@ void DemodulatorInstance::run() {
currentFrequency = demodulatorPreThread->getParams().frequency; currentFrequency = demodulatorPreThread->getParams().frequency;
currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()]; currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()];
demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate; demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate;
setDemodulatorType(demodulatorPreThread->getParams().demodType);
t_Audio = new std::thread(&AudioThread::threadMain, audioThread); t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
@ -101,7 +102,6 @@ void DemodulatorInstance::run() {
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread); t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
#endif #endif
setDemodulatorType(demodulatorPreThread->getParams().demodType);
active = true; active = true;
audioTerminated = demodTerminated = preDemodTerminated = terminated = false; audioTerminated = demodTerminated = preDemodTerminated = terminated = false;
@ -289,6 +289,7 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
demodulatorPreThread->getParams().demodType = currentDemodType; demodulatorPreThread->getParams().demodType = currentDemodType;
if (!active) { if (!active) {
checkBandwidth(); checkBandwidth();
demodulatorPreThread->setDemodType(currentDemodType);
} else if (demodulatorThread && threadQueueControl) { } else if (demodulatorThread && threadQueueControl) {
demodulatorPreThread->setDemodType(currentDemodType); demodulatorPreThread->setDemodType(currentDemodType);
} }

View File

@ -19,7 +19,7 @@ void DemodulatorWorkerThread::run() {
while (!terminated) { while (!terminated) {
bool filterChanged = false; bool filterChanged = false;
bool makeDemod = false; bool makeDemod = false;
DemodulatorWorkerThreadCommand filterCommand; DemodulatorWorkerThreadCommand filterCommand, demodCommand;
DemodulatorWorkerThreadCommand command; DemodulatorWorkerThreadCommand command;
bool done = false; bool done = false;
@ -32,7 +32,7 @@ void DemodulatorWorkerThread::run() {
break; break;
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD: case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD:
makeDemod = true; makeDemod = true;
filterCommand = command; demodCommand = command;
break; break;
default: default:
break; break;
@ -52,15 +52,19 @@ void DemodulatorWorkerThread::run() {
} }
if (makeDemod) { if (makeDemod) {
cModem = Modem::makeModem(filterCommand.demodType); cModem = Modem::makeModem(demodCommand.demodType);
cModemType = filterCommand.demodType; cModemType = demodCommand.demodType;
} }
result.modem = cModem; result.modem = cModem;
if (filterCommand.bandwidth && filterCommand.audioSampleRate) { if (makeDemod && demodCommand.bandwidth && demodCommand.audioSampleRate) {
if (cModem != nullptr) { if (cModem != nullptr) {
cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate); cModemKit = cModem->buildKit(demodCommand.bandwidth, demodCommand.audioSampleRate);
} else {
cModemKit = nullptr;
} }
} else if (makeDemod) {
cModemKit = nullptr;
} }
result.modemKit = cModemKit; result.modemKit = cModemKit;