Merge pull request #999 from cjcliffe/fix-janky-bandwidth-ui

Fix modem bandwidth interaction lag; favor visual responsiveness
This commit is contained in:
Charles J. Cliffe 2023-04-17 23:38:53 -04:00 committed by GitHub
commit 87f5d8835a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 18 deletions

View File

@ -33,7 +33,7 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance* parent) : IOThre
workerThread->setOutputQueue("WorkerResultQueue",workerResults); workerThread->setOutputQueue("WorkerResultQueue",workerResults);
newSampleRate = currentSampleRate = 0; newSampleRate = currentSampleRate = 0;
newBandwidth = currentBandwidth = 0; currentBandwidth = 0;
newAudioSampleRate = currentAudioSampleRate = 0; newAudioSampleRate = currentAudioSampleRate = 0;
newFrequency = currentFrequency = 0; newFrequency = currentFrequency = 0;
@ -102,12 +102,12 @@ void DemodulatorPreThread::run() {
} }
} }
if (demodTypeChanged.load() && (newSampleRate && newAudioSampleRate && newBandwidth)) { if (demodTypeChanged.load() && (newSampleRate && newAudioSampleRate && currentBandwidth)) {
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::Type::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD); DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::Type::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD);
command.frequency = newFrequency; command.frequency = newFrequency;
command.sampleRate = newSampleRate; command.sampleRate = newSampleRate;
command.demodType = newDemodType; command.demodType = newDemodType;
command.bandwidth = newBandwidth; command.bandwidth = currentBandwidth;
command.audioSampleRate = newAudioSampleRate; command.audioSampleRate = newAudioSampleRate;
demodType = newDemodType; demodType = newDemodType;
sampleRateChanged.store(false); sampleRateChanged.store(false);
@ -135,12 +135,12 @@ void DemodulatorPreThread::run() {
else if ( else if (
cModemKit && cModem && cModemKit && cModem &&
(bandwidthChanged.load() || sampleRateChanged.load() || audioSampleRateChanged.load() || cModem->shouldRebuildKit()) && (bandwidthChanged.load() || sampleRateChanged.load() || audioSampleRateChanged.load() || cModem->shouldRebuildKit()) &&
(newSampleRate && newAudioSampleRate && newBandwidth) (newSampleRate && newAudioSampleRate && currentBandwidth)
) { ) {
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::Type::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS); DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::Type::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
command.frequency = newFrequency; command.frequency = newFrequency;
command.sampleRate = newSampleRate; command.sampleRate = newSampleRate;
command.bandwidth = newBandwidth; command.bandwidth = currentBandwidth;
command.audioSampleRate = newAudioSampleRate; command.audioSampleRate = newAudioSampleRate;
bandwidthChanged.store(false); bandwidthChanged.store(false);
sampleRateChanged.store(false); sampleRateChanged.store(false);
@ -249,10 +249,6 @@ void DemodulatorPreThread::run() {
currentAudioSampleRate = cModemKit->audioSampleRate; currentAudioSampleRate = cModemKit->audioSampleRate;
} }
if (result.bandwidth) {
currentBandwidth = result.bandwidth;
}
if (result.sampleRate) { if (result.sampleRate) {
currentSampleRate = result.sampleRate; currentSampleRate = result.sampleRate;
} }
@ -295,8 +291,8 @@ std::string DemodulatorPreThread::getDemodType() {
} }
void DemodulatorPreThread::setFrequency(long long freq) { void DemodulatorPreThread::setFrequency(long long freq) {
frequencyChanged.store(true);
newFrequency = freq; newFrequency = freq;
frequencyChanged.store(true);
} }
long long DemodulatorPreThread::getFrequency() { long long DemodulatorPreThread::getFrequency() {
@ -307,8 +303,8 @@ long long DemodulatorPreThread::getFrequency() {
} }
void DemodulatorPreThread::setSampleRate(long long sampleRate) { void DemodulatorPreThread::setSampleRate(long long sampleRate) {
sampleRateChanged.store(true);
newSampleRate = sampleRate; newSampleRate = sampleRate;
sampleRateChanged.store(true);
} }
long long DemodulatorPreThread::getSampleRate() { long long DemodulatorPreThread::getSampleRate() {
@ -319,21 +315,17 @@ long long DemodulatorPreThread::getSampleRate() {
} }
void DemodulatorPreThread::setBandwidth(int bandwidth) { void DemodulatorPreThread::setBandwidth(int bandwidth) {
currentBandwidth = bandwidth;
bandwidthChanged.store(true); bandwidthChanged.store(true);
newBandwidth = bandwidth;
} }
int DemodulatorPreThread::getBandwidth() { int DemodulatorPreThread::getBandwidth() {
// if (bandwidthChanged.load()) {
// return newBandwidth;
// }
return currentBandwidth; return currentBandwidth;
} }
void DemodulatorPreThread::setAudioSampleRate(int rate) { void DemodulatorPreThread::setAudioSampleRate(int rate) {
audioSampleRateChanged.store(true);
newAudioSampleRate = rate; newAudioSampleRate = rate;
audioSampleRateChanged.store(true);
} }
int DemodulatorPreThread::getAudioSampleRate() { int DemodulatorPreThread::getAudioSampleRate() {

View File

@ -62,7 +62,7 @@ protected:
std::atomic_llong currentSampleRate, newSampleRate; std::atomic_llong currentSampleRate, newSampleRate;
std::atomic_llong currentFrequency, newFrequency; std::atomic_llong currentFrequency, newFrequency;
std::atomic_int currentBandwidth, newBandwidth; std::atomic_int currentBandwidth;
std::atomic_int currentAudioSampleRate, newAudioSampleRate; std::atomic_int currentAudioSampleRate, newAudioSampleRate;
std::atomic_bool sampleRateChanged, frequencyChanged, bandwidthChanged, audioSampleRateChanged; std::atomic_bool sampleRateChanged, frequencyChanged, bandwidthChanged, audioSampleRateChanged;