diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ce982bb..9b7c9743f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,7 @@ option(ENABLE_CHANNELTX_MODCHIRPCHAT "Enable channeltx modchirpchat plugin" ON) option(ENABLE_CHANNELTX_MODMESHTASTIC "Enable channeltx modmeshtastic plugin" ON) option(ENABLE_CHANNELTX_MODMESHCORE "Enable channeltx modmeshcore plugin" ON) option(ENABLE_CHANNELTX_MODWFM "Enable channeltx modwfm plugin" ON) +option(ENABLE_CHANNELTX_MODBFM "Enable channeltx modbfm plugin" ON) option(ENABLE_CHANNELTX_MODATV "Enable channeltx modatv plugin" ON) option(ENABLE_CHANNELTX_MOD802.15.4 "Enable channeltx mod802.15.4 plugin" ON) option(ENABLE_CHANNELTX_REMOTESOURCE "Enable channeltx remotesource plugin" ON) diff --git a/doc/img/BFMMmod_audio_tab.png b/doc/img/BFMMmod_audio_tab.png new file mode 100644 index 000000000..e78b1e40d Binary files /dev/null and b/doc/img/BFMMmod_audio_tab.png differ diff --git a/doc/img/BFMMmod_morse_tab.png b/doc/img/BFMMmod_morse_tab.png new file mode 100644 index 000000000..3d1fa7f10 Binary files /dev/null and b/doc/img/BFMMmod_morse_tab.png differ diff --git a/doc/img/BFMMmod_plugin.png b/doc/img/BFMMmod_plugin.png new file mode 100644 index 000000000..093f997bd Binary files /dev/null and b/doc/img/BFMMmod_plugin.png differ diff --git a/doc/img/BFMMmod_rds_tab.png b/doc/img/BFMMmod_rds_tab.png new file mode 100644 index 000000000..00b1b34d8 Binary files /dev/null and b/doc/img/BFMMmod_rds_tab.png differ diff --git a/plugins/channelrx/demodbfm/bfmdemod.cpp b/plugins/channelrx/demodbfm/bfmdemod.cpp index f1ded1896..326b92460 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -21,6 +21,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include "boost/format.hpp" +#include "util/rds.h" #include #include @@ -559,7 +560,7 @@ void BFMDemod::webapiFormatRDSReport(SWGSDRangel::SWGRDSReport *report) report->setRdsDemodAccumDb(CalcDb::dbPower(std::fabs(getDemodAcc()))); report->setRdsDemodFrequency(getDemodFclk()); report->setPid(new QString(str(boost::format("%04X") % getRDSParser()->m_pi_program_identification).c_str())); - report->setPiType(new QString(getRDSParser()->pty_table[getRDSParser()->m_pi_program_type].c_str())); + report->setPiType(new QString(RDS::m_programmeTypes[getRDSParser()->m_pi_program_type])); report->setPiCoverage(new QString(getRDSParser()->coverage_area_codes[getRDSParser()->m_pi_area_coverage_index].c_str())); // RDS pads these to a fixed width, which is a transport detail rather than part of the // name, and the radio text ends with a carriage return diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.cpp b/plugins/channelrx/demodbfm/bfmdemodgui.cpp index fb4c74ee5..f49c81adf 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodgui.cpp @@ -22,6 +22,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include "bfmdemodgui.h" +#include "util/rds.h" #include "device/deviceuiset.h" #include @@ -699,7 +700,7 @@ void BFMDemodGUI::rdsUpdate(bool force) ui->piTPIndicator->setStyleSheet("QLabel { background:rgb(79,79,79); }"); } - ui->piType->setText(QString(m_bfmDemod->getRDSParser()->pty_table[m_bfmDemod->getRDSParser()->m_pi_program_type].c_str())); + ui->piType->setText(QString(RDS::m_programmeTypes[m_bfmDemod->getRDSParser()->m_pi_program_type])); ui->piCoverage->setText(QString(m_bfmDemod->getRDSParser()->coverage_area_codes[m_bfmDemod->getRDSParser()->m_pi_area_coverage_index].c_str())); } else @@ -776,13 +777,13 @@ void BFMDemodGUI::rdsUpdate(bool force) ui->g02CountText->setNum((int) m_bfmDemod->getRDSParser()->m_g2_count); bool radiotext_AB_flag = m_bfmDemod->getRDSParser()->m_radiotext_AB_flag; - if (!m_radiotext_AB_flag && radiotext_AB_flag) // B -> A transiition is start of new text + if (m_radiotext_AB_flag != radiotext_AB_flag) { QString oldText = ui->go2Text->text(); ui->go2PrevText->setText(oldText); } - ui->go2Text->setText(QString(m_bfmDemod->getRDSParser()->m_g2_radiotext)); + ui->go2Text->setText(QString(m_bfmDemod->getRDSParser()->m_g2_radiotext).trimmed()); m_radiotext_AB_flag = radiotext_AB_flag; } else diff --git a/plugins/channelrx/demodbfm/bfmdemodsink.cpp b/plugins/channelrx/demodbfm/bfmdemodsink.cpp index 75637be66..bbb0cc912 100644 --- a/plugins/channelrx/demodbfm/bfmdemodsink.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodsink.cpp @@ -137,6 +137,13 @@ void BFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV m_sampleBuffer.push_back(Sample(demod * SDR_RX_SCALEF, 0.0)); } + // RDS also uses the pilot PLL's third harmonic. Keep the reference + // running when mono audio is selected so RDS is independent of the + // audio output mode and can free-run for mono+RDS transmissions. + if (m_settings.m_audioStereo || m_settings.m_rdsActive) { + m_pilotPLL.process(demod, m_pilotPLLSamples); + } + if (m_settings.m_rdsActive) { //Complex r(demod * 2.0 * std::cos(3.0 * m_pilotPLLSamples[3]), 0.0); @@ -163,8 +170,6 @@ void BFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV if (m_settings.m_audioStereo) { - m_pilotPLL.process(demod, m_pilotPLLSamples); - if (m_settings.m_showPilot) { m_sampleBuffer.push_back(Sample(m_pilotPLLSamples[1] * SDR_RX_SCALEF, 0.0)); // debug 38 kHz pilot } diff --git a/plugins/channelrx/demodbfm/rdsparser.cpp b/plugins/channelrx/demodbfm/rdsparser.cpp index b629eb264..0688920f6 100644 --- a/plugins/channelrx/demodbfm/rdsparser.cpp +++ b/plugins/channelrx/demodbfm/rdsparser.cpp @@ -18,6 +18,7 @@ #include "rdsparser.h" #include "rdstmc.h" +#include "util/rds.h" #include #include @@ -33,42 +34,6 @@ const unsigned int RDSParser::offset_word[5] = {252,408,360,436,848}; const unsigned int RDSParser::syndrome[5] = {383,14,303,663,748}; const char * const RDSParser::offset_name[] = {"A","B","C","D","C'"}; -/* page 77, Annex F in the standard */ -const std::string RDSParser::pty_table[32] = { - "None", - "News", - "Current Affairs", - "Information", - "Sport", - "Education", - "Drama", - "Cultures", - "Science", - "Varied Speech", - "Pop Music", - "Rock Music", - "Easy Listening", - "Light Classics M", - "Serious Classics", - "Other Music", - "Weather & Metr", - "Finance", - "Children’s Progs", - "Social Affairs", - "Religion", - "Phone In", - "Travel & Touring", - "Leisure & Hobby", - "Jazz Music", - "Country Music", - "National Music", - "Oldies Music", - "Folk Music", - "Documentary", - "Alarm Test", - "Alarm-Alarm!" -}; - /* page 71, Annex D, table D.1 in the standard */ const std::string RDSParser::pi_country_codes[15][5] = { {"DE","GR","MA","__","MD"}, @@ -397,7 +362,7 @@ void RDSParser::parseGroup(unsigned int *group) qDebug() << "RDSParser::parseGroup:" << " PI:" << pistring.c_str() - << " - " << "PTY:" << pty_table[m_pi_program_type].c_str() + << " - " << "PTY:" << RDS::m_programmeTypes[m_pi_program_type] << " (country:" << (pi_country_codes[m_pi_country_identification - 1][0]).c_str() << "/" << (pi_country_codes[m_pi_country_identification - 1][1]).c_str() << "/" << (pi_country_codes[m_pi_country_identification - 1][2]).c_str() @@ -704,8 +669,8 @@ void RDSParser::decode_type2(unsigned int *group, bool B) m_g2_count++; bool radiotext_AB_flag = ((group[1] >> 4) & 0x01); - // when the flag goes from B to A (false -> true), flush your current radiotext - if (!m_radiotext_AB_flag && radiotext_AB_flag) + // A change in either direction marks a new RadioText message. + if (m_radiotext_AB_flag != radiotext_AB_flag) { // qDebug("RDSParser::decode_type2: ---------"); std::memset(m_g2_radiotext, ' ', sizeof(m_g2_radiotext)); @@ -1162,7 +1127,7 @@ void RDSParser::decode_type14(unsigned int *group, bool B) case 13: // PTY(ON), TA(ON) { ta_on = information & 0x01; - //qDebug() << "RDSParser::decode_type14: PTY(ON):" << pty_table[int(pty_on)].c_str(); + //qDebug() << "RDSParser::decode_type14: PTY(ON):" << RDS::m_programmeTypes[int(pty_on)]; if(ta_on) { qDebug() << "RDSParser::decode_type14: - TA"; } @@ -1203,4 +1168,3 @@ void RDSParser::decode_type15(unsigned int *group, bool B) m_g15_updated = true; m_g15_count++; } - diff --git a/plugins/channelrx/demodbfm/rdsparser.h b/plugins/channelrx/demodbfm/rdsparser.h index 49e62a15b..4a5b9e2e6 100644 --- a/plugins/channelrx/demodbfm/rdsparser.h +++ b/plugins/channelrx/demodbfm/rdsparser.h @@ -161,7 +161,6 @@ public: static const unsigned int offset_word[5]; static const unsigned int syndrome[5]; static const char * const offset_name[]; - static const std::string pty_table[32]; static const std::string pi_country_codes[15][5]; static const std::string coverage_area_codes[16]; static const std::string rds_group_acronyms[16]; diff --git a/plugins/channelrx/demodbfm/readme.md b/plugins/channelrx/demodbfm/readme.md index 2f0046abc..bb8352fab 100644 --- a/plugins/channelrx/demodbfm/readme.md +++ b/plugins/channelrx/demodbfm/readme.md @@ -14,7 +14,7 @@ The main three areas are: - **A**: radio settings - **B**: spectrum of FM demodulated signal. Please note that the annotations are custom and not generally available. Controls are similar to other spectrum displays including the main spectrum display. - - **C**: RDS data. Note that decoding RDS data requires the locking to the stereo pilot carrier therefore you should switch to stereo (A.3) to be able to decode RDS data + - **C**: RDS data. RDS decoding requires a transmitted 19 kHz pilot, but the audio output can remain in mono mode (A.3)

A: Radio settings

diff --git a/plugins/channeltx/CMakeLists.txt b/plugins/channeltx/CMakeLists.txt index db6b79163..d34e4d9e4 100644 --- a/plugins/channeltx/CMakeLists.txt +++ b/plugins/channeltx/CMakeLists.txt @@ -40,6 +40,10 @@ if (ENABLE_CHANNELTX_MODWFM) add_subdirectory(modwfm) endif() +if (ENABLE_CHANNELTX_MODBFM) + add_subdirectory(modbfm) +endif() + if (ENABLE_CHANNELTX_MODPACKET) add_subdirectory(modpacket) endif() diff --git a/plugins/channeltx/modam/ammodsource.cpp b/plugins/channeltx/modam/ammodsource.cpp index 895ed2b3e..37ac850f4 100644 --- a/plugins/channeltx/modam/ammodsource.cpp +++ b/plugins/channeltx/modam/ammodsource.cpp @@ -343,10 +343,12 @@ void AMModSource::applyFeedbackAudioSampleRate(int sampleRate) qDebug("AMModSource::applyFeedbackAudioSampleRate: %u", sampleRate); + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. m_feedbackInterpolatorDistanceRemain = 0; - m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; Real cutoff = ((float) std::min(sampleRate, m_audioSampleRate)) / 2.2f; - m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } diff --git a/plugins/channeltx/modbfm/CMakeLists.txt b/plugins/channeltx/modbfm/CMakeLists.txt new file mode 100644 index 000000000..58b84ed6e --- /dev/null +++ b/plugins/channeltx/modbfm/CMakeLists.txt @@ -0,0 +1,70 @@ +project(modbfm) + +set(modbfm_SOURCES + bfmmod.cpp + bfmmodbaseband.cpp + bfmmodsource.cpp + rdsencoder.cpp + lookaheadlimiter.cpp + bfmmodsettings.cpp + bfmmodwebapiadapter.cpp + bfmmodplugin.cpp +) + +set(modbfm_HEADERS + bfmmod.h + bfmmodbaseband.h + bfmmodsource.h + rdsencoder.h + lookaheadlimiter.h + bfmmodsettings.h + bfmmodwebapiadapter.h + bfmmodplugin.h +) + +include_directories( + ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client +) + +if(NOT SERVER_MODE) + list(APPEND modbfm_SOURCES + bfmmodgui.cpp + bfmmodgui.ui + ) + list(APPEND modbfm_HEADERS bfmmodgui.h) + set(TARGET_NAME ${PLUGINS_PREFIX}modbfm) + set(TARGET_LIB "Qt::Widgets") + set(TARGET_LIB_GUI "sdrgui") + set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR}) +else() + set(TARGET_NAME ${PLUGINSSRV_PREFIX}modbfmsrv) + set(TARGET_LIB "") + set(TARGET_LIB_GUI "") + set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR}) +endif() + +if(NOT Qt6_FOUND) + add_library(${TARGET_NAME} ${modbfm_SOURCES}) +else() + qt_add_plugin(${TARGET_NAME} CLASS_NAME BFMModPlugin) + target_sources(${TARGET_NAME} PRIVATE ${modbfm_SOURCES}) +endif() + +if(NOT BUILD_SHARED_LIBS) + set_property(GLOBAL APPEND PROPERTY STATIC_PLUGINS_PROPERTY ${TARGET_NAME}) +endif() + +target_link_libraries(${TARGET_NAME} PRIVATE + Qt::Core + ${TARGET_LIB} + sdrbase + ${TARGET_LIB_GUI} + swagger +) + +install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) + +if (WIN32) + install(FILES $ CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER}) +endif() + diff --git a/plugins/channeltx/modbfm/bfmmod.cpp b/plugins/channeltx/modbfm/bfmmod.cpp new file mode 100644 index 000000000..91436e4a9 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmod.cpp @@ -0,0 +1,898 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +#include + +#include "SWGChannelSettings.h" +#include "SWGWorkspaceInfo.h" +#include "SWGChannelReport.h" + +#include "dsp/dspcommands.h" +#include "device/deviceapi.h" +#include "util/db.h" +#include "maincore.h" + +#include "bfmmodbaseband.h" +#include "bfmmod.h" + +MESSAGE_CLASS_DEFINITION(BFMMod::MsgConfigureBFMMod, Message) +MESSAGE_CLASS_DEFINITION(BFMMod::MsgConfigureFileSourceSeek, Message) +MESSAGE_CLASS_DEFINITION(BFMMod::MsgConfigureFileSourceStreamTiming, Message) +MESSAGE_CLASS_DEFINITION(BFMMod::MsgReportFileSourceStreamData, Message) +MESSAGE_CLASS_DEFINITION(BFMMod::MsgReportFileSourceStreamTiming, Message) + +const char* const BFMMod::m_channelIdURI = "sdrangel.channeltx.modbfm"; +const char* const BFMMod::m_channelId = "BFMMod"; + +BFMMod::BFMMod(DeviceAPI *deviceAPI) : + ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), + m_deviceAPI(deviceAPI), + m_recordLength(0), + m_sampleRate(48000) +{ + setObjectName(m_channelId); + + m_thread = new QThread(this); + m_thread->setObjectName(m_channelId); + m_basebandSource = new BFMModBaseband(); + m_basebandSource->setInputFileReader(&m_audioFileReader); + m_basebandSource->setChannel(this); + m_basebandSource->moveToThread(m_thread); + + applySettings(QStringList(), m_settings, true); + + m_deviceAPI->addChannelSource(this); + m_deviceAPI->addChannelSourceAPI(this); + + m_networkManager = new QNetworkAccessManager(); + QObject::connect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &BFMMod::networkManagerFinished + ); +} + +BFMMod::~BFMMod() +{ + QObject::disconnect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &BFMMod::networkManagerFinished + ); + delete m_networkManager; + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this, true); + stop(); + delete m_basebandSource; + delete m_thread; +} + +void BFMMod::setDeviceAPI(DeviceAPI *deviceAPI) +{ + if (deviceAPI != m_deviceAPI) + { + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this, false); + m_deviceAPI = deviceAPI; + m_deviceAPI->addChannelSource(this); + m_deviceAPI->addChannelSourceAPI(this); + } +} + +void BFMMod::start() +{ + qDebug("BFMMod::start"); + m_basebandSource->reset(); + m_thread->start(); +} + +void BFMMod::stop() +{ + qDebug("BFMMod::stop"); + m_thread->exit(); + m_thread->wait(); +} + +void BFMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) +{ + m_basebandSource->pull(begin, nbSamples); +} + +void BFMMod::setCenterFrequency(qint64 frequency) +{ + BFMModSettings settings = m_settings; + settings.m_inputFrequencyOffset = frequency; + applySettings(QStringList("inputFrequencyOffset"), settings, false); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureBFMMod *msgToGUI = MsgConfigureBFMMod::create(QStringList("inputFrequencyOffset"), settings, false); + m_guiMessageQueue->push(msgToGUI); + } +} + +bool BFMMod::handleMessage(const Message& cmd) +{ + if (MsgConfigureBFMMod::match(cmd)) + { + MsgConfigureBFMMod& cfg = (MsgConfigureBFMMod&) cmd; + qDebug() << "BFMMod::handleMessage: MsgConfigureBFMMod"; + + BFMModSettings settings = cfg.getSettings(); + + applySettings(cfg.getSettingsKeys(), settings, cfg.getForce()); + + return true; + } + else if (MsgConfigureFileSourceSeek::match(cmd)) + { + MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; + int seekPercentage = conf.getPercentage(); + seekFileStream(seekPercentage); + + return true; + } + else if (MsgConfigureFileSourceStreamTiming::match(cmd)) + { + std::size_t samplesCount; + + samplesCount = m_audioFileReader.getPosition(); + + MsgReportFileSourceStreamTiming *report; + report = MsgReportFileSourceStreamTiming::create(samplesCount); + getMessageQueueToGUI()->push(report); + + return true; + } + else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) + { + const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; + + if (m_settings.m_useReverseAPI) { + webapiReverseSendCWSettings(cfg.getSettings()); + } + + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + // Forward to the source + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "BFMMod::handleMessage: DSPSignalNotification"; + m_basebandSource->getInputMessageQueue()->push(rep); + // Forward to GUI if any + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); + } + + return true; + } + else if (MainCore::MsgChannelDemodQuery::match(cmd)) + { + qDebug() << "BFMMod::handleMessage: MsgChannelDemodQuery"; + sendSampleRateToDemodAnalyzer(); + + return true; + } + else + { + return false; + } +} + +void BFMMod::openFileStream(const QString& fileName) +{ + if (fileName.isEmpty()) + { + m_audioFileReader.close(); + m_sampleRate = 0; + m_recordLength = 0; + } + else if (m_audioFileReader.open(fileName)) + { + m_sampleRate = m_audioFileReader.getSampleRate(); + m_recordLength = m_sampleRate > 0 ? + static_cast(m_audioFileReader.getFrameCount() / m_sampleRate) : 0; + + qDebug() << "BFMMod::openFileStream:" << fileName + << "sampleRate:" << m_sampleRate + << "channels:" << m_audioFileReader.getChannelCount() + << "frames:" << m_audioFileReader.getFrameCount() + << "length:" << m_recordLength << "seconds"; + + BFMModBaseband::MsgConfigureFileSampleRate *sampleRateMessage = + BFMModBaseband::MsgConfigureFileSampleRate::create(m_sampleRate); + m_basebandSource->getInputMessageQueue()->push(sampleRateMessage); + } + else + { + qWarning() << "BFMMod::openFileStream:" << fileName + << m_audioFileReader.getErrorString(); + m_sampleRate = 0; + m_recordLength = 0; + } + + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(MsgReportFileSourceStreamData::create(m_sampleRate, m_recordLength)); + } +} + +void BFMMod::seekFileStream(int seekPercentage) +{ + if (m_audioFileReader.isOpen()) + { + const quint64 seekFrame = (m_audioFileReader.getFrameCount() * seekPercentage) / 100; + m_audioFileReader.seek(seekFrame); + } +} + +void BFMMod::applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) +{ + qDebug() << "BFMMod::applySettings:" << settings.getDebugString(settingsKeys, force); + + if (settingsKeys.contains("streamIndex") && m_settings.m_streamIndex != settings.m_streamIndex) + { + if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only + { + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this, false, m_settings.m_streamIndex); + m_deviceAPI->addChannelSource(this, settings.m_streamIndex); + m_deviceAPI->addChannelSourceAPI(this); + m_settings.m_streamIndex = settings.m_streamIndex; // make sure ChannelAPI::getStreamIndex() is consistent + emit streamIndexChanged(settings.m_streamIndex); + } + } + + BFMModBaseband::MsgConfigureBFMModBaseband *msg = BFMModBaseband::MsgConfigureBFMModBaseband::create(settingsKeys, settings, force); + m_basebandSource->getInputMessageQueue()->push(msg); + + // Open the file when it changes, including when settings are loaded from a preset + if ((settingsKeys.contains("fileName") && (settings.m_fileName != m_settings.m_fileName)) || force) { + openFileStream(settings.m_fileName); + } + + if (settings.m_useReverseAPI) + { + bool fullUpdate = ((settingsKeys.contains("useReverseAPI") && m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || + (settingsKeys.contains("reverseAPIAddress") && m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || + (settingsKeys.contains("reverseAPIPort") && m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || + (settingsKeys.contains("reverseAPIDeviceIndex") && m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) || + (settingsKeys.contains("reverseAPIChannelIndex") && m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex); + webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); + } + + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); + + if (pipes.size() > 0) { + sendChannelSettings(pipes, settingsKeys, settings, force); + } + + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } +} + +QByteArray BFMMod::serialize() const +{ + return m_settings.serialize(); +} + +bool BFMMod::deserialize(const QByteArray& data) +{ + if (m_settings.deserialize(data)) + { + MsgConfigureBFMMod *msg = MsgConfigureBFMMod::create(QStringList(), m_settings, true); + m_inputMessageQueue.push(msg); + return true; + } + else + { + m_settings.resetToDefaults(); + MsgConfigureBFMMod *msg = MsgConfigureBFMMod::create(QStringList(), m_settings, true); + m_inputMessageQueue.push(msg); + return false; + } +} + +void BFMMod::sendSampleRateToDemodAnalyzer() +{ + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); + + if (pipes.size() > 0) + { + for (const auto& pipe : pipes) + { + MessageQueue* messageQueue = qobject_cast(pipe->m_element); + MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create( + this, + m_basebandSource->getChannelSampleRate() + ); + messageQueue->push(msg); + } + } +} + +int BFMMod::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setBfmModSettings(new SWGSDRangel::SWGBFMModSettings()); + response.getBfmModSettings()->init(); + webapiFormatChannelSettings(response, m_settings); + + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getBfmModSettings()->getCwKeyer(); + const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + + return 200; +} + +int BFMMod::webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setIndex(m_settings.m_workspaceIndex); + return 200; +} + +int BFMMod::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + BFMModSettings settings = m_settings; + webapiUpdateChannelSettings(settings, channelSettingsKeys, response); + + if (channelSettingsKeys.contains("cwKeyer")) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getBfmModSettings()->getCwKeyer(); + CWKeyerSettings cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); + + CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); + m_basebandSource->getCWKeyer().getInputMessageQueue()->push(msgCwKeyer); + + if (m_guiMessageQueue) // forward to GUI if any + { + CWKeyer::MsgConfigureCWKeyer *msgCwKeyerToGUI = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); + m_guiMessageQueue->push(msgCwKeyerToGUI); + } + } + + MsgConfigureBFMMod *msg = MsgConfigureBFMMod::create(channelSettingsKeys, settings, force); + m_inputMessageQueue.push(msg); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureBFMMod *msgToGUI = MsgConfigureBFMMod::create(channelSettingsKeys, settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatChannelSettings(response, settings); + + return 200; +} + +void BFMMod::webapiUpdateChannelSettings( + BFMModSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response) +{ + if (channelSettingsKeys.contains("channelMute")) { + settings.m_channelMute = response.getBfmModSettings()->getChannelMute() != 0; + } + if (channelSettingsKeys.contains("inputFrequencyOffset")) { + settings.m_inputFrequencyOffset = response.getBfmModSettings()->getInputFrequencyOffset(); + } + if (channelSettingsKeys.contains("modAFInput")) { + settings.m_modAFInput = (BFMModSettings::BFMModInputAF) response.getBfmModSettings()->getModAfInput(); + } + if (channelSettingsKeys.contains("playLoop")) { + settings.m_playLoop = response.getBfmModSettings()->getPlayLoop() != 0; + } + if (channelSettingsKeys.contains("rfBandwidth")) { + settings.m_rfBandwidth = BFMModSettings::boundRFBandwidth(response.getBfmModSettings()->getRfBandwidth()); + } + if (channelSettingsKeys.contains("afBandwidth")) { + settings.m_afBandwidth = BFMModSettings::boundAFBandwidth(response.getBfmModSettings()->getAfBandwidth()); + } + if (channelSettingsKeys.contains("rgbColor")) { + settings.m_rgbColor = response.getBfmModSettings()->getRgbColor(); + } + if (channelSettingsKeys.contains("title")) { + settings.m_title = *response.getBfmModSettings()->getTitle(); + } + if (channelSettingsKeys.contains("toneFrequency")) { + settings.m_toneFrequency = BFMModSettings::boundToneFrequency(response.getBfmModSettings()->getToneFrequency()); + } + if (channelSettingsKeys.contains("volumeFactor")) { + settings.m_volumeFactor = BFMModSettings::boundVolumeFactor(response.getBfmModSettings()->getVolumeFactor()); + } + if (channelSettingsKeys.contains("audioStereo")) { + settings.m_audioStereo = response.getBfmModSettings()->getAudioStereo() != 0; + } + if (channelSettingsKeys.contains("preEmphasis")) { + settings.m_preEmphasis = qBound(0, response.getBfmModSettings()->getPreEmphasis(), 2); + } + if (channelSettingsKeys.contains("pilotLevel")) { + settings.m_pilotLevel = qBound(0.0f, response.getBfmModSettings()->getPilotLevel(), 0.2f); + } + if (channelSettingsKeys.contains("rdsActive")) { + settings.m_rdsActive = response.getBfmModSettings()->getRdsActive() != 0; + } + if (channelSettingsKeys.contains("rdsLevel")) { + settings.m_rdsLevel = qBound(0.0f, response.getBfmModSettings()->getRdsLevel(), 0.1f); + } + if (channelSettingsKeys.contains("rdsPI")) { + settings.m_rdsPI = quint16(qBound(0, response.getBfmModSettings()->getRdsPi(), 0xffff)); + } + if (channelSettingsKeys.contains("rdsPTY")) { + settings.m_rdsPTY = quint8(qBound(0, response.getBfmModSettings()->getRdsPty(), 31)); + } + if (channelSettingsKeys.contains("rdsPS") && response.getBfmModSettings()->getRdsPs()) { + settings.m_rdsPS = response.getBfmModSettings()->getRdsPs()->left(8); + } + if (channelSettingsKeys.contains("rdsRadioText") && response.getBfmModSettings()->getRdsRadioText()) { + settings.m_rdsRadioText = response.getBfmModSettings()->getRdsRadioText()->left(64); + } + if (channelSettingsKeys.contains("fmDeviation")) { + settings.m_fmDeviation = BFMModSettings::boundFMDeviation(response.getBfmModSettings()->getFmDeviation()); + } + if (channelSettingsKeys.contains("audioDeviceName") && response.getBfmModSettings()->getAudioDeviceName()) { + settings.m_audioDeviceName = *response.getBfmModSettings()->getAudioDeviceName(); + } + if (channelSettingsKeys.contains("feedbackAudioDeviceName") && response.getBfmModSettings()->getFeedbackAudioDeviceName()) { + settings.m_feedbackAudioDeviceName = *response.getBfmModSettings()->getFeedbackAudioDeviceName(); + } + if (channelSettingsKeys.contains("feedbackVolumeFactor")) { + settings.m_feedbackVolumeFactor = BFMModSettings::boundFeedbackVolumeFactor(response.getBfmModSettings()->getFeedbackVolumeFactor()); + } + if (channelSettingsKeys.contains("fileName") && response.getBfmModSettings()->getFileName()) { + settings.m_fileName = *response.getBfmModSettings()->getFileName(); + } + if (channelSettingsKeys.contains("feedbackAudioEnable")) { + settings.m_feedbackAudioEnable = response.getBfmModSettings()->getFeedbackAudioEnable() != 0; + } + if (channelSettingsKeys.contains("streamIndex")) { + settings.m_streamIndex = response.getBfmModSettings()->getStreamIndex(); + } + if (channelSettingsKeys.contains("useReverseAPI")) { + settings.m_useReverseAPI = response.getBfmModSettings()->getUseReverseApi() != 0; + } + if (channelSettingsKeys.contains("reverseAPIAddress")) { + settings.m_reverseAPIAddress = *response.getBfmModSettings()->getReverseApiAddress(); + } + if (channelSettingsKeys.contains("reverseAPIPort")) { + settings.m_reverseAPIPort = response.getBfmModSettings()->getReverseApiPort(); + } + if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { + settings.m_reverseAPIDeviceIndex = response.getBfmModSettings()->getReverseApiDeviceIndex(); + } + if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { + settings.m_reverseAPIChannelIndex = response.getBfmModSettings()->getReverseApiChannelIndex(); + } + if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { + settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getBfmModSettings()->getChannelMarker()); + } + if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) { + settings.m_rollupState->updateFrom(channelSettingsKeys, response.getBfmModSettings()->getRollupState()); + } +} + +int BFMMod::webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setBfmModReport(new SWGSDRangel::SWGBFMModReport()); + response.getBfmModReport()->init(); + webapiFormatChannelReport(response); + return 200; +} + +void BFMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const BFMModSettings& settings) +{ + response.getBfmModSettings()->setChannelMute(settings.m_channelMute ? 1 : 0); + response.getBfmModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + response.getBfmModSettings()->setModAfInput((int) settings.m_modAFInput); + response.getBfmModSettings()->setPlayLoop(settings.m_playLoop ? 1 : 0); + response.getBfmModSettings()->setRfBandwidth(settings.m_rfBandwidth); + response.getBfmModSettings()->setAfBandwidth(settings.m_afBandwidth); + response.getBfmModSettings()->setFmDeviation(settings.m_fmDeviation); + response.getBfmModSettings()->setRgbColor(settings.m_rgbColor); + + if (response.getBfmModSettings()->getTitle()) { + *response.getBfmModSettings()->getTitle() = settings.m_title; + } else { + response.getBfmModSettings()->setTitle(new QString(settings.m_title)); + } + + response.getBfmModSettings()->setToneFrequency(settings.m_toneFrequency); + response.getBfmModSettings()->setVolumeFactor(settings.m_volumeFactor); + response.getBfmModSettings()->setAudioStereo(settings.m_audioStereo ? 1 : 0); + response.getBfmModSettings()->setPreEmphasis(settings.m_preEmphasis); + response.getBfmModSettings()->setPilotLevel(settings.m_pilotLevel); + response.getBfmModSettings()->setRdsActive(settings.m_rdsActive ? 1 : 0); + response.getBfmModSettings()->setRdsLevel(settings.m_rdsLevel); + response.getBfmModSettings()->setRdsPi(settings.m_rdsPI); + response.getBfmModSettings()->setRdsPty(settings.m_rdsPTY); + if (response.getBfmModSettings()->getRdsPs()) { + *response.getBfmModSettings()->getRdsPs() = settings.m_rdsPS; + } else { + response.getBfmModSettings()->setRdsPs(new QString(settings.m_rdsPS)); + } + if (response.getBfmModSettings()->getRdsRadioText()) { + *response.getBfmModSettings()->getRdsRadioText() = settings.m_rdsRadioText; + } else { + response.getBfmModSettings()->setRdsRadioText(new QString(settings.m_rdsRadioText)); + } + + if (!response.getBfmModSettings()->getCwKeyer()) { + response.getBfmModSettings()->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings); + } + + if (response.getBfmModSettings()->getAudioDeviceName()) { + *response.getBfmModSettings()->getAudioDeviceName() = settings.m_audioDeviceName; + } else { + response.getBfmModSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName)); + } + + if (response.getBfmModSettings()->getFeedbackAudioDeviceName()) { + *response.getBfmModSettings()->getFeedbackAudioDeviceName() = settings.m_feedbackAudioDeviceName; + } else { + response.getBfmModSettings()->setFeedbackAudioDeviceName(new QString(settings.m_feedbackAudioDeviceName)); + } + + response.getBfmModSettings()->setFeedbackVolumeFactor(settings.m_feedbackVolumeFactor); + + if (response.getBfmModSettings()->getFileName()) { + *response.getBfmModSettings()->getFileName() = settings.m_fileName; + } else { + response.getBfmModSettings()->setFileName(new QString(settings.m_fileName)); + } + + response.getBfmModSettings()->setFeedbackAudioEnable(settings.m_feedbackAudioEnable ? 1 : 0); + response.getBfmModSettings()->setStreamIndex(settings.m_streamIndex); + response.getBfmModSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); + + if (response.getBfmModSettings()->getReverseApiAddress()) { + *response.getBfmModSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; + } else { + response.getBfmModSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); + } + + response.getBfmModSettings()->setReverseApiPort(settings.m_reverseAPIPort); + response.getBfmModSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); + response.getBfmModSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex); + + if (settings.m_channelMarker) + { + if (response.getBfmModSettings()->getChannelMarker()) + { + settings.m_channelMarker->formatTo(response.getBfmModSettings()->getChannelMarker()); + } + else + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + response.getBfmModSettings()->setChannelMarker(swgChannelMarker); + } + } + + if (settings.m_rollupState) + { + if (response.getBfmModSettings()->getRollupState()) + { + settings.m_rollupState->formatTo(response.getBfmModSettings()->getRollupState()); + } + else + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + response.getBfmModSettings()->setRollupState(swgRollupState); + } + } +} + +void BFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +{ + response.getBfmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getBfmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); + response.getBfmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); +} + +void BFMMod::webapiReverseSendSettings(const QList& channelSettingsKeys, const BFMModSettings& settings, bool force) +{ + SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); + + QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") + .arg(settings.m_reverseAPIAddress) + .arg(settings.m_reverseAPIPort) + .arg(settings.m_reverseAPIDeviceIndex) + .arg(settings.m_reverseAPIChannelIndex); + m_networkRequest.setUrl(QUrl(channelSettingsURL)); + m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + QBuffer *buffer = new QBuffer(); + buffer->open((QBuffer::ReadWrite)); + buffer->write(swgChannelSettings->asJson().toUtf8()); + buffer->seek(0); + + // Always use PATCH to avoid passing reverse API settings + QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); + buffer->setParent(reply); + + delete swgChannelSettings; +} + +void BFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) +{ + SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + swgChannelSettings->setDirection(1); // single source (Tx) + swgChannelSettings->setChannelType(new QString(m_channelId)); + swgChannelSettings->setBfmModSettings(new SWGSDRangel::SWGBFMModSettings()); + SWGSDRangel::SWGBFMModSettings *swgBFMModSettings = swgChannelSettings->getBfmModSettings(); + + swgBFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgBFMModSettings->getCwKeyer(); + m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + + QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") + .arg(m_settings.m_reverseAPIAddress) + .arg(m_settings.m_reverseAPIPort) + .arg(m_settings.m_reverseAPIDeviceIndex) + .arg(m_settings.m_reverseAPIChannelIndex); + m_networkRequest.setUrl(QUrl(channelSettingsURL)); + m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + QBuffer *buffer = new QBuffer(); + buffer->open((QBuffer::ReadWrite)); + buffer->write(swgChannelSettings->asJson().toUtf8()); + buffer->seek(0); + + // Always use PATCH to avoid passing reverse API settings + QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); + buffer->setParent(reply); + + delete swgChannelSettings; +} + +void BFMMod::sendChannelSettings( + const QList& pipes, + const QList& channelSettingsKeys, + const BFMModSettings& settings, + bool force) +{ + for (const auto& pipe : pipes) + { + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + + if (messageQueue) + { + SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); + MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( + this, + channelSettingsKeys, + swgChannelSettings, + force + ); + messageQueue->push(msg); + } + } +} + +void BFMMod::webapiFormatChannelSettings( + const QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const BFMModSettings& settings, + bool force +) +{ + swgChannelSettings->setDirection(1); // single source (Tx) + swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); + swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex()); + if (swgChannelSettings->getChannelType()) { + *swgChannelSettings->getChannelType() = m_channelId; + } else { + swgChannelSettings->setChannelType(new QString(m_channelId)); + } + swgChannelSettings->setBfmModSettings(new SWGSDRangel::SWGBFMModSettings()); + SWGSDRangel::SWGBFMModSettings *swgBFMModSettings = swgChannelSettings->getBfmModSettings(); + + // transfer data that has been modified. When force is on transfer all data except reverse API data + + if (channelSettingsKeys.contains("channelMute") || force) { + swgBFMModSettings->setChannelMute(settings.m_channelMute ? 1 : 0); + } + if (channelSettingsKeys.contains("inputFrequencyOffset") || force) { + swgBFMModSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + } + if (channelSettingsKeys.contains("modAFInput") || force) { + swgBFMModSettings->setModAfInput((int) settings.m_modAFInput); + } + if (channelSettingsKeys.contains("playLoop") || force) { + swgBFMModSettings->setPlayLoop(settings.m_playLoop ? 1 : 0); + } + if (channelSettingsKeys.contains("rfBandwidth") || force) { + swgBFMModSettings->setRfBandwidth(settings.m_rfBandwidth); + } + if (channelSettingsKeys.contains("afBandwidth") || force) { + swgBFMModSettings->setAfBandwidth(settings.m_afBandwidth); + } + if (channelSettingsKeys.contains("rgbColor") || force) { + swgBFMModSettings->setRgbColor(settings.m_rgbColor); + } + if (channelSettingsKeys.contains("title") || force) { + if (swgBFMModSettings->getTitle()) { + *swgBFMModSettings->getTitle() = settings.m_title; + } else { + swgBFMModSettings->setTitle(new QString(settings.m_title)); + } + } + if (channelSettingsKeys.contains("toneFrequency") || force) { + swgBFMModSettings->setToneFrequency(settings.m_toneFrequency); + } + if (channelSettingsKeys.contains("volumeFactor") || force) { + swgBFMModSettings->setVolumeFactor(settings.m_volumeFactor); + } + if (channelSettingsKeys.contains("audioStereo") || force) { + swgBFMModSettings->setAudioStereo(settings.m_audioStereo ? 1 : 0); + } + if (channelSettingsKeys.contains("preEmphasis") || force) { + swgBFMModSettings->setPreEmphasis(settings.m_preEmphasis); + } + if (channelSettingsKeys.contains("pilotLevel") || force) { + swgBFMModSettings->setPilotLevel(settings.m_pilotLevel); + } + if (channelSettingsKeys.contains("rdsActive") || force) { + swgBFMModSettings->setRdsActive(settings.m_rdsActive ? 1 : 0); + } + if (channelSettingsKeys.contains("rdsLevel") || force) { + swgBFMModSettings->setRdsLevel(settings.m_rdsLevel); + } + if (channelSettingsKeys.contains("rdsPI") || force) { + swgBFMModSettings->setRdsPi(settings.m_rdsPI); + } + if (channelSettingsKeys.contains("rdsPTY") || force) { + swgBFMModSettings->setRdsPty(settings.m_rdsPTY); + } + if (channelSettingsKeys.contains("rdsPS") || force) { + swgBFMModSettings->setRdsPs(new QString(settings.m_rdsPS)); + } + if (channelSettingsKeys.contains("rdsRadioText") || force) { + swgBFMModSettings->setRdsRadioText(new QString(settings.m_rdsRadioText)); + } + if (channelSettingsKeys.contains("fmDeviation") || force) { + swgBFMModSettings->setFmDeviation(settings.m_fmDeviation); + } + if (channelSettingsKeys.contains("streamIndex") || force) { + swgBFMModSettings->setStreamIndex(settings.m_streamIndex); + } + if (channelSettingsKeys.contains("audioDeviceName") || force) { + if (swgBFMModSettings->getAudioDeviceName()) { + *swgBFMModSettings->getAudioDeviceName() = settings.m_audioDeviceName; + } else { + swgBFMModSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName)); + } + } + if (channelSettingsKeys.contains("feedbackAudioDeviceName") || force) { + swgBFMModSettings->setFeedbackAudioDeviceName(new QString(settings.m_feedbackAudioDeviceName)); + } + if (channelSettingsKeys.contains("feedbackVolumeFactor") || force) { + swgBFMModSettings->setFeedbackVolumeFactor(settings.m_feedbackVolumeFactor); + } + if (channelSettingsKeys.contains("fileName") || force) { + swgBFMModSettings->setFileName(new QString(settings.m_fileName)); + } + if (channelSettingsKeys.contains("feedbackAudioEnable") || force) { + swgBFMModSettings->setFeedbackAudioEnable(settings.m_feedbackAudioEnable ? 1 : 0); + } + + if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + swgBFMModSettings->setChannelMarker(swgChannelMarker); + } + + if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + swgBFMModSettings->setRollupState(swgRollupState); + } + + if (force) + { + const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + swgBFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgBFMModSettings->getCwKeyer(); + m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + } +} + +void BFMMod::networkManagerFinished(QNetworkReply *reply) +{ + QNetworkReply::NetworkError replyError = reply->error(); + + if (replyError) + { + qWarning() << "BFMMod::networkManagerFinished:" + << " error(" << (int) replyError + << "): " << replyError + << ": " << reply->errorString(); + } + else + { + QString answer = reply->readAll(); + answer.chop(1); // remove last \n + qDebug("BFMMod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); + } + + reply->deleteLater(); +} + +double BFMMod::getMagSq() const +{ + return m_basebandSource->getMagSq(); +} + +CWKeyer *BFMMod::getCWKeyer() +{ + return &m_basebandSource->getCWKeyer(); +} + +void BFMMod::setLevelMeter(QObject *levelMeter) +{ + connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); +} + +uint32_t BFMMod::getNumberOfDeviceStreams() const +{ + return m_deviceAPI->getNbSinkStreams(); +} + +int BFMMod::getAudioSampleRate() const +{ + return m_basebandSource->getAudioSampleRate(); +} + +int BFMMod::getFeedbackAudioSampleRate() const +{ + return m_basebandSource->getFeedbackAudioSampleRate(); +} diff --git a/plugins/channeltx/modbfm/bfmmod.h b/plugins/channeltx/modbfm/bfmmod.h new file mode 100644 index 000000000..90351aacc --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmod.h @@ -0,0 +1,263 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODBFM_BFMMOD_H_ +#define PLUGINS_CHANNELTX_MODBFM_BFMMOD_H_ + +#include +#include + +#include "dsp/basebandsamplesource.h" +#include "audio/audiofilereader.h" +#include "channel/channelapi.h" +#include "util/message.h" + +#include "bfmmodsettings.h" + +class QNetworkAccessManager; +class QNetworkReply; +class QThread; +class DeviceAPI; +class CWKeyer; +class BFMModBaseband; +class ObjectPipe; + +class BFMMod : public BasebandSampleSource, public ChannelAPI { +public: + class MsgConfigureBFMMod : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const BFMModSettings& getSettings() const { return m_settings; } + const QStringList& getSettingsKeys() const { return m_settingsKeys; } + bool getForce() const { return m_force; } + + static MsgConfigureBFMMod* create(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) + { + return new MsgConfigureBFMMod(settingsKeys, settings, force); + } + + private: + BFMModSettings m_settings; + QStringList m_settingsKeys; + bool m_force; + + MsgConfigureBFMMod(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) : + Message(), + m_settings(settings), + m_settingsKeys(settingsKeys), + m_force(force) + { } + }; + + class MsgConfigureFileSourceSeek : public Message + { + MESSAGE_CLASS_DECLARATION + + public: + int getPercentage() const { return m_seekPercentage; } + + static MsgConfigureFileSourceSeek* create(int seekPercentage) + { + return new MsgConfigureFileSourceSeek(seekPercentage); + } + + protected: + int m_seekPercentage; //!< percentage of seek position from the beginning 0..100 + + MsgConfigureFileSourceSeek(int seekPercentage) : + Message(), + m_seekPercentage(seekPercentage) + { } + }; + + class MsgConfigureFileSourceStreamTiming : public Message { + MESSAGE_CLASS_DECLARATION + + public: + + static MsgConfigureFileSourceStreamTiming* create() + { + return new MsgConfigureFileSourceStreamTiming(); + } + + private: + + MsgConfigureFileSourceStreamTiming() : + Message() + { } + }; + + class MsgReportFileSourceStreamTiming : public Message + { + MESSAGE_CLASS_DECLARATION + + public: + std::size_t getSamplesCount() const { return m_samplesCount; } + + static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount) + { + return new MsgReportFileSourceStreamTiming(samplesCount); + } + + protected: + std::size_t m_samplesCount; + + MsgReportFileSourceStreamTiming(std::size_t samplesCount) : + Message(), + m_samplesCount(samplesCount) + { } + }; + + class MsgReportFileSourceStreamData : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSampleRate() const { return m_sampleRate; } + quint32 getRecordLength() const { return m_recordLength; } + + static MsgReportFileSourceStreamData* create(int sampleRate, + quint32 recordLength) + { + return new MsgReportFileSourceStreamData(sampleRate, recordLength); + } + + protected: + int m_sampleRate; + quint32 m_recordLength; + + MsgReportFileSourceStreamData(int sampleRate, + quint32 recordLength) : + Message(), + m_sampleRate(sampleRate), + m_recordLength(recordLength) + { } + }; + + //================================================================= + + explicit BFMMod(DeviceAPI *deviceAPI); + virtual ~BFMMod(); + virtual void destroy() { delete this; } + virtual void setDeviceAPI(DeviceAPI *deviceAPI); + virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + + virtual void start(); + virtual void stop(); + virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples); + virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } + virtual QString getSourceName() { return objectName(); } + + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } + virtual void getTitle(QString& title) { title = m_settings.m_title; } + virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + virtual void setCenterFrequency(qint64 frequency); + + virtual QByteArray serialize() const; + virtual bool deserialize(const QByteArray& data); + + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return m_settings.m_inputFrequencyOffset; + } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage); + + static void webapiFormatChannelSettings( + SWGSDRangel::SWGChannelSettings& response, + const BFMModSettings& settings); + + static void webapiUpdateChannelSettings( + BFMModSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); + + double getMagSq() const; + CWKeyer *getCWKeyer(); + void setLevelMeter(QObject *levelMeter); + uint32_t getNumberOfDeviceStreams() const; + int getAudioSampleRate() const; + int getFeedbackAudioSampleRate() const; + + static const char* const m_channelIdURI; + static const char* const m_channelId; + +private: + DeviceAPI* m_deviceAPI; + QThread *m_thread; + BFMModBaseband* m_basebandSource; + BFMModSettings m_settings; + + AudioFileReader m_audioFileReader; //!< Thread safe, so needs no lock + quint32 m_recordLength; //!< record length in seconds + int m_sampleRate; + + QNetworkAccessManager *m_networkManager; + QNetworkRequest m_networkRequest; + + virtual bool handleMessage(const Message& cmd); + void applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force = false); + void sendSampleRateToDemodAnalyzer(); + void openFileStream(const QString& fileName); + void seekFileStream(int seekPercentage); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); + void webapiReverseSendSettings(const QList& channelSettingsKeys, const BFMModSettings& settings, bool force); + void webapiReverseSendCWSettings(const CWKeyerSettings& settings); + void sendChannelSettings( + const QList& pipes, + const QList& channelSettingsKeys, + const BFMModSettings& settings, + bool force + ); + void webapiFormatChannelSettings( + const QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const BFMModSettings& settings, + bool force + ); + +private slots: + void networkManagerFinished(QNetworkReply *reply); +}; + + +#endif /* PLUGINS_CHANNELTX_MODBFM_BFMMOD_H_ */ diff --git a/plugins/channeltx/modbfm/bfmmodbaseband.cpp b/plugins/channeltx/modbfm/bfmmodbaseband.cpp new file mode 100644 index 000000000..b365006ad --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodbaseband.cpp @@ -0,0 +1,271 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "dsp/upchannelizer.h" +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" + +#include "bfmmodbaseband.h" + +MESSAGE_CLASS_DEFINITION(BFMModBaseband::MsgConfigureBFMModBaseband, Message) +MESSAGE_CLASS_DEFINITION(BFMModBaseband::MsgConfigureFileSampleRate, Message) + +BFMModBaseband::BFMModBaseband() : + m_fileSampleRate(48000) +{ + m_sampleFifo.resize(SampleSourceFifo::getSizePolicy(48000)); + m_channelizer = new UpChannelizer(&m_source); + + qDebug("BFMModBaseband::BFMModBaseband"); + QObject::connect( + &m_sampleFifo, + &SampleSourceFifo::dataRead, + this, + &BFMModBaseband::handleData, + Qt::QueuedConnection + ); + + DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(m_source.getFeedbackAudioFifo(), getInputMessageQueue()); + m_source.applyFeedbackAudioSampleRate(DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate()); + + connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); +} + +BFMModBaseband::~BFMModBaseband() +{ + DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(m_source.getFeedbackAudioFifo()); + DSPEngine::instance()->getAudioDeviceManager()->removeAudioSource(m_source.getAudioFifo()); + delete m_channelizer; +} + +void BFMModBaseband::reset() +{ + QMutexLocker mutexLocker(&m_mutex); + m_sampleFifo.reset(); +} + +void BFMModBaseband::setChannel(ChannelAPI *channel) +{ + m_source.setChannel(channel); +} + +void BFMModBaseband::pull(const SampleVector::iterator& begin, unsigned int nbSamples) +{ + unsigned int part1Begin, part1End, part2Begin, part2End; + m_sampleFifo.read(nbSamples, part1Begin, part1End, part2Begin, part2End); + SampleVector& data = m_sampleFifo.getData(); + + if (part1Begin != part1End) + { + std::copy( + data.begin() + part1Begin, + data.begin() + part1End, + begin + ); + } + + unsigned int shift = part1End - part1Begin; + + if (part2Begin != part2End) + { + std::copy( + data.begin() + part2Begin, + data.begin() + part2End, + begin + shift + ); + } +} + +void BFMModBaseband::handleData() +{ + QMutexLocker mutexLocker(&m_mutex); + SampleVector& data = m_sampleFifo.getData(); + unsigned int ipart1begin; + unsigned int ipart1end; + unsigned int ipart2begin; + unsigned int ipart2end; + qreal rmsLevel, peakLevel; + int numSamples; + + unsigned int remainder = m_sampleFifo.remainder(); + + while ((remainder > 0) && (m_inputMessageQueue.size() == 0)) + { + m_sampleFifo.write(remainder, ipart1begin, ipart1end, ipart2begin, ipart2end); + + if (ipart1begin != ipart1end) { // first part of FIFO data + processFifo(data, ipart1begin, ipart1end); + } + + if (ipart2begin != ipart2end) { // second part of FIFO data (used when block wraps around) + processFifo(data, ipart2begin, ipart2end); + } + + remainder = m_sampleFifo.remainder(); + } + + m_source.getLevels(rmsLevel, peakLevel, numSamples); + emit levelChanged(rmsLevel, peakLevel, numSamples); +} + +void BFMModBaseband::processFifo(SampleVector& data, unsigned int iBegin, unsigned int iEnd) +{ + m_channelizer->prefetch(iEnd - iBegin); + m_channelizer->pull(data.begin() + iBegin, iEnd - iBegin); +} + +void BFMModBaseband::handleInputMessages() +{ + Message* message; + + while ((message = m_inputMessageQueue.pop())) + { + if (!handleMessage(*message)) { + qDebug("%s: unhandled message: %s", Q_FUNC_INFO, message->getIdentifier()); + } + delete message; + } +} + +bool BFMModBaseband::handleMessage(const Message& cmd) +{ + if (MsgConfigureBFMModBaseband::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + MsgConfigureBFMModBaseband& cfg = (MsgConfigureBFMModBaseband&) cmd; + qDebug() << "BFMModBaseband::handleMessage: MsgConfigureBFMModBaseband"; + + applySettings(cfg.getSettingsKeys(), cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (MsgConfigureFileSampleRate::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + const MsgConfigureFileSampleRate& cfg = (const MsgConfigureFileSampleRate&) cmd; + m_fileSampleRate = cfg.getSampleRate(); + + if ((m_settings.m_modAFInput == BFMModSettings::BFMModInputFile) && + (m_source.getAudioSampleRate() != m_fileSampleRate)) + { + m_source.applyAudioSampleRate(m_fileSampleRate); + } + + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + qDebug() << "BFMModBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate(); + m_sampleFifo.resize(SampleSourceFifo::getSizePolicy(notif.getSampleRate())); + m_channelizer->setBasebandSampleRate(notif.getSampleRate()); + m_source.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); + m_source.applyAudioSampleRate(m_source.getAudioSampleRate()); // reapply in case of channel sample rate change + + return true; + } + else if (DSPConfigureAudio::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + const DSPConfigureAudio& cfg = (const DSPConfigureAudio&) cmd; + if (cfg.getAudioType() == DSPConfigureAudio::AudioOutput) { + m_source.applyFeedbackAudioSampleRate(cfg.getSampleRate()); + } else if (m_settings.m_modAFInput == BFMModSettings::BFMModInputAudio) { + m_source.applyAudioSampleRate(cfg.getSampleRate()); + } + return true; + } + else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; + CWKeyer::MsgConfigureCWKeyer *notif = new CWKeyer::MsgConfigureCWKeyer(cfg); + CWKeyer& cwKeyer = m_source.getCWKeyer(); + cwKeyer.getInputMessageQueue()->push(notif); + + return true; + } + else + { + return false; + } +} + +void BFMModBaseband::applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) +{ + if ((settingsKeys.contains("rfBandwidth") && m_settings.m_rfBandwidth != settings.m_rfBandwidth) + || (settingsKeys.contains("inputFrequencyOffset") && m_settings.m_inputFrequencyOffset != settings.m_inputFrequencyOffset) || force) + { + m_channelizer->setChannelization(settings.m_rfBandwidth, settings.m_inputFrequencyOffset); + m_source.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); + m_source.applyAudioSampleRate(m_source.getAudioSampleRate()); // reapply in case of channel sample rate change + } + + if ((settingsKeys.contains("audioDeviceName") && settings.m_audioDeviceName != m_settings.m_audioDeviceName) + || (settingsKeys.contains("modAFInput") && settings.m_modAFInput != m_settings.m_modAFInput) || force) + { + AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager(); + int audioDeviceIndex = audioDeviceManager->getInputDeviceIndex(settings.m_audioDeviceName); + + audioDeviceManager->removeAudioSource(getAudioFifo()); + if (settings.m_modAFInput == BFMModSettings::BFMModInputAudio) { + audioDeviceManager->addAudioSource(getAudioFifo(), getInputMessageQueue(), audioDeviceIndex); + } + + int inputSampleRate = m_source.getAudioSampleRate(); + + if (settings.m_modAFInput == BFMModSettings::BFMModInputAudio) { + inputSampleRate = audioDeviceManager->getInputSampleRate(audioDeviceIndex); + } else if (settings.m_modAFInput == BFMModSettings::BFMModInputFile) { + inputSampleRate = m_fileSampleRate; + } + + if (m_source.getAudioSampleRate() != inputSampleRate) { + m_source.applyAudioSampleRate(inputSampleRate); + } + } + + if ((settingsKeys.contains("feedbackAudioDeviceName") && settings.m_feedbackAudioDeviceName != m_settings.m_feedbackAudioDeviceName) || force) + { + AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager(); + const int audioDeviceIndex = audioDeviceManager->getOutputDeviceIndex(settings.m_feedbackAudioDeviceName); + audioDeviceManager->removeAudioSink(m_source.getFeedbackAudioFifo()); + audioDeviceManager->addAudioSink(m_source.getFeedbackAudioFifo(), getInputMessageQueue(), audioDeviceIndex); + const int audioSampleRate = audioDeviceManager->getOutputSampleRate(audioDeviceIndex); + if (m_source.getFeedbackAudioSampleRate() != audioSampleRate) { + m_source.applyFeedbackAudioSampleRate(audioSampleRate); + } + } + + m_source.applySettings(settingsKeys, settings, force); + + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } +} + +int BFMModBaseband::getChannelSampleRate() const +{ + return m_channelizer->getChannelSampleRate(); +} diff --git a/plugins/channeltx/modbfm/bfmmodbaseband.h b/plugins/channeltx/modbfm/bfmmodbaseband.h new file mode 100644 index 000000000..4eca6ea0a --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodbaseband.h @@ -0,0 +1,128 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_BFMMODBASEBAND_H +#define INCLUDE_BFMMODBASEBAND_H + +#include +#include + +#include "dsp/samplesourcefifo.h" +#include "util/message.h" +#include "util/messagequeue.h" + +#include "bfmmodsource.h" + +class UpChannelizer; +class ChannelAPI; +class AudioFileReader; + +class BFMModBaseband : public QObject +{ + Q_OBJECT +public: + class MsgConfigureBFMModBaseband : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const BFMModSettings& getSettings() const { return m_settings; } + const QStringList& getSettingsKeys() const { return m_settingsKeys; } + bool getForce() const { return m_force; } + + static MsgConfigureBFMModBaseband* create(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) + { + return new MsgConfigureBFMModBaseband(settingsKeys, settings, force); + } + + private: + BFMModSettings m_settings; + QStringList m_settingsKeys; + bool m_force; + + MsgConfigureBFMModBaseband(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) : + Message(), + m_settings(settings), + m_settingsKeys(settingsKeys), + m_force(force) + { } + }; + + class MsgConfigureFileSampleRate : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSampleRate() const { return m_sampleRate; } + + static MsgConfigureFileSampleRate* create(int sampleRate) + { + return new MsgConfigureFileSampleRate(sampleRate); + } + + private: + int m_sampleRate; + + explicit MsgConfigureFileSampleRate(int sampleRate) : + Message(), + m_sampleRate(sampleRate) + { } + }; + + BFMModBaseband(); + ~BFMModBaseband(); + void reset(); + void pull(const SampleVector::iterator& begin, unsigned int nbSamples); + MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication + CWKeyer& getCWKeyer() { return m_source.getCWKeyer(); } + double getMagSq() const { return m_source.getMagSq(); } + int getAudioSampleRate() const { return m_source.getAudioSampleRate(); } + int getFeedbackAudioSampleRate() const { return m_source.getFeedbackAudioSampleRate(); } + int getChannelSampleRate() const; + void setInputFileReader(AudioFileReader *audioFileReader) { m_source.setInputFileReader(audioFileReader); } + AudioFifo *getAudioFifo() { return m_source.getAudioFifo(); } + void setChannel(ChannelAPI *channel); + +signals: + /** + * Level changed + * \param rmsLevel RMS level in range 0.0 - 1.0 + * \param peakLevel Peak level in range 0.0 - 1.0 + * \param numSamples Number of audio samples analyzed + */ + void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples); + +private: + SampleSourceFifo m_sampleFifo; + UpChannelizer *m_channelizer; + BFMModSource m_source; + MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication + BFMModSettings m_settings; + int m_fileSampleRate; + QRecursiveMutex m_mutex; + + void processFifo(SampleVector& data, unsigned int iBegin, unsigned int iEnd); + bool handleMessage(const Message& cmd); + void applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force = false); + +private slots: + void handleInputMessages(); + void handleData(); //!< Handle data when samples have to be processed +}; + + +#endif // INCLUDE_BFMMODBASEBAND_H diff --git a/plugins/channeltx/modbfm/bfmmodgui.cpp b/plugins/channeltx/modbfm/bfmmodgui.cpp new file mode 100644 index 000000000..3dc18b004 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodgui.cpp @@ -0,0 +1,761 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include + +#include "device/deviceuiset.h" +#include "plugin/pluginapi.h" +#include "util/db.h" +#include "dsp/dspengine.h" +#include "dsp/cwkeyer.h" +#include "dsp/dspcommands.h" +#include "gui/crightclickenabler.h" +#include "gui/audioselectdialog.h" +#include "gui/basicchannelsettingsdialog.h" +#include "gui/dialpopup.h" +#include "gui/dialogpositioner.h" +#include "maincore.h" +#include "util/rds.h" + +#include "ui_bfmmodgui.h" +#include "bfmmodgui.h" + +BFMModGUI* BFMModGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx) +{ + BFMModGUI* gui = new BFMModGUI(pluginAPI, deviceUISet, channelTx); + return gui; +} + +void BFMModGUI::destroy() +{ + delete this; +} + +void BFMModGUI::resetToDefaults() +{ + m_settings.resetToDefaults(); + displaySettings(); + applySettings(QStringList(), true); +} + +QByteArray BFMModGUI::serialize() const +{ + return m_settings.serialize(); +} + +bool BFMModGUI::deserialize(const QByteArray& data) +{ + if(m_settings.deserialize(data)) { + displaySettings(); + applySettings(QStringList(), true); + return true; + } else { + resetToDefaults(); + return false; + } +} + +bool BFMModGUI::handleMessage(const Message& message) +{ + if (BFMMod::MsgReportFileSourceStreamData::match(message)) + { + m_recordSampleRate = ((BFMMod::MsgReportFileSourceStreamData&)message).getSampleRate(); + m_recordLength = ((BFMMod::MsgReportFileSourceStreamData&)message).getRecordLength(); + m_samplesCount = 0; + updateWithStreamData(); + return true; + } + else if (BFMMod::MsgReportFileSourceStreamTiming::match(message)) + { + m_samplesCount = ((BFMMod::MsgReportFileSourceStreamTiming&)message).getSamplesCount(); + updateWithStreamTime(); + return true; + } + else if (BFMMod::MsgConfigureBFMMod::match(message)) + { + const BFMMod::MsgConfigureBFMMod& cfg = (BFMMod::MsgConfigureBFMMod&) message; + m_settings = cfg.getSettings(); + blockApplySettings(true); + m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); + displaySettings(); + blockApplySettings(false); + return true; + } + else if (CWKeyer::MsgConfigureCWKeyer::match(message)) + { + const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) message; + ui->cwKeyerGUI->setSettings(cfg.getSettings()); + ui->cwKeyerGUI->displaySettings(); + return true; + } + else if (DSPSignalNotification::match(message)) + { + const DSPSignalNotification& notif = (const DSPSignalNotification&) message; + m_deviceCenterFrequency = notif.getCenterFrequency(); + m_basebandSampleRate = notif.getSampleRate(); + ui->deltaFrequency->setValueRange(false, 8, -m_basebandSampleRate/2, m_basebandSampleRate/2); + ui->deltaFrequencyLabel->setToolTip(tr("Range %1 %L2 Hz").arg(QChar(0xB1)).arg(m_basebandSampleRate/2)); + updateAbsoluteCenterFrequency(); + updateSampleRateStatus(); + return true; + } + else + { + return false; + } +} + +void BFMModGUI::channelMarkerChangedByCursor() +{ + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + applySettings(QStringList("inputFrequencyOffset")); +} + +void BFMModGUI::handleSourceMessages() +{ + Message* message; + + while ((message = getInputMessageQueue()->pop()) != 0) + { + if (handleMessage(*message)) + { + delete message; + } + } +} + +void BFMModGUI::on_deltaFrequency_changed(qint64 value) +{ + m_channelMarker.setCenterFrequency(value); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + updateAbsoluteCenterFrequency(); + applySettings(QStringList("inputFrequencyOffset")); +} + +void BFMModGUI::on_rfBW_currentIndexChanged(int index) +{ + float rfBW = BFMModSettings::getRFBW(index); + m_channelMarker.setBandwidth(rfBW); + m_settings.m_rfBandwidth = rfBW; + updateSampleRateStatus(); + applySettings(QStringList("rfBandwidth")); +} + +// The channel sample rate cannot exceed the device's. When it is below the RF +// bandwidth, the FM sidebands are cut and, below about 120 kHz, the 57 kHz RDS +// subcarrier aliases. +void BFMModGUI::updateSampleRateStatus() +{ + if ((m_basebandSampleRate > 1) && (m_basebandSampleRate < m_settings.m_rfBandwidth)) { + setStatusText(tr("Sample rate must be >= %1 Hz (currently %2 Hz)").arg(m_settings.m_rfBandwidth, 0, 'f', 0).arg(m_basebandSampleRate)); + } else { + setStatusText(""); + } +} + +void BFMModGUI::on_afBW_valueChanged(int value) +{ + ui->afBWText->setText(QString("%1k").arg(value)); + m_settings.m_afBandwidth = value * 1000.0; + applySettings(QStringList("afBandwidth")); +} + +void BFMModGUI::on_fmDev_valueChanged(int value) +{ + ui->fmDevText->setText(QString("%1%2k").arg(QChar(0xB1, 0x00)).arg(value)); + m_settings.m_fmDeviation = value * 1000.0; + applySettings(QStringList("fmDeviation")); +} + +void BFMModGUI::on_volume_valueChanged(int value) +{ + ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); + m_settings.m_volumeFactor = value / 10.0; + applySettings(QStringList("volumeFactor")); +} + +void BFMModGUI::on_stereo_toggled(bool checked) +{ + m_settings.m_audioStereo = checked; + applySettings(QStringList("audioStereo")); +} + +void BFMModGUI::on_preEmphasis_currentIndexChanged(int index) +{ + m_settings.m_preEmphasis = index; + applySettings(QStringList("preEmphasis")); +} + +void BFMModGUI::on_rdsActive_toggled(bool checked) +{ + m_settings.m_rdsActive = checked; + applySettings(QStringList("rdsActive")); +} + +void BFMModGUI::on_pilotLevel_valueChanged(double value) +{ + m_settings.m_pilotLevel = value / 100.0; + applySettings(QStringList("pilotLevel")); +} + +void BFMModGUI::on_rdsLevel_valueChanged(double value) +{ + m_settings.m_rdsLevel = value / 100.0; + applySettings(QStringList("rdsLevel")); +} + +void BFMModGUI::on_rdsPTY_currentIndexChanged(int index) +{ + m_settings.m_rdsPTY = index; + applySettings(QStringList("rdsPTY")); +} + +void BFMModGUI::on_rdsPI_editingFinished() +{ + // editingFinished is also emitted when focus leaves an unchanged field + bool ok = false; + const uint value = ui->rdsPI->text().toUInt(&ok, 16); + const bool changed = ok && (value <= 0xffffU) && (value != m_settings.m_rdsPI); + if (changed) { + m_settings.m_rdsPI = quint16(value); + } + ui->rdsPI->setText(QString("%1").arg(m_settings.m_rdsPI, 4, 16, QChar('0')).toUpper()); + if (changed) { + applySettings(QStringList("rdsPI")); + } +} + +void BFMModGUI::on_rdsPS_editingFinished() +{ + const QString ps = ui->rdsPS->text().left(8); + if (ps != m_settings.m_rdsPS) + { + m_settings.m_rdsPS = ps; + applySettings(QStringList("rdsPS")); + } +} + +void BFMModGUI::on_rdsRadioText_editingFinished() +{ + const QString radioText = ui->rdsRadioText->text().left(64); + if (radioText != m_settings.m_rdsRadioText) + { + m_settings.m_rdsRadioText = radioText; + applySettings(QStringList("rdsRadioText")); + } +} + +void BFMModGUI::on_toneFrequency_valueChanged(int value) +{ + ui->toneFrequencyText->setText(QString("%1k").arg(value / 100.0, 0, 'f', 2)); + m_settings.m_toneFrequency = value * 10.0; + applySettings(QStringList("toneFrequency")); +} + +void BFMModGUI::on_channelMute_toggled(bool checked) +{ + m_settings.m_channelMute = checked; + applySettings(QStringList("channelMute")); +} + +void BFMModGUI::on_playLoop_toggled(bool checked) +{ + m_settings.m_playLoop = checked; + applySettings(QStringList("playLoop")); +} + +void BFMModGUI::on_play_toggled(bool checked) +{ + selectInput(BFMModSettings::BFMModInputFile, checked); +} + +void BFMModGUI::on_tone_toggled(bool checked) +{ + selectInput(BFMModSettings::BFMModInputTone, checked); +} + +void BFMModGUI::on_morseKeyer_toggled(bool checked) +{ + selectInput(BFMModSettings::BFMModInputCWTone, checked); +} + +void BFMModGUI::on_mic_toggled(bool checked) +{ + selectInput(BFMModSettings::BFMModInputAudio, checked); +} + +// The input buttons act as a radio group: selecting one deselects the others. +// Unlike a QButtonGroup, the selected input can also be switched off, leaving none. +void BFMModGUI::selectInput(BFMModSettings::BFMModInputAF input, bool checked) +{ + m_settings.m_modAFInput = checked ? input : BFMModSettings::BFMModInputNone; + displayInput(); + applySettings(QStringList("modAFInput")); +} + +void BFMModGUI::displayInput() +{ + const BFMModSettings::BFMModInputAF input = m_settings.m_modAFInput; + const std::pair buttons[] = { + {ui->mic, BFMModSettings::BFMModInputAudio}, + {ui->play, BFMModSettings::BFMModInputFile}, + {ui->tone, BFMModSettings::BFMModInputTone}, + {ui->morseKeyer, BFMModSettings::BFMModInputCWTone} + }; + + for (const auto& button : buttons) + { + button.first->blockSignals(true); + button.first->setChecked(input == button.second); + button.first->blockSignals(false); + } + + // While the file is playing, the slider shows its position rather than seeking + const bool playing = input == BFMModSettings::BFMModInputFile; + ui->navTimeSlider->setEnabled(!playing); + m_enableNavTime = !playing; + + // Show the controls for the selected input + if (playing) { + ui->tabWidget->setCurrentWidget(ui->tabPlay); + } else if (input == BFMModSettings::BFMModInputCWTone) { + ui->tabWidget->setCurrentWidget(ui->tabMorseKeyer); + } +} + +void BFMModGUI::on_feedbackEnable_toggled(bool checked) +{ + m_settings.m_feedbackAudioEnable = checked; + applySettings(QStringList("feedbackAudioEnable")); +} + +void BFMModGUI::on_feedbackVolume_valueChanged(int value) +{ + ui->feedbackVolumeText->setText(QString("%1").arg(value / 100.0, 0, 'f', 2)); + m_settings.m_feedbackVolumeFactor = value / 100.0; + applySettings(QStringList("feedbackVolumeFactor")); +} + +void BFMModGUI::on_navTimeSlider_valueChanged(int value) +{ + if (m_enableNavTime && ((value >= 0) && (value <= 100))) + { + BFMMod::MsgConfigureFileSourceSeek* message = BFMMod::MsgConfigureFileSourceSeek::create(value); + m_bfmMod->getInputMessageQueue()->push(message); + } +} + +void BFMModGUI::on_showFileDialog_clicked(bool checked) +{ + (void) checked; + // Start in the directory of the current file, if any + const QString directory = m_settings.m_fileName.isEmpty() ? QString(".") : QFileInfo(m_settings.m_fileName).absolutePath(); + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open audio file"), directory, tr("Audio files (*.wav *.raw)"), 0, QFileDialog::DontUseNativeDialog); + + if (fileName != "") + { + m_settings.m_fileName = fileName; + displayFileName(); + applySettings(QStringList("fileName")); + } +} + +void BFMModGUI::displayFileName() +{ + ui->recordFileText->setText(m_settings.m_fileName.isEmpty() ? QString("...") : m_settings.m_fileName); + ui->recordFileText->setToolTip(m_settings.m_fileName); +} + +void BFMModGUI::onWidgetRolled(QWidget* widget, bool rollDown) +{ + (void) widget; + (void) rollDown; + + getRollupContents()->saveState(m_rollupState); + applySettings(QStringList()); +} + +void BFMModGUI::onMenuDialogCalled(const QPoint &p) +{ + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) + { + BasicChannelSettingsDialog dialog(&m_channelMarker, this); + dialog.setUseReverseAPI(m_settings.m_useReverseAPI); + dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); + dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); + dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex); + dialog.setReverseAPIChannelIndex(m_settings.m_reverseAPIChannelIndex); + dialog.setDefaultTitle(m_displayedName); + + if (m_deviceUISet->m_deviceMIMOEngine) + { + dialog.setNumberOfStreams(m_bfmMod->getNumberOfDeviceStreams()); + dialog.setStreamIndex(m_settings.m_streamIndex); + } + + dialog.move(p); + new DialogPositioner(&dialog, false); + dialog.exec(); + + m_settings.m_rgbColor = m_channelMarker.getColor().rgb(); + m_settings.m_title = m_channelMarker.getTitle(); + m_settings.m_useReverseAPI = dialog.useReverseAPI(); + m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); + m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); + m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex(); + m_settings.m_reverseAPIChannelIndex = dialog.getReverseAPIChannelIndex(); + + setWindowTitle(m_settings.m_title); + setTitle(m_channelMarker.getTitle()); + setTitleColor(m_settings.m_rgbColor); + + if (m_deviceUISet->m_deviceMIMOEngine) + { + m_settings.m_streamIndex = dialog.getSelectedStreamIndex(); + m_channelMarker.clearStreamIndexes(); + m_channelMarker.addStreamIndex(m_settings.m_streamIndex); + updateIndexLabel(); + } + + applySettings(QStringList({"title", "rgbColor", "useReverseAPI", + "reverseAPIAddress", "reverseAPIPort", "reverseAPIDeviceIndex", + "reverseAPIChannelIndex", "streamIndex"})); + } + + resetContextMenuType(); +} + +BFMModGUI::BFMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent) : + ChannelGUI(parent), + ui(new Ui::BFMModGUI), + m_pluginAPI(pluginAPI), + m_deviceUISet(deviceUISet), + m_channelMarker(this), + m_deviceCenterFrequency(0), + m_basebandSampleRate(1), + m_doApplySettings(true), + m_recordLength(0), + m_recordSampleRate(48000), + m_samplesCount(0), + m_audioSampleRate(-1), + m_feedbackAudioSampleRate(-1), + m_tickCount(0), + m_enableNavTime(false) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + m_helpURL = "plugins/channeltx/modbfm/readme.md"; + RollupContents *rollupContents = getRollupContents(); + ui->setupUi(rollupContents); + setSizePolicy(rollupContents->sizePolicy()); + rollupContents->arrangeRollups(); + connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + + blockApplySettings(true); + + ui->rfBW->clear(); + for (int i = 0; i < BFMModSettings::m_nbRfBW; i++) { + ui->rfBW->addItem(QString("%1").arg(BFMModSettings::getRFBW(i) / 1000.0, 0, 'f', 2)); + } + ui->rfBW->setCurrentIndex(BFMModSettings::getRFBWIndex(m_settings.m_rfBandwidth)); + + // Same names as the programme type shown by the BFM demodulator. Index is the PTY code. + for (int i = 0; i < RDS::m_nbProgrammeTypes; i++) { + ui->rdsPTY->addItem(QString::fromUtf8(RDS::m_programmeTypes[i])); + } + + blockApplySettings(false); + + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); + + m_bfmMod = (BFMMod*) channelTx; + m_bfmMod->setMessageQueueToGUI(getInputMessageQueue()); + + connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); + + CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->mic); + connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect(const QPoint &))); + + CRightClickEnabler *feedbackRightClickEnabler = new CRightClickEnabler(ui->feedbackEnable); + connect(feedbackRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioFeedbackSelect(const QPoint &))); + + ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); + ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); + ui->deltaFrequency->setValueRange(false, 8, -99999999, 99999999); + + m_channelMarker.blockSignals(true); + m_channelMarker.setColor(m_settings.m_rgbColor); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + m_channelMarker.setCenterFrequency(0); + m_channelMarker.setTitle(m_settings.m_title); + m_channelMarker.setSourceOrSinkStream(false); + m_channelMarker.blockSignals(false); + m_channelMarker.setVisible(true); // activate signal on the last setting only + + m_deviceUISet->addChannelMarker(&m_channelMarker); + + connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); + + ui->cwKeyerGUI->setCWKeyer(m_bfmMod->getCWKeyer()); + + m_settings.setChannelMarker(&m_channelMarker); + m_settings.setCWKeyerGUI(ui->cwKeyerGUI); + m_settings.setRollupState(&m_rollupState); + + connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + m_bfmMod->setLevelMeter(ui->volumeMeter); + + displaySettings(); + makeUIConnections(); + applySettings(QStringList(), true); + DialPopup::addPopupsToChildDials(this); + m_resizer.enableChildMouseTracking(); +} + +BFMModGUI::~BFMModGUI() +{ + delete ui; +} + +void BFMModGUI::blockApplySettings(bool block) +{ + m_doApplySettings = !block; +} + +void BFMModGUI::applySettings(const QStringList& settingsKeys, bool force) +{ + if (m_doApplySettings) + { + BFMMod::MsgConfigureBFMMod *msgConf = BFMMod::MsgConfigureBFMMod::create(settingsKeys, m_settings, force); + m_bfmMod->getInputMessageQueue()->push(msgConf); + } +} + +void BFMModGUI::displaySettings() +{ + m_channelMarker.blockSignals(true); + m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setTitle(m_settings.m_title); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + m_channelMarker.blockSignals(false); + m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only + + setTitleColor(m_settings.m_rgbColor); + setWindowTitle(m_channelMarker.getTitle()); + setTitle(m_channelMarker.getTitle()); + updateIndexLabel(); + + blockApplySettings(true); + + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + + ui->rfBW->setCurrentIndex(BFMModSettings::getRFBWIndex(m_settings.m_rfBandwidth)); + + ui->afBWText->setText(QString("%1k").arg(m_settings.m_afBandwidth / 1000.0)); + ui->afBW->setValue(m_settings.m_afBandwidth / 1000.0); + + ui->fmDevText->setText(QString("%1%2k").arg(QChar(0xB1, 0x00)).arg(m_settings.m_fmDeviation / 1000.0)); + ui->fmDev->setValue(m_settings.m_fmDeviation / 1000.0); + + ui->volumeText->setText(QString("%1").arg(m_settings.m_volumeFactor, 0, 'f', 1)); + ui->volume->setValue(m_settings.m_volumeFactor * 10.0); + ui->stereo->setChecked(m_settings.m_audioStereo); + ui->preEmphasis->setCurrentIndex(m_settings.m_preEmphasis); + ui->rdsActive->setChecked(m_settings.m_rdsActive); + ui->pilotLevel->setValue(m_settings.m_pilotLevel * 100.0); + ui->rdsLevel->setValue(m_settings.m_rdsLevel * 100.0); + ui->rdsPTY->setCurrentIndex(m_settings.m_rdsPTY); + ui->rdsPI->setText(QString("%1").arg(m_settings.m_rdsPI, 4, 16, QChar('0')).toUpper()); + ui->rdsPS->setText(m_settings.m_rdsPS); + ui->rdsRadioText->setText(m_settings.m_rdsRadioText); + + ui->toneFrequencyText->setText(QString("%1k").arg(m_settings.m_toneFrequency / 1000.0, 0, 'f', 2)); + ui->toneFrequency->setValue(m_settings.m_toneFrequency / 10.0); + + ui->channelMute->setChecked(m_settings.m_channelMute); + ui->playLoop->setChecked(m_settings.m_playLoop); + displayFileName(); + + displayInput(); + + ui->feedbackEnable->setChecked(m_settings.m_feedbackAudioEnable); + ui->feedbackVolume->setValue(roundf(m_settings.m_feedbackVolumeFactor * 100.0)); + ui->feedbackVolumeText->setText(QString("%1").arg(m_settings.m_feedbackVolumeFactor, 0, 'f', 2)); + + getRollupContents()->restoreState(m_rollupState); + updateAbsoluteCenterFrequency(); + updateSampleRateStatus(); + blockApplySettings(false); +} + +void BFMModGUI::leaveEvent(QEvent* event) +{ + m_channelMarker.setHighlighted(false); + ChannelGUI::leaveEvent(event); +} + +void BFMModGUI::enterEvent(EnterEventType* event) +{ + m_channelMarker.setHighlighted(true); + ChannelGUI::enterEvent(event); +} + +void BFMModGUI::audioSelect(const QPoint& p) +{ + qDebug("BFMModGUI::audioSelect"); + AudioSelectDialog audioSelect(DSPEngine::instance()->getAudioDeviceManager(), m_settings.m_audioDeviceName, true); // true for input + audioSelect.move(p); + new DialogPositioner(&audioSelect, false); + audioSelect.exec(); + + if (audioSelect.m_selected) + { + m_settings.m_audioDeviceName = audioSelect.m_audioDeviceName; + applySettings(QStringList("audioDeviceName")); + } +} + +void BFMModGUI::audioFeedbackSelect(const QPoint& p) +{ + qDebug("BFMModGUI::audioFeedbackSelect"); + AudioSelectDialog audioSelect(DSPEngine::instance()->getAudioDeviceManager(), m_settings.m_feedbackAudioDeviceName, false); // false for output + audioSelect.move(p); + new DialogPositioner(&audioSelect, false); + audioSelect.exec(); + + if (audioSelect.m_selected) + { + m_settings.m_feedbackAudioDeviceName = audioSelect.m_audioDeviceName; + applySettings(QStringList("feedbackAudioDeviceName")); + } +} + +void BFMModGUI::tick() +{ + double powDb = CalcDb::dbPower(m_bfmMod->getMagSq()); + m_channelPowerDbAvg(powDb); + ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1)); + + int audioSampleRate = m_bfmMod->getAudioSampleRate(); + + if (audioSampleRate != m_audioSampleRate) + { + if (audioSampleRate < 0) { + ui->mic->setColor(QColor("red")); + } else { + ui->mic->resetColor(); + } + + m_audioSampleRate = audioSampleRate; + } + + int feedbackAudioSampleRate = m_bfmMod->getFeedbackAudioSampleRate(); + + if (feedbackAudioSampleRate != m_feedbackAudioSampleRate) + { + if (feedbackAudioSampleRate < 0) { + ui->feedbackEnable->setStyleSheet("QToolButton { background-color : red; }"); + } else { + ui->feedbackEnable->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); + } + + m_feedbackAudioSampleRate = feedbackAudioSampleRate; + } + + if (((++m_tickCount & 0xf) == 0) && (m_settings.m_modAFInput == BFMModSettings::BFMModInputFile)) + { + BFMMod::MsgConfigureFileSourceStreamTiming* message = BFMMod::MsgConfigureFileSourceStreamTiming::create(); + m_bfmMod->getInputMessageQueue()->push(message); + } +} + +void BFMModGUI::updateWithStreamData() +{ + QTime recordLength(0, 0, 0, 0); + recordLength = recordLength.addSecs(m_recordLength); + QString s_time = recordLength.toString("HH:mm:ss"); + ui->recordLengthText->setText(s_time); + updateWithStreamTime(); +} + +void BFMModGUI::updateWithStreamTime() +{ + int t_sec = 0; + int t_msec = 0; + + if (m_recordSampleRate > 0) + { + t_msec = ((m_samplesCount * 1000) / m_recordSampleRate) % 1000; + t_sec = m_samplesCount / m_recordSampleRate; + } + + QTime t(0, 0, 0, 0); + t = t.addSecs(t_sec); + t = t.addMSecs(t_msec); + QString s_timems = t.toString("HH:mm:ss.zzz"); + QString s_time = t.toString("HH:mm:ss"); + ui->relTimeText->setText(s_timems); + + if (!m_enableNavTime && (m_recordLength > 0)) + { + float posRatio = (float) t_sec / (float) m_recordLength; + ui->navTimeSlider->setValue((int) (posRatio * 100.0)); + } +} + +void BFMModGUI::makeUIConnections() +{ + QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &BFMModGUI::on_deltaFrequency_changed); + QObject::connect(ui->rfBW, QOverload::of(&QComboBox::currentIndexChanged), this, &BFMModGUI::on_rfBW_currentIndexChanged); + QObject::connect(ui->afBW, &QSlider::valueChanged, this, &BFMModGUI::on_afBW_valueChanged); + QObject::connect(ui->fmDev, &QSlider::valueChanged, this, &BFMModGUI::on_fmDev_valueChanged); + QObject::connect(ui->toneFrequency, &QDial::valueChanged, this, &BFMModGUI::on_toneFrequency_valueChanged); + QObject::connect(ui->volume, &QDial::valueChanged, this, &BFMModGUI::on_volume_valueChanged); + QObject::connect(ui->stereo, &ButtonSwitch::toggled, this, &BFMModGUI::on_stereo_toggled); + QObject::connect(ui->preEmphasis, QOverload::of(&QComboBox::currentIndexChanged), this, &BFMModGUI::on_preEmphasis_currentIndexChanged); + QObject::connect(ui->rdsActive, &ButtonSwitch::toggled, this, &BFMModGUI::on_rdsActive_toggled); + QObject::connect(ui->pilotLevel, QOverload::of(&QDoubleSpinBox::valueChanged), this, &BFMModGUI::on_pilotLevel_valueChanged); + QObject::connect(ui->rdsLevel, QOverload::of(&QDoubleSpinBox::valueChanged), this, &BFMModGUI::on_rdsLevel_valueChanged); + QObject::connect(ui->rdsPTY, QOverload::of(&QComboBox::currentIndexChanged), this, &BFMModGUI::on_rdsPTY_currentIndexChanged); + QObject::connect(ui->rdsPI, &QLineEdit::editingFinished, this, &BFMModGUI::on_rdsPI_editingFinished); + QObject::connect(ui->rdsPS, &QLineEdit::editingFinished, this, &BFMModGUI::on_rdsPS_editingFinished); + QObject::connect(ui->rdsRadioText, &QLineEdit::editingFinished, this, &BFMModGUI::on_rdsRadioText_editingFinished); + QObject::connect(ui->channelMute, &QToolButton::toggled, this, &BFMModGUI::on_channelMute_toggled); + QObject::connect(ui->tone, &ButtonSwitch::toggled, this, &BFMModGUI::on_tone_toggled); + QObject::connect(ui->morseKeyer, &ButtonSwitch::toggled, this, &BFMModGUI::on_morseKeyer_toggled); + QObject::connect(ui->mic, &ButtonSwitch::toggled, this, &BFMModGUI::on_mic_toggled); + QObject::connect(ui->play, &ButtonSwitch::toggled, this, &BFMModGUI::on_play_toggled); + QObject::connect(ui->playLoop, &ButtonSwitch::toggled, this, &BFMModGUI::on_playLoop_toggled); + QObject::connect(ui->navTimeSlider, &QSlider::valueChanged, this, &BFMModGUI::on_navTimeSlider_valueChanged); + QObject::connect(ui->showFileDialog, &QPushButton::clicked, this, &BFMModGUI::on_showFileDialog_clicked); + QObject::connect(ui->feedbackEnable, &QToolButton::toggled, this, &BFMModGUI::on_feedbackEnable_toggled); + QObject::connect(ui->feedbackVolume, &QDial::valueChanged, this, &BFMModGUI::on_feedbackVolume_valueChanged); +} + +void BFMModGUI::updateAbsoluteCenterFrequency() +{ + setStatusFrequency(m_deviceCenterFrequency + m_settings.m_inputFrequencyOffset); +} diff --git a/plugins/channeltx/modbfm/bfmmodgui.h b/plugins/channeltx/modbfm/bfmmodgui.h new file mode 100644 index 000000000..a9eab1fde --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodgui.h @@ -0,0 +1,156 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODBFM_BFMMODGUI_H_ +#define PLUGINS_CHANNELTX_MODBFM_BFMMODGUI_H_ + +#include "channel/channelgui.h" +#include "dsp/channelmarker.h" +#include "util/movingaverage.h" +#include "util/messagequeue.h" +#include "settings/rollupstate.h" + +#include "bfmmod.h" +#include "bfmmodsettings.h" + +class PluginAPI; +class DeviceUISet; +class BasebandSampleSource; + +namespace Ui { + class BFMModGUI; +} + +class BFMModGUI : public ChannelGUI { + Q_OBJECT + +public: + static BFMModGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx); + virtual void destroy(); + + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } + virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; + virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; + virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; + virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; + virtual QString getTitle() const { return m_settings.m_title; }; + virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; + virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } + virtual bool getHidden() const { return m_settings.m_hidden; } + virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } + virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + virtual void setStreamIndex(int streamIndex) { m_settings.m_streamIndex = streamIndex; } + +public slots: + void channelMarkerChangedByCursor(); + +private: + Ui::BFMModGUI* ui; + PluginAPI* m_pluginAPI; + DeviceUISet* m_deviceUISet; + ChannelMarker m_channelMarker; + RollupState m_rollupState; + BFMModSettings m_settings; + qint64 m_deviceCenterFrequency; + int m_basebandSampleRate; + bool m_doApplySettings; + + BFMMod* m_bfmMod; + MovingAverageUtil m_channelPowerDbAvg; + + quint32 m_recordLength; + int m_recordSampleRate; + int m_samplesCount; + int m_audioSampleRate; + int m_feedbackAudioSampleRate; + std::size_t m_tickCount; + bool m_enableNavTime; + MessageQueue m_inputMessageQueue; + + explicit BFMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent = 0); + virtual ~BFMModGUI(); + + void blockApplySettings(bool block); + void applySettings(const QStringList& settingsKeys, bool force = false); + void displaySettings(); + void selectInput(BFMModSettings::BFMModInputAF input, bool checked); + void displayInput(); + void displayFileName(); + void updateWithStreamData(); + void updateWithStreamTime(); + bool handleMessage(const Message& message); + void makeUIConnections(); + void updateAbsoluteCenterFrequency(); + void updateSampleRateStatus(); + + void leaveEvent(QEvent*); + void enterEvent(EnterEventType*); + + static int requiredBW(int rfBW) + { + if (rfBW <= 96000) { + return 96000; + } else { + return (3*rfBW)/2; + } + } + +private slots: + void handleSourceMessages(); + + void on_deltaFrequency_changed(qint64 value); + void on_rfBW_currentIndexChanged(int index); + void on_afBW_valueChanged(int value); + void on_fmDev_valueChanged(int value); + void on_toneFrequency_valueChanged(int value); + void on_volume_valueChanged(int value); + void on_stereo_toggled(bool checked); + void on_preEmphasis_currentIndexChanged(int index); + void on_rdsActive_toggled(bool checked); + void on_pilotLevel_valueChanged(double value); + void on_rdsLevel_valueChanged(double value); + void on_rdsPTY_currentIndexChanged(int index); + void on_rdsPI_editingFinished(); + void on_rdsPS_editingFinished(); + void on_rdsRadioText_editingFinished(); + void on_channelMute_toggled(bool checked); + void on_tone_toggled(bool checked); + void on_morseKeyer_toggled(bool checked); + void on_mic_toggled(bool checked); + void on_play_toggled(bool checked); + + void on_playLoop_toggled(bool checked); + void on_navTimeSlider_valueChanged(int value); + void on_showFileDialog_clicked(bool checked); + + void on_feedbackEnable_toggled(bool checked); + void on_feedbackVolume_valueChanged(int value); + + void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDialogCalled(const QPoint& p); + + void audioSelect(const QPoint& p); + void audioFeedbackSelect(const QPoint& p); + void tick(); +}; + +#endif /* PLUGINS_CHANNELTX_MODBFM_BFMMODGUI_H_ */ diff --git a/plugins/channeltx/modbfm/bfmmodgui.ui b/plugins/channeltx/modbfm/bfmmodgui.ui new file mode 100644 index 000000000..6e974def4 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodgui.ui @@ -0,0 +1,1125 @@ + + + BFMModGUI + + + + 0 + 0 + 310 + 397 + + + + + 0 + 0 + + + + + 300 + 0 + + + + + 560 + 16777215 + + + + + Liberation Sans + 9 + + + + Qt::FocusPolicy::StrongFocus + + + Broadcast FM Modulator + + + + + 2 + 2 + 291 + 371 + + + + + 280 + 0 + + + + Settings + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + + + + + + 16 + 0 + + + + Df + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Liberation Mono + 12 + + + + PointingHandCursor + + + Qt::FocusPolicy::StrongFocus + + + Demod shift frequency from center in Hz + + + + + + + Hz + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 60 + 0 + + + + Channel power + + + Qt::LayoutDirection::RightToLeft + + + -100.0 dB + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + Mute/Unmute channel + + + ... + + + + :/txon.png + :/txoff.png:/txon.png + + + true + + + + + + + + + + + RFBW + + + + + + + + 70 + 16777215 + + + + + + + + + 10 + 0 + + + + k + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + + Qt::Orientation::Vertical + + + + + + + Dev + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Peak frequency deviation + + + 100 + + + 1 + + + 50 + + + Qt::Orientation::Horizontal + + + + + + + + 30 + 0 + + + + ±50k + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + + + AFBW + + + + + + + Audio bandwidth (kHz). Limited to 15 kHz to keep audio clear of the pilot and RDS + + + 1 + + + 15 + + + 1 + + + 15 + + + Qt::Orientation::Horizontal + + + + + + + + 25 + 0 + + + + 8k + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + Qt::Orientation::Vertical + + + + + + + Pre-emphasis + + + + + + + Pre-emphasis time constant + + + + Off + + + + + 50 us + + + + + 75 us + + + + + + + + + + + + Mono/Stereo toggle. Stereo transmits the 19 kHz pilot and 38 kHz stereo difference signal + + + + + + + :/mono.png + :/stereo.png:/mono.png + + + + + + + Toggle RDS transmission on the 57 kHz subcarrier + + + + + + + :/rds.png:/rds.png + + + + + + + Pilot + + + + + + + 19 kHz pilot level as a percentage of peak deviation + + + % + + + 1 + + + 0.000000000000000 + + + 20.000000000000000 + + + 0.500000000000000 + + + 9.000000000000000 + + + + + + + RDS + + + + + + + RDS subcarrier level as a percentage of peak deviation + + + % + + + 1 + + + 0.000000000000000 + + + 10.000000000000000 + + + 0.500000000000000 + + + 3.000000000000000 + + + + + + + Qt::Orientation::Horizontal + + + + 0 + 0 + + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + Vol + + + + + + + + 24 + 24 + + + + Audio input gain + + + 20 + + + 1 + + + 10 + + + + + + + + 25 + 0 + + + + Audio input gain value + + + 1.0 + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + 0 + 0 + + + + + Liberation Mono + 8 + + + + Level (% full range) top trace: average, bottom trace: instantaneous peak, tip: peak hold + + + + + + + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + Audio input + + + ... + + + + :/microphone.png:/microphone.png + + + true + + + + + + + Record file play/pause + + + ... + + + + :/play.png + :/pause.png + :/play.png + :/play.png:/play.png + + + + + + + Tone modulation (1 kHz) + + + ... + + + + :/carrier.png:/carrier.png + + + + + + + Morse keyer at tone frequency + + + ... + + + + :/morsekey.png:/morsekey.png + + + + + + + + 24 + 24 + + + + Tone frequency + + + 10 + + + 1000 + + + 1 + + + 100 + + + + + + + + 36 + 0 + + + + Tone frequency (kHz) + + + 1.00k + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + Qt::Orientation::Vertical + + + + + + + Left: enable / disable audio feedback - Right: select audio output device + + + ... + + + + :/sound_off.png + :/sound_on.png:/sound_off.png + + + true + + + + + + + + 24 + 24 + + + + Audio feedback volume + + + 0 + + + 100 + + + 1 + + + 50 + + + + + + + + 30 + 16777215 + + + + Audio feedback volume + + + 1.00 + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + 0 + + + + + :/play.png:/play.png + + + + + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Open mono/stereo WAV or 48 kHz 32-bit float LE mono raw audio + + + + + + + :/preset-load.png:/preset-load.png + + + + + + + ... + + + + + + + + + + + Play file in a loop + + + ... + + + + :/playloop.png:/playloop.png + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Orientation::Vertical + + + + + + + false + + + + 90 + 0 + + + + Record time from start + + + 00:00:00.000 + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + Qt::Orientation::Vertical + + + + + + + false + + + + 60 + 0 + + + + Total record time + + + 00:00:00 + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + + + Record file time navigator + + + 100 + + + 1 + + + Qt::Orientation::Horizontal + + + + + + + + + + + :/morsekey.png:/morsekey.png + + + + + + TX Morse Code + + + + + + + + + + + :/rds.png:/rds.png + + + + + + + + + + + PI + + + + + + + + 50 + 16777215 + + + + RDS programme identification code (4 hexadecimal digits) + + + 1234 + + + 4 + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + PTY + + + + + + + RDS programme type + + + + + + + + + + + PS + + + + + + + RDS Program Service + + + 8 + + + Programme service + + + + + + + RT + + + + + + + RDS Radio Text + + + 64 + + + RadioText + + + + + + + + + + + + + + + + + RollupContents + QWidget +
gui/rollupcontents.h
+ 1 +
+ + ValueDialZ + QWidget +
gui/valuedialz.h
+ 1 +
+ + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
+ + LevelMeterVU + QWidget +
gui/levelmeter.h
+ 1 +
+ + CWKeyerGUI + QWidget +
gui/cwkeyergui.h
+ 1 +
+
+ + + + +
diff --git a/plugins/channeltx/modbfm/bfmmodplugin.cpp b/plugins/channeltx/modbfm/bfmmodplugin.cpp new file mode 100644 index 000000000..1f7c9147a --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodplugin.cpp @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "plugin/pluginapi.h" +#include "bfmmod.h" +#include "bfmmodwebapiadapter.h" +#ifndef SERVER_MODE +#include "bfmmodgui.h" +#endif +#include "bfmmodplugin.h" + +namespace { +const char *channelIdURI = "sdrangel.channeltx.modbfm"; +const char *channelId = "BFMMod"; +} + +const PluginDescriptor BFMModPlugin::m_pluginDescriptor = { + channelId, + QStringLiteral("Broadcast FM Modulator"), + QStringLiteral("7.28.0"), + QStringLiteral("(c) Jon Beniston, M7RCE"), + QStringLiteral("https://github.com/f4exb/sdrangel"), + true, + QStringLiteral("https://github.com/f4exb/sdrangel") +}; + +BFMModPlugin::BFMModPlugin(QObject *parent) : + QObject(parent), + m_pluginAPI(nullptr) +{} + +const PluginDescriptor& BFMModPlugin::getPluginDescriptor() const +{ + return m_pluginDescriptor; +} + +void BFMModPlugin::initPlugin(PluginAPI *pluginAPI) +{ + m_pluginAPI = pluginAPI; + m_pluginAPI->registerTxChannel(channelIdURI, channelId, this); +} + +void BFMModPlugin::createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const +{ + if (!bs && !cs) { + return; + } + + BFMMod *instance = new BFMMod(deviceAPI); + if (bs) { + *bs = instance; + } + if (cs) { + *cs = instance; + } +} + +#ifdef SERVER_MODE +ChannelGUI* BFMModPlugin::createTxChannelGUI(DeviceUISet *, BasebandSampleSource *) const +{ + return nullptr; +} +#else +ChannelGUI* BFMModPlugin::createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const +{ + return BFMModGUI::create(m_pluginAPI, deviceUISet, txChannel); +} +#endif + +ChannelWebAPIAdapter* BFMModPlugin::createChannelWebAPIAdapter() const +{ + return new BFMModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modbfm/bfmmodplugin.h b/plugins/channeltx/modbfm/bfmmodplugin.h new file mode 100644 index 000000000..c89416fec --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodplugin.h @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_BFMMODPLUGIN_H +#define INCLUDE_BFMMODPLUGIN_H + +#include +#include "plugin/plugininterface.h" + +class BFMModPlugin : public QObject, PluginInterface +{ + Q_OBJECT + Q_INTERFACES(PluginInterface) + Q_PLUGIN_METADATA(IID "sdrangel.channeltx.bfmmod") + +public: + explicit BFMModPlugin(QObject *parent = nullptr); + const PluginDescriptor& getPluginDescriptor() const override; + void initPlugin(PluginAPI *pluginAPI) override; + void createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const override; + ChannelGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const override; + ChannelWebAPIAdapter* createChannelWebAPIAdapter() const override; + +private: + static const PluginDescriptor m_pluginDescriptor; + PluginAPI *m_pluginAPI; +}; + +#endif // INCLUDE_BFMMODPLUGIN_H diff --git a/plugins/channeltx/modbfm/bfmmodsettings.cpp b/plugins/channeltx/modbfm/bfmmodsettings.cpp new file mode 100644 index 000000000..d74a8ef29 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodsettings.cpp @@ -0,0 +1,521 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include "dsp/dspengine.h" +#include "util/simpleserializer.h" +#include "settings/serializable.h" + +#include "bfmmodsettings.h" + +// Stereo with RDS needs about 256 kHz (Carson's rule with 75 kHz deviation and a +// 53 kHz multiplex). Narrower settings truncate the FM sidebands, and below about +// 150 kHz the channel sample rate is too low for the 57 kHz RDS subcarrier. +const int BFMModSettings::m_rfBW[] = { + 150000, 180000, 200000, 220000, 240000, 256000, 280000, 300000 +}; +const int BFMModSettings::m_nbRfBW = 8; +const Real BFMModSettings::m_minAFBandwidth = 1000.0f; +const Real BFMModSettings::m_maxAFBandwidth = 15000.0f; + +BFMModSettings::BFMModSettings() : + m_channelMarker(nullptr), + m_cwKeyerGUI(nullptr), + m_rollupState(nullptr) +{ + resetToDefaults(); +} + +void BFMModSettings::resetToDefaults() +{ + m_inputFrequencyOffset = 0; + m_rfBandwidth = 256000.0f; + m_afBandwidth = 15000.0f; + m_fmDeviation = 75000.0f; + m_toneFrequency = 1000.0f; + m_volumeFactor = 1.0f; + m_audioStereo = true; + m_preEmphasis = 1; + m_pilotLevel = 0.09f; + m_rdsActive = true; + m_rdsLevel = 0.03f; + m_rdsPI = 0x1234; + m_rdsPTY = 0; + m_rdsPS = "SDRangel"; + m_rdsRadioText = "SDRangel Broadcast FM"; + m_fileName = ""; + m_channelMute = false; + m_playLoop = false; + m_rgbColor = QColor(0, 96, 255).rgb(); + m_title = "Broadcast FM Modulator"; + m_modAFInput = BFMModInputNone; + m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName; + m_feedbackAudioDeviceName = AudioDeviceManager::m_defaultDeviceName; + m_feedbackVolumeFactor = 0.5f; + m_feedbackAudioEnable = false; + m_streamIndex = 0; + m_useReverseAPI = false; + m_reverseAPIAddress = "127.0.0.1"; + m_reverseAPIPort = 8888; + m_reverseAPIDeviceIndex = 0; + m_reverseAPIChannelIndex = 0; + m_workspaceIndex = 0; + m_hidden = false; +} + +QByteArray BFMModSettings::serialize() const +{ + SimpleSerializer s(1); + + s.writeS32(1, m_inputFrequencyOffset); + s.writeReal(2, m_rfBandwidth); + s.writeReal(3, m_afBandwidth); + s.writeReal(4, m_fmDeviation); + s.writeU32(5, m_rgbColor); + s.writeReal(6, m_toneFrequency); + s.writeReal(7, m_volumeFactor); + + if (m_cwKeyerGUI) { + s.writeBlob(8, m_cwKeyerGUI->serialize()); + } else { // standalone operation with presets + s.writeBlob(8, m_cwKeyerSettings.serialize()); + } + + if (m_channelMarker) { + s.writeBlob(9, m_channelMarker->serialize()); + } + + s.writeString(10, m_title); + s.writeString(11, m_audioDeviceName); + s.writeS32(12, (int) m_modAFInput); + s.writeBool(13, m_useReverseAPI); + s.writeString(14, m_reverseAPIAddress); + s.writeU32(15, m_reverseAPIPort); + s.writeU32(16, m_reverseAPIDeviceIndex); + s.writeU32(17, m_reverseAPIChannelIndex); + s.writeS32(18, m_streamIndex); + s.writeString(19, m_feedbackAudioDeviceName); + s.writeReal(20, m_feedbackVolumeFactor); + s.writeBool(21, m_feedbackAudioEnable); + + if (m_rollupState) { + s.writeBlob(22, m_rollupState->serialize()); + } + + s.writeS32(23, m_workspaceIndex); + s.writeBlob(24, m_geometryBytes); + s.writeBool(25, m_hidden); + s.writeBool(26, m_audioStereo); + s.writeS32(27, m_preEmphasis); + s.writeReal(28, m_pilotLevel); + s.writeBool(29, m_rdsActive); + s.writeReal(30, m_rdsLevel); + s.writeU32(31, m_rdsPI); + s.writeU32(32, m_rdsPTY); + s.writeString(33, m_rdsPS); + s.writeString(34, m_rdsRadioText); + s.writeString(35, m_fileName); + + return s.final(); +} + +bool BFMModSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) + { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) + { + QByteArray bytetmp; + qint32 tmp; + uint32_t utmp; + + d.readS32(1, &tmp, 0); + m_inputFrequencyOffset = tmp; + d.readReal(2, &m_rfBandwidth, 256000.0); + m_rfBandwidth = boundRFBandwidth(m_rfBandwidth); + d.readReal(3, &m_afBandwidth, 15000.0); + m_afBandwidth = boundAFBandwidth(m_afBandwidth); + d.readReal(4, &m_fmDeviation, 75000.0); + m_fmDeviation = boundFMDeviation(m_fmDeviation); + d.readU32(5, &m_rgbColor); + d.readReal(6, &m_toneFrequency, 1000.0); + m_toneFrequency = boundToneFrequency(m_toneFrequency); + d.readReal(7, &m_volumeFactor, 1.0); + m_volumeFactor = boundVolumeFactor(m_volumeFactor); + d.readBlob(8, &bytetmp); + + if (m_cwKeyerGUI) { + m_cwKeyerGUI->deserialize(bytetmp); + } else { // standalone operation with presets + m_cwKeyerSettings.deserialize(bytetmp); + } + + if (m_channelMarker) + { + d.readBlob(9, &bytetmp); + m_channelMarker->deserialize(bytetmp); + } + + d.readString(10, &m_title, "Broadcast FM Modulator"); + d.readString(11, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName); + + d.readS32(12, &tmp, 0); + if ((tmp < 0) || (tmp > (int) BFMModInputAF::BFMModInputCWTone)) { + m_modAFInput = BFMModInputNone; + } else { + m_modAFInput = (BFMModInputAF) tmp; + } + + d.readBool(13, &m_useReverseAPI, false); + d.readString(14, &m_reverseAPIAddress, "127.0.0.1"); + d.readU32(15, &utmp, 0); + + if ((utmp > 1023) && (utmp < 65535)) { + m_reverseAPIPort = utmp; + } else { + m_reverseAPIPort = 8888; + } + + d.readU32(16, &utmp, 0); + m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp; + d.readU32(17, &utmp, 0); + m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp; + d.readS32(18, &m_streamIndex, 0); + d.readString(19, &m_feedbackAudioDeviceName, AudioDeviceManager::m_defaultDeviceName); + d.readReal(20, &m_feedbackVolumeFactor, 0.5); + m_feedbackVolumeFactor = boundFeedbackVolumeFactor(m_feedbackVolumeFactor); + d.readBool(21, &m_feedbackAudioEnable, false); + + if (m_rollupState) + { + d.readBlob(22, &bytetmp); + m_rollupState->deserialize(bytetmp); + } + + d.readS32(23, &m_workspaceIndex, 0); + d.readBlob(24, &m_geometryBytes); + d.readBool(25, &m_hidden, false); + d.readBool(26, &m_audioStereo, true); + d.readS32(27, &m_preEmphasis, 1); + m_preEmphasis = qBound(0, m_preEmphasis, 2); + d.readReal(28, &m_pilotLevel, 0.09f); + m_pilotLevel = qBound(0.0f, m_pilotLevel, 0.2f); + d.readBool(29, &m_rdsActive, true); + d.readReal(30, &m_rdsLevel, 0.03f); + m_rdsLevel = qBound(0.0f, m_rdsLevel, 0.1f); + d.readU32(31, &utmp, 0x1234); + m_rdsPI = quint16(utmp); + d.readU32(32, &utmp, 0); + m_rdsPTY = quint8(qMin(utmp, 31U)); + d.readString(33, &m_rdsPS, "SDRangel"); + m_rdsPS = m_rdsPS.left(8); + d.readString(34, &m_rdsRadioText, "SDRangel Broadcast FM"); + m_rdsRadioText = m_rdsRadioText.left(64); + d.readString(35, &m_fileName, ""); + + return true; + } + else + { + qDebug() << "BFMModSettings::deserialize: ERROR"; + resetToDefaults(); + return false; + } +} + +void BFMModSettings::applySettings(const QStringList& settingsKeys, const BFMModSettings& settings) +{ + if (settingsKeys.contains("inputFrequencyOffset")) { + m_inputFrequencyOffset = settings.m_inputFrequencyOffset; + } + if (settingsKeys.contains("rfBandwidth")) { + m_rfBandwidth = settings.m_rfBandwidth; + } + if (settingsKeys.contains("afBandwidth")) { + m_afBandwidth = settings.m_afBandwidth; + } + if (settingsKeys.contains("fmDeviation")) { + m_fmDeviation = settings.m_fmDeviation; + } + if (settingsKeys.contains("toneFrequency")) { + m_toneFrequency = settings.m_toneFrequency; + } + if (settingsKeys.contains("volumeFactor")) { + m_volumeFactor = settings.m_volumeFactor; + } + if (settingsKeys.contains("audioStereo")) { + m_audioStereo = settings.m_audioStereo; + } + if (settingsKeys.contains("preEmphasis")) { + m_preEmphasis = settings.m_preEmphasis; + } + if (settingsKeys.contains("pilotLevel")) { + m_pilotLevel = settings.m_pilotLevel; + } + if (settingsKeys.contains("rdsActive")) { + m_rdsActive = settings.m_rdsActive; + } + if (settingsKeys.contains("rdsLevel")) { + m_rdsLevel = settings.m_rdsLevel; + } + if (settingsKeys.contains("rdsPI")) { + m_rdsPI = settings.m_rdsPI; + } + if (settingsKeys.contains("rdsPTY")) { + m_rdsPTY = settings.m_rdsPTY; + } + if (settingsKeys.contains("rdsPS")) { + m_rdsPS = settings.m_rdsPS; + } + if (settingsKeys.contains("rdsRadioText")) { + m_rdsRadioText = settings.m_rdsRadioText; + } + if (settingsKeys.contains("fileName")) { + m_fileName = settings.m_fileName; + } + if (settingsKeys.contains("channelMute")) { + m_channelMute = settings.m_channelMute; + } + if (settingsKeys.contains("playLoop")) { + m_playLoop = settings.m_playLoop; + } + if (settingsKeys.contains("rgbColor")) { + m_rgbColor = settings.m_rgbColor; + } + if (settingsKeys.contains("title")) { + m_title = settings.m_title; + } + if (settingsKeys.contains("modAFInput")) { + m_modAFInput = settings.m_modAFInput; + } + if (settingsKeys.contains("audioDeviceName")) { + m_audioDeviceName = settings.m_audioDeviceName; + } + if (settingsKeys.contains("feedbackAudioDeviceName")) { + m_feedbackAudioDeviceName = settings.m_feedbackAudioDeviceName; + } + if (settingsKeys.contains("feedbackVolumeFactor")) { + m_feedbackVolumeFactor = settings.m_feedbackVolumeFactor; + } + if (settingsKeys.contains("feedbackAudioEnable")) { + m_feedbackAudioEnable = settings.m_feedbackAudioEnable; + } + if (settingsKeys.contains("streamIndex")) { + m_streamIndex = settings.m_streamIndex; + } + if (settingsKeys.contains("useReverseAPI")) { + m_useReverseAPI = settings.m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress")) { + m_reverseAPIAddress = settings.m_reverseAPIAddress; + } + if (settingsKeys.contains("reverseAPIPort")) { + m_reverseAPIPort = settings.m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex")) { + m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex; + } + if (settingsKeys.contains("reverseAPIChannelIndex")) { + m_reverseAPIChannelIndex = settings.m_reverseAPIChannelIndex; + } + if (settingsKeys.contains("workspaceIndex")) { + m_workspaceIndex = settings.m_workspaceIndex; + } + if (settingsKeys.contains("geometryBytes")) { + m_geometryBytes = settings.m_geometryBytes; + } + if (settingsKeys.contains("hidden")) { + m_hidden = settings.m_hidden; + } + if (settingsKeys.contains("cwKeyerSettings")) { + m_cwKeyerSettings = settings.m_cwKeyerSettings; + } +} + +QString BFMModSettings::getDebugString(const QStringList& settingsKeys, bool force) const +{ + std::ostringstream ostr; + + if (settingsKeys.contains("inputFrequencyOffset") || force) { + ostr << " m_inputFrequencyOffset: " << m_inputFrequencyOffset; + } + if (settingsKeys.contains("rfBandwidth") || force) { + ostr << " m_rfBandwidth: " << m_rfBandwidth; + } + if (settingsKeys.contains("afBandwidth") || force) { + ostr << " m_afBandwidth: " << m_afBandwidth; + } + if (settingsKeys.contains("fmDeviation") || force) { + ostr << " m_fmDeviation: " << m_fmDeviation; + } + if (settingsKeys.contains("toneFrequency") || force) { + ostr << " m_toneFrequency: " << m_toneFrequency; + } + if (settingsKeys.contains("volumeFactor") || force) { + ostr << " m_volumeFactor: " << m_volumeFactor; + } + if (settingsKeys.contains("audioStereo") || force) { + ostr << " m_audioStereo: " << m_audioStereo; + } + if (settingsKeys.contains("preEmphasis") || force) { + ostr << " m_preEmphasis: " << m_preEmphasis; + } + if (settingsKeys.contains("rdsActive") || force) { + ostr << " m_rdsActive: " << m_rdsActive; + } + if (settingsKeys.contains("pilotLevel") || force) { + ostr << " m_pilotLevel: " << m_pilotLevel; + } + if (settingsKeys.contains("rdsLevel") || force) { + ostr << " m_rdsLevel: " << m_rdsLevel; + } + if (settingsKeys.contains("rdsPI") || force) { + ostr << " m_rdsPI: " << m_rdsPI; + } + if (settingsKeys.contains("rdsPTY") || force) { + ostr << " m_rdsPTY: " << (int) m_rdsPTY; + } + if (settingsKeys.contains("rdsPS") || force) { + ostr << " m_rdsPS: " << m_rdsPS.toStdString(); + } + if (settingsKeys.contains("rdsRadioText") || force) { + ostr << " m_rdsRadioText: " << m_rdsRadioText.toStdString(); + } + if (settingsKeys.contains("fileName") || force) { + ostr << " m_fileName: " << m_fileName.toStdString(); + } + if (settingsKeys.contains("channelMute") || force) { + ostr << " m_channelMute: " << m_channelMute; + } + if (settingsKeys.contains("playLoop") || force) { + ostr << " m_playLoop: " << m_playLoop; + } + if (settingsKeys.contains("rgbColor") || force) { + ostr << " m_rgbColor: " << m_rgbColor; + } + if (settingsKeys.contains("title") || force) { + ostr << " m_title: " << m_title.toStdString(); + } + if (settingsKeys.contains("modAFInput") || force) { + ostr << " m_modAFInput: " << (int)m_modAFInput; + } + if (settingsKeys.contains("audioDeviceName") || force) { + ostr << " m_audioDeviceName: " << m_audioDeviceName.toStdString(); + } + if (settingsKeys.contains("feedbackAudioDeviceName") || force) { + ostr << " m_feedbackAudioDeviceName: " << m_feedbackAudioDeviceName.toStdString(); + } + if (settingsKeys.contains("feedbackVolumeFactor") || force) { + ostr << " m_feedbackVolumeFactor: " << m_feedbackVolumeFactor; + } + if (settingsKeys.contains("feedbackAudioEnable") || force) { + ostr << " m_feedbackAudioEnable: " << m_feedbackAudioEnable; + } + if (settingsKeys.contains("streamIndex") || force) { + ostr << " m_streamIndex: " << m_streamIndex; + } + if (settingsKeys.contains("useReverseAPI") || force) { + ostr << " m_useReverseAPI: " << m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress") || force) { + ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString(); + } + if (settingsKeys.contains("reverseAPIPort") || force) { + ostr << " m_reverseAPIPort: " << m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex") || force) { + ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex; + } + if (settingsKeys.contains("reverseAPIChannelIndex") || force) { + ostr << " m_reverseAPIChannelIndex: " << m_reverseAPIChannelIndex; + } + if (settingsKeys.contains("workspaceIndex") || force) { + ostr << " m_workspaceIndex: " << m_workspaceIndex; + } + if (settingsKeys.contains("hidden") || force) { + ostr << " m_hidden: " << m_hidden; + } + + return QString(ostr.str().c_str()); +} + +int BFMModSettings::getRFBW(int index) +{ + if (index < 0) { + return m_rfBW[0]; + } else if (index < m_nbRfBW) { + return m_rfBW[index]; + } else { + return m_rfBW[m_nbRfBW-1]; + } +} + +int BFMModSettings::getRFBWIndex(int rfbw) +{ + for (int i = 0; i < m_nbRfBW; i++) + { + if (rfbw <= m_rfBW[i]) + { + return i; + } + } + + return m_nbRfBW-1; +} + +Real BFMModSettings::boundRFBandwidth(Real rfBandwidth) +{ + // Round up to one of the bandwidths the GUI offers + return getRFBW(getRFBWIndex(rfBandwidth)); +} + +Real BFMModSettings::boundAFBandwidth(Real afBandwidth) +{ + return qBound(m_minAFBandwidth, afBandwidth, m_maxAFBandwidth); +} + +// The remaining limits match the ranges of the GUI controls + +float BFMModSettings::boundFMDeviation(float fmDeviation) +{ + return qBound(0.0f, fmDeviation, 100000.0f); +} + +float BFMModSettings::boundToneFrequency(float toneFrequency) +{ + return qBound(100.0f, toneFrequency, 10000.0f); +} + +float BFMModSettings::boundVolumeFactor(float volumeFactor) +{ + return qBound(0.0f, volumeFactor, 2.0f); +} + +float BFMModSettings::boundFeedbackVolumeFactor(float feedbackVolumeFactor) +{ + return qBound(0.0f, feedbackVolumeFactor, 1.0f); +} diff --git a/plugins/channeltx/modbfm/bfmmodsettings.h b/plugins/channeltx/modbfm/bfmmodsettings.h new file mode 100644 index 000000000..ae800f135 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodsettings.h @@ -0,0 +1,111 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODBFM_BFMMODSETTINGS_H_ +#define PLUGINS_CHANNELTX_MODBFM_BFMMODSETTINGS_H_ + +#include + +#include "dsp/cwkeyersettings.h" +#include "dsp/dsptypes.h" + +class Serializable; + +struct BFMModSettings +{ + typedef enum + { + BFMModInputNone, + BFMModInputTone, + BFMModInputFile, + BFMModInputAudio, + BFMModInputCWTone + } BFMModInputAF; + + static const int m_nbRfBW; + static const int m_rfBW[]; + static const Real m_minAFBandwidth; + static const Real m_maxAFBandwidth; //!< Keeps audio clear of the pilot and, in stereo, the RDS band + + qint64 m_inputFrequencyOffset; + Real m_rfBandwidth; + Real m_afBandwidth; + float m_fmDeviation; //!< Peak frequency deviation in Hz + float m_toneFrequency; + float m_volumeFactor; + bool m_audioStereo; + int m_preEmphasis; //!< 0: off, 1: 50 us, 2: 75 us + float m_pilotLevel; + bool m_rdsActive; + float m_rdsLevel; + quint16 m_rdsPI; + quint8 m_rdsPTY; + QString m_rdsPS; + QString m_rdsRadioText; + QString m_fileName; //!< WAV or raw audio file played when the file input is selected + bool m_channelMute; + bool m_playLoop; + quint32 m_rgbColor; + QString m_title; + BFMModInputAF m_modAFInput; + QString m_audioDeviceName; //!< This is the audio device you get the audio samples from + QString m_feedbackAudioDeviceName; //!< This is the audio device you send the audio samples to for audio feedback + float m_feedbackVolumeFactor; + bool m_feedbackAudioEnable; + int m_streamIndex; + bool m_useReverseAPI; + QString m_reverseAPIAddress; + uint16_t m_reverseAPIPort; + uint16_t m_reverseAPIDeviceIndex; + uint16_t m_reverseAPIChannelIndex; + int m_workspaceIndex; + QByteArray m_geometryBytes; + bool m_hidden; + + Serializable *m_channelMarker; + Serializable *m_cwKeyerGUI; + + CWKeyerSettings m_cwKeyerSettings; //!< For standalone deserialize operation (without m_cwKeyerGUI) + Serializable *m_rollupState; + + BFMModSettings(); + void resetToDefaults(); + void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } + void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; } + void setCWKeyerGUI(Serializable *cwKeyerGUI) { m_cwKeyerGUI = cwKeyerGUI; } + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + void applySettings(const QStringList& settingsKeys, const BFMModSettings& settings); + QString getDebugString(const QStringList& settingsKeys, bool force=false) const; + const CWKeyerSettings& getCWKeyerSettings() const { return m_cwKeyerSettings; } + void setCWKeyerSettings(const CWKeyerSettings& cwKeyerSettings) { m_cwKeyerSettings = cwKeyerSettings; } + + static int getRFBW(int index); + static int getRFBWIndex(int rfbw); + static Real boundRFBandwidth(Real rfBandwidth); + static Real boundAFBandwidth(Real afBandwidth); + static float boundFMDeviation(float fmDeviation); + static float boundToneFrequency(float toneFrequency); + static float boundVolumeFactor(float volumeFactor); + static float boundFeedbackVolumeFactor(float feedbackVolumeFactor); +}; + + + +#endif /* PLUGINS_CHANNELTX_MODBFM_BFMMODSETTINGS_H_ */ diff --git a/plugins/channeltx/modbfm/bfmmodsource.cpp b/plugins/channeltx/modbfm/bfmmodsource.cpp new file mode 100644 index 000000000..37051d63d --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodsource.cpp @@ -0,0 +1,628 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include + +#include "dsp/datafifo.h" +#include "audio/audiofilereader.h" +#include "util/messagequeue.h" +#include "maincore.h" + +#include "bfmmodsource.h" + +const int BFMModSource::m_rfFilterFFTLength = 1024; +const int BFMModSource::m_levelNbSamples = 480; // every 10ms + +BFMModSource::BFMModSource() : + m_channelSampleRate(384000), + m_channelFrequencyOffset(0), + m_channel(nullptr), + m_modPhasor(0.0f), + m_mpxPhase(0.0), + m_preemphasisLeft(48000), + m_preemphasisRight(48000), + m_audioSampleRate(48000), + m_audioFifo(12000), + m_feedbackAudioSampleRate(48000), + m_feedbackAudioFifo(48000), + m_levelCalcCount(0), + m_rmsLevel(0.0), + m_peakLevelOut(0.0), + m_peakLevel(0.0f), + m_levelSum(0.0f), + m_audioFileReader(nullptr), + m_limiterGain(1.0f), + m_limiterRelease(0.0f) +{ + m_audioFifo.setLabel("BFMModSource.m_audioFifo"); + m_feedbackAudioFifo.setLabel("BFMModSource.m_feedbackAudioFifo"); + m_rfFilter = new fftfilt(-62500.0 / 384000.0, 62500.0 / 384000.0, m_rfFilterFFTLength); + m_rfFilterBuffer = new Complex[m_rfFilterFFTLength]; + std::fill(m_rfFilterBuffer, m_rfFilterBuffer+m_rfFilterFFTLength, Complex{0,0}); + m_rfFilterBufferIndex = 0; + m_audioBuffer.resize(24000); + m_audioBufferFill = 0; + m_audioReadBuffer.resize(24000); + m_audioReadBufferFill = 0; + m_magsq = 0.0; + m_feedbackAudioBuffer.resize(1<<14); + m_feedbackAudioBufferFill = 0; + m_demodBuffer.resize(1<<12); + m_demodBufferFill = 0; + + applySettings(QStringList(), m_settings, true); + applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); + applyAudioSampleRate(m_audioSampleRate); +} + +BFMModSource::~BFMModSource() +{ + delete m_rfFilter; + delete[] m_rfFilterBuffer; +} + +void BFMModSource::pull(SampleVector::iterator begin, unsigned int nbSamples) +{ + std::for_each( + begin, + begin + nbSamples, + [this](Sample& s) { + pullOne(s); + } + ); +} + +void BFMModSource::pullOne(Sample& sample) +{ + if (m_settings.m_channelMute) + { + sample.m_real = 0.0f; + sample.m_imag = 0.0f; + return; + } + + Complex ci, ri; + fftfilt::cmplx *rf; + int rf_out; + Real t; + + if (m_interpolatorDistance > 1.0f) // decimate + { + modulateAudio(); + + while (!m_interpolator.decimate(&m_interpolatorDistanceRemain, m_modSample, &ri)) { + modulateAudio(); + } + } + else // interpolate + { + if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, m_modSample, &ri)) { + modulateAudio(); + } + } + + // The audio was limited before interpolation, but the interpolation filter + // can overshoot. The program part of the multiplex is a weighted average of + // left and right, so limiting both to 1 keeps the multiplex within full scale. + const Complex limited = m_lookaheadLimiter.process(ri); + const Real left = limited.real(); + const Real right = limited.imag(); + const Real mono = 0.5f * (left + right); + const bool pilotActive = m_settings.m_audioStereo || m_settings.m_rdsActive; + const Real pilotLevel = pilotActive ? m_settings.m_pilotLevel : 0.0f; + const Real rdsLevel = m_settings.m_rdsActive ? m_settings.m_rdsLevel : 0.0f; + const Real programLevel = std::max(0.0f, 1.0f - pilotLevel - rdsLevel); + t = programLevel * mono; + + if (pilotActive) + { + // The 38 and 57 kHz subcarriers are derived from the pilot's sin/cos + // with trigonometric identities, so only one sin/cos pair is needed. + const Real pilotSin = std::sin(m_mpxPhase); + const Real pilotCos = std::cos(m_mpxPhase); + + if (m_settings.m_audioStereo) + { + const Real difference = 0.5f * (left - right); + // sin(2x): the 38 kHz subcarrier crosses zero positively at every pilot zero. + t += programLevel * difference * 2.0f * pilotSin * pilotCos; + } + + t += pilotLevel * pilotSin; + + if (m_settings.m_rdsActive) + { + // cos(3x): the 57 kHz subcarrier is in quadrature with the third pilot harmonic. + const Real cos3 = pilotCos * (4.0f * pilotCos * pilotCos - 3.0f); + t += rdsLevel * m_rdsEncoder.sample() * cos3; + } + } + + m_mpxPhase += (2.0 * M_PI * 19000.0) / m_channelSampleRate; + if (m_mpxPhase >= 2.0 * M_PI) { + m_mpxPhase -= 2.0 * M_PI; + } + m_interpolatorDistanceRemain += m_interpolatorDistance; + + m_modPhasor += (m_settings.m_fmDeviation / (float) m_channelSampleRate) * t * M_PI * 2.0f; + + // limit phasor range to ]-pi,pi] + if (m_modPhasor > M_PI) { + m_modPhasor -= (2.0f * M_PI); + } else if (m_modPhasor <= -M_PI) { + m_modPhasor += (2.0f * M_PI); + } + + ci.real(cos(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF); // -1 dB + ci.imag(sin(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF); + + // RF filtering + rf_out = m_rfFilter->runFilt(ci, &rf); + + if (rf_out > 0) + { + memcpy((void *) m_rfFilterBuffer, (const void *) rf, rf_out*sizeof(Complex)); + m_rfFilterBufferIndex = 0; + } + + ci = m_rfFilterBuffer[m_rfFilterBufferIndex] * m_carrierNco.nextIQ(); // shift to carrier frequency + m_rfFilterBufferIndex++; + + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_TX_SCALED*SDR_TX_SCALED); + m_movingAverage(magsq); + m_magsq = m_movingAverage.asDouble(); + + sample.m_real = (FixReal) ci.real(); + sample.m_imag = (FixReal) ci.imag(); + + m_demodBuffer[m_demodBufferFill] = std::clamp(t, -1.0f, 1.0f) * std::numeric_limits::max(); + ++m_demodBufferFill; + + if (m_demodBufferFill >= m_demodBuffer.size()) + { + QList dataPipes; + MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes); + + if (dataPipes.size() > 0) + { + QList::iterator it = dataPipes.begin(); + + for (; it != dataPipes.end(); ++it) + { + DataFifo *fifo = qobject_cast((*it)->m_element); + + if (fifo) { + fifo->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16), DataFifo::DataTypeI16); + } + } + } + + m_demodBufferFill = 0; + } +} + +void BFMModSource::modulateAudio() +{ + Real left; + Real right; + pullAF(left, right); + + if (m_settings.m_preEmphasis != 0) + { + left = m_preemphasisLeft.filter(left); + right = m_preemphasisRight.filter(right); + } + + applyLimiter(left, right); + + calculateLevel(0.5f * (left + right)); + m_modSample.real(left); + m_modSample.imag(right); + + if (m_settings.m_feedbackAudioEnable) { + pushFeedback(Complex(left, right) * m_settings.m_feedbackVolumeFactor * 16384.0f); + } +} + +void BFMModSource::prefetch(unsigned int nbSamples) +{ + if (m_settings.m_modAFInput != BFMModSettings::BFMModInputAudio) { + return; + } + + // The interpolator consumes a fractional number of audio samples per block, so + // request one more than needed. pullAudio keeps samples that are not consumed. + unsigned int nbSamplesAudio = (unsigned int) std::ceil(nbSamples * ((double) m_audioSampleRate / m_channelSampleRate)) + 1; + pullAudio(nbSamplesAudio); +} + +void BFMModSource::pullAudio(unsigned int nbSamplesAudio) +{ + QMutexLocker mlock(&m_mutex); + + // Keep samples prefetched for the previous block that it did not consume, + // then top up to the number requested with as much audio as is available. + // If not enough is available, pullAF outputs silence after the last sample. + const unsigned int unconsumed = m_audioBufferFill < m_audioBuffer.size() ? m_audioBuffer.size() - m_audioBufferFill : 0; + std::copy(m_audioBuffer.begin() + m_audioBufferFill, m_audioBuffer.end(), m_audioBuffer.begin()); + const unsigned int wanted = nbSamplesAudio > unconsumed ? nbSamplesAudio - unconsumed : 0; + + // Audio queued beyond this block is latency. It builds up while the transmitter + // is stopped, or slowly when the audio device's clock is faster than the SDR's. + // When it exceeds 200 ms, skip the oldest audio, keeping 50 ms to absorb jitter. + const unsigned int backlog = m_audioReadBufferFill > wanted ? m_audioReadBufferFill - wanted : 0; + if (backlog > (unsigned int) m_audioSampleRate / 5) { + discardAudio(backlog - m_audioSampleRate / 20); + } + + const unsigned int available = std::min(wanted, m_audioReadBufferFill); + m_audioBuffer.resize(unconsumed + available); + std::copy_n(m_audioReadBuffer.begin(), available, m_audioBuffer.begin() + unconsumed); + m_audioBufferFill = 0; + + discardAudio(available); +} + +void BFMModSource::discardAudio(unsigned int nbSamples) +{ + // Remove the oldest samples from the audio read buffer + nbSamples = std::min(nbSamples, m_audioReadBufferFill); + std::copy(m_audioReadBuffer.begin() + nbSamples, + m_audioReadBuffer.begin() + m_audioReadBufferFill, m_audioReadBuffer.begin()); + m_audioReadBufferFill -= nbSamples; +} + +void BFMModSource::pullAF(Real& left, Real& right) +{ + switch (m_settings.m_modAFInput) + { + case BFMModSettings::BFMModInputTone: + left = m_toneNco.next() * m_settings.m_volumeFactor; + right = left; + break; + case BFMModSettings::BFMModInputFile: + if (m_audioFileReader) + { + if (!m_audioFileReader->readFrame(left, right)) + { + if (!m_settings.m_playLoop || + !m_audioFileReader->rewind() || + !m_audioFileReader->readFrame(left, right)) + { + left = 0.0f; + right = 0.0f; + } + } + + left *= m_settings.m_volumeFactor; + right *= m_settings.m_volumeFactor; + } + else + { + left = 0.0f; + right = 0.0f; + } + break; + case BFMModSettings::BFMModInputAudio: + { + if (m_audioBufferFill < m_audioBuffer.size()) + { + left = (m_audioBuffer[m_audioBufferFill].l / 32768.0f) * m_settings.m_volumeFactor; + right = (m_audioBuffer[m_audioBufferFill].r / 32768.0f) * m_settings.m_volumeFactor; + m_audioBufferFill++; + } + else + { + left = 0.0f; + right = 0.0f; + } + } + break; + case BFMModSettings::BFMModInputCWTone: + Real fadeFactor; + + if (m_cwKeyer.getSample()) + { + m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor); + left = m_cwToneNco.next() * m_settings.m_volumeFactor * fadeFactor * 0.99f; + } + else + { + if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor)) + { + left = m_cwToneNco.next() * m_settings.m_volumeFactor * fadeFactor * 0.99f; + } + else + { + left = 0.0f; + m_cwToneNco.setPhase(0); + } + } + right = left; + break; + case BFMModSettings::BFMModInputNone: + default: + left = 0.0f; + right = 0.0f; + break; + } +} + +void BFMModSource::pushFeedback(Complex c) +{ + Complex ci; + + if (m_feedbackInterpolatorDistance < 1.0f) // interpolate + { + while (!m_feedbackInterpolator.interpolate(&m_feedbackInterpolatorDistanceRemain, c, &ci)) + { + processOneSample(ci); + m_feedbackInterpolatorDistanceRemain += m_feedbackInterpolatorDistance; + } + } + else // decimate + { + if (m_feedbackInterpolator.decimate(&m_feedbackInterpolatorDistanceRemain, c, &ci)) + { + processOneSample(ci); + m_feedbackInterpolatorDistanceRemain += m_feedbackInterpolatorDistance; + } + } +} + +void BFMModSource::processOneSample(Complex& ci) +{ + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = ci.real(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = ci.imag(); + ++m_feedbackAudioBufferFill; + + if (m_feedbackAudioBufferFill >= m_feedbackAudioBuffer.size()) + { + unsigned int res = m_feedbackAudioFifo.write((const quint8*)&m_feedbackAudioBuffer[0], m_feedbackAudioBufferFill); + + if (res != m_feedbackAudioBufferFill) + { + qDebug("BFMModSource::processOneSample: %u/%u audio samples written m_feedbackInterpolatorDistance: %f", + res, m_feedbackAudioBufferFill, m_feedbackInterpolatorDistance); + m_feedbackAudioFifo.clear(); + } + + m_feedbackAudioBufferFill = 0; + } +} + +void BFMModSource::applyLimiter(Real& left, Real& right) +{ + // Stereo-linked peak limiter with instant attack and slow release. Pre-emphasis + // can boost high frequencies well above full scale, and reducing the gain + // briefly is far less audible than hard clipping. + const Real peak = std::max(std::fabs(left), std::fabs(right)); + m_limiterGain += (1.0f - m_limiterGain) * m_limiterRelease; + + if (peak * m_limiterGain > 1.0f) { + m_limiterGain = 1.0f / peak; + } + + left *= m_limiterGain; + right *= m_limiterGain; +} + +void BFMModSource::calculateLevel(const Real& sample) +{ + m_peakLevel = std::max(m_peakLevel, std::fabs(sample)); + m_levelSum += sample * sample; + m_levelCalcCount++; + + if (m_levelCalcCount >= (quint32) m_levelNbSamples) + { + m_rmsLevel = sqrt(m_levelSum / m_levelNbSamples); + m_peakLevelOut = m_peakLevel; + m_peakLevel = 0.0f; + m_levelSum = 0.0f; + m_levelCalcCount = 0; + } +} + +Real BFMModSource::audioCutoff(Real afBandwidth, int audioSampleRate) +{ + // Audio must stay clear of the 19 kHz pilot and, once modulated onto the + // 38 kHz subcarrier, of the RDS band starting at 54.6 kHz. + return std::min({afBandwidth, BFMModSettings::m_maxAFBandwidth, audioSampleRate * 0.45f}); +} + +void BFMModSource::createAudioInterpolator(Real afBandwidth) +{ + m_interpolatorDistanceRemain = 0; + m_interpolatorDistance = (Real) m_audioSampleRate / (Real) m_channelSampleRate; + m_interpolator.create(48, m_audioSampleRate, audioCutoff(afBandwidth, m_audioSampleRate), 3.0); +} + +void BFMModSource::createRFFilter(Real rfBandwidth, int channelSampleRate) +{ + const Real cut = std::min(0.5f, (rfBandwidth / 2.0f) / channelSampleRate); + m_rfFilter->create_filter(-cut, cut); +} + +void BFMModSource::applyAudioSampleRate(int sampleRate) +{ + if (sampleRate < 0) + { + qWarning("BFMModSource::applyAudioSampleRate: %d", sampleRate); + return; + } + + qDebug("BFMModSource::applyAudioSampleRate: %d", sampleRate); + + m_audioSampleRate = sampleRate; + + { + // Hold at least 0.5 s, comfortably more than the latency allowed by pullAudio + QMutexLocker mlock(&m_mutex); + m_audioReadBuffer.resize(std::max(24000, sampleRate / 2)); + m_audioReadBufferFill = std::min(m_audioReadBufferFill, m_audioReadBuffer.size()); + } + + createAudioInterpolator(m_settings.m_afBandwidth); + m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); + m_cwToneNco.setFreq(m_settings.m_toneFrequency, sampleRate); + m_cwKeyer.setSampleRate(sampleRate); + m_cwKeyer.reset(); + const Real tau = m_settings.m_preEmphasis == 2 ? FMPREEMPHASIS_TAU_US : FMPREEMPHASIS_TAU_EU; + m_preemphasisLeft.configure(sampleRate, tau, audioCutoff(m_settings.m_afBandwidth, sampleRate)); + m_preemphasisRight.configure(sampleRate, tau, audioCutoff(m_settings.m_afBandwidth, sampleRate)); + m_limiterRelease = 1.0f - std::exp(-1.0f / (0.2f * sampleRate)); // 200 ms release + applyFeedbackAudioSampleRate(m_feedbackAudioSampleRate); +} + +void BFMModSource::applyFeedbackAudioSampleRate(int sampleRate) +{ + if (sampleRate < 0) + { + qWarning("BFMModSource::applyFeedbackAudioSampleRate: invalid sample rate %d", sampleRate); + return; + } + + qDebug("BFMModSource::applyFeedbackAudioSampleRate: %d", sampleRate); + + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. + m_feedbackInterpolatorDistanceRemain = 0; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; + Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); + + m_feedbackAudioSampleRate = sampleRate; +} + +void BFMModSource::applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force) +{ + if ((settingsKeys.contains("preEmphasis") || settingsKeys.contains("afBandwidth")) || force) + { + const Real tau = settings.m_preEmphasis == 2 ? FMPREEMPHASIS_TAU_US : FMPREEMPHASIS_TAU_EU; + const Real highFreq = audioCutoff(settings.m_afBandwidth, m_audioSampleRate); + m_preemphasisLeft.configure(m_audioSampleRate, tau, highFreq); + m_preemphasisRight.configure(m_audioSampleRate, tau, highFreq); + } + + if (settingsKeys.contains("rdsPI") || settingsKeys.contains("rdsPTY") + || settingsKeys.contains("rdsPS") || settingsKeys.contains("rdsRadioText") || force) + { + m_rdsEncoder.setData(settings.m_rdsPI, settings.m_rdsPTY, settings.m_rdsPS, settings.m_rdsRadioText); + } + + if (settingsKeys.contains("audioStereo") || force) { + m_rdsEncoder.setStereo(settings.m_audioStereo); + } + + if ((settingsKeys.contains("afBandwidth") && (settings.m_afBandwidth != m_settings.m_afBandwidth)) || force) { + createAudioInterpolator(settings.m_afBandwidth); + } + + if ((settingsKeys.contains("rfBandwidth") && (settings.m_rfBandwidth != m_settings.m_rfBandwidth)) || force) { + createRFFilter(settings.m_rfBandwidth, m_channelSampleRate); + } + + if ((settingsKeys.contains("toneFrequency") && (settings.m_toneFrequency != m_settings.m_toneFrequency)) || force) + { + m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate); + m_cwToneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate); + } + + if ((settingsKeys.contains("modAFInput") && (settings.m_modAFInput != m_settings.m_modAFInput)) + || (settingsKeys.contains("audioDeviceName") && settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force) + { + QMutexLocker mlock(&m_mutex); + m_audioFifo.clear(); + m_audioReadBufferFill = 0; + m_audioBuffer.clear(); + m_audioBufferFill = 0; + if (settings.m_modAFInput == BFMModSettings::BFMModInputAudio) { + connect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio()), Qt::UniqueConnection); + } else { + disconnect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio())); + } + } + + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } +} + +void BFMModSource::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force) +{ + qDebug() << "BFMModSource::applyChannelSettings:" + << " channelSampleRate: " << channelSampleRate + << " channelFrequencyOffset: " << channelFrequencyOffset; + + if ((channelFrequencyOffset != m_channelFrequencyOffset) + || (channelSampleRate != m_channelSampleRate) || force) { + m_carrierNco.setFreq(channelFrequencyOffset, channelSampleRate); + } + + const bool sampleRateChanged = (channelSampleRate != m_channelSampleRate) || force; + m_channelSampleRate = channelSampleRate; + m_channelFrequencyOffset = channelFrequencyOffset; + + if (sampleRateChanged) + { + createAudioInterpolator(m_settings.m_afBandwidth); + createRFFilter(m_settings.m_rfBandwidth, channelSampleRate); + m_toneNco.setFreq(m_settings.m_toneFrequency, m_audioSampleRate); + // 1 ms look-ahead keeps gain changes, and so distortion, below about 1 kHz + m_lookaheadLimiter.configure(std::max(1, channelSampleRate / 1000), channelSampleRate / 5); + m_mpxPhase = 0.0; + m_rdsEncoder.setSampleRate(channelSampleRate); + + m_demodBufferFill = 0; + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); + for (const auto& pipe : pipes) + { + MessageQueue* messageQueue = qobject_cast(pipe->m_element); + messageQueue->push(MainCore::MsgChannelDemodReport::create(m_channel, m_channelSampleRate)); + } + } +} + +void BFMModSource::handleAudio() +{ + QMutexLocker mlock(&m_mutex); + while (!m_audioFifo.isEmpty()) + { + // When the buffer is full, such as while the transmitter is stopped, + // discard the oldest audio, so that the newest is sent when it starts + const unsigned int chunk = std::min(m_audioFifo.fill(), 4096U); + if (m_audioReadBufferFill + chunk > m_audioReadBuffer.size()) { + discardAudio(m_audioReadBufferFill + chunk - m_audioReadBuffer.size()); + } + const unsigned int nbRead = m_audioFifo.read( + reinterpret_cast(m_audioReadBuffer.data() + m_audioReadBufferFill), + chunk); + if (nbRead == 0) { + break; + } + m_audioReadBufferFill += nbRead; + } +} diff --git a/plugins/channeltx/modbfm/bfmmodsource.h b/plugins/channeltx/modbfm/bfmmodsource.h new file mode 100644 index 000000000..e516fd996 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodsource.h @@ -0,0 +1,153 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_BFMMODSOURCE_H +#define INCLUDE_BFMMODSOURCE_H + +#include +#include +#include + +#include "dsp/channelsamplesource.h" +#include "dsp/nco.h" +#include "dsp/interpolator.h" +#include "dsp/fftfilt.h" +#include "util/movingaverage.h" +#include "dsp/cwkeyer.h" +#include "dsp/fmpreemphasis.h" +#include "audio/audiofifo.h" + +#include "bfmmodsettings.h" +#include "rdsencoder.h" +#include "lookaheadlimiter.h" + +class ChannelAPI; +class AudioFileReader; + +class BFMModSource : public QObject, public ChannelSampleSource +{ + Q_OBJECT +public: + BFMModSource(); + virtual ~BFMModSource(); + + virtual void pull(SampleVector::iterator begin, unsigned int nbSamples); + virtual void pullOne(Sample& sample); + virtual void prefetch(unsigned int nbSamples); + + void setInputFileReader(AudioFileReader *audioFileReader) { m_audioFileReader = audioFileReader; } + AudioFifo *getAudioFifo() { return &m_audioFifo; } + AudioFifo *getFeedbackAudioFifo() { return &m_feedbackAudioFifo; } + void applyAudioSampleRate(int sampleRate); + void applyFeedbackAudioSampleRate(int sampleRate); + int getAudioSampleRate() const { return m_audioSampleRate; } + int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; } + void setChannel(ChannelAPI *channel) { m_channel = channel; } + CWKeyer& getCWKeyer() { return m_cwKeyer; } + double getMagSq() const { return m_magsq; } + void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const + { + rmsLevel = m_rmsLevel; + peakLevel = m_peakLevelOut; + numSamples = m_levelNbSamples; + } + void applySettings(const QStringList& settingsKeys, const BFMModSettings& settings, bool force = false); + void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); + +private: + int m_channelSampleRate; + int m_channelFrequencyOffset; + BFMModSettings m_settings; + ChannelAPI *m_channel; + + NCO m_carrierNco; + NCO m_toneNco; + NCO m_cwToneNco; + float m_modPhasor; //!< baseband modulator phasor + double m_mpxPhase; //!< phase of the common 19 kHz multiplex reference + Complex m_modSample; + FMPreemphasis m_preemphasisLeft; + FMPreemphasis m_preemphasisRight; + RDSEncoder m_rdsEncoder; + LookaheadLimiter m_lookaheadLimiter; //!< Limits overshoot from audio interpolation + + Interpolator m_interpolator; + Real m_interpolatorDistance; + Real m_interpolatorDistanceRemain; + + Interpolator m_feedbackInterpolator; + Real m_feedbackInterpolatorDistance; + Real m_feedbackInterpolatorDistanceRemain; + + QVector m_demodBuffer; + int m_demodBufferFill; + + fftfilt* m_rfFilter; + static const int m_rfFilterFFTLength; + fftfilt::cmplx *m_rfFilterBuffer; + int m_rfFilterBufferIndex; + + double m_magsq; + MovingAverageUtil m_movingAverage; + + int m_audioSampleRate; + AudioVector m_audioBuffer; + unsigned int m_audioBufferFill; + AudioVector m_audioReadBuffer; + unsigned int m_audioReadBufferFill; + AudioFifo m_audioFifo; + + int m_feedbackAudioSampleRate; + AudioVector m_feedbackAudioBuffer; + uint m_feedbackAudioBufferFill; + AudioFifo m_feedbackAudioFifo; + + quint32 m_levelCalcCount; + qreal m_rmsLevel; + qreal m_peakLevelOut; + Real m_peakLevel; + Real m_levelSum; + + AudioFileReader *m_audioFileReader; + CWKeyer m_cwKeyer; + + Real m_limiterGain; //!< Stereo-linked peak limiter gain + Real m_limiterRelease; //!< Per audio sample release coefficient of the limiter + + QRecursiveMutex m_mutex; + + static const int m_levelNbSamples; + + void processOneSample(Complex& ci); + void pullAF(Real& left, Real& right); + void pullAudio(unsigned int nbSamples); + void discardAudio(unsigned int nbSamples); + void pushFeedback(Complex sample); + void calculateLevel(const Real& sample); + void modulateAudio(); + void applyLimiter(Real& left, Real& right); + void createAudioInterpolator(Real afBandwidth); + void createRFFilter(Real rfBandwidth, int channelSampleRate); + static Real audioCutoff(Real afBandwidth, int audioSampleRate); + +private slots: + void handleAudio(); +}; + +#endif // INCLUDE_BFMMODSOURCE_H diff --git a/plugins/channeltx/modbfm/bfmmodwebapiadapter.cpp b/plugins/channeltx/modbfm/bfmmodwebapiadapter.cpp new file mode 100644 index 000000000..a5041da2e --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodwebapiadapter.cpp @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "dsp/cwkeyer.h" +#include "bfmmod.h" +#include "bfmmodwebapiadapter.h" + +BFMModWebAPIAdapter::BFMModWebAPIAdapter() +{} + +BFMModWebAPIAdapter::~BFMModWebAPIAdapter() +{} + +bool BFMModWebAPIAdapter::deserialize(const QByteArray& data) +{ + return m_settings.deserialize(data); +} + +int BFMModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setBfmModSettings(new SWGSDRangel::SWGBFMModSettings()); + response.getBfmModSettings()->init(); + BFMMod::webapiFormatChannelSettings(response, m_settings); + + const CWKeyerSettings& cwKeyerSettings = m_settings.getCWKeyerSettings(); + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getBfmModSettings()->getCwKeyer(); + apiCwKeyerSettings->init(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + + return 200; +} + +int BFMModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) force; // no action + (void) errorMessage; + BFMMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + + if (channelSettingsKeys.contains("cwKeyer")) + { + CWKeyerSettings newCWKeyerSettings; + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getBfmModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, newCWKeyerSettings, apiCwKeyerSettings); + m_settings.setCWKeyerSettings(newCWKeyerSettings); + } + + BFMMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} + diff --git a/plugins/channeltx/modbfm/bfmmodwebapiadapter.h b/plugins/channeltx/modbfm/bfmmodwebapiadapter.h new file mode 100644 index 000000000..b34391b95 --- /dev/null +++ b/plugins/channeltx/modbfm/bfmmodwebapiadapter.h @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_BFMMOD_WEBAPIADAPTER_H +#define INCLUDE_BFMMOD_WEBAPIADAPTER_H + +#include "channel/channelwebapiadapter.h" +#include "bfmmodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class BFMModWebAPIAdapter : public ChannelWebAPIAdapter { +public: + BFMModWebAPIAdapter(); + virtual ~BFMModWebAPIAdapter(); + + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data); + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + BFMModSettings m_settings; +}; + +#endif // INCLUDE_BFMMOD_WEBAPIADAPTER_H diff --git a/plugins/channeltx/modbfm/lookaheadlimiter.cpp b/plugins/channeltx/modbfm/lookaheadlimiter.cpp new file mode 100644 index 000000000..b5fbb307f --- /dev/null +++ b/plugins/channeltx/modbfm/lookaheadlimiter.cpp @@ -0,0 +1,96 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +#include "lookaheadlimiter.h" + +LookaheadLimiter::LookaheadLimiter() +{ + configure(1, 1); +} + +void LookaheadLimiter::configure(int lookaheadSamples, int releaseSamples) +{ + m_lookahead = std::max(lookaheadSamples, 1); + m_release = 1.0f - std::exp(-1.0f / std::max(releaseSamples, 1)); + m_delay.resize(m_lookahead); + m_minCount.resize(m_lookahead + 2); + m_minGain.resize(m_lookahead + 2); + m_box.resize(m_lookahead); + reset(); +} + +void LookaheadLimiter::reset() +{ + std::fill(m_delay.begin(), m_delay.end(), Complex(0.0f, 0.0f)); + m_delayIdx = 0; + m_minHead = 0; + m_minSize = 0; + std::fill(m_box.begin(), m_box.end(), 1.0f); + m_boxSum = m_lookahead; + m_boxIdx = 0; + m_count = 0; + m_gain = 1.0f; +} + +Complex LookaheadLimiter::process(const Complex& input) +{ + const int capacity = (int) m_minGain.size(); + const float peak = std::max(std::fabs(input.real()), std::fabs(input.imag())); + const float required = peak > 1.0f ? 1.0f / peak : 1.0f; + + // Minimum required gain over samples m_count - m_lookahead to m_count + while ((m_minSize > 0) && (m_minGain[(m_minHead + m_minSize - 1) % capacity] >= required)) { + m_minSize--; + } + const int tail = (m_minHead + m_minSize) % capacity; + m_minCount[tail] = m_count; + m_minGain[tail] = required; + m_minSize++; + while (m_minCount[m_minHead] < m_count - m_lookahead) + { + m_minHead = (m_minHead + 1) % capacity; + m_minSize--; + } + const float windowMin = m_minGain[m_minHead]; + + // Each of the last m_lookahead window minimums covers the sample now leaving + // the delay line, so their average is no more than the gain that sample needs + m_boxSum += windowMin - m_box[m_boxIdx]; + m_box[m_boxIdx] = windowMin; + m_boxIdx = (m_boxIdx + 1) % m_lookahead; + if (m_boxIdx == 0) { // Avoid accumulating rounding errors + m_boxSum = std::accumulate(m_box.begin(), m_box.end(), 0.0); + } + const float boxGain = (float) (m_boxSum / m_lookahead); + + // Recover slowly, but never above the gain required by the coming samples + m_gain = std::min(boxGain, m_gain + (1.0f - m_gain) * m_release); + + const Complex delayed = m_delay[m_delayIdx]; + m_delay[m_delayIdx] = input; + m_delayIdx = (m_delayIdx + 1) % m_lookahead; + m_count++; + + // Rounding of the average could exceed the limit by a tiny amount + return Complex(std::clamp(delayed.real() * m_gain, -1.0f, 1.0f), + std::clamp(delayed.imag() * m_gain, -1.0f, 1.0f)); +} diff --git a/plugins/channeltx/modbfm/lookaheadlimiter.h b/plugins/channeltx/modbfm/lookaheadlimiter.h new file mode 100644 index 000000000..a49bdb7df --- /dev/null +++ b/plugins/channeltx/modbfm/lookaheadlimiter.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODBFM_LOOKAHEADLIMITER_H_ +#define PLUGINS_CHANNELTX_MODBFM_LOOKAHEADLIMITER_H_ + +#include + +#include "dsp/dsptypes.h" + +/** Stereo-linked look-ahead peak limiter. The left channel is the real part + * and the right channel the imaginary part. Neither output channel exceeds 1. + * + * The output is delayed by the look-ahead time. The gain is reduced over a + * linear ramp lasting the look-ahead time before each peak, then recovers + * exponentially. Gain changes are therefore smooth, so the limiter adds little + * energy outside the bandwidth of the input. Input that never exceeds 1 is + * passed through unchanged, apart from the delay. + */ +class LookaheadLimiter +{ +public: + LookaheadLimiter(); + + void configure(int lookaheadSamples, int releaseSamples); + void reset(); + Complex process(const Complex& input); + float getGain() const { return m_gain; } + +private: + int m_lookahead; //!< Look-ahead in samples + float m_release; //!< Release coefficient per sample + std::vector m_delay; + int m_delayIdx; + + // Minimum required gain over the last m_lookahead + 1 samples, as a + // monotonic queue of (sample count, gain) in a ring buffer + std::vector m_minCount; + std::vector m_minGain; + int m_minHead; + int m_minSize; + + // Moving average of those minimums over m_lookahead samples + std::vector m_box; + double m_boxSum; + int m_boxIdx; + + qint64 m_count; + float m_gain; +}; + +#endif // PLUGINS_CHANNELTX_MODBFM_LOOKAHEADLIMITER_H_ diff --git a/plugins/channeltx/modbfm/rdsencoder.cpp b/plugins/channeltx/modbfm/rdsencoder.cpp new file mode 100644 index 000000000..18198e4ab --- /dev/null +++ b/plugins/channeltx/modbfm/rdsencoder.cpp @@ -0,0 +1,307 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include "rdsencoder.h" + +namespace { +const quint16 offsetWords[4] = {252, 408, 360, 436}; // A, B, C, D +const double rdsBitRate = 1187.5; + +// Block B flags common to groups 0A and 2A +const quint16 trafficProgramme = 0; // TP: this is not a traffic programme +const quint16 trafficAnnouncement = 0; // TA: no traffic announcement in progress +const quint16 musicSpeech = 1; // M/S: music + +/** Biphase symbol shaping from IEC 62106. The data spectrum is shaped by + * H(f) = cos(pi f td / 4) for |f| <= 2 / td and zero above, which confines RDS + * to +/-2.4 kHz around 57 kHz. With time t in bit periods, the impulse response is + * h(t) = 2a cos(4 pi t) / (a^2 - 4 pi^2 t^2) with a = pi / 4. + */ +class SymbolShape +{ +public: + static constexpr double m_delay = 2.75; //!< Delay in bits so that every symbol contributing to a sample is known + + SymbolShape() : + m_table(2 * m_span * m_resolution + 1), + m_scale(1.0) + { + for (int i = 0; i < (int) m_table.size(); i++) { + m_table[i] = impulse((double) (i - m_span * m_resolution) / m_resolution); + } + + // Scale so that the sum of all overlapping symbols can never exceed 1 + double worst = 0.0; + + for (int p = 0; p < m_resolution; p++) + { + double sum = 0.0; + + for (int j = 0; j < RDSEncoder::m_nbSymbols; j++) { + sum += std::fabs(symbol((double) p / m_resolution + j - m_delay)); + } + + worst = std::max(worst, sum); + } + + m_scale = 1.0 / worst; + } + + /** Shaped biphase symbol: a positive impulse at 1/4 bit and a negative one at 3/4 bit. + * tau is the time since the start of the symbol in bit periods. + */ + Real symbol(double tau) const { + return m_scale * (h(tau - 0.25) - h(tau - 0.75)); + } + +private: + static const int m_span = 3; //!< Impulse response is truncated to +/-3 bits + static const int m_resolution = 256; //!< Table entries per bit + std::vector m_table; + double m_scale; + + double h(double t) const + { + const double x = (t + m_span) * m_resolution; + + if ((x < 0.0) || (x >= m_table.size() - 1)) { + return 0.0; + } + + const int i = (int) x; + const double frac = x - i; + return m_table[i] + frac * (m_table[i + 1] - m_table[i]); + } + + static double impulse(double t) + { + const double a = M_PI / 4.0; + const double d = a * a - 4.0 * M_PI * M_PI * t * t; + + if (std::fabs(d) < 1e-9) { + return 2.0; // limit at |t| = 1/8 + } + + return 2.0 * a * std::cos(4.0 * M_PI * t) / d; + } +}; + +const SymbolShape& symbolShape() +{ + static const SymbolShape shape; + return shape; +} + +} + +RDSEncoder::RDSEncoder() : + m_sampleRate(456000), + m_pi(0x1234), + m_pty(0), + m_stereo(true), + m_bitIndex(0), + m_bitPhase(0.0), + m_differentialState(false), + m_radioTextAB(false), + m_radioTextSegments(16), + m_radioTextSegment(0), + m_groupIndex(0) +{ + setData(m_pi, m_pty, "SDRangel", "SDRangel Broadcast FM"); + reset(); +} + +QByteArray RDSEncoder::rdsText(const QString& text, int length) +{ + QByteArray result = text.toLatin1().left(length); + result.replace('\n', ' '); + result.replace('\r', ' '); + result.append(QByteArray(length - result.size(), ' ')); + return result; +} + +QByteArray RDSEncoder::rdsRadioText(const QString& text) +{ + QByteArray result = text.toLatin1().left(64); + result.replace('\n', ' '); + result.replace('\r', ' '); + if (result.size() < 64) { + result.append('\r'); + } + result.append(QByteArray(64 - result.size(), ' ')); + return result; +} + +void RDSEncoder::setSampleRate(int sampleRate) +{ + // The bit phase is in bit periods, so the stream continues at the new rate + m_sampleRate = std::max(sampleRate, 1); +} + +void RDSEncoder::setData(quint16 pi, quint8 pty, const QString& ps, const QString& radioText) +{ + // Groups are built from these when the previous group has been sent + const QByteArray normalizedRadioText = rdsRadioText(radioText); + if (normalizedRadioText != m_radioText) + { + if (!m_radioText.isEmpty()) { + m_radioTextAB = !m_radioTextAB; // Tells receivers to clear the old text + } + m_radioText = normalizedRadioText; + const int end = m_radioText.indexOf('\r'); + m_radioTextSegments = end < 0 ? 16U : (unsigned int) end / 4U + 1U; + m_radioTextSegment = 0; + } + m_pi = pi; + m_pty = std::min(pty, 31); + m_ps = rdsText(ps, 8); +} + +void RDSEncoder::reset() +{ + m_bits.clear(); + m_bitIndex = 0; + m_bitPhase = 0.0; + m_differentialState = false; + m_groupIndex = 0; + m_radioTextSegment = 0; + m_symbols.fill(0.0f); + buildNextGroup(); + pushSymbol(); +} + +quint16 RDSEncoder::crc(quint16 data) +{ + quint32 reg = 0; + const quint32 polynomial = 0x5B9; + + for (int i = 15; i >= 0; --i) + { + reg = (reg << 1) | ((data >> i) & 1U); + if (reg & 0x400U) { + reg ^= polynomial; + } + } + + for (int i = 0; i < 10; ++i) + { + reg <<= 1; + if (reg & 0x400U) { + reg ^= polynomial; + } + } + + return reg & 0x3ffU; +} + +void RDSEncoder::appendBlock(quint16 data, quint16 offsetWord) +{ + quint32 block = (quint32(data) << 10) | (crc(data) ^ offsetWord); + for (int bit = 25; bit >= 0; --bit) { + m_bits.push_back(((block >> bit) & 1U) != 0); + } +} + +void RDSEncoder::buildNextGroup() +{ + m_bits.clear(); + m_bitIndex = 0; + + // Four PS groups followed by one RadioText group gives rapid station-name + // acquisition while continuously refreshing the text. + const bool psGroup = (m_groupIndex % 5U) != 4U; + quint16 blocks[4] = {}; + blocks[0] = m_pi; + + if (psGroup) + { + const unsigned int segment = (m_groupIndex % 5U); + // Decoder identification bits are sent one per segment, d3 first. Only + // d0 (stereo) is set: no dynamic PTY, compression or artificial head. + const quint16 di = ((segment == 3U) && m_stereo) ? 1U : 0U; + blocks[1] = quint16((trafficProgramme << 10) | (quint16(m_pty) << 5) + | (trafficAnnouncement << 4) | (musicSpeech << 3) | (di << 2) | (segment & 3U)); + blocks[2] = 0xE0CD; // AF codes: 224 = no alternative frequencies, 205 = filler + blocks[3] = (quint16(quint8(m_ps[segment * 2])) << 8) + | quint16(quint8(m_ps[segment * 2 + 1])); + } + else + { + // Only the segments up to the one containing the end-of-text carriage return are sent + const unsigned int segment = m_radioTextSegment; + m_radioTextSegment = (m_radioTextSegment + 1) % m_radioTextSegments; + blocks[1] = quint16((2U << 12) | (trafficProgramme << 10) | (quint16(m_pty) << 5) + | (m_radioTextAB ? (1U << 4) : 0U) | (segment & 0xfU)); + blocks[2] = (quint16(quint8(m_radioText[segment * 4])) << 8) + | quint16(quint8(m_radioText[segment * 4 + 1])); + blocks[3] = (quint16(quint8(m_radioText[segment * 4 + 2])) << 8) + | quint16(quint8(m_radioText[segment * 4 + 3])); + } + + for (int i = 0; i < 4; ++i) { + appendBlock(blocks[i], offsetWords[i]); + } + + ++m_groupIndex; +} + +bool RDSEncoder::nextDifferentialBit() +{ + if (m_bitIndex >= m_bits.size()) { + buildNextGroup(); + } + + // RDS differential coding: a data one changes state at the bit boundary. + if (m_bits[m_bitIndex++]) { + m_differentialState = !m_differentialState; + } + return m_differentialState; +} + +void RDSEncoder::pushSymbol() +{ + std::copy_backward(m_symbols.begin(), m_symbols.end() - 1, m_symbols.end()); + m_symbols[0] = nextDifferentialBit() ? 1.0f : -1.0f; +} + +Real RDSEncoder::sample() +{ + const SymbolShape& shape = symbolShape(); + Real out = 0.0f; + + // Symbol j started (m_bitPhase + j) bits ago. Sum the shaped symbols that overlap. + for (int j = 0; j < m_nbSymbols; j++) + { + if (m_symbols[j] != 0.0f) { + out += m_symbols[j] * shape.symbol(m_bitPhase + j - SymbolShape::m_delay); + } + } + + m_bitPhase += rdsBitRate / m_sampleRate; + + if (m_bitPhase >= 1.0) + { + m_bitPhase -= 1.0; + pushSymbol(); + } + + return out; +} diff --git a/plugins/channeltx/modbfm/rdsencoder.h b/plugins/channeltx/modbfm/rdsencoder.h new file mode 100644 index 000000000..1b9bf871e --- /dev/null +++ b/plugins/channeltx/modbfm/rdsencoder.h @@ -0,0 +1,75 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODBFM_RDSENCODER_H_ +#define PLUGINS_CHANNELTX_MODBFM_RDSENCODER_H_ + +#include +#include + +#include + +#include "dsp/dsptypes.h" + +/** Generates the shaped baseband component used to DSB-SC modulate the RDS + * 57 kHz subcarrier. Groups 0A (PS) and 2A (RadioText) are interleaved. + * Output peak amplitude is at most 1. + */ +class RDSEncoder +{ +public: + RDSEncoder(); + + void setSampleRate(int sampleRate); + /** Changes take effect from the next group, without interrupting the bit stream, + * so receivers keep block synchronisation. + */ + void setData(quint16 pi, quint8 pty, const QString& ps, const QString& radioText); + void setStereo(bool stereo) { m_stereo = stereo; } + Real sample(); + void reset(); + + static const int m_nbSymbols = 6; //!< Number of overlapping shaped symbols contributing to each sample + +private: + int m_sampleRate; + quint16 m_pi; + quint8 m_pty; + bool m_stereo; + QByteArray m_ps; + QByteArray m_radioText; + std::vector m_bits; + unsigned int m_bitIndex; + double m_bitPhase; + bool m_differentialState; + bool m_radioTextAB; + unsigned int m_radioTextSegments; //!< Number of 4 character RadioText segments to send + unsigned int m_radioTextSegment; //!< Next RadioText segment to send + unsigned int m_groupIndex; + std::array m_symbols; //!< Newest first: +1/-1 per biphase symbol, 0 before start + + static quint16 crc(quint16 data); + static QByteArray rdsText(const QString& text, int length); + static QByteArray rdsRadioText(const QString& text); + void appendBlock(quint16 data, quint16 offsetWord); + void buildNextGroup(); + bool nextDifferentialBit(); + void pushSymbol(); +}; + +#endif // PLUGINS_CHANNELTX_MODBFM_RDSENCODER_H_ diff --git a/plugins/channeltx/modbfm/readme.md b/plugins/channeltx/modbfm/readme.md new file mode 100644 index 000000000..0587311e2 --- /dev/null +++ b/plugins/channeltx/modbfm/readme.md @@ -0,0 +1,228 @@ +

Broadcast FM modulator plugin

+ +

Introduction

+ +This plugin generates a broadcast FM signal for use with [Broadcast FM Demodulator](../../channelrx/demodbfm/readme.md) or a conventional FM receiver. +It supports mono and stereo programme audio, 50 or 75 microsecond pre-emphasis, and RDS programme identification, programme service name and RadioText. +Audio can come from a live audio device, a WAV or raw file, a tone generator, or the Morse keyer. + +The default broadcast configuration is stereo, 50 microsecond pre-emphasis, RDS enabled, 75 kHz peak deviation and 256 kHz RF bandwidth. + +

Interface

+ +The top and bottom bars of the channel window are described in the [channel window documentation](../../../sdrgui/channel/readme.md). + +![Broadcast FM Modulator plugin GUI](../../../doc/img/BFMMmod_plugin.png) + +

1: Frequency shift from center frequency of transmission

+ +Sets the channel frequency offset in Hz from the device's center frequency. Use the mouse wheel over a digit, or select a digit and use the keyboard arrows. Holding Shift changes the digit by 5; holding Control changes it by 2. Right click a digit to set the digits to its right to zero. The channel marker in the spectrum can also be dragged to change the offset. + +

2: Channel power

+ +Displays the average transmitted channel power in dB relative to a full-scale signal with an amplitude of ±1.0. + +

3: Channel mute

+ +Toggles the channel's RF output on or off. Muting suppresses the complete signal, including the carrier, pilot and RDS. + +

4: RF bandwidth (RFBW)

+ +Sets the bandwidth of the channel filter applied after FM modulation. Available values are 150, 180, 200, 220, 240, 256, 280 and 300 kHz. The default is 256 kHz. Narrower settings can truncate the FM sidebands and reduce stereo separation, particularly with stereo and RDS enabled. The device sample rate must be at least the RF bandwidth; when it is lower, a warning is shown in the status bar at the bottom of the channel window. + +

5: Frequency deviation (Dev)

+ +Sets the peak frequency deviation from 0 to 100 kHz in 1 kHz steps. The default is 75 kHz. This applies to the complete multiplex, including programme audio, pilot and RDS. Match the receiver's deviation setting to the transmitted signal. + +

6: Audio frequency bandwidth (AFBW)

+ +Sets the programme audio bandwidth from 1 to 15 kHz in 1 kHz steps. The default is 15 kHz. The upper limit keeps programme audio clear of the 19 kHz pilot and keeps the stereo difference sidebands clear of the RDS band. + +

7: Pre-emphasis

+ +Selects Off, 50 microseconds or 75 microseconds. Pre-emphasis boosts higher audio frequencies before transmission; the receiver's matching de-emphasis restores the audio response. The default is 50 microseconds, commonly used in Europe. 75 microseconds is commonly used in North America. + +

8: Stereo

+ +Toggles between mono and stereo; the icon shows the selected mode. Stereo enables stereo transmission using a 19 kHz pilot and a 38 kHz subcarrier carrying the left-minus-right signal. Live audio and stereo WAV files preserve their left and right channels. +Mono files, the tone generator and the Morse keyer feed both channels equally. + +When disabled, the left and right inputs are averaged for mono transmission. RDS can still be transmitted in mono mode and keeps the pilot enabled. Stereo is enabled by default. + +

9: RDS enable

+ +Toggles Radio Data System information on a 57 kHz subcarrier. This includes the programme identification code, programme type, programme service name and RadioText configured below. RDS is enabled by default and also enables the 19 kHz reference pilot, including in mono mode. + +The RDS signal is shaped to occupy ±2.4 kHz around 57 kHz. The station is flagged as music and not as a traffic programme. The stereo decoder identification flag follows the Stereo setting. + +

10: Pilot level (Pilot)

+ +Sets the 19 kHz pilot level as a percentage of peak deviation, from 0% to 20% in 0.5 percentage-point steps. The default is 9%. This setting applies when Stereo or RDS is enabled. Setting it to zero removes the pilot even when either feature is enabled, preventing normal pilot-based stereo decoding. + +

11: RDS subcarrier level (RDS)

+ +Sets the RDS subcarrier level as a percentage of peak deviation, from 0% to 10% in 0.5 percentage-point steps. The default is 3%. This setting applies when RDS is enabled. Increasing the pilot or RDS level reduces the modulation range available for programme audio. + +

12: Volume (Vol)

+ +Sets the audio input gain from 0.0 to 2.0 in steps of 0.1. The default is 1.0. After pre-emphasis, a stereo-linked peak limiter reduces the gain when necessary to keep audio peaks within range. Lower the input gain if sustained limiting causes audible changes in volume. + +

13: Audio level meter

+ +Shows the level of the mono sum of the processed left and right audio channels as a percentage of full scale: + +* Top bar: average level. +* Bottom bar: instantaneous peak level. +* Tip marker: peak hold level. + +Use this meter when adjusting the audio input gain. + +

14: Microphone input

+ +Set input audio from a live microphone or line input device. Left click the microphone button to select live audio input. Right click it to choose the audio input device. +The device's left and right channels are used for stereo transmission or averaged for mono transmission. + +See the [audio management documentation](../../../sdrgui/audio.md) for device configuration. + +

15: Audio file input

+ +Set input audio from a .raw or .wav file. Selecting the audio file source shows the audio file playback tab, as described below. + +

16: Tone input

+ +Set input audio to a continuous audio tone at the frequency set by the tone frequency dial. The tone is sent equally to the left and right channels. + +

17: Morse keyer input

+ +Selects the Morse keyer as the audio source, using the tone frequency dial for its audio pitch. Configure the text or manual keying controls described below. + +

18: Tone frequency

+ +Sets the audio frequency used by both the continuous tone and Morse keyer from 0.10 to 10.00 kHz in 0.01 kHz steps. The default is 1.00 kHz. Keep the tone within the selected audio bandwidth to avoid attenuating it. + +

19: Audio feedback and output device

+ +Left click the feedback button to enable or disable local monitoring of the processed programme audio. +Right click it to select the audio output device. Feedback is disabled by default. +Audio buffering introduces a delay, so feedback is best used to monitor the programme rather than to time manual Morse keying. + +

20: Audio feedback volume

+ +Sets the local monitoring volume from 0.00 to 1.00 in steps of 0.01. The default is 0.50. This adjusts the feedback output independently of the transmitted audio input gain. + +

Audio file playback tab

+ +Select the Audio file input (15) to transmit the output of these controls. + +![Audio file playback tab](../../../doc/img/BFMMmod_audio_tab.png) + +

21: Select audio file

+ +Opens a file dialog to select a `.wav` or `.raw` file. Supported formats are: + +* Mono or stereo WAV with 8-, 16-, 24- or 32-bit PCM samples, or 32- or 64-bit floating-point samples. Playback uses the sample rate stored in the WAV file. +* Mono, 48 kHz, 32-bit little-endian floating-point raw audio (F32LE). + +Mono files feed both audio channels equally. Stereo WAV files retain separate channels when Stereo is enabled. + +

22: Audio file path

+ +Displays the path of the selected audio file, or dots when no file has been selected. + +

23: Loop audio file

+ +Restarts playback from the beginning when the end of the file is reached. + +

24: Current file position

+ +Displays the current playback time relative to the beginning of the file. + +

25: File length

+ +Displays the total duration of the selected audio file. + +

26: File position slider

+Shows the playback position as a percentage of the file length. Pause playback to enable the slider, move it to the desired position, then resume playback. + +

Morse keyer tab

+ +Select the Morse keyer input (17) to transmit the output of these controls. + +![Morse keyer tab](../../../doc/img/BFMMmod_morse_tab.png) + +

27: CW text

+Enter the message to send in text mode. Press Enter or leave the field to apply the text. + +

28: Clear CW text

+ +Clears the message in the CW text field. + +

29: CW speed

+Sets the keying speed from 1 to 26 words per minute (WPM). The default is 13 WPM. Timing uses the standard word PARIS: a dot lasts 1.2 / WPM seconds, a dash lasts three dot lengths, and the gaps between elements, characters and words last one, three and seven dot lengths respectively. + +

30: Send dots

+ +Sends dots continuously at the selected CW speed. Switch it off before selecting another keying mode. + +

31: Send dashes

+Sends dashes continuously at the selected CW speed. Switch it off before selecting another keying mode. + +

32: Send text

+ +Selects text mode and starts sending the message in the CW text field. + +

33: Repeat CW text

+Repeats the message continuously while text mode is active. + +

34: CW text play/stop

+ +Stops or starts text keying. Starting again restarts the message from its beginning. + +

35: Keyboard and mouse keying

+ +Enables manual keying with the assigned keyboard keys or the mouse pad. This mode is mutually exclusive with text, continuous dots and continuous dashes. If the keyboard focus is lost, toggle this control off and on to restore the key bindings. + +

36: Keying style

+ +Selects iambic or straight keying. In iambic mode the dot and dash controls act as separate paddles. In straight mode either control keys the tone while held down. + +

37: Mouse keying pad

+ +With keyboard and mouse keying enabled, move the pointer over the pad and use the left mouse button for dots and the right button for dashes. In straight mode both buttons act as key down. + +

38: Dot key assignment

+Select the dot key capture button, then press the key or key-and-modifier combination to assign to dots. The assigned key is displayed beside the button. + +

39: Dash key assignment

+ +Select the dash key capture button, then press the key or key-and-modifier combination to assign to dashes. The assigned key is displayed beside the button. + +

RDS tab

+ +Check RDS enable (9) to transmit these fields. + +![RDS tab](../../../doc/img/BFMMmod_rds_tab.png) + +

40: RDS programme identification (PI)

+ +Sets the station's 16-bit programme identification code. +Enter up to four hexadecimal digits; the display is normalized to four digits when editing finishes. +The default is `1234`. An invalid entry leaves the previous value in place. + +

41: RDS programme type (PTY)

+ +Selects the programme type. Receivers use this to describe or select the programme category. +The names are those of the RDS programme type table, which the BFM demodulator also displays, and the position in the list is the code transmitted (0 to 31). +The default is None (0). North American receivers use the RBDS table, which gives some codes different names. + +

42: RDS programme service name (PS)

+ +Sets the station name displayed by RDS receivers, up to eight characters. +Shorter names are padded with spaces for transmission. +The default is `SDRangel`. Press Enter or leave the field to apply the change. + +

43: RDS RadioText (RT)

+ +Sets a message of up to 64 characters, such as programme information or a track title. +The default is `SDRangel Broadcast FM`. Press Enter or leave the field to apply the change. +Receivers may take several RDS groups to display the complete message. diff --git a/plugins/channeltx/modm17/m17modsource.cpp b/plugins/channeltx/modm17/m17modsource.cpp index 888eab0e3..bd0878190 100644 --- a/plugins/channeltx/modm17/m17modsource.cpp +++ b/plugins/channeltx/modm17/m17modsource.cpp @@ -518,11 +518,13 @@ void M17ModSource::applyFeedbackAudioSampleRate(int sampleRate) qDebug("NFMModSource::applyFeedbackAudioSampleRate: %d", sampleRate); + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorConsumed = false; - m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; - m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index fe0e8567a..35082363b 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -17,7 +17,6 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include #include #include #include @@ -31,8 +30,6 @@ #include "SWGChannelReport.h" #include "SWGNFMModReport.h" -#include -#include #include #include "dsp/dspcommands.h" diff --git a/plugins/channeltx/modnfm/nfmmod.h b/plugins/channeltx/modnfm/nfmmod.h index 659fd1c76..7382ec727 100644 --- a/plugins/channeltx/modnfm/nfmmod.h +++ b/plugins/channeltx/modnfm/nfmmod.h @@ -248,11 +248,6 @@ public: static const char* const m_channelId; private: - enum RateState { - RSInitialFill, - RSRunning - }; - DeviceAPI* m_deviceAPI; QThread *m_thread; bool m_running = false; @@ -261,7 +256,6 @@ private: int m_basebandSampleRate; qint64 m_centerFrequency; - SampleVector m_sampleBuffer; QRecursiveMutex m_settingsMutex; std::ifstream m_ifstream; diff --git a/plugins/channeltx/modnfm/nfmmodsource.cpp b/plugins/channeltx/modnfm/nfmmodsource.cpp index eb7f561c7..e0176d7f1 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.cpp +++ b/plugins/channeltx/modnfm/nfmmodsource.cpp @@ -364,7 +364,6 @@ void NFMModSource::applyAudioSampleRate(int sampleRate) qDebug("NFMModSource::applyAudioSampleRate: %d", sampleRate); m_interpolatorDistanceRemain = 0; - m_interpolatorConsumed = false; m_interpolatorDistance = (Real) sampleRate / (Real) m_channelSampleRate; m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); m_lowpass.create(301, sampleRate, m_settings.m_afBandwidth); @@ -409,11 +408,12 @@ void NFMModSource::applyFeedbackAudioSampleRate(int sampleRate) qDebug("NFMModSource::applyFeedbackAudioSampleRate: %d", sampleRate); + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. m_feedbackInterpolatorDistanceRemain = 0; - m_feedbackInterpolatorConsumed = false; - m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; Real cutoff = (float) std::min(sampleRate, m_audioSampleRate) / 2.2f; - m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } @@ -474,7 +474,6 @@ void NFMModSource::applyChannelSettings(int channelSampleRate, int channelFreque if ((channelSampleRate != m_channelSampleRate) || force) { m_interpolatorDistanceRemain = 0; - m_interpolatorConsumed = false; m_interpolatorDistance = (Real) m_audioSampleRate / (Real) channelSampleRate; m_interpolator.create(48, m_audioSampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); } diff --git a/plugins/channeltx/modnfm/nfmmodsource.h b/plugins/channeltx/modnfm/nfmmodsource.h index 236853cfc..237061dc6 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.h +++ b/plugins/channeltx/modnfm/nfmmodsource.h @@ -88,12 +88,10 @@ private: Interpolator m_interpolator; Real m_interpolatorDistance; Real m_interpolatorDistanceRemain; - bool m_interpolatorConsumed; Interpolator m_feedbackInterpolator; Real m_feedbackInterpolatorDistance; Real m_feedbackInterpolatorDistanceRemain; - bool m_feedbackInterpolatorConsumed; QVector m_demodBuffer; int m_demodBufferFill; diff --git a/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp b/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp index da7a20ea0..32f704401 100644 --- a/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp +++ b/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp @@ -59,7 +59,6 @@ int NFMModWebAPIAdapter::webapiSettingsPutPatch( SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, newCWKeyerSettings, apiCwKeyerSettings); m_settings.setCWKeyerSettings(newCWKeyerSettings); - const QByteArray& serializedNewSettings = m_settings.serialize(); // effectively update CW keyer settings } NFMMod::webapiFormatChannelSettings(response, m_settings); diff --git a/plugins/channeltx/modssb/ssbmodsource.cpp b/plugins/channeltx/modssb/ssbmodsource.cpp index bea9c2dbf..bc936fd7a 100644 --- a/plugins/channeltx/modssb/ssbmodsource.cpp +++ b/plugins/channeltx/modssb/ssbmodsource.cpp @@ -644,11 +644,13 @@ void SSBModSource::applyFeedbackAudioSampleRate(int sampleRate) qDebug("SSBModSource::applyFeedbackAudioSampleRate: %d", sampleRate); + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorConsumed = false; - m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; Real cutoff = (float) (std::min(sampleRate, m_audioSampleRate)) / 2.2f; - m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } diff --git a/plugins/channeltx/modwfm/wfmmodsource.cpp b/plugins/channeltx/modwfm/wfmmodsource.cpp index c03698a1a..f9a3f16c0 100644 --- a/plugins/channeltx/modwfm/wfmmodsource.cpp +++ b/plugins/channeltx/modwfm/wfmmodsource.cpp @@ -398,11 +398,13 @@ void WFMModSource::applyFeedbackAudioSampleRate(int sampleRate) qDebug("WFMModSource::applyFeedbackAudioSampleRate: %d", sampleRate); + // Resample from the audio input rate to the feedback device rate. The distance is + // input samples per output sample and the filter is designed at the input rate. m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorConsumed = false; - m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; + m_feedbackInterpolatorDistance = (Real) m_audioSampleRate / (Real) sampleRate; Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; - m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); + m_feedbackInterpolator.create(48, m_audioSampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } diff --git a/plugins/feature/demodanalyzer/demodanalyzersettings.cpp b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp index 9b179aa08..b7f5e9c68 100644 --- a/plugins/feature/demodanalyzer/demodanalyzersettings.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp @@ -48,6 +48,7 @@ const QStringList DemodAnalyzerSettings::m_channelURIs = { QStringLiteral("sdrangel.channeltx.modssb"), QStringLiteral("sdrangel.channel.wfmdemod"), QStringLiteral("sdrangel.channeltx.modwfm"), + QStringLiteral("sdrangel.channeltx.modbfm"), QStringLiteral("sdrangel.channel.wdsprx"), QStringLiteral("sdrangel.feature.denoiser"), }; diff --git a/plugins/feature/jogdialcontroller/jogdialcontrollersettings.cpp b/plugins/feature/jogdialcontroller/jogdialcontrollersettings.cpp index cafd36324..3871645da 100644 --- a/plugins/feature/jogdialcontroller/jogdialcontrollersettings.cpp +++ b/plugins/feature/jogdialcontroller/jogdialcontrollersettings.cpp @@ -40,6 +40,7 @@ const QStringList JogdialControllerSettings::m_channelTypes = { QStringLiteral("SSBMod"), QStringLiteral("WFMDemod"), QStringLiteral("WFMMod"), + QStringLiteral("BFMMod"), }; const QStringList JogdialControllerSettings::m_channelURIs = { @@ -57,6 +58,7 @@ const QStringList JogdialControllerSettings::m_channelURIs = { QStringLiteral("sdrangel.channeltx.modssb"), QStringLiteral("sdrangel.channel.wfmdemod"), QStringLiteral("sdrangel.channeltx.modwfm"), + QStringLiteral("sdrangel.channeltx.modbfm"), }; JogdialControllerSettings::JogdialControllerSettings() : diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index bd4158511..d8b8e428c 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -96,6 +96,7 @@ set(sdrbase_SOURCES audio/audiocompressorsnd.cpp audio/audiodeviceinfo.cpp audio/audiodevicemanager.cpp + audio/audiofilereader.cpp audio/audiofifo.cpp audio/audiofilter.cpp audio/audiog722.cpp @@ -276,6 +277,7 @@ set(sdrbase_SOURCES util/spyserverlist.cpp util/stix.cpp util/stringlist.cpp + util/rds.cpp util/rtty.cpp util/uid.cpp util/units.cpp @@ -320,6 +322,7 @@ set(sdrbase_HEADERS audio/audiocompressorsnd.h audio/audiodeviceinfo.h audio/audiodevicemanager.h + audio/audiofilereader.h audio/audiofifo.h audio/audiofilter.h audio/audiog722.h @@ -533,6 +536,7 @@ set(sdrbase_HEADERS util/psk31.h util/radiosonde.h util/rainviewer.h + util/rds.h util/rtpsink.h util/rtty.h util/syncmessenger.h diff --git a/sdrbase/audio/audiofilereader.cpp b/sdrbase/audio/audiofilereader.cpp new file mode 100644 index 000000000..f26cf7fa7 --- /dev/null +++ b/sdrbase/audio/audiofilereader.cpp @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include +#include + +#include "audiofilereader.h" + +namespace { + +bool chunkIdEquals(const char *id, const char *expected) +{ + return std::memcmp(id, expected, 4) == 0; +} + +} + +AudioFileReader::AudioFileReader() : + m_fileType(FileTypeNone), + m_wavFormat(0), + m_channelCount(0), + m_bitsPerSample(0), + m_blockAlign(0), + m_sampleRate(0), + m_dataOffset(0), + m_dataSize(0), + m_frameCount(0), + m_position(0) +{ +} + +AudioFileReader::~AudioFileReader() +{ + close(); +} + +bool AudioFileReader::open(const QString& fileName) +{ + QMutexLocker locker(&m_mutex); + closeUnlocked(); + m_errorString.clear(); + + m_file.setFileName(fileName); + + if (!m_file.open(QIODevice::ReadOnly | QIODevice::ExistingOnly)) { + return failUnlocked(QStringLiteral("Unable to open audio file: %1").arg(m_file.errorString())); + } + + const qint64 size = m_file.size(); + + if (size < 0) { + return failUnlocked(QStringLiteral("Unable to determine audio file size")); + } + + const quint64 fileSize = static_cast(size); + char signature[12] = {}; + const bool hasSignature = (fileSize >= sizeof(signature)) && readExact(signature, sizeof(signature)); + + if (!m_file.seek(0)) { + return failUnlocked(QStringLiteral("Unable to seek in audio file")); + } + + if (hasSignature && + (chunkIdEquals(signature, "RIFF") || chunkIdEquals(signature, "RF64")) && + chunkIdEquals(signature + 8, "WAVE")) + { + return openWavUnlocked(fileSize); + } + + if (fileName.endsWith(QStringLiteral(".raw"), Qt::CaseInsensitive)) { + return openRawUnlocked(fileSize); + } + + return failUnlocked(QStringLiteral("Audio file is neither WAV nor F32LE raw data")); +} + +void AudioFileReader::close() +{ + QMutexLocker locker(&m_mutex); + closeUnlocked(); +} + +void AudioFileReader::closeUnlocked() +{ + if (m_file.isOpen()) { + m_file.close(); + } + + m_fileType = FileTypeNone; + m_wavFormat = 0; + m_channelCount = 0; + m_bitsPerSample = 0; + m_blockAlign = 0; + m_sampleRate = 0; + m_dataOffset = 0; + m_dataSize = 0; + m_frameCount = 0; + m_position = 0; + m_frameBuffer.clear(); +} + +bool AudioFileReader::failUnlocked(const QString& error) +{ + m_errorString = error; + closeUnlocked(); + return false; +} + +bool AudioFileReader::readExact(char *data, qint64 size) +{ + return m_file.read(data, size) == size; +} + +bool AudioFileReader::openRawUnlocked(quint64 fileSize) +{ + m_fileType = FileTypeRawFloat32; + m_wavFormat = WavFormatIEEEFloat; + m_channelCount = 1; + m_bitsPerSample = 32; + m_blockAlign = 4; + m_sampleRate = 48000; + m_dataOffset = 0; + m_dataSize = fileSize - (fileSize % m_blockAlign); + m_frameCount = m_dataSize / m_blockAlign; + m_position = 0; + m_frameBuffer.resize(m_blockAlign); + return true; +} + +bool AudioFileReader::openWavUnlocked(quint64 fileSize) +{ + char riffHeader[12]; + + if (!readExact(riffHeader, sizeof(riffHeader))) { + return failUnlocked(QStringLiteral("WAV file has an incomplete RIFF header")); + } + + const bool rf64 = chunkIdEquals(riffHeader, "RF64"); + bool haveFormat = false; + bool haveData = false; + quint64 rf64DataSize = 0; + quint64 dataOffset = 0; + quint64 dataSize = 0; + + while (static_cast(m_file.pos()) + 8 <= fileSize) + { + char chunkHeader[8]; + + if (!readExact(chunkHeader, sizeof(chunkHeader))) { + break; + } + + const quint32 chunkSize = qFromLittleEndian(chunkHeader + 4); + const quint64 payloadOffset = static_cast(m_file.pos()); + const quint64 payloadSize = chunkSize; + + if (chunkIdEquals(chunkHeader, "ds64")) + { + uchar ds64[28]; + + if ((chunkSize < sizeof(ds64)) || !readExact(reinterpret_cast(ds64), sizeof(ds64))) { + return failUnlocked(QStringLiteral("WAV file has an invalid RF64 ds64 chunk")); + } + + rf64DataSize = qFromLittleEndian(ds64 + 8); + } + else if (chunkIdEquals(chunkHeader, "fmt ")) + { + if (chunkSize < 16) { + return failUnlocked(QStringLiteral("WAV format chunk is too short")); + } + + const quint32 formatBytes = std::min(chunkSize, 40); + QByteArray formatData(formatBytes, 0); + + if (!readExact(formatData.data(), formatBytes)) { + return failUnlocked(QStringLiteral("WAV format chunk is incomplete")); + } + + const uchar *format = reinterpret_cast(formatData.constData()); + m_wavFormat = qFromLittleEndian(format); + m_channelCount = qFromLittleEndian(format + 2); + m_sampleRate = qFromLittleEndian(format + 4); + m_blockAlign = qFromLittleEndian(format + 12); + m_bitsPerSample = qFromLittleEndian(format + 14); + + if (m_wavFormat == WavFormatExtensible) + { + if (formatBytes < 40) { + return failUnlocked(QStringLiteral("WAV extensible format chunk is incomplete")); + } + + // First two bytes of the sub-format GUID are the format code + m_wavFormat = qFromLittleEndian(format + 24); + } + + haveFormat = true; + } + else if (chunkIdEquals(chunkHeader, "data")) + { + dataOffset = payloadOffset; + dataSize = (rf64 && chunkSize == std::numeric_limits::max()) ? rf64DataSize : chunkSize; + haveData = true; + } + + if (haveFormat && haveData) { + break; + } + + if (payloadSize > fileSize - std::min(payloadOffset, fileSize)) { + return failUnlocked(QStringLiteral("WAV chunk extends beyond the end of the file")); + } + + // Chunks are padded to an even size + const quint64 nextChunk = payloadOffset + payloadSize + (payloadSize & 1U); + + if ((nextChunk > fileSize) || !m_file.seek(static_cast(nextChunk))) { + return failUnlocked(QStringLiteral("WAV chunk padding extends beyond the end of the file")); + } + } + + if (!haveFormat || !haveData) { + return failUnlocked(QStringLiteral("WAV file is missing a format or data chunk")); + } + + if ((m_wavFormat != WavFormatPCM) && (m_wavFormat != WavFormatIEEEFloat)) { + return failUnlocked(QStringLiteral("WAV encoding is not PCM or IEEE float")); + } + + if ((m_channelCount < 1) || (m_channelCount > 2)) { + return failUnlocked(QStringLiteral("WAV file must contain one or two channels")); + } + + if (m_sampleRate == 0) { + return failUnlocked(QStringLiteral("WAV file has an invalid sample rate")); + } + + const bool validPCM = (m_wavFormat == WavFormatPCM) && + ((m_bitsPerSample == 8) || (m_bitsPerSample == 16) || + (m_bitsPerSample == 24) || (m_bitsPerSample == 32)); + const bool validFloat = (m_wavFormat == WavFormatIEEEFloat) && + ((m_bitsPerSample == 32) || (m_bitsPerSample == 64)); + + if (!validPCM && !validFloat) { + return failUnlocked(QStringLiteral("WAV sample size is unsupported")); + } + + const quint16 bytesPerSample = m_bitsPerSample / 8; + const quint16 minimumBlockAlign = m_channelCount * bytesPerSample; + + if (m_blockAlign < minimumBlockAlign) { + return failUnlocked(QStringLiteral("WAV block alignment is invalid")); + } + + if (dataOffset > fileSize) { + return failUnlocked(QStringLiteral("WAV data offset is outside the file")); + } + + dataSize = std::min(dataSize, fileSize - dataOffset); + dataSize -= dataSize % m_blockAlign; + + m_fileType = FileTypeWav; + m_dataOffset = dataOffset; + m_dataSize = dataSize; + m_frameCount = dataSize / m_blockAlign; + m_position = 0; + m_frameBuffer.resize(m_blockAlign); + + if (!m_file.seek(static_cast(m_dataOffset))) { + return failUnlocked(QStringLiteral("Unable to seek to WAV data")); + } + + return true; +} + +bool AudioFileReader::readFrame(float& left, float& right) +{ + QMutexLocker locker(&m_mutex); + + if (!m_file.isOpen() || (m_position >= m_frameCount)) { + return false; + } + + if (!readExact(m_frameBuffer.data(), m_blockAlign)) + { + m_position = m_frameCount; + return false; + } + + const uchar *frame = reinterpret_cast(m_frameBuffer.constData()); + const quint16 bytesPerSample = m_bitsPerSample / 8; + left = decodeSample(frame); + right = m_channelCount == 2 ? decodeSample(frame + bytesPerSample) : left; + ++m_position; + return true; +} + +float AudioFileReader::decodeSample(const uchar *data) const +{ + if (m_wavFormat == WavFormatIEEEFloat) + { + if (m_bitsPerSample == 32) + { + const quint32 bits = qFromLittleEndian(data); + float sample; + std::memcpy(&sample, &bits, sizeof(sample)); + return std::isfinite(sample) ? sample : 0.0f; + } + + const quint64 bits = qFromLittleEndian(data); + double sample; + std::memcpy(&sample, &bits, sizeof(sample)); + return std::isfinite(sample) ? static_cast(sample) : 0.0f; + } + + switch (m_bitsPerSample) + { + case 8: + return (static_cast(data[0]) - 128) / 128.0f; + case 16: + return qFromLittleEndian(data) / 32768.0f; + case 24: + { + qint32 sample = static_cast(data[0]) | + (static_cast(data[1]) << 8) | + (static_cast(data[2]) << 16); + + if (sample & 0x00800000) { + sample |= ~0x00ffffff; + } + + return sample / 8388608.0f; + } + case 32: + return qFromLittleEndian(data) / 2147483648.0f; + default: + return 0.0f; + } +} + +bool AudioFileReader::seek(quint64 frameIndex) +{ + QMutexLocker locker(&m_mutex); + return seekUnlocked(frameIndex); +} + +bool AudioFileReader::seekUnlocked(quint64 frameIndex) +{ + if (!m_file.isOpen()) { + return false; + } + + frameIndex = std::min(frameIndex, m_frameCount); + const quint64 byteOffset = m_dataOffset + frameIndex * m_blockAlign; + + if (!m_file.seek(static_cast(byteOffset))) { + return false; + } + + m_position = frameIndex; + return true; +} + +bool AudioFileReader::isOpen() const +{ + QMutexLocker locker(&m_mutex); + return m_file.isOpen(); +} + +bool AudioFileReader::atEnd() const +{ + QMutexLocker locker(&m_mutex); + return !m_file.isOpen() || (m_position >= m_frameCount); +} + +quint32 AudioFileReader::getSampleRate() const +{ + QMutexLocker locker(&m_mutex); + return m_sampleRate; +} + +quint16 AudioFileReader::getChannelCount() const +{ + QMutexLocker locker(&m_mutex); + return m_channelCount; +} + +quint64 AudioFileReader::getFrameCount() const +{ + QMutexLocker locker(&m_mutex); + return m_frameCount; +} + +quint64 AudioFileReader::getPosition() const +{ + QMutexLocker locker(&m_mutex); + return m_position; +} + +QString AudioFileReader::getErrorString() const +{ + QMutexLocker locker(&m_mutex); + return m_errorString; +} diff --git a/sdrbase/audio/audiofilereader.h b/sdrbase/audio/audiofilereader.h new file mode 100644 index 000000000..705b7c558 --- /dev/null +++ b/sdrbase/audio/audiofilereader.h @@ -0,0 +1,101 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_AUDIOFILEREADER_H +#define INCLUDE_AUDIOFILEREADER_H + +#include +#include +#include +#include +#include + +#include "export.h" + +/** + * Reads audio frames from SDRangel's legacy F32LE raw format or from a WAV file. + * + * Raw files are interpreted as mono, 48 kHz, 32-bit little-endian float samples. + * WAV files may contain one or two channels of 8/16/24/32-bit PCM or 32/64-bit + * IEEE floating-point samples. Samples are returned as normalized floats and a + * mono input is copied to both output channels. + * + * Files are accessed with QFile, so names returned by the Android file picker + * can be opened. All methods are thread safe. + */ +class SDRBASE_API AudioFileReader +{ +public: + AudioFileReader(); + ~AudioFileReader(); + + bool open(const QString& fileName); + void close(); + + bool readFrame(float& left, float& right); + bool seek(quint64 frameIndex); + bool rewind() { return seek(0); } + + bool isOpen() const; + bool atEnd() const; + quint32 getSampleRate() const; + quint16 getChannelCount() const; + quint64 getFrameCount() const; + quint64 getPosition() const; + QString getErrorString() const; + +private: + enum FileType + { + FileTypeNone, + FileTypeRawFloat32, + FileTypeWav + }; + + enum WavFormat + { + WavFormatPCM = 1, + WavFormatIEEEFloat = 3, + WavFormatExtensible = 0xfffe + }; + + mutable QMutex m_mutex; + QFile m_file; + FileType m_fileType; + quint16 m_wavFormat; + quint16 m_channelCount; + quint16 m_bitsPerSample; + quint16 m_blockAlign; + quint32 m_sampleRate; + quint64 m_dataOffset; + quint64 m_dataSize; + quint64 m_frameCount; + quint64 m_position; + QByteArray m_frameBuffer; + QString m_errorString; + + void closeUnlocked(); + bool openRawUnlocked(quint64 fileSize); + bool openWavUnlocked(quint64 fileSize); + bool failUnlocked(const QString& error); + bool seekUnlocked(quint64 frameIndex); + bool readExact(char *data, qint64 size); + float decodeSample(const uchar *data) const; +}; + +#endif // INCLUDE_AUDIOFILEREADER_H diff --git a/sdrbase/resources/webapi.qrc b/sdrbase/resources/webapi.qrc index fabfc0479..ed90c421f 100644 --- a/sdrbase/resources/webapi.qrc +++ b/sdrbase/resources/webapi.qrc @@ -24,6 +24,7 @@ webapi/doc/swagger/include/AudioOutput.yaml webapi/doc/swagger/include/BeamSteeringCWMod.yaml webapi/doc/swagger/include/BFMDemod.yaml + webapi/doc/swagger/include/BFMMod.yaml webapi/doc/swagger/include/BladeRF1.yaml webapi/doc/swagger/include/BladeRF2.yaml webapi/doc/swagger/include/ChannelActions.yaml diff --git a/sdrbase/resources/webapi/doc/swagger/include/BFMMod.yaml b/sdrbase/resources/webapi/doc/swagger/include/BFMMod.yaml new file mode 100644 index 000000000..2415691bd --- /dev/null +++ b/sdrbase/resources/webapi/doc/swagger/include/BFMMod.yaml @@ -0,0 +1,154 @@ +BFMModSettings: + description: BFMMod + properties: + inputFrequencyOffset: + type: integer + format: int64 + description: "Channel frequency offset from the device center frequency in Hz." + rfBandwidth: + type: number + format: float + description: "RF bandwidth in Hz (150000 to 300000)." + afBandwidth: + type: number + format: float + description: "Audio-frequency bandwidth in Hz (1000 to 15000)." + fmDeviation: + type: number + format: float + description: "FM frequency deviation in Hz." + toneFrequency: + type: number + format: float + description: "Tone frequency in Hz." + volumeFactor: + type: number + format: float + description: "Volume factor setting for Broadcast FM mod." + audioStereo: + type: integer + minimum: 0 + maximum: 1 + description: "Generate the 19 kHz pilot and 38 kHz stereo difference signal." + preEmphasis: + type: integer + minimum: 0 + maximum: 2 + description: "Pre-emphasis: 0 off, 1 50 microseconds, 2 75 microseconds." + pilotLevel: + type: number + format: float + minimum: 0 + maximum: 0.2 + description: "Stereo pilot amplitude relative to maximum multiplex amplitude." + rdsActive: + type: integer + minimum: 0 + maximum: 1 + description: "Enable the 57 kHz RDS subcarrier." + rdsLevel: + type: number + format: float + minimum: 0 + maximum: 0.1 + description: "RDS subcarrier amplitude relative to maximum multiplex amplitude." + rdsPI: + type: integer + minimum: 0 + maximum: 65535 + description: "RDS programme identification code." + rdsPTY: + type: integer + minimum: 0 + maximum: 31 + description: "RDS programme type." + rdsPS: + type: string + maxLength: 8 + description: "RDS programme service name, up to 8 characters." + rdsRadioText: + type: string + maxLength: 64 + description: "RDS RadioText, up to 64 characters." + channelMute: + type: integer + description: "Mute the channel output (1 muted, 0 unmuted)." + minimum: 0 + maximum: 1 + playLoop: + type: integer + description: "Loop playback at end of file (1 enabled, 0 disabled)." + minimum: 0 + maximum: 1 + rgbColor: + type: integer + description: "Display color encoded as an RGB integer." + title: + type: string + description: "User-visible title." + audioDeviceName: + type: string + description: "Name of the audio device to use." + feedbackAudioDeviceName: + type: string + description: "Name of the audio output device used for audio feedback." + feedbackVolumeFactor: + type: number + format: float + description: "Audio feedback volume factor." + fileName: + type: string + description: "WAV or raw audio file played when modAFInput selects the file input." + feedbackAudioEnable: + type: integer + minimum: 0 + maximum: 1 + description: "Enable audio feedback (1 enabled, 0 disabled)." + modAFInput: + type: integer + description: "Audio-frequency modulation input selection." + streamIndex: + description: MIMO channel. Not relevant when connected to SI (single Rx). + type: integer + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + minimum: 0 + maximum: 1 + reverseAPIAddress: + type: string + description: "IPv4 address or host name of the reverse API peer." + reverseAPIPort: + type: integer + description: "TCP port of the reverse API peer." + minimum: 1 + maximum: 65535 + reverseAPIDeviceIndex: + type: integer + description: "Device-set index used by the reverse API peer." + reverseAPIChannelIndex: + type: integer + description: "Channel index used by the reverse API peer." + cwKeyer: + $ref: "/doc/swagger/include/CWKeyer.yaml#/CWKeyerSettings" + description: "CW keyer configuration." + channelMarker: + $ref: "/doc/swagger/include/ChannelMarker.yaml#/ChannelMarker" + description: "Channel-marker display configuration." + rollupState: + $ref: "/doc/swagger/include/RollupState.yaml#/RollupState" + description: "Saved expanded or collapsed state of the GUI sections." + +BFMModReport: + description: BFMMod + properties: + channelPowerDB: + description: power transmitted in channel (dB) + type: number + format: float + audioSampleRate: + type: integer + description: "Audio sample rate in samples per second." + channelSampleRate: + type: integer + description: "Effective sample rate delivered to the channel in samples per second." diff --git a/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml b/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml index ebfbf089b..2613080d0 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml @@ -37,6 +37,9 @@ ChannelReport: BFMDemodReport: $ref: "/doc/swagger/include/BFMDemod.yaml#/BFMDemodReport" description: "BFM demod report data for Channel." + BFMModReport: + $ref: "/doc/swagger/include/BFMMod.yaml#/BFMModReport" + description: "Broadcast FM mod report data for Channel." DABDemodReport: $ref: "/doc/swagger/include/DABDemod.yaml#/DABDemodReport" description: "DAB demod report data for Channel." diff --git a/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml b/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml index bd68fb1fa..8b2afcffb 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml @@ -52,6 +52,9 @@ ChannelSettings: BFMDemodSettings: $ref: "/doc/swagger/include/BFMDemod.yaml#/BFMDemodSettings" description: "BFM demod settings configuration for Channel." + BFMModSettings: + $ref: "/doc/swagger/include/BFMMod.yaml#/BFMModSettings" + description: "Broadcast FM mod settings configuration for Channel." ChannelAnalyzerSettings: $ref: "/doc/swagger/include/ChannelAnalyzer.yaml#/ChannelAnalyzerSettings" description: "Channel analyzer settings configuration for Channel." diff --git a/sdrbase/util/rds.cpp b/sdrbase/util/rds.cpp new file mode 100644 index 000000000..04f69fb42 --- /dev/null +++ b/sdrbase/util/rds.cpp @@ -0,0 +1,56 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015-2019, 2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2016 Ziga S // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "rds.h" + +/* page 77, Annex F in the standard */ +const char * const RDS::m_programmeTypes[RDS::m_nbProgrammeTypes] = { + "None", + "News", + "Current Affairs", + "Information", + "Sport", + "Education", + "Drama", + "Cultures", + "Science", + "Varied Speech", + "Pop Music", + "Rock Music", + "Easy Listening", + "Light Classics M", + "Serious Classics", + "Other Music", + "Weather & Metr", + "Finance", + "Children’s Progs", + "Social Affairs", + "Religion", + "Phone In", + "Travel & Touring", + "Leisure & Hobby", + "Jazz Music", + "Country Music", + "National Music", + "Oldies Music", + "Folk Music", + "Documentary", + "Alarm Test", + "Alarm-Alarm!" +}; diff --git a/sdrbase/util/rds.h b/sdrbase/util/rds.h new file mode 100644 index 000000000..c0de1c70a --- /dev/null +++ b/sdrbase/util/rds.h @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015-2019, 2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2016 Ziga S // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_UTIL_RDS_H +#define INCLUDE_UTIL_RDS_H + +#include "export.h" + +// Radio Data System definitions shared by the broadcast FM modulator and demodulator +struct SDRBASE_API RDS +{ + static const int m_nbProgrammeTypes = 32; + static const char * const m_programmeTypes[m_nbProgrammeTypes]; //!< Programme type (PTY) names, indexed by code. UTF-8. +}; + +#endif // INCLUDE_UTIL_RDS_H diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 4e2f05646..8c4a948c1 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -4918,6 +4918,12 @@ bool WebAPIRequestMapper::getChannelSettings( channelSettings->getBfmDemodSettings()->init(); channelSettings->getBfmDemodSettings()->fromJsonObject(settingsJsonObject); } + else if (channelSettingsKey == "BFMModSettings") + { + channelSettings->setBfmModSettings(new SWGSDRangel::SWGBFMModSettings()); + channelSettings->getBfmModSettings()->init(); + channelSettings->getBfmModSettings()->fromJsonObject(settingsJsonObject); + } else if (channelSettingsKey == "ChannelAnalyzerSettings") { channelSettings->setChannelAnalyzerSettings(new SWGSDRangel::SWGChannelAnalyzerSettings()); @@ -6066,6 +6072,7 @@ void WebAPIRequestMapper::resetChannelSettings(SWGSDRangel::SWGChannelSettings& channelSettings.setWefaxDemodSettings(nullptr); channelSettings.setAtvModSettings(nullptr); channelSettings.setBfmDemodSettings(nullptr); + channelSettings.setBfmModSettings(nullptr); channelSettings.setChannelPowerSettings(nullptr); channelSettings.setDatvModSettings(nullptr); channelSettings.setDabDemodSettings(nullptr); @@ -6115,6 +6122,7 @@ void WebAPIRequestMapper::resetChannelReport(SWGSDRangel::SWGChannelReport& chan channelReport.setAmModReport(nullptr); channelReport.setAtvModReport(nullptr); channelReport.setBfmDemodReport(nullptr); + channelReport.setBfmModReport(nullptr); channelReport.setChannelPowerReport(nullptr); channelReport.setDatvModReport(nullptr); channelReport.setDsdDemodReport(nullptr); diff --git a/sdrbase/webapi/webapiutils.cpp b/sdrbase/webapi/webapiutils.cpp index 4183a7588..ecdd1ad7d 100644 --- a/sdrbase/webapi/webapiutils.cpp +++ b/sdrbase/webapi/webapiutils.cpp @@ -97,6 +97,7 @@ const QMap WebAPIUtils::m_channelURIToSettingsKey = { {"sdrangel.channel.wfmdemod", "WFMDemodSettings"}, {"de.maintech.sdrangelove.channel.wfm", "WFMDemodSettings"}, // remap {"sdrangel.channeltx.modwfm", "WFMModSettings"}, + {"sdrangel.channeltx.modbfm", "BFMModSettings"}, {"sdrangel.channel.beamsteeringcwmod", "BeamSteeringCWModSettings"}, {"sdrangel.channelmimo.interferometer", "InterferometerSettings"}, {"sdrangel.channel.sigmffilesink", "SigMFFileSinkSettings"} @@ -221,6 +222,7 @@ const QMap WebAPIUtils::m_channelTypeToSettingsKey = { {"VORDemod", "VORDemodSettings"}, {"WFMDemod", "WFMDemodSettings"}, {"WFMMod", "WFMModSettings"}, + {"BFMMod", "BFMModSettings"}, {"BeamSteeringCWMod", "BeamSteeringCWModSettings"}, {"Interferometer", "InterferometerSettings"}, {"SigMFFileSink", "SigMFFileSinkSettings"} diff --git a/swagger/sdrangel/api/swagger/include/BFMMod.yaml b/swagger/sdrangel/api/swagger/include/BFMMod.yaml new file mode 100644 index 000000000..ed51f3151 --- /dev/null +++ b/swagger/sdrangel/api/swagger/include/BFMMod.yaml @@ -0,0 +1,154 @@ +BFMModSettings: + description: BFMMod + properties: + inputFrequencyOffset: + type: integer + format: int64 + description: "Channel frequency offset from the device center frequency in Hz." + rfBandwidth: + type: number + format: float + description: "RF bandwidth in Hz (150000 to 300000)." + afBandwidth: + type: number + format: float + description: "Audio-frequency bandwidth in Hz (1000 to 15000)." + fmDeviation: + type: number + format: float + description: "FM frequency deviation in Hz." + toneFrequency: + type: number + format: float + description: "Tone frequency in Hz." + volumeFactor: + type: number + format: float + description: "Volume factor setting for Broadcast FM mod." + audioStereo: + type: integer + minimum: 0 + maximum: 1 + description: "Generate the 19 kHz pilot and 38 kHz stereo difference signal." + preEmphasis: + type: integer + minimum: 0 + maximum: 2 + description: "Pre-emphasis: 0 off, 1 50 microseconds, 2 75 microseconds." + pilotLevel: + type: number + format: float + minimum: 0 + maximum: 0.2 + description: "Stereo pilot amplitude relative to maximum multiplex amplitude." + rdsActive: + type: integer + minimum: 0 + maximum: 1 + description: "Enable the 57 kHz RDS subcarrier." + rdsLevel: + type: number + format: float + minimum: 0 + maximum: 0.1 + description: "RDS subcarrier amplitude relative to maximum multiplex amplitude." + rdsPI: + type: integer + minimum: 0 + maximum: 65535 + description: "RDS programme identification code." + rdsPTY: + type: integer + minimum: 0 + maximum: 31 + description: "RDS programme type." + rdsPS: + type: string + maxLength: 8 + description: "RDS programme service name, up to 8 characters." + rdsRadioText: + type: string + maxLength: 64 + description: "RDS RadioText, up to 64 characters." + channelMute: + type: integer + description: "Mute the channel output (1 muted, 0 unmuted)." + minimum: 0 + maximum: 1 + playLoop: + type: integer + description: "Loop playback at end of file (1 enabled, 0 disabled)." + minimum: 0 + maximum: 1 + rgbColor: + type: integer + description: "Display color encoded as an RGB integer." + title: + type: string + description: "User-visible title." + audioDeviceName: + type: string + description: "Name of the audio device to use." + feedbackAudioDeviceName: + type: string + description: "Name of the audio output device used for audio feedback." + feedbackVolumeFactor: + type: number + format: float + description: "Audio feedback volume factor." + fileName: + type: string + description: "WAV or raw audio file played when modAFInput selects the file input." + feedbackAudioEnable: + type: integer + minimum: 0 + maximum: 1 + description: "Enable audio feedback (1 enabled, 0 disabled)." + modAFInput: + type: integer + description: "Audio-frequency modulation input selection." + streamIndex: + description: MIMO channel. Not relevant when connected to SI (single Rx). + type: integer + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + minimum: 0 + maximum: 1 + reverseAPIAddress: + type: string + description: "IPv4 address or host name of the reverse API peer." + reverseAPIPort: + type: integer + description: "TCP port of the reverse API peer." + minimum: 1 + maximum: 65535 + reverseAPIDeviceIndex: + type: integer + description: "Device-set index used by the reverse API peer." + reverseAPIChannelIndex: + type: integer + description: "Channel index used by the reverse API peer." + cwKeyer: + $ref: "http://swgserver:8081/api/swagger/include/CWKeyer.yaml#/CWKeyerSettings" + description: "CW keyer configuration." + channelMarker: + $ref: "http://swgserver:8081/api/swagger/include/ChannelMarker.yaml#/ChannelMarker" + description: "Channel-marker display configuration." + rollupState: + $ref: "http://swgserver:8081/api/swagger/include/RollupState.yaml#/RollupState" + description: "Saved expanded or collapsed state of the GUI sections." + +BFMModReport: + description: BFMMod + properties: + channelPowerDB: + description: power transmitted in channel (dB) + type: number + format: float + audioSampleRate: + type: integer + description: "Audio sample rate in samples per second." + channelSampleRate: + type: integer + description: "Effective sample rate delivered to the channel in samples per second." diff --git a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml index 64c11a20f..70910ad28 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml @@ -37,6 +37,9 @@ ChannelReport: BFMDemodReport: $ref: "http://swgserver:8081/api/swagger/include/BFMDemod.yaml#/BFMDemodReport" description: "BFM demod report data for Channel." + BFMModReport: + $ref: "http://swgserver:8081/api/swagger/include/BFMMod.yaml#/BFMModReport" + description: "Broadcast FM mod report data for Channel." DABDemodReport: $ref: "http://swgserver:8081/api/swagger/include/DABDemod.yaml#/DABDemodReport" description: "DAB demod report data for Channel." diff --git a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml index 63dc30c4b..97e8468cb 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml @@ -52,6 +52,9 @@ ChannelSettings: BFMDemodSettings: $ref: "http://swgserver:8081/api/swagger/include/BFMDemod.yaml#/BFMDemodSettings" description: "BFM demod settings configuration for Channel." + BFMModSettings: + $ref: "http://swgserver:8081/api/swagger/include/BFMMod.yaml#/BFMModSettings" + description: "Broadcast FM mod settings configuration for Channel." ChannelAnalyzerSettings: $ref: "http://swgserver:8081/api/swagger/include/ChannelAnalyzer.yaml#/ChannelAnalyzerSettings" description: "Channel analyzer settings configuration for Channel." diff --git a/swagger/sdrangel/code/qt5/client/SWGBFMModReport.cpp b/swagger/sdrangel/code/qt5/client/SWGBFMModReport.cpp new file mode 100644 index 000000000..0511d6368 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGBFMModReport.cpp @@ -0,0 +1,155 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 7.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include "SWGBFMModReport.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGBFMModReport::SWGBFMModReport(QString* json) { + init(); + this->fromJson(*json); +} + +SWGBFMModReport::SWGBFMModReport() { + channel_power_db = 0.0f; + m_channel_power_db_isSet = false; + audio_sample_rate = 0; + m_audio_sample_rate_isSet = false; + channel_sample_rate = 0; + m_channel_sample_rate_isSet = false; +} + +SWGBFMModReport::~SWGBFMModReport() { + this->cleanup(); +} + +void +SWGBFMModReport::init() { + channel_power_db = 0.0f; + m_channel_power_db_isSet = false; + audio_sample_rate = 0; + m_audio_sample_rate_isSet = false; + channel_sample_rate = 0; + m_channel_sample_rate_isSet = false; +} + +void +SWGBFMModReport::cleanup() { + + + +} + +SWGBFMModReport* +SWGBFMModReport::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGBFMModReport::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&channel_power_db, pJson["channelPowerDB"], "float", ""); + + ::SWGSDRangel::setValue(&audio_sample_rate, pJson["audioSampleRate"], "qint32", ""); + + ::SWGSDRangel::setValue(&channel_sample_rate, pJson["channelSampleRate"], "qint32", ""); + +} + +QString +SWGBFMModReport::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGBFMModReport::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_channel_power_db_isSet){ + obj->insert("channelPowerDB", QJsonValue(channel_power_db)); + } + if(m_audio_sample_rate_isSet){ + obj->insert("audioSampleRate", QJsonValue(audio_sample_rate)); + } + if(m_channel_sample_rate_isSet){ + obj->insert("channelSampleRate", QJsonValue(channel_sample_rate)); + } + + return obj; +} + +float +SWGBFMModReport::getChannelPowerDb() { + return channel_power_db; +} +void +SWGBFMModReport::setChannelPowerDb(float channel_power_db) { + this->channel_power_db = channel_power_db; + this->m_channel_power_db_isSet = true; +} + +qint32 +SWGBFMModReport::getAudioSampleRate() { + return audio_sample_rate; +} +void +SWGBFMModReport::setAudioSampleRate(qint32 audio_sample_rate) { + this->audio_sample_rate = audio_sample_rate; + this->m_audio_sample_rate_isSet = true; +} + +qint32 +SWGBFMModReport::getChannelSampleRate() { + return channel_sample_rate; +} +void +SWGBFMModReport::setChannelSampleRate(qint32 channel_sample_rate) { + this->channel_sample_rate = channel_sample_rate; + this->m_channel_sample_rate_isSet = true; +} + + +bool +SWGBFMModReport::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_channel_power_db_isSet){ + isObjectUpdated = true; break; + } + if(m_audio_sample_rate_isSet){ + isObjectUpdated = true; break; + } + if(m_channel_sample_rate_isSet){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} + + diff --git a/swagger/sdrangel/code/qt5/client/SWGBFMModReport.h b/swagger/sdrangel/code/qt5/client/SWGBFMModReport.h new file mode 100644 index 000000000..f9a7a57d8 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGBFMModReport.h @@ -0,0 +1,71 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 7.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * SWGBFMModReport.h + * + * BFMMod + */ + +#ifndef SWGBFMModReport_H_ +#define SWGBFMModReport_H_ + +#include + + + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGBFMModReport: public SWGObject { +public: + SWGBFMModReport(); + SWGBFMModReport(QString* json); + virtual ~SWGBFMModReport(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGBFMModReport* fromJson(QString &jsonString) override; + + float getChannelPowerDb(); + void setChannelPowerDb(float channel_power_db); + + qint32 getAudioSampleRate(); + void setAudioSampleRate(qint32 audio_sample_rate); + + qint32 getChannelSampleRate(); + void setChannelSampleRate(qint32 channel_sample_rate); + + + virtual bool isSet() override; + +private: + float channel_power_db; + bool m_channel_power_db_isSet; + + qint32 audio_sample_rate; + bool m_audio_sample_rate_isSet; + + qint32 channel_sample_rate; + bool m_channel_sample_rate_isSet; + +}; + +} + +#endif /* SWGBFMModReport_H_ */ + diff --git a/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.cpp new file mode 100644 index 000000000..8f6032496 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.cpp @@ -0,0 +1,761 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 7.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include "SWGBFMModSettings.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGBFMModSettings::SWGBFMModSettings(QString* json) { + init(); + this->fromJson(*json); +} + +SWGBFMModSettings::SWGBFMModSettings() { + input_frequency_offset = 0L; + m_input_frequency_offset_isSet = false; + rf_bandwidth = 0.0f; + m_rf_bandwidth_isSet = false; + af_bandwidth = 0.0f; + m_af_bandwidth_isSet = false; + fm_deviation = 0.0f; + m_fm_deviation_isSet = false; + tone_frequency = 0.0f; + m_tone_frequency_isSet = false; + volume_factor = 0.0f; + m_volume_factor_isSet = false; + audio_stereo = 0; + m_audio_stereo_isSet = false; + pre_emphasis = 0; + m_pre_emphasis_isSet = false; + pilot_level = 0.0f; + m_pilot_level_isSet = false; + rds_active = 0; + m_rds_active_isSet = false; + rds_level = 0.0f; + m_rds_level_isSet = false; + rds_pi = 0; + m_rds_pi_isSet = false; + rds_pty = 0; + m_rds_pty_isSet = false; + rds_ps = nullptr; + m_rds_ps_isSet = false; + rds_radio_text = nullptr; + m_rds_radio_text_isSet = false; + channel_mute = 0; + m_channel_mute_isSet = false; + play_loop = 0; + m_play_loop_isSet = false; + rgb_color = 0; + m_rgb_color_isSet = false; + title = nullptr; + m_title_isSet = false; + audio_device_name = nullptr; + m_audio_device_name_isSet = false; + feedback_audio_device_name = nullptr; + m_feedback_audio_device_name_isSet = false; + feedback_volume_factor = 0.0f; + m_feedback_volume_factor_isSet = false; + feedback_audio_enable = 0; + m_feedback_audio_enable_isSet = false; + file_name = nullptr; + m_file_name_isSet = false; + mod_af_input = 0; + m_mod_af_input_isSet = false; + stream_index = 0; + m_stream_index_isSet = false; + use_reverse_api = 0; + m_use_reverse_api_isSet = false; + reverse_api_address = nullptr; + m_reverse_api_address_isSet = false; + reverse_api_port = 0; + m_reverse_api_port_isSet = false; + reverse_api_device_index = 0; + m_reverse_api_device_index_isSet = false; + reverse_api_channel_index = 0; + m_reverse_api_channel_index_isSet = false; + cw_keyer = nullptr; + m_cw_keyer_isSet = false; + channel_marker = nullptr; + m_channel_marker_isSet = false; + rollup_state = nullptr; + m_rollup_state_isSet = false; +} + +SWGBFMModSettings::~SWGBFMModSettings() { + this->cleanup(); +} + +void +SWGBFMModSettings::init() { + input_frequency_offset = 0L; + m_input_frequency_offset_isSet = false; + rf_bandwidth = 0.0f; + m_rf_bandwidth_isSet = false; + af_bandwidth = 0.0f; + m_af_bandwidth_isSet = false; + fm_deviation = 0.0f; + m_fm_deviation_isSet = false; + tone_frequency = 0.0f; + m_tone_frequency_isSet = false; + volume_factor = 0.0f; + m_volume_factor_isSet = false; + audio_stereo = 0; + m_audio_stereo_isSet = false; + pre_emphasis = 0; + m_pre_emphasis_isSet = false; + pilot_level = 0.0f; + m_pilot_level_isSet = false; + rds_active = 0; + m_rds_active_isSet = false; + rds_level = 0.0f; + m_rds_level_isSet = false; + rds_pi = 0; + m_rds_pi_isSet = false; + rds_pty = 0; + m_rds_pty_isSet = false; + rds_ps = new QString(""); + m_rds_ps_isSet = false; + rds_radio_text = new QString(""); + m_rds_radio_text_isSet = false; + channel_mute = 0; + m_channel_mute_isSet = false; + play_loop = 0; + m_play_loop_isSet = false; + rgb_color = 0; + m_rgb_color_isSet = false; + title = new QString(""); + m_title_isSet = false; + audio_device_name = new QString(""); + m_audio_device_name_isSet = false; + feedback_audio_device_name = new QString(""); + m_feedback_audio_device_name_isSet = false; + feedback_volume_factor = 0.0f; + m_feedback_volume_factor_isSet = false; + feedback_audio_enable = 0; + m_feedback_audio_enable_isSet = false; + file_name = new QString(""); + m_file_name_isSet = false; + mod_af_input = 0; + m_mod_af_input_isSet = false; + stream_index = 0; + m_stream_index_isSet = false; + use_reverse_api = 0; + m_use_reverse_api_isSet = false; + reverse_api_address = new QString(""); + m_reverse_api_address_isSet = false; + reverse_api_port = 0; + m_reverse_api_port_isSet = false; + reverse_api_device_index = 0; + m_reverse_api_device_index_isSet = false; + reverse_api_channel_index = 0; + m_reverse_api_channel_index_isSet = false; + cw_keyer = new SWGCWKeyerSettings(); + m_cw_keyer_isSet = false; + channel_marker = new SWGChannelMarker(); + m_channel_marker_isSet = false; + rollup_state = new SWGRollupState(); + m_rollup_state_isSet = false; +} + +void +SWGBFMModSettings::cleanup() { + + if(rds_ps != nullptr) { + delete rds_ps; + } + if(rds_radio_text != nullptr) { + delete rds_radio_text; + } + + + + + + + + + + if(title != nullptr) { + delete title; + } + if(audio_device_name != nullptr) { + delete audio_device_name; + } + if(feedback_audio_device_name != nullptr) { + delete feedback_audio_device_name; + } + if(file_name != nullptr) { + delete file_name; + } + + + + if(reverse_api_address != nullptr) { + delete reverse_api_address; + } + + + + if(cw_keyer != nullptr) { + delete cw_keyer; + } + if(channel_marker != nullptr) { + delete channel_marker; + } + if(rollup_state != nullptr) { + delete rollup_state; + } +} + +SWGBFMModSettings* +SWGBFMModSettings::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGBFMModSettings::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&input_frequency_offset, pJson["inputFrequencyOffset"], "qint64", ""); + + ::SWGSDRangel::setValue(&rf_bandwidth, pJson["rfBandwidth"], "float", ""); + + ::SWGSDRangel::setValue(&af_bandwidth, pJson["afBandwidth"], "float", ""); + + ::SWGSDRangel::setValue(&fm_deviation, pJson["fmDeviation"], "float", ""); + + ::SWGSDRangel::setValue(&tone_frequency, pJson["toneFrequency"], "float", ""); + + ::SWGSDRangel::setValue(&volume_factor, pJson["volumeFactor"], "float", ""); + ::SWGSDRangel::setValue(&audio_stereo, pJson["audioStereo"], "qint32", ""); + ::SWGSDRangel::setValue(&pre_emphasis, pJson["preEmphasis"], "qint32", ""); + ::SWGSDRangel::setValue(&pilot_level, pJson["pilotLevel"], "float", ""); + ::SWGSDRangel::setValue(&rds_active, pJson["rdsActive"], "qint32", ""); + ::SWGSDRangel::setValue(&rds_level, pJson["rdsLevel"], "float", ""); + ::SWGSDRangel::setValue(&rds_pi, pJson["rdsPI"], "qint32", ""); + ::SWGSDRangel::setValue(&rds_pty, pJson["rdsPTY"], "qint32", ""); + ::SWGSDRangel::setValue(&rds_ps, pJson["rdsPS"], "QString", "QString"); + ::SWGSDRangel::setValue(&rds_radio_text, pJson["rdsRadioText"], "QString", "QString"); + + ::SWGSDRangel::setValue(&channel_mute, pJson["channelMute"], "qint32", ""); + + ::SWGSDRangel::setValue(&play_loop, pJson["playLoop"], "qint32", ""); + + ::SWGSDRangel::setValue(&rgb_color, pJson["rgbColor"], "qint32", ""); + + ::SWGSDRangel::setValue(&title, pJson["title"], "QString", "QString"); + + ::SWGSDRangel::setValue(&audio_device_name, pJson["audioDeviceName"], "QString", "QString"); + + ::SWGSDRangel::setValue(&feedback_audio_device_name, pJson["feedbackAudioDeviceName"], "QString", "QString"); + + ::SWGSDRangel::setValue(&feedback_volume_factor, pJson["feedbackVolumeFactor"], "float", ""); + + ::SWGSDRangel::setValue(&feedback_audio_enable, pJson["feedbackAudioEnable"], "qint32", ""); + + ::SWGSDRangel::setValue(&file_name, pJson["fileName"], "QString", "QString"); + + ::SWGSDRangel::setValue(&mod_af_input, pJson["modAFInput"], "qint32", ""); + + ::SWGSDRangel::setValue(&stream_index, pJson["streamIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&use_reverse_api, pJson["useReverseAPI"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_address, pJson["reverseAPIAddress"], "QString", "QString"); + + ::SWGSDRangel::setValue(&reverse_api_port, pJson["reverseAPIPort"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_device_index, pJson["reverseAPIDeviceIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_channel_index, pJson["reverseAPIChannelIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&cw_keyer, pJson["cwKeyer"], "SWGCWKeyerSettings", "SWGCWKeyerSettings"); + + ::SWGSDRangel::setValue(&channel_marker, pJson["channelMarker"], "SWGChannelMarker", "SWGChannelMarker"); + + ::SWGSDRangel::setValue(&rollup_state, pJson["rollupState"], "SWGRollupState", "SWGRollupState"); + +} + +QString +SWGBFMModSettings::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGBFMModSettings::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_input_frequency_offset_isSet){ + obj->insert("inputFrequencyOffset", QJsonValue(input_frequency_offset)); + } + if(m_rf_bandwidth_isSet){ + obj->insert("rfBandwidth", QJsonValue(rf_bandwidth)); + } + if(m_af_bandwidth_isSet){ + obj->insert("afBandwidth", QJsonValue(af_bandwidth)); + } + if(m_fm_deviation_isSet){ + obj->insert("fmDeviation", QJsonValue(fm_deviation)); + } + if(m_tone_frequency_isSet){ + obj->insert("toneFrequency", QJsonValue(tone_frequency)); + } + if(m_volume_factor_isSet){ + obj->insert("volumeFactor", QJsonValue(volume_factor)); + } + if(m_audio_stereo_isSet){ obj->insert("audioStereo", QJsonValue(audio_stereo)); } + if(m_pre_emphasis_isSet){ obj->insert("preEmphasis", QJsonValue(pre_emphasis)); } + if(m_pilot_level_isSet){ obj->insert("pilotLevel", QJsonValue(pilot_level)); } + if(m_rds_active_isSet){ obj->insert("rdsActive", QJsonValue(rds_active)); } + if(m_rds_level_isSet){ obj->insert("rdsLevel", QJsonValue(rds_level)); } + if(m_rds_pi_isSet){ obj->insert("rdsPI", QJsonValue(rds_pi)); } + if(m_rds_pty_isSet){ obj->insert("rdsPTY", QJsonValue(rds_pty)); } + if(rds_ps != nullptr && *rds_ps != QString("")){ toJsonValue(QString("rdsPS"), rds_ps, obj, QString("QString")); } + if(rds_radio_text != nullptr && *rds_radio_text != QString("")){ toJsonValue(QString("rdsRadioText"), rds_radio_text, obj, QString("QString")); } + if(m_channel_mute_isSet){ + obj->insert("channelMute", QJsonValue(channel_mute)); + } + if(m_play_loop_isSet){ + obj->insert("playLoop", QJsonValue(play_loop)); + } + if(m_rgb_color_isSet){ + obj->insert("rgbColor", QJsonValue(rgb_color)); + } + if(title != nullptr && *title != QString("")){ + toJsonValue(QString("title"), title, obj, QString("QString")); + } + if(audio_device_name != nullptr && *audio_device_name != QString("")){ + toJsonValue(QString("audioDeviceName"), audio_device_name, obj, QString("QString")); + } + if(feedback_audio_device_name != nullptr && *feedback_audio_device_name != QString("")){ + toJsonValue(QString("feedbackAudioDeviceName"), feedback_audio_device_name, obj, QString("QString")); + } + if(m_feedback_volume_factor_isSet){ + obj->insert("feedbackVolumeFactor", QJsonValue(feedback_volume_factor)); + } + if(m_feedback_audio_enable_isSet){ + obj->insert("feedbackAudioEnable", QJsonValue(feedback_audio_enable)); + } + if(file_name != nullptr && m_file_name_isSet){ + toJsonValue(QString("fileName"), file_name, obj, QString("QString")); + } + if(m_mod_af_input_isSet){ + obj->insert("modAFInput", QJsonValue(mod_af_input)); + } + if(m_stream_index_isSet){ + obj->insert("streamIndex", QJsonValue(stream_index)); + } + if(m_use_reverse_api_isSet){ + obj->insert("useReverseAPI", QJsonValue(use_reverse_api)); + } + if(reverse_api_address != nullptr && *reverse_api_address != QString("")){ + toJsonValue(QString("reverseAPIAddress"), reverse_api_address, obj, QString("QString")); + } + if(m_reverse_api_port_isSet){ + obj->insert("reverseAPIPort", QJsonValue(reverse_api_port)); + } + if(m_reverse_api_device_index_isSet){ + obj->insert("reverseAPIDeviceIndex", QJsonValue(reverse_api_device_index)); + } + if(m_reverse_api_channel_index_isSet){ + obj->insert("reverseAPIChannelIndex", QJsonValue(reverse_api_channel_index)); + } + if((cw_keyer != nullptr) && (cw_keyer->isSet())){ + toJsonValue(QString("cwKeyer"), cw_keyer, obj, QString("SWGCWKeyerSettings")); + } + if((channel_marker != nullptr) && (channel_marker->isSet())){ + toJsonValue(QString("channelMarker"), channel_marker, obj, QString("SWGChannelMarker")); + } + if((rollup_state != nullptr) && (rollup_state->isSet())){ + toJsonValue(QString("rollupState"), rollup_state, obj, QString("SWGRollupState")); + } + + return obj; +} + +qint64 +SWGBFMModSettings::getInputFrequencyOffset() { + return input_frequency_offset; +} +void +SWGBFMModSettings::setInputFrequencyOffset(qint64 input_frequency_offset) { + this->input_frequency_offset = input_frequency_offset; + this->m_input_frequency_offset_isSet = true; +} + +float +SWGBFMModSettings::getRfBandwidth() { + return rf_bandwidth; +} +void +SWGBFMModSettings::setRfBandwidth(float rf_bandwidth) { + this->rf_bandwidth = rf_bandwidth; + this->m_rf_bandwidth_isSet = true; +} + +float +SWGBFMModSettings::getAfBandwidth() { + return af_bandwidth; +} +void +SWGBFMModSettings::setAfBandwidth(float af_bandwidth) { + this->af_bandwidth = af_bandwidth; + this->m_af_bandwidth_isSet = true; +} + +float +SWGBFMModSettings::getFmDeviation() { + return fm_deviation; +} +void +SWGBFMModSettings::setFmDeviation(float fm_deviation) { + this->fm_deviation = fm_deviation; + this->m_fm_deviation_isSet = true; +} + +float +SWGBFMModSettings::getToneFrequency() { + return tone_frequency; +} +void +SWGBFMModSettings::setToneFrequency(float tone_frequency) { + this->tone_frequency = tone_frequency; + this->m_tone_frequency_isSet = true; +} + +float +SWGBFMModSettings::getVolumeFactor() { + return volume_factor; +} +void +SWGBFMModSettings::setVolumeFactor(float volume_factor) { + this->volume_factor = volume_factor; + this->m_volume_factor_isSet = true; +} + +qint32 SWGBFMModSettings::getAudioStereo() { return audio_stereo; } +void SWGBFMModSettings::setAudioStereo(qint32 value) { audio_stereo = value; m_audio_stereo_isSet = true; } +qint32 SWGBFMModSettings::getPreEmphasis() { return pre_emphasis; } +void SWGBFMModSettings::setPreEmphasis(qint32 value) { pre_emphasis = value; m_pre_emphasis_isSet = true; } +float SWGBFMModSettings::getPilotLevel() { return pilot_level; } +void SWGBFMModSettings::setPilotLevel(float value) { pilot_level = value; m_pilot_level_isSet = true; } +qint32 SWGBFMModSettings::getRdsActive() { return rds_active; } +void SWGBFMModSettings::setRdsActive(qint32 value) { rds_active = value; m_rds_active_isSet = true; } +float SWGBFMModSettings::getRdsLevel() { return rds_level; } +void SWGBFMModSettings::setRdsLevel(float value) { rds_level = value; m_rds_level_isSet = true; } +qint32 SWGBFMModSettings::getRdsPi() { return rds_pi; } +void SWGBFMModSettings::setRdsPi(qint32 value) { rds_pi = value; m_rds_pi_isSet = true; } +qint32 SWGBFMModSettings::getRdsPty() { return rds_pty; } +void SWGBFMModSettings::setRdsPty(qint32 value) { rds_pty = value; m_rds_pty_isSet = true; } +QString* SWGBFMModSettings::getRdsPs() { return rds_ps; } +void SWGBFMModSettings::setRdsPs(QString* value) { rds_ps = value; m_rds_ps_isSet = true; } +QString* SWGBFMModSettings::getRdsRadioText() { return rds_radio_text; } +void SWGBFMModSettings::setRdsRadioText(QString* value) { rds_radio_text = value; m_rds_radio_text_isSet = true; } + +qint32 +SWGBFMModSettings::getChannelMute() { + return channel_mute; +} +void +SWGBFMModSettings::setChannelMute(qint32 channel_mute) { + this->channel_mute = channel_mute; + this->m_channel_mute_isSet = true; +} + +qint32 +SWGBFMModSettings::getPlayLoop() { + return play_loop; +} +void +SWGBFMModSettings::setPlayLoop(qint32 play_loop) { + this->play_loop = play_loop; + this->m_play_loop_isSet = true; +} + +qint32 +SWGBFMModSettings::getRgbColor() { + return rgb_color; +} +void +SWGBFMModSettings::setRgbColor(qint32 rgb_color) { + this->rgb_color = rgb_color; + this->m_rgb_color_isSet = true; +} + +QString* +SWGBFMModSettings::getTitle() { + return title; +} +void +SWGBFMModSettings::setTitle(QString* title) { + this->title = title; + this->m_title_isSet = true; +} + +QString* +SWGBFMModSettings::getAudioDeviceName() { + return audio_device_name; +} +void +SWGBFMModSettings::setAudioDeviceName(QString* audio_device_name) { + this->audio_device_name = audio_device_name; + this->m_audio_device_name_isSet = true; +} + +QString* +SWGBFMModSettings::getFeedbackAudioDeviceName() { + return feedback_audio_device_name; +} +void +SWGBFMModSettings::setFeedbackAudioDeviceName(QString* feedback_audio_device_name) { + this->feedback_audio_device_name = feedback_audio_device_name; + this->m_feedback_audio_device_name_isSet = true; +} + +float +SWGBFMModSettings::getFeedbackVolumeFactor() { + return feedback_volume_factor; +} +void +SWGBFMModSettings::setFeedbackVolumeFactor(float feedback_volume_factor) { + this->feedback_volume_factor = feedback_volume_factor; + this->m_feedback_volume_factor_isSet = true; +} + +qint32 +SWGBFMModSettings::getFeedbackAudioEnable() { + return feedback_audio_enable; +} +void +SWGBFMModSettings::setFeedbackAudioEnable(qint32 feedback_audio_enable) { + this->feedback_audio_enable = feedback_audio_enable; + this->m_feedback_audio_enable_isSet = true; +} + +QString* +SWGBFMModSettings::getFileName() { + return file_name; +} +void +SWGBFMModSettings::setFileName(QString* file_name) { + this->file_name = file_name; + this->m_file_name_isSet = true; +} + +qint32 +SWGBFMModSettings::getModAfInput() { + return mod_af_input; +} +void +SWGBFMModSettings::setModAfInput(qint32 mod_af_input) { + this->mod_af_input = mod_af_input; + this->m_mod_af_input_isSet = true; +} + +qint32 +SWGBFMModSettings::getStreamIndex() { + return stream_index; +} +void +SWGBFMModSettings::setStreamIndex(qint32 stream_index) { + this->stream_index = stream_index; + this->m_stream_index_isSet = true; +} + +qint32 +SWGBFMModSettings::getUseReverseApi() { + return use_reverse_api; +} +void +SWGBFMModSettings::setUseReverseApi(qint32 use_reverse_api) { + this->use_reverse_api = use_reverse_api; + this->m_use_reverse_api_isSet = true; +} + +QString* +SWGBFMModSettings::getReverseApiAddress() { + return reverse_api_address; +} +void +SWGBFMModSettings::setReverseApiAddress(QString* reverse_api_address) { + this->reverse_api_address = reverse_api_address; + this->m_reverse_api_address_isSet = true; +} + +qint32 +SWGBFMModSettings::getReverseApiPort() { + return reverse_api_port; +} +void +SWGBFMModSettings::setReverseApiPort(qint32 reverse_api_port) { + this->reverse_api_port = reverse_api_port; + this->m_reverse_api_port_isSet = true; +} + +qint32 +SWGBFMModSettings::getReverseApiDeviceIndex() { + return reverse_api_device_index; +} +void +SWGBFMModSettings::setReverseApiDeviceIndex(qint32 reverse_api_device_index) { + this->reverse_api_device_index = reverse_api_device_index; + this->m_reverse_api_device_index_isSet = true; +} + +qint32 +SWGBFMModSettings::getReverseApiChannelIndex() { + return reverse_api_channel_index; +} +void +SWGBFMModSettings::setReverseApiChannelIndex(qint32 reverse_api_channel_index) { + this->reverse_api_channel_index = reverse_api_channel_index; + this->m_reverse_api_channel_index_isSet = true; +} + +SWGCWKeyerSettings* +SWGBFMModSettings::getCwKeyer() { + return cw_keyer; +} +void +SWGBFMModSettings::setCwKeyer(SWGCWKeyerSettings* cw_keyer) { + this->cw_keyer = cw_keyer; + this->m_cw_keyer_isSet = true; +} + +SWGChannelMarker* +SWGBFMModSettings::getChannelMarker() { + return channel_marker; +} +void +SWGBFMModSettings::setChannelMarker(SWGChannelMarker* channel_marker) { + this->channel_marker = channel_marker; + this->m_channel_marker_isSet = true; +} + +SWGRollupState* +SWGBFMModSettings::getRollupState() { + return rollup_state; +} +void +SWGBFMModSettings::setRollupState(SWGRollupState* rollup_state) { + this->rollup_state = rollup_state; + this->m_rollup_state_isSet = true; +} + + +bool +SWGBFMModSettings::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_input_frequency_offset_isSet){ + isObjectUpdated = true; break; + } + if(m_rf_bandwidth_isSet){ + isObjectUpdated = true; break; + } + if(m_af_bandwidth_isSet){ + isObjectUpdated = true; break; + } + if(m_fm_deviation_isSet){ + isObjectUpdated = true; break; + } + if(m_tone_frequency_isSet){ + isObjectUpdated = true; break; + } + if(m_volume_factor_isSet){ + isObjectUpdated = true; break; + } + if(m_audio_stereo_isSet || m_pre_emphasis_isSet || m_pilot_level_isSet + || m_rds_active_isSet || m_rds_level_isSet || m_rds_pi_isSet || m_rds_pty_isSet){ + isObjectUpdated = true; break; + } + if((rds_ps && *rds_ps != QString("")) || (rds_radio_text && *rds_radio_text != QString(""))){ + isObjectUpdated = true; break; + } + if(m_channel_mute_isSet){ + isObjectUpdated = true; break; + } + if(m_play_loop_isSet){ + isObjectUpdated = true; break; + } + if(m_rgb_color_isSet){ + isObjectUpdated = true; break; + } + if(title && *title != QString("")){ + isObjectUpdated = true; break; + } + if(audio_device_name && *audio_device_name != QString("")){ + isObjectUpdated = true; break; + } + if(feedback_audio_device_name && *feedback_audio_device_name != QString("")){ + isObjectUpdated = true; break; + } + if(m_feedback_volume_factor_isSet){ + isObjectUpdated = true; break; + } + if(m_feedback_audio_enable_isSet){ + isObjectUpdated = true; break; + } + if(file_name && m_file_name_isSet){ + isObjectUpdated = true; break; + } + if(m_mod_af_input_isSet){ + isObjectUpdated = true; break; + } + if(m_stream_index_isSet){ + isObjectUpdated = true; break; + } + if(m_use_reverse_api_isSet){ + isObjectUpdated = true; break; + } + if(reverse_api_address && *reverse_api_address != QString("")){ + isObjectUpdated = true; break; + } + if(m_reverse_api_port_isSet){ + isObjectUpdated = true; break; + } + if(m_reverse_api_device_index_isSet){ + isObjectUpdated = true; break; + } + if(m_reverse_api_channel_index_isSet){ + isObjectUpdated = true; break; + } + if(cw_keyer && cw_keyer->isSet()){ + isObjectUpdated = true; break; + } + if(channel_marker && channel_marker->isSet()){ + isObjectUpdated = true; break; + } + if(rollup_state && rollup_state->isSet()){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} + diff --git a/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.h b/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.h new file mode 100644 index 000000000..239d09e3d --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGBFMModSettings.h @@ -0,0 +1,252 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 7.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * SWGBFMModSettings.h + * + * BFMMod + */ + +#ifndef SWGBFMModSettings_H_ +#define SWGBFMModSettings_H_ + +#include + + +#include "SWGCWKeyerSettings.h" +#include "SWGChannelMarker.h" +#include "SWGRollupState.h" +#include + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGBFMModSettings: public SWGObject { +public: + SWGBFMModSettings(); + SWGBFMModSettings(QString* json); + virtual ~SWGBFMModSettings(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGBFMModSettings* fromJson(QString &jsonString) override; + + qint64 getInputFrequencyOffset(); + void setInputFrequencyOffset(qint64 input_frequency_offset); + + float getRfBandwidth(); + void setRfBandwidth(float rf_bandwidth); + + float getAfBandwidth(); + void setAfBandwidth(float af_bandwidth); + + float getFmDeviation(); + void setFmDeviation(float fm_deviation); + + float getToneFrequency(); + void setToneFrequency(float tone_frequency); + + float getVolumeFactor(); + void setVolumeFactor(float volume_factor); + + qint32 getAudioStereo(); + void setAudioStereo(qint32 audio_stereo); + + qint32 getPreEmphasis(); + void setPreEmphasis(qint32 pre_emphasis); + + float getPilotLevel(); + void setPilotLevel(float pilot_level); + + qint32 getRdsActive(); + void setRdsActive(qint32 rds_active); + + float getRdsLevel(); + void setRdsLevel(float rds_level); + + qint32 getRdsPi(); + void setRdsPi(qint32 rds_pi); + + qint32 getRdsPty(); + void setRdsPty(qint32 rds_pty); + + QString* getRdsPs(); + void setRdsPs(QString* rds_ps); + + QString* getRdsRadioText(); + void setRdsRadioText(QString* rds_radio_text); + + qint32 getChannelMute(); + void setChannelMute(qint32 channel_mute); + + qint32 getPlayLoop(); + void setPlayLoop(qint32 play_loop); + + qint32 getRgbColor(); + void setRgbColor(qint32 rgb_color); + + QString* getTitle(); + void setTitle(QString* title); + + QString* getAudioDeviceName(); + void setAudioDeviceName(QString* audio_device_name); + + QString* getFeedbackAudioDeviceName(); + void setFeedbackAudioDeviceName(QString* feedback_audio_device_name); + + float getFeedbackVolumeFactor(); + void setFeedbackVolumeFactor(float feedback_volume_factor); + + qint32 getFeedbackAudioEnable(); + void setFeedbackAudioEnable(qint32 feedback_audio_enable); + + QString* getFileName(); + void setFileName(QString* file_name); + + qint32 getModAfInput(); + void setModAfInput(qint32 mod_af_input); + + qint32 getStreamIndex(); + void setStreamIndex(qint32 stream_index); + + qint32 getUseReverseApi(); + void setUseReverseApi(qint32 use_reverse_api); + + QString* getReverseApiAddress(); + void setReverseApiAddress(QString* reverse_api_address); + + qint32 getReverseApiPort(); + void setReverseApiPort(qint32 reverse_api_port); + + qint32 getReverseApiDeviceIndex(); + void setReverseApiDeviceIndex(qint32 reverse_api_device_index); + + qint32 getReverseApiChannelIndex(); + void setReverseApiChannelIndex(qint32 reverse_api_channel_index); + + SWGCWKeyerSettings* getCwKeyer(); + void setCwKeyer(SWGCWKeyerSettings* cw_keyer); + + SWGChannelMarker* getChannelMarker(); + void setChannelMarker(SWGChannelMarker* channel_marker); + + SWGRollupState* getRollupState(); + void setRollupState(SWGRollupState* rollup_state); + + + virtual bool isSet() override; + +private: + qint64 input_frequency_offset; + bool m_input_frequency_offset_isSet; + + float rf_bandwidth; + bool m_rf_bandwidth_isSet; + + float af_bandwidth; + bool m_af_bandwidth_isSet; + + float fm_deviation; + bool m_fm_deviation_isSet; + + float tone_frequency; + bool m_tone_frequency_isSet; + + float volume_factor; + bool m_volume_factor_isSet; + + qint32 audio_stereo; + bool m_audio_stereo_isSet; + qint32 pre_emphasis; + bool m_pre_emphasis_isSet; + float pilot_level; + bool m_pilot_level_isSet; + qint32 rds_active; + bool m_rds_active_isSet; + float rds_level; + bool m_rds_level_isSet; + qint32 rds_pi; + bool m_rds_pi_isSet; + qint32 rds_pty; + bool m_rds_pty_isSet; + QString* rds_ps; + bool m_rds_ps_isSet; + QString* rds_radio_text; + bool m_rds_radio_text_isSet; + + qint32 channel_mute; + bool m_channel_mute_isSet; + + qint32 play_loop; + bool m_play_loop_isSet; + + qint32 rgb_color; + bool m_rgb_color_isSet; + + QString* title; + bool m_title_isSet; + + QString* audio_device_name; + bool m_audio_device_name_isSet; + + QString* feedback_audio_device_name; + bool m_feedback_audio_device_name_isSet; + + float feedback_volume_factor; + bool m_feedback_volume_factor_isSet; + + qint32 feedback_audio_enable; + bool m_feedback_audio_enable_isSet; + + QString* file_name; + bool m_file_name_isSet; + + qint32 mod_af_input; + bool m_mod_af_input_isSet; + + qint32 stream_index; + bool m_stream_index_isSet; + + qint32 use_reverse_api; + bool m_use_reverse_api_isSet; + + QString* reverse_api_address; + bool m_reverse_api_address_isSet; + + qint32 reverse_api_port; + bool m_reverse_api_port_isSet; + + qint32 reverse_api_device_index; + bool m_reverse_api_device_index_isSet; + + qint32 reverse_api_channel_index; + bool m_reverse_api_channel_index_isSet; + + SWGCWKeyerSettings* cw_keyer; + bool m_cw_keyer_isSet; + + SWGChannelMarker* channel_marker; + bool m_channel_marker_isSet; + + SWGRollupState* rollup_state; + bool m_rollup_state_isSet; + +}; + +} + +#endif /* SWGBFMModSettings_H_ */ diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp b/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp index ee5a62885..1acd54ea8 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp @@ -48,6 +48,8 @@ SWGChannelReport::SWGChannelReport() { m_atv_mod_report_isSet = false; bfm_demod_report = nullptr; m_bfm_demod_report_isSet = false; + bfm_mod_report = nullptr; + m_bfm_mod_report_isSet = false; dab_demod_report = nullptr; m_dab_demod_report_isSet = false; channel_power_report = nullptr; @@ -178,6 +180,8 @@ SWGChannelReport::init() { m_atv_mod_report_isSet = false; bfm_demod_report = new SWGBFMDemodReport(); m_bfm_demod_report_isSet = false; + bfm_mod_report = new SWGBFMModReport(); + m_bfm_mod_report_isSet = false; dab_demod_report = new SWGDABDemodReport(); m_dab_demod_report_isSet = false; channel_power_report = new SWGChannelPowerReport(); @@ -312,6 +316,9 @@ SWGChannelReport::cleanup() { if(bfm_demod_report != nullptr) { delete bfm_demod_report; } + if(bfm_mod_report != nullptr) { + delete bfm_mod_report; + } if(dab_demod_report != nullptr) { delete dab_demod_report; } @@ -496,6 +503,7 @@ SWGChannelReport::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&atv_mod_report, pJson["ATVModReport"], "SWGATVModReport", "SWGATVModReport"); ::SWGSDRangel::setValue(&bfm_demod_report, pJson["BFMDemodReport"], "SWGBFMDemodReport", "SWGBFMDemodReport"); + ::SWGSDRangel::setValue(&bfm_mod_report, pJson["BFMModReport"], "SWGBFMModReport", "SWGBFMModReport"); ::SWGSDRangel::setValue(&dab_demod_report, pJson["DABDemodReport"], "SWGDABDemodReport", "SWGDABDemodReport"); @@ -644,6 +652,9 @@ SWGChannelReport::asJsonObject() { if((bfm_demod_report != nullptr) && (bfm_demod_report->isSet())){ toJsonValue(QString("BFMDemodReport"), bfm_demod_report, obj, QString("SWGBFMDemodReport")); } + if((bfm_mod_report != nullptr) && (bfm_mod_report->isSet())){ + toJsonValue(QString("BFMModReport"), bfm_mod_report, obj, QString("SWGBFMModReport")); + } if((dab_demod_report != nullptr) && (dab_demod_report->isSet())){ toJsonValue(QString("DABDemodReport"), dab_demod_report, obj, QString("SWGDABDemodReport")); } @@ -901,6 +912,16 @@ SWGChannelReport::setBfmDemodReport(SWGBFMDemodReport* bfm_demod_report) { this->m_bfm_demod_report_isSet = true; } +SWGBFMModReport* +SWGChannelReport::getBfmModReport() { + return bfm_mod_report; +} +void +SWGChannelReport::setBfmModReport(SWGBFMModReport* bfm_mod_report) { + this->bfm_mod_report = bfm_mod_report; + this->m_bfm_mod_report_isSet = true; +} + SWGDABDemodReport* SWGChannelReport::getDabDemodReport() { return dab_demod_report; @@ -1446,6 +1467,9 @@ SWGChannelReport::isSet(){ if(bfm_demod_report && bfm_demod_report->isSet()){ isObjectUpdated = true; break; } + if(bfm_mod_report && bfm_mod_report->isSet()){ + isObjectUpdated = true; break; + } if(dab_demod_report && dab_demod_report->isSet()){ isObjectUpdated = true; break; } diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelReport.h b/swagger/sdrangel/code/qt5/client/SWGChannelReport.h index 739568e08..b66b20193 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelReport.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannelReport.h @@ -30,6 +30,7 @@ #include "SWGAMModReport.h" #include "SWGATVModReport.h" #include "SWGBFMDemodReport.h" +#include "SWGBFMModReport.h" #include "SWGChannelPowerReport.h" #include "SWGChirpChatDemodReport.h" #include "SWGChirpChatModReport.h" @@ -131,6 +132,9 @@ public: SWGBFMDemodReport* getBfmDemodReport(); void setBfmDemodReport(SWGBFMDemodReport* bfm_demod_report); + SWGBFMModReport* getBfmModReport(); + void setBfmModReport(SWGBFMModReport* bfm_mod_report); + SWGDABDemodReport* getDabDemodReport(); void setDabDemodReport(SWGDABDemodReport* dab_demod_report); @@ -318,6 +322,9 @@ private: SWGBFMDemodReport* bfm_demod_report; bool m_bfm_demod_report_isSet; + SWGBFMModReport* bfm_mod_report; + bool m_bfm_mod_report_isSet; + SWGDABDemodReport* dab_demod_report; bool m_dab_demod_report_isSet; diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp index b3f4b74c8..13cd6e429 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp @@ -58,6 +58,8 @@ SWGChannelSettings::SWGChannelSettings() { m_beam_steering_cw_mod_settings_isSet = false; bfm_demod_settings = nullptr; m_bfm_demod_settings_isSet = false; + bfm_mod_settings = nullptr; + m_bfm_mod_settings_isSet = false; channel_analyzer_settings = nullptr; m_channel_analyzer_settings_isSet = false; channel_power_settings = nullptr; @@ -210,6 +212,8 @@ SWGChannelSettings::init() { m_beam_steering_cw_mod_settings_isSet = false; bfm_demod_settings = new SWGBFMDemodSettings(); m_bfm_demod_settings_isSet = false; + bfm_mod_settings = new SWGBFMModSettings(); + m_bfm_mod_settings_isSet = false; channel_analyzer_settings = new SWGChannelAnalyzerSettings(); m_channel_analyzer_settings_isSet = false; channel_power_settings = new SWGChannelPowerSettings(); @@ -367,6 +371,9 @@ SWGChannelSettings::cleanup() { if(bfm_demod_settings != nullptr) { delete bfm_demod_settings; } + if(bfm_mod_settings != nullptr) { + delete bfm_mod_settings; + } if(channel_analyzer_settings != nullptr) { delete channel_analyzer_settings; } @@ -579,6 +586,7 @@ SWGChannelSettings::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&beam_steering_cw_mod_settings, pJson["BeamSteeringCWModSettings"], "SWGBeamSteeringCWModSettings", "SWGBeamSteeringCWModSettings"); ::SWGSDRangel::setValue(&bfm_demod_settings, pJson["BFMDemodSettings"], "SWGBFMDemodSettings", "SWGBFMDemodSettings"); + ::SWGSDRangel::setValue(&bfm_mod_settings, pJson["BFMModSettings"], "SWGBFMModSettings", "SWGBFMModSettings"); ::SWGSDRangel::setValue(&channel_analyzer_settings, pJson["ChannelAnalyzerSettings"], "SWGChannelAnalyzerSettings", "SWGChannelAnalyzerSettings"); @@ -754,6 +762,9 @@ SWGChannelSettings::asJsonObject() { if((bfm_demod_settings != nullptr) && (bfm_demod_settings->isSet())){ toJsonValue(QString("BFMDemodSettings"), bfm_demod_settings, obj, QString("SWGBFMDemodSettings")); } + if((bfm_mod_settings != nullptr) && (bfm_mod_settings->isSet())){ + toJsonValue(QString("BFMModSettings"), bfm_mod_settings, obj, QString("SWGBFMModSettings")); + } if((channel_analyzer_settings != nullptr) && (channel_analyzer_settings->isSet())){ toJsonValue(QString("ChannelAnalyzerSettings"), channel_analyzer_settings, obj, QString("SWGChannelAnalyzerSettings")); } @@ -1079,6 +1090,16 @@ SWGChannelSettings::setBfmDemodSettings(SWGBFMDemodSettings* bfm_demod_settings) this->m_bfm_demod_settings_isSet = true; } +SWGBFMModSettings* +SWGChannelSettings::getBfmModSettings() { + return bfm_mod_settings; +} +void +SWGChannelSettings::setBfmModSettings(SWGBFMModSettings* bfm_mod_settings) { + this->bfm_mod_settings = bfm_mod_settings; + this->m_bfm_mod_settings_isSet = true; +} + SWGChannelAnalyzerSettings* SWGChannelSettings::getChannelAnalyzerSettings() { return channel_analyzer_settings; @@ -1699,6 +1720,9 @@ SWGChannelSettings::isSet(){ if(bfm_demod_settings && bfm_demod_settings->isSet()){ isObjectUpdated = true; break; } + if(bfm_mod_settings && bfm_mod_settings->isSet()){ + isObjectUpdated = true; break; + } if(channel_analyzer_settings && channel_analyzer_settings->isSet()){ isObjectUpdated = true; break; } diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h index 7c5c7d765..a3f84d7fc 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h @@ -32,6 +32,7 @@ #include "SWGATVDemodSettings.h" #include "SWGATVModSettings.h" #include "SWGBFMDemodSettings.h" +#include "SWGBFMModSettings.h" #include "SWGBeamSteeringCWModSettings.h" #include "SWGChannelAnalyzerSettings.h" #include "SWGChannelPowerSettings.h" @@ -155,6 +156,9 @@ public: SWGBFMDemodSettings* getBfmDemodSettings(); void setBfmDemodSettings(SWGBFMDemodSettings* bfm_demod_settings); + SWGBFMModSettings* getBfmModSettings(); + void setBfmModSettings(SWGBFMModSettings* bfm_mod_settings); + SWGChannelAnalyzerSettings* getChannelAnalyzerSettings(); void setChannelAnalyzerSettings(SWGChannelAnalyzerSettings* channel_analyzer_settings); @@ -375,6 +379,9 @@ private: SWGBFMDemodSettings* bfm_demod_settings; bool m_bfm_demod_settings_isSet; + SWGBFMModSettings* bfm_mod_settings; + bool m_bfm_mod_settings_isSet; + SWGChannelAnalyzerSettings* channel_analyzer_settings; bool m_channel_analyzer_settings_isSet; diff --git a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h index 8593198b9..a28a7aa0c 100644 --- a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h +++ b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h @@ -72,6 +72,8 @@ #include "SWGAudioOutputSettings.h" #include "SWGBFMDemodReport.h" #include "SWGBFMDemodSettings.h" +#include "SWGBFMModReport.h" +#include "SWGBFMModSettings.h" #include "SWGBandwidth.h" #include "SWGBase64Blob.h" #include "SWGBeamSteeringCWModSettings.h" @@ -720,6 +722,16 @@ namespace SWGSDRangel { obj->init(); return obj; } + if(QString("SWGBFMModReport").compare(type) == 0) { + SWGBFMModReport *obj = new SWGBFMModReport(); + obj->init(); + return obj; + } + if(QString("SWGBFMModSettings").compare(type) == 0) { + SWGBFMModSettings *obj = new SWGBFMModSettings(); + obj->init(); + return obj; + } if(QString("SWGBandwidth").compare(type) == 0) { SWGBandwidth *obj = new SWGBandwidth(); obj->init();