From a174db1725f6dab5f0e0eba40ea3e0cd580c47dc Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 19 Mar 2021 22:42:42 -0400 Subject: [PATCH] Minor warning/formatting clean-up --- src/modules/modem/analog/ModemCW.cpp | 148 ++++++++++++--------------- src/modules/modem/analog/ModemCW.h | 37 +++---- 2 files changed, 87 insertions(+), 98 deletions(-) diff --git a/src/modules/modem/analog/ModemCW.cpp b/src/modules/modem/analog/ModemCW.cpp index 6efb321..acb40f4 100644 --- a/src/modules/modem/analog/ModemCW.cpp +++ b/src/modules/modem/analog/ModemCW.cpp @@ -13,27 +13,25 @@ // 0 150 650 1150 // ModemCW::ModemCW() - : ModemAnalog(), - mBeepFrequency(650.0), - mGain(15.0), - mAutoGain(true), - mLO(nullptr), - mToReal(nullptr) -{ - mLO = nco_crcf_create (LIQUID_NCO); - mToReal = firhilbf_create (5,60.0f); - useSignalOutput(true); + : ModemAnalog(), + mBeepFrequency(650.0), + mGain(15.0), + mAutoGain(true), + mLO(nullptr), + mToReal(nullptr) { + mLO = nco_crcf_create(LIQUID_NCO); + mToReal = firhilbf_create(5, 60.0f); + useSignalOutput(true); } ModemCW::~ModemCW() { - if (mLO) - nco_crcf_destroy (mLO); - if (mToReal) - firhilbf_destroy (mToReal); + if (mLO) + nco_crcf_destroy(mLO); + if (mToReal) + firhilbf_destroy(mToReal); } -ModemArgInfoList ModemCW::getSettings() -{ +ModemArgInfoList ModemCW::getSettings() { ModemArgInfoList args; ModemArgInfo offsetArg; @@ -41,9 +39,9 @@ ModemArgInfoList ModemCW::getSettings() offsetArg.name = "Frequency Offset"; offsetArg.value = std::to_string(mBeepFrequency); offsetArg.units = "Hz"; - offsetArg.description = "Frequency Offset / Beep frequency"; - offsetArg.type = ModemArgInfo::FLOAT; - offsetArg.range = ModemRange (200.0,1000.0); + offsetArg.description = "Frequency Offset / Beep frequency (200-1000Hz)"; + offsetArg.type = ModemArgInfo::FLOAT; + offsetArg.range = ModemRange(200.0, 1000.0); args.push_back(offsetArg); ModemArgInfo autoGain; @@ -63,39 +61,33 @@ ModemArgInfoList ModemCW::getSettings() gain.name = "Audio Gain"; gain.value = "15"; gain.units = "dB"; - gain.description = "Gain Setting"; - gain.range = ModemRange(0.0,40.0); + gain.description = "Gain Setting (0-40dB)"; + gain.range = ModemRange(0.0, 40.0); gain.type = ModemArgInfo::FLOAT; args.push_back(gain); return args; } -void ModemCW::writeSetting(std::string setting, std::string value) -{ - if (setting == "offset") { - mBeepFrequency = std::stof(value); - rebuildKit(); - } else - if (setting == "auto") { - mAutoGain = (value=="on")?true:false; - } else - if (setting == "gain") { - mGain = std::stof(value); - } +void ModemCW::writeSetting(std::string setting, std::string value) { + if (setting == "offset") { + mBeepFrequency = std::stof(value); + rebuildKit(); + } else if (setting == "auto") { + mAutoGain = (value == "on"); + } else if (setting == "gain") { + mGain = std::stof(value); + } } -std::string ModemCW::readSetting(std::string setting) -{ - if (setting == "offset") { - return std::to_string(mBeepFrequency); - } else - if (setting == "auto") { - return (mAutoGain)?"on":"off"; - } else - if (setting == "gain") { - return std::to_string(mGain); - } - return ""; +std::string ModemCW::readSetting(std::string setting) { + if (setting == "offset") { + return std::to_string(mBeepFrequency); + } else if (setting == "auto") { + return (mAutoGain) ? "on" : "off"; + } else if (setting == "gain") { + return std::to_string(mGain); + } + return ""; } ModemBase *ModemCW::factory() { @@ -106,15 +98,14 @@ std::string ModemCW::getName() { return "CW"; } -int ModemCW::checkSampleRate (long long srate, int arate) -{ - if (srate < MIN_BANDWIDTH) - return MIN_BANDWIDTH; - return srate; +int ModemCW::checkSampleRate(long long srate, int /* arate */) { + if (srate < MIN_BANDWIDTH) + return MIN_BANDWIDTH; + return srate; } int ModemCW::getDefaultSampleRate() { - return MIN_BANDWIDTH; + return MIN_BANDWIDTH; } // 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 // 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. -ModemKit *ModemCW::buildKit (long long sampleRate, int audioSampleRate) -{ - ModemKitCW *kit = new ModemKitCW(); - float As = 60.0f; - double ratio = double(audioSampleRate) / double(sampleRate); - kit->sampleRate = sampleRate; - kit->audioSampleRate = audioSampleRate; - kit->audioResampleRatio = ratio; - kit->mInputResampler = msresamp_cccf_create (ratio,As); - return kit; +ModemKit *ModemCW::buildKit(long long sampleRate, int audioSampleRate) { + ModemKitCW *kit = new ModemKitCW(); + float As = 60.0f; + double ratio = double(audioSampleRate) / double(sampleRate); + kit->sampleRate = sampleRate; + kit->audioSampleRate = audioSampleRate; + kit->audioResampleRatio = ratio; + kit->mInputResampler = msresamp_cccf_create(ratio, As); + return kit; } -void ModemCW::disposeKit (ModemKit *kit) -{ - ModemKitCW *cwkit = (ModemKitCW*) kit; - msresamp_cccf_destroy (cwkit->mInputResampler); - delete kit; +void ModemCW::disposeKit(ModemKit *kit) { + ModemKitCW *cwkit = (ModemKitCW *) kit; + msresamp_cccf_destroy(cwkit->mInputResampler); + delete kit; } -void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input) -{ +void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input) { bufSize = input->data.size(); if (!bufSize) { @@ -153,7 +141,7 @@ void ModemCW::initOutputBuffers(ModemKitAnalog *akit, ModemIQData *input) 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 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) { - unsigned int outSize; + unsigned int outSize; float lsb; liquid_float_complex sig; - ModemKitCW *cwkit = (ModemKitCW *)kit; + ModemKitCW *cwkit = (ModemKitCW *) kit; 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 // 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. if (demodOutputData.size() != outSize) { - demodOutputData.resize(outSize); + demodOutputData.resize(outSize); } // 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 - for (int i = 0; i < outSize; i++) { - nco_crcf_mix_up (mLO,mInput[i],&sig); - nco_crcf_step (mLO); - firhilbf_c2r_execute (mToReal,sig,&lsb,&demodOutputData[i]); + for (unsigned int i = 0; i < outSize; i++) { + nco_crcf_mix_up(mLO, mInput[i], &sig); + nco_crcf_step(mLO); + firhilbf_c2r_execute(mToReal, sig, &lsb, &demodOutputData[i]); } // 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 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; diff --git a/src/modules/modem/analog/ModemCW.h b/src/modules/modem/analog/ModemCW.h index 297d7ba..522ca23 100644 --- a/src/modules/modem/analog/ModemCW.h +++ b/src/modules/modem/analog/ModemCW.h @@ -2,33 +2,34 @@ // SPDX-License-Identifier: GPL-2.0+ #pragma once + #include "Modem.h" #include "ModemAnalog.h" -class ModemKitCW : public ModemKitAnalog -{ +class ModemKitCW : public ModemKitAnalog { public: - ModemKitCW() : ModemKitAnalog() { - }; - msresamp_cccf mInputResampler; + ModemKitCW() : ModemKitAnalog() { + }; + msresamp_cccf mInputResampler; }; class ModemCW : public ModemAnalog { public: ModemCW(); + ~ModemCW(); std::string getName(); 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(); @@ -36,18 +37,18 @@ public: ModemArgInfoList getSettings(); - void writeSetting(std::string setting,std::string value); + void writeSetting(std::string setting, std::string value); std::string readSetting(std::string setting); // No resampling required. - std::vector *getResampledOutputData () { return &demodOutputData; } - + std::vector *getResampledOutputData() { return &demodOutputData; } + private: - bool mAutoGain; - float mGain; - float mBeepFrequency; - nco_crcf mLO; - firhilbf mToReal; - std::vector mInput; + float mBeepFrequency; + float mGain; + bool mAutoGain; + nco_crcf mLO; + firhilbf mToReal; + std::vector mInput; };