Minor warning/formatting clean-up

This commit is contained in:
Charles J. Cliffe 2021-03-19 22:42:42 -04:00
parent 95b7a86ed9
commit a174db1725
2 changed files with 87 additions and 98 deletions

View File

@ -13,27 +13,25 @@
// 0 150 650 1150 // 0 150 650 1150
// //
ModemCW::ModemCW() ModemCW::ModemCW()
: ModemAnalog(), : ModemAnalog(),
mBeepFrequency(650.0), mBeepFrequency(650.0),
mGain(15.0), mGain(15.0),
mAutoGain(true), mAutoGain(true),
mLO(nullptr), mLO(nullptr),
mToReal(nullptr) mToReal(nullptr) {
{ mLO = nco_crcf_create(LIQUID_NCO);
mLO = nco_crcf_create (LIQUID_NCO); mToReal = firhilbf_create(5, 60.0f);
mToReal = firhilbf_create (5,60.0f); useSignalOutput(true);
useSignalOutput(true);
} }
ModemCW::~ModemCW() { ModemCW::~ModemCW() {
if (mLO) if (mLO)
nco_crcf_destroy (mLO); nco_crcf_destroy(mLO);
if (mToReal) if (mToReal)
firhilbf_destroy (mToReal); firhilbf_destroy(mToReal);
} }
ModemArgInfoList ModemCW::getSettings() ModemArgInfoList ModemCW::getSettings() {
{
ModemArgInfoList args; ModemArgInfoList args;
ModemArgInfo offsetArg; ModemArgInfo offsetArg;
@ -41,9 +39,9 @@ ModemArgInfoList ModemCW::getSettings()
offsetArg.name = "Frequency Offset"; offsetArg.name = "Frequency Offset";
offsetArg.value = std::to_string(mBeepFrequency); offsetArg.value = std::to_string(mBeepFrequency);
offsetArg.units = "Hz"; offsetArg.units = "Hz";
offsetArg.description = "Frequency Offset / Beep frequency"; offsetArg.description = "Frequency Offset / Beep frequency (200-1000Hz)";
offsetArg.type = ModemArgInfo::FLOAT; offsetArg.type = ModemArgInfo::FLOAT;
offsetArg.range = ModemRange (200.0,1000.0); offsetArg.range = ModemRange(200.0, 1000.0);
args.push_back(offsetArg); args.push_back(offsetArg);
ModemArgInfo autoGain; ModemArgInfo autoGain;
@ -63,39 +61,33 @@ ModemArgInfoList ModemCW::getSettings()
gain.name = "Audio Gain"; gain.name = "Audio Gain";
gain.value = "15"; gain.value = "15";
gain.units = "dB"; gain.units = "dB";
gain.description = "Gain Setting"; gain.description = "Gain Setting (0-40dB)";
gain.range = ModemRange(0.0,40.0); gain.range = ModemRange(0.0, 40.0);
gain.type = ModemArgInfo::FLOAT; gain.type = ModemArgInfo::FLOAT;
args.push_back(gain); args.push_back(gain);
return args; return args;
} }
void ModemCW::writeSetting(std::string setting, std::string value) void ModemCW::writeSetting(std::string setting, std::string value) {
{ if (setting == "offset") {
if (setting == "offset") { mBeepFrequency = std::stof(value);
mBeepFrequency = std::stof(value); rebuildKit();
rebuildKit(); } else if (setting == "auto") {
} else mAutoGain = (value == "on");
if (setting == "auto") { } else if (setting == "gain") {
mAutoGain = (value=="on")?true:false; mGain = std::stof(value);
} else }
if (setting == "gain") {
mGain = std::stof(value);
}
} }
std::string ModemCW::readSetting(std::string setting) std::string ModemCW::readSetting(std::string setting) {
{ if (setting == "offset") {
if (setting == "offset") { return std::to_string(mBeepFrequency);
return std::to_string(mBeepFrequency); } else if (setting == "auto") {
} else return (mAutoGain) ? "on" : "off";
if (setting == "auto") { } else if (setting == "gain") {
return (mAutoGain)?"on":"off"; return std::to_string(mGain);
} else }
if (setting == "gain") { return "";
return std::to_string(mGain);
}
return "";
} }
ModemBase *ModemCW::factory() { ModemBase *ModemCW::factory() {
@ -106,15 +98,14 @@ std::string ModemCW::getName() {
return "CW"; return "CW";
} }
int ModemCW::checkSampleRate (long long srate, int arate) int ModemCW::checkSampleRate(long long srate, int /* arate */) {
{ if (srate < MIN_BANDWIDTH)
if (srate < MIN_BANDWIDTH) return MIN_BANDWIDTH;
return MIN_BANDWIDTH; return srate;
return srate;
} }
int ModemCW::getDefaultSampleRate() { int ModemCW::getDefaultSampleRate() {
return MIN_BANDWIDTH; return MIN_BANDWIDTH;
} }
// The modem object is asked to make a "ModemKit" given the IQ sample rate // The modem object is asked to make a "ModemKit" given the IQ sample rate
@ -124,27 +115,24 @@ int ModemCW::getDefaultSampleRate() {
// one doesn't have the bandwidth for these tones. So we need to interpolate // one doesn't have the bandwidth for these tones. So we need to interpolate
// the input IQ to audioOut, frequency shift, then pass the real part. // the input IQ to audioOut, frequency shift, then pass the real part.
// Simple solution is just interpolate the IQ data to the audio sample rate. // Simple solution is just interpolate the IQ data to the audio sample rate.
ModemKit *ModemCW::buildKit (long long sampleRate, int audioSampleRate) ModemKit *ModemCW::buildKit(long long sampleRate, int audioSampleRate) {
{ ModemKitCW *kit = new ModemKitCW();
ModemKitCW *kit = new ModemKitCW(); float As = 60.0f;
float As = 60.0f; double ratio = double(audioSampleRate) / double(sampleRate);
double ratio = double(audioSampleRate) / double(sampleRate); kit->sampleRate = sampleRate;
kit->sampleRate = sampleRate; kit->audioSampleRate = audioSampleRate;
kit->audioSampleRate = audioSampleRate; kit->audioResampleRatio = ratio;
kit->audioResampleRatio = ratio; kit->mInputResampler = msresamp_cccf_create(ratio, As);
kit->mInputResampler = msresamp_cccf_create (ratio,As); return kit;
return kit;
} }
void ModemCW::disposeKit (ModemKit *kit) void ModemCW::disposeKit(ModemKit *kit) {
{ ModemKitCW *cwkit = (ModemKitCW *) kit;
ModemKitCW *cwkit = (ModemKitCW*) kit; msresamp_cccf_destroy(cwkit->mInputResampler);
msresamp_cccf_destroy (cwkit->mInputResampler); delete kit;
delete kit;
} }
void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input) void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input) {
{
bufSize = input->data.size(); bufSize = input->data.size();
if (!bufSize) { if (!bufSize) {
@ -153,7 +141,7 @@ void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input)
double audio_resample_ratio = akit->audioResampleRatio; double audio_resample_ratio = akit->audioResampleRatio;
size_t audio_out_size = (size_t)ceil((double) (bufSize) * audio_resample_ratio) + 512; size_t audio_out_size = (size_t) ceil((double) (bufSize) * audio_resample_ratio) + 512;
// Just make everything the audio out size // Just make everything the audio out size
if (mInput.size() != audio_out_size) { if (mInput.size() != audio_out_size) {
@ -165,10 +153,10 @@ void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input)
} }
void ModemCW::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) { void ModemCW::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) {
unsigned int outSize; unsigned int outSize;
float lsb; float lsb;
liquid_float_complex sig; liquid_float_complex sig;
ModemKitCW *cwkit = (ModemKitCW *)kit; ModemKitCW *cwkit = (ModemKitCW *) kit;
initOutputBuffers(cwkit, input); initOutputBuffers(cwkit, input);
@ -178,21 +166,21 @@ void ModemCW::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *au
// Interpolate IQ samples to full audio band. We need to be able to // Interpolate IQ samples to full audio band. We need to be able to
// sample at 2 times the desired beep frequency. // sample at 2 times the desired beep frequency.
msresamp_cccf_execute (cwkit->mInputResampler,&input->data[0],bufSize,&mInput[0],&outSize); msresamp_cccf_execute(cwkit->mInputResampler, &input->data[0], bufSize, &mInput[0], &outSize);
// Make the shoe fit. // Make the shoe fit.
if (demodOutputData.size() != outSize) { if (demodOutputData.size() != outSize) {
demodOutputData.resize(outSize); demodOutputData.resize(outSize);
} }
// Set the LO to the desired beep frequency. // Set the LO to the desired beep frequency.
nco_crcf_set_frequency(mLO,2.0*M_PI*mBeepFrequency/kit->audioSampleRate); nco_crcf_set_frequency(mLO, 2.0 * M_PI * mBeepFrequency / kit->audioSampleRate);
// Mix up from base band by beep frequency. Extract real part // Mix up from base band by beep frequency. Extract real part
for (int i = 0; i < outSize; i++) { for (unsigned int i = 0; i < outSize; i++) {
nco_crcf_mix_up (mLO,mInput[i],&sig); nco_crcf_mix_up(mLO, mInput[i], &sig);
nco_crcf_step (mLO); nco_crcf_step(mLO);
firhilbf_c2r_execute (mToReal,sig,&lsb,&demodOutputData[i]); firhilbf_c2r_execute(mToReal, sig, &lsb, &demodOutputData[i]);
} }
// Determine gain automagically (if desired) // Determine gain automagically (if desired)
@ -207,12 +195,12 @@ void ModemCW::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *au
} }
} }
mGain = 10.0*std::log10(0.5f / aOutputCeilMAA); mGain = 10.0 * std::log10(0.5f / aOutputCeilMAA);
} }
// Apply gain to demodulated output data // Apply gain to demodulated output data
for (size_t i = 0; i < outSize; i++) { for (size_t i = 0; i < outSize; i++) {
demodOutputData[i] *= std::pow(10.0,mGain/10.0); demodOutputData[i] *= std::pow(10.0, mGain / 10.0);
} }
audioOut->channels = 1; audioOut->channels = 1;

View File

@ -2,33 +2,34 @@
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
#pragma once #pragma once
#include "Modem.h" #include "Modem.h"
#include "ModemAnalog.h" #include "ModemAnalog.h"
class ModemKitCW : public ModemKitAnalog class ModemKitCW : public ModemKitAnalog {
{
public: public:
ModemKitCW() : ModemKitAnalog() { ModemKitCW() : ModemKitAnalog() {
}; };
msresamp_cccf mInputResampler; msresamp_cccf mInputResampler;
}; };
class ModemCW : public ModemAnalog { class ModemCW : public ModemAnalog {
public: public:
ModemCW(); ModemCW();
~ModemCW(); ~ModemCW();
std::string getName(); std::string getName();
static ModemBase *factory(); static ModemBase *factory();
int checkSampleRate (long long srate, int arate ); int checkSampleRate(long long srate, int arate);
ModemKit *buildKit (long long srate, int arate); ModemKit *buildKit(long long srate, int arate);
void disposeKit (ModemKit *kit); void disposeKit(ModemKit *kit);
void initOutputBuffers (ModemKitAnalog *akit, ModemIQData *input); void initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input);
int getDefaultSampleRate(); int getDefaultSampleRate();
@ -36,18 +37,18 @@ public:
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);
// No resampling required. // No resampling required.
std::vector<float> *getResampledOutputData () { return &demodOutputData; } std::vector<float> *getResampledOutputData() { return &demodOutputData; }
private: private:
bool mAutoGain; float mBeepFrequency;
float mGain; float mGain;
float mBeepFrequency; bool mAutoGain;
nco_crcf mLO; nco_crcf mLO;
firhilbf mToReal; firhilbf mToReal;
std::vector<liquid_float_complex> mInput; std::vector<liquid_float_complex> mInput;
}; };