Modem can now trigger kit rebuild, add FSK test settings

This commit is contained in:
Charles J. Cliffe 2015-11-23 20:44:48 -05:00
parent 4a62eae096
commit 4af943791b
5 changed files with 64 additions and 5 deletions

View File

@ -108,7 +108,12 @@ void DemodulatorPreThread::run() {
sampleRateChanged.store(false);
audioSampleRateChanged.store(false);
demodTypeChanged.store(false);
} else if (cModemKit && cModem && (bandwidthChanged.load() || sampleRateChanged.load() || audioSampleRateChanged.load()) && (newSampleRate && newAudioSampleRate && newBandwidth)) {
}
else if (
cModemKit && cModem &&
(bandwidthChanged.load() || sampleRateChanged.load() || audioSampleRateChanged.load() || cModem->shouldRebuildKit()) &&
(newSampleRate && newAudioSampleRate && newBandwidth)
) {
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
command.frequency = newFrequency;
command.sampleRate = newSampleRate;

View File

@ -72,6 +72,9 @@ void DemodulatorWorkerThread::run() {
} else if (makeDemod) {
cModemKit = nullptr;
}
if (cModem != nullptr) {
cModem->clearRebuildKit();
}
float As = 60.0f; // stop-band attenuation [dB]

View File

@ -55,3 +55,15 @@ Modem::Modem() {
Modem::~Modem() {
}
bool Modem::shouldRebuildKit() {
return refreshKit.load();
}
void Modem::rebuildKit() {
refreshKit.store(true);
}
void Modem::clearRebuildKit() {
refreshKit.store(false);
}

View File

@ -4,6 +4,7 @@
#include "IOThread.h"
#include "AudioThread.h"
#include <cmath>
#include <atomic>
class ModemKit {
public:
@ -108,9 +109,12 @@ class Modem {
public:
static void addModemFactory(Modem *factorySingle);
static ModemFactoryList getFactories();
static Modem *makeModem(std::string modemType);
virtual std::string getType() = 0;
virtual std::string getName() = 0;
virtual Modem *factory() = 0;
Modem();
@ -126,6 +130,12 @@ public:
virtual void disposeKit(ModemKit *kit) = 0;
virtual void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) = 0;
bool shouldRebuildKit();
void rebuildKit();
void clearRebuildKit();
private:
static ModemFactoryList modemFactories;
std::atomic_bool refreshKit;
};

View File

@ -1,6 +1,7 @@
#include "ModemFSK.h"
ModemFSK::ModemFSK() {
// DMR defaults?
bps = 9600;
spacing = 7000;
}
@ -12,14 +13,42 @@ Modem *ModemFSK::factory() {
ModemArgInfoList ModemFSK::getSettings() {
ModemArgInfoList args;
ModemArgInfo bpsArg;
bpsArg.key = "bps";
bpsArg.name = "Bits per-symbol";
bpsArg.value = std::to_string(bps);
bpsArg.description = "FSK modem bits-per-symbol";
bpsArg.type = ModemArgInfo::STRING;
std::vector<std::string> bpsOpts;
bpsOpts.push_back("9600");
bpsArg.options = bpsOpts;
args.push_back(bpsArg);
ModemArgInfo spacingArg;
spacingArg.key = "spacing";
spacingArg.name = "Symbol Spacing?";
spacingArg.description = "Not quite sure yet :-)";
spacingArg.type = ModemArgInfo::STRING;
spacingArg.value = std::to_string(spacing);
std::vector<std::string> spacingOpts;
spacingOpts.push_back("7000");
spacingArg.options = spacingOpts;
args.push_back(spacingArg);
return args;
}
void ModemFSK::writeSetting(std::string setting, std::string value) {
if (setting == "bps") {
bps = std::stoi(value);
rebuildKit();
} else if (setting == "spacing") {
spacing = std::stoi(value);
rebuildKit();
}
}
@ -35,8 +64,8 @@ std::string ModemFSK::readSetting(std::string setting) {
ModemKit *ModemFSK::buildKit(long long sampleRate, int audioSampleRate) {
ModemKitFSK *dkit = new ModemKitFSK;
dkit->m = 1;
dkit->k = sampleRate / 9600;
dkit->bandwidth = 7000.0 / sampleRate;
dkit->k = sampleRate / bps;
dkit->bandwidth = double(spacing) / sampleRate;
dkit->demodFSK = fskdem_create(dkit->m, dkit->k, dkit->bandwidth);