FSK now appears somewhat functional (outputs symbols to console)

This commit is contained in:
Charles J. Cliffe 2015-11-24 00:20:17 -05:00
parent 6e74662518
commit d14dfed063
3 changed files with 56 additions and 28 deletions

View File

@ -20,12 +20,17 @@ class ModemFMStereo : public Modem {
public: public:
ModemFMStereo(); ModemFMStereo();
~ModemFMStereo(); ~ModemFMStereo();
std::string getType(); std::string getType();
std::string getName(); std::string getName();
Modem *factory(); Modem *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
ModemKit *buildKit(long long sampleRate, int audioSampleRate); ModemKit *buildKit(long long sampleRate, int audioSampleRate);
void disposeKit(ModemKit *kit); void disposeKit(ModemKit *kit);
void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut);
private: private:

View File

@ -2,43 +2,62 @@
ModemFSK::ModemFSK() { ModemFSK::ModemFSK() {
// DMR defaults? // DMR defaults?
bps = 9600; bps = 1;
spacing = 7000; sps = 9600;
} }
Modem *ModemFSK::factory() { Modem *ModemFSK::factory() {
return new ModemFSK; return new ModemFSK;
} }
int ModemFSK::checkSampleRate(long long sampleRate, int audioSampleRate) {
float minSps = pow(2.0,bps);
float nextSps = (float(sampleRate) / float(sps));
if (nextSps < minSps) {
return 2 * bps * sps;
} else {
return sampleRate;
}
}
ModemArgInfoList ModemFSK::getSettings() { ModemArgInfoList ModemFSK::getSettings() {
ModemArgInfoList args; ModemArgInfoList args;
ModemArgInfo bpsArg; ModemArgInfo bpsArg;
bpsArg.key = "bps"; bpsArg.key = "bps";
bpsArg.name = "Bits per-symbol"; bpsArg.name = "Bits/symbol";
bpsArg.value = std::to_string(bps); bpsArg.value = std::to_string(bps);
bpsArg.description = "FSK modem bits-per-symbol"; bpsArg.description = "Modem bits-per-symbol";
bpsArg.type = ModemArgInfo::STRING; bpsArg.type = ModemArgInfo::STRING;
std::vector<std::string> bpsOpts; std::vector<std::string> bpsOpts;
bpsOpts.push_back("9600"); bpsOpts.push_back("1");
bpsOpts.push_back("2");
bpsOpts.push_back("4");
bpsOpts.push_back("8");
bpsArg.options = bpsOpts; bpsArg.options = bpsOpts;
args.push_back(bpsArg); 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); ModemArgInfo spsArg;
spsArg.key = "sps";
spsArg.name = "Symbols/second";
spsArg.value = std::to_string(sps);
spsArg.description = "Modem symbols-per-second";
spsArg.type = ModemArgInfo::STRING;
std::vector<std::string> spsOpts;
// some common modem rates ..?
spsOpts.push_back("1200");
spsOpts.push_back("2400");
spsOpts.push_back("4800");
spsOpts.push_back("9600");
spsOpts.push_back("19200");
spsOpts.push_back("38400");
spsArg.options = spsOpts;
args.push_back(spsArg);
return args; return args;
} }
@ -46,8 +65,8 @@ void ModemFSK::writeSetting(std::string setting, std::string value) {
if (setting == "bps") { if (setting == "bps") {
bps = std::stoi(value); bps = std::stoi(value);
rebuildKit(); rebuildKit();
} else if (setting == "spacing") { } else if (setting == "sps") {
spacing = std::stoi(value); sps = std::stoi(value);
rebuildKit(); rebuildKit();
} }
} }
@ -55,19 +74,18 @@ void ModemFSK::writeSetting(std::string setting, std::string value) {
std::string ModemFSK::readSetting(std::string setting) { std::string ModemFSK::readSetting(std::string setting) {
if (setting == "bps") { if (setting == "bps") {
return std::to_string(bps); return std::to_string(bps);
} else if (setting == "spacing") { } else if (setting == "sps") {
return std::to_string(spacing); return std::to_string(sps);
} }
return ""; return "";
} }
ModemKit *ModemFSK::buildKit(long long sampleRate, int audioSampleRate) { ModemKit *ModemFSK::buildKit(long long sampleRate, int audioSampleRate) {
ModemKitFSK *dkit = new ModemKitFSK; ModemKitFSK *dkit = new ModemKitFSK;
dkit->m = 1; dkit->m = bps;
dkit->k = sampleRate / bps; dkit->k = sampleRate / sps;
dkit->bandwidth = double(spacing) / sampleRate;
dkit->demodFSK = fskdem_create(dkit->m, dkit->k, dkit->bandwidth); dkit->demodFSK = fskdem_create(dkit->m, dkit->k, 0.45);
dkit->sampleRate = sampleRate; dkit->sampleRate = sampleRate;
dkit->audioSampleRate = audioSampleRate; dkit->audioSampleRate = audioSampleRate;
@ -78,6 +96,8 @@ ModemKit *ModemFSK::buildKit(long long sampleRate, int audioSampleRate) {
void ModemFSK::disposeKit(ModemKit *kit) { void ModemFSK::disposeKit(ModemKit *kit) {
ModemKitFSK *dkit = (ModemKitFSK *)kit; ModemKitFSK *dkit = (ModemKitFSK *)kit;
fskdem_destroy(dkit->demodFSK);
delete dkit; delete dkit;
} }
@ -100,7 +120,8 @@ void ModemFSK::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *a
unsigned int sym_out; unsigned int sym_out;
sym_out = fskdem_demodulate(dkit->demodFSK, &dkit->inputBuffer[0]); sym_out = fskdem_demodulate(dkit->demodFSK, &dkit->inputBuffer[0]);
// std::cout << "ferror: " << fskdem_get_frequency_error(dkit->demodFSK) << std::endl; // float err = fskdem_get_frequency_error(dkit->demodFSK);
// std::cout << "ferror: " << err << std::endl;
printf("%01X", sym_out); printf("%01X", sym_out);
dkit->inputBuffer.erase(dkit->inputBuffer.begin(),dkit->inputBuffer.begin()+dkit->k); dkit->inputBuffer.erase(dkit->inputBuffer.begin(),dkit->inputBuffer.begin()+dkit->k);
} }

View File

@ -3,7 +3,6 @@
class ModemKitFSK : public ModemKitDigital { class ModemKitFSK : public ModemKitDigital {
public: public:
float sps, spacing, bandwidth;
unsigned int m, k; unsigned int m, k;
fskdem demodFSK; fskdem demodFSK;
@ -20,6 +19,8 @@ public:
Modem *factory(); Modem *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate);
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);
std::string readSetting(std::string setting); std::string readSetting(std::string setting);
@ -30,6 +31,7 @@ public:
void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut);
private: private:
int bps, spacing; int sps;
int bps;
}; };