Browse Source

Add NVIDIA Denoiser support.

Add VST3 effects plugins support.
chirpmodem-v8.0.0
Jon Beniston 2 months ago
parent
commit
8b13ca699a
  1. 6
      cmake/cpack/deploy_mac.cmake.in
  2. 83
      plugins/feature/demodanalyzer/demodanalyzer.cpp
  3. 13
      plugins/feature/demodanalyzer/demodanalyzer.h
  4. 2
      plugins/feature/demodanalyzer/demodanalyzergui.cpp
  5. 2
      plugins/feature/demodanalyzer/demodanalyzergui.h
  6. 1
      plugins/feature/demodanalyzer/demodanalyzersettings.cpp
  7. 7
      plugins/feature/demodanalyzer/readme.md
  8. 29
      plugins/feature/denoiser/CMakeLists.txt
  9. 441
      plugins/feature/denoiser/denoiser.cpp
  10. 43
      plugins/feature/denoiser/denoiser.h
  11. 517
      plugins/feature/denoiser/denoisergui.cpp
  12. 19
      plugins/feature/denoiser/denoisergui.h
  13. 158
      plugins/feature/denoiser/denoisergui.ui
  14. 83
      plugins/feature/denoiser/denoisersettings.cpp
  15. 10
      plugins/feature/denoiser/denoisersettings.h
  16. 344
      plugins/feature/denoiser/denoiserworker.cpp
  17. 58
      plugins/feature/denoiser/denoiserworker.h
  18. 302
      plugins/feature/denoiser/nvidiaaudioeffects.cpp
  19. 41
      plugins/feature/denoiser/nvidiaaudioeffects.h
  20. 73
      plugins/feature/denoiser/readme.md
  21. 27
      plugins/feature/denoiser/vst3/LICENSE.txt
  22. 3777
      plugins/feature/denoiser/vst3/vst3_c_api.h
  23. 1415
      plugins/feature/denoiser/vst3effect.cpp
  24. 87
      plugins/feature/denoiser/vst3effect.h
  25. 83
      plugins/feature/denoiser/vst3scan.cpp
  26. 1
      sdrbase/maincore.cpp
  27. 22
      sdrbase/maincore.h
  28. 25
      sdrbase/resources/webapi/doc/swagger/include/Denoiser.yaml
  29. 25
      swagger/sdrangel/api/swagger/include/Denoiser.yaml
  30. 110
      swagger/sdrangel/code/qt5/client/SWGDenoiserSettings.cpp
  31. 32
      swagger/sdrangel/code/qt5/client/SWGDenoiserSettings.h

6
cmake/cpack/deploy_mac.cmake.in

@ -11,6 +11,12 @@ execute_process (COMMAND mkdir ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/SDRangel.app
execute_process (COMMAND pwd) execute_process (COMMAND pwd)
execute_process (COMMAND cp sdrangel ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/SDRangel.app/Contents/MacOS/SDRangel) execute_process (COMMAND cp sdrangel ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/SDRangel.app/Contents/MacOS/SDRangel)
# The Denoiser launches the VST3 scanner beside the app executable.
if(EXISTS "@CMAKE_BINARY_DIR@/sdrangel-vst3-scan")
file(COPY "@CMAKE_BINARY_DIR@/sdrangel-vst3-scan"
DESTINATION "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/SDRangel.app/Contents/MacOS")
endif()
# Add RPATHS to libraries so macdeployqt can find out and copy all dependencies # Add RPATHS to libraries so macdeployqt can find out and copy all dependencies
message ("Adding RPATHs to executables and libraries") message ("Adding RPATHs to executables and libraries")

83
plugins/feature/demodanalyzer/demodanalyzer.cpp

@ -207,12 +207,21 @@ bool DemodAnalyzer::handleMessage(const Message& cmd)
else if (MsgSelectChannel::match(cmd)) else if (MsgSelectChannel::match(cmd))
{ {
MsgSelectChannel& cfg = (MsgSelectChannel&) cmd; MsgSelectChannel& cfg = (MsgSelectChannel&) cmd;
ChannelAPI *selectedChannel = cfg.getChannel(); QObject *selectedChannel = cfg.getChannel();
if (!selectedChannel) {
return true;
}
qDebug("DemodAnalyzer::handleMessage: MsgSelectChannel: %p %s", qDebug("DemodAnalyzer::handleMessage: MsgSelectChannel: %p %s",
selectedChannel, qPrintable(selectedChannel->objectName())); selectedChannel, qPrintable(selectedChannel->objectName()));
setChannel(selectedChannel); setChannel(selectedChannel);
MainCore::MsgChannelDemodQuery *msg = MainCore::MsgChannelDemodQuery::create(); if (m_selectedChannel == selectedChannel)
selectedChannel->getInputMessageQueue()->push(msg); {
if (auto *channel = qobject_cast<ChannelAPI*>(selectedChannel)) {
channel->getInputMessageQueue()->push(MainCore::MsgChannelDemodQuery::create());
} else if (auto *feature = qobject_cast<Feature*>(selectedChannel)) {
feature->getInputMessageQueue()->push(MainCore::MsgChannelDemodQuery::create());
}
}
return true; return true;
} }
@ -221,32 +230,17 @@ bool DemodAnalyzer::handleMessage(const Message& cmd)
qDebug() << "DemodAnalyzer::handleMessage: MainCore::MsgChannelDemodReport"; qDebug() << "DemodAnalyzer::handleMessage: MainCore::MsgChannelDemodReport";
MainCore::MsgChannelDemodReport& report = (MainCore::MsgChannelDemodReport&) cmd; MainCore::MsgChannelDemodReport& report = (MainCore::MsgChannelDemodReport&) cmd;
if (report.getChannelAPI() == m_selectedChannel) if (report.getChannelAPI() == m_selectedChannel) {
{ applyReportedSampleRate(report.getSampleRate());
m_sampleRate = report.getSampleRate(); }
m_scopeVis.setLiveRate(m_sampleRate);
if (m_running) {
m_worker->applySampleRate(m_sampleRate);
}
DSPSignalNotification *msg = new DSPSignalNotification(0, m_sampleRate);
m_spectrumVis.getInputMessageQueue()->push(msg);
if (m_dataPipe)
{
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
if (fifo) {
fifo->setSize(2*m_sampleRate);
}
}
if (getMessageQueueToGUI()) return true;
{ }
MsgReportSampleRate *msg = MsgReportSampleRate::create(m_sampleRate); else if (MainCore::MsgFeatureDemodReport::match(cmd))
getMessageQueueToGUI()->push(msg); {
} const auto& report = static_cast<const MainCore::MsgFeatureDemodReport&>(cmd);
if (report.getFeature() == m_selectedChannel) {
applyReportedSampleRate(report.getSampleRate());
} }
return true; return true;
@ -257,6 +251,35 @@ bool DemodAnalyzer::handleMessage(const Message& cmd)
} }
} }
void DemodAnalyzer::applyReportedSampleRate(int sampleRate)
{
if (sampleRate <= 0) {
return;
}
m_sampleRate = sampleRate;
m_scopeVis.setLiveRate(m_sampleRate);
if (m_running) {
m_worker->applySampleRate(m_sampleRate);
}
m_spectrumVis.getInputMessageQueue()->push(new DSPSignalNotification(0, m_sampleRate));
if (m_dataPipe)
{
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
if (fifo) {
fifo->setSize(2*m_sampleRate);
}
}
if (getMessageQueueToGUI()) {
getMessageQueueToGUI()->push(MsgReportSampleRate::create(m_sampleRate));
}
}
QByteArray DemodAnalyzer::serialize() const QByteArray DemodAnalyzer::serialize() const
{ {
return m_settings.serialize(); return m_settings.serialize();
@ -331,7 +354,7 @@ void DemodAnalyzer::getAvailableChannelsReport()
} }
void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel) void DemodAnalyzer::setChannel(QObject *selectedChannel)
{ {
if ((selectedChannel == m_selectedChannel) || (m_availableChannels.indexOfObject(selectedChannel) == -1)) { if ((selectedChannel == m_selectedChannel) || (m_availableChannels.indexOfObject(selectedChannel) == -1)) {
return; return;
@ -342,7 +365,7 @@ void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel)
if (m_selectedChannel) if (m_selectedChannel)
{ {
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element); DataFifo *fifo = pipe ? qobject_cast<DataFifo*>(pipe->m_element) : nullptr;
if ((fifo) && m_running) if ((fifo) && m_running)
{ {

13
plugins/feature/demodanalyzer/demodanalyzer.h

@ -118,15 +118,15 @@ public:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
ChannelAPI *getChannel() { return m_channel; } QObject *getChannel() { return m_channel; }
static MsgSelectChannel* create(ChannelAPI *channel) { static MsgSelectChannel* create(QObject *channel) {
return new MsgSelectChannel(channel); return new MsgSelectChannel(channel);
} }
protected: protected:
ChannelAPI *m_channel; QObject *m_channel;
MsgSelectChannel(ChannelAPI *channel) : MsgSelectChannel(QObject *channel) :
Message(), Message(),
m_channel(channel) m_channel(channel)
{ } { }
@ -209,7 +209,7 @@ private:
ScopeVis m_scopeVis; ScopeVis m_scopeVis;
AvailableChannelOrFeatureList m_availableChannels; AvailableChannelOrFeatureList m_availableChannels;
AvailableChannelOrFeatureHandler m_availableChannelOrFeatureHandler; AvailableChannelOrFeatureHandler m_availableChannelOrFeatureHandler;
ChannelAPI *m_selectedChannel; QObject *m_selectedChannel;
ObjectPipe *m_dataPipe; ObjectPipe *m_dataPipe;
int m_sampleRate; int m_sampleRate;
@ -220,7 +220,8 @@ private:
void stop(); void stop();
void applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force = false); void applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo); void notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo);
void setChannel(ChannelAPI *selectedChannel); void setChannel(QObject *selectedChannel);
void applyReportedSampleRate(int sampleRate);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force); void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force);
private slots: private slots:

2
plugins/feature/demodanalyzer/demodanalyzergui.cpp

@ -316,7 +316,7 @@ void DemodAnalyzerGUI::on_channels_currentIndexChanged(int index)
{ {
if ((index >= 0) && (index < m_availableChannels.size())) if ((index >= 0) && (index < m_availableChannels.size()))
{ {
m_selectedChannel = qobject_cast<ChannelAPI*>(m_availableChannels[index].m_object); m_selectedChannel = m_availableChannels[index].m_object;
DemodAnalyzer::MsgSelectChannel *msg = DemodAnalyzer::MsgSelectChannel::create(m_selectedChannel); DemodAnalyzer::MsgSelectChannel *msg = DemodAnalyzer::MsgSelectChannel::create(m_selectedChannel);
m_demodAnalyzer->getInputMessageQueue()->push(msg); m_demodAnalyzer->getInputMessageQueue()->push(msg);
} }

2
plugins/feature/demodanalyzer/demodanalyzergui.h

@ -70,7 +70,7 @@ private:
ScopeVis* m_scopeVis; ScopeVis* m_scopeVis;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
AvailableChannelOrFeatureList m_availableChannels; AvailableChannelOrFeatureList m_availableChannels;
ChannelAPI *m_selectedChannel; QObject *m_selectedChannel;
MovingAverageUtil<double, double, 40> m_channelPowerAvg; MovingAverageUtil<double, double, 40> m_channelPowerAvg;
explicit DemodAnalyzerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr); explicit DemodAnalyzerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);

1
plugins/feature/demodanalyzer/demodanalyzersettings.cpp

@ -49,6 +49,7 @@ const QStringList DemodAnalyzerSettings::m_channelURIs = {
QStringLiteral("sdrangel.channel.wfmdemod"), QStringLiteral("sdrangel.channel.wfmdemod"),
QStringLiteral("sdrangel.channeltx.modwfm"), QStringLiteral("sdrangel.channeltx.modwfm"),
QStringLiteral("sdrangel.channel.wdsprx"), QStringLiteral("sdrangel.channel.wdsprx"),
QStringLiteral("sdrangel.feature.denoiser"),
}; };
DemodAnalyzerSettings::DemodAnalyzerSettings() : DemodAnalyzerSettings::DemodAnalyzerSettings() :

7
plugins/feature/demodanalyzer/readme.md

@ -3,6 +3,7 @@
<h2>Introduction</h2> <h2>Introduction</h2>
This plugin can be used to analyze the real demodulated signal from some Rx channel plugins. It can also be used to view the modulating signal of some Tx channel plugins. This plugin can be used to analyze the real demodulated signal from some Rx channel plugins. It can also be used to view the modulating signal of some Tx channel plugins.
It can also display filtered audio from some feature plugins.
Rx plugins are: Rx plugins are:
@ -32,6 +33,10 @@ Tx plugins are:
- SSB modulator - SSB modulator
- WFM modulator - WFM modulator
Features are:
- Denoiser feature
<h2>General interface</h2> <h2>General interface</h2>
![Demod Analyzer plugin GUI](../../../doc/img/DemodAnalyzer_plugin.png) ![Demod Analyzer plugin GUI](../../../doc/img/DemodAnalyzer_plugin.png)
@ -58,7 +63,7 @@ This button starts or stops the plugin
<h3>A.3: Channel selection</h3> <h3>A.3: Channel selection</h3>
Use this combo to select which channel to use for display. Channel is selected upon change. If channel is not changed or there is only one in the list you have to use the (re)apply button (A.4) to effectively connect the channel to the analyzer. Use this combo to select which channel or feature to use for display. The source is selected upon change. If the selection is not changed or there is only one in the list, use the (re)apply button (A.4) to connect it to the analyzer.
<h3>A.4: (Re)apply channel selection</h3> <h3>A.4: (Re)apply channel selection</h3>

29
plugins/feature/denoiser/CMakeLists.txt

@ -1,11 +1,20 @@
project(denoiser) project(denoiser)
if(APPLE)
find_library(VST3_COREFOUNDATION_FRAMEWORK CoreFoundation)
if(NOT VST3_COREFOUNDATION_FRAMEWORK)
message(FATAL_ERROR "CoreFoundation is required for VST3 support on macOS")
endif()
endif()
set(denoiser_SOURCES set(denoiser_SOURCES
denoiser.cpp denoiser.cpp
denoisersettings.cpp denoisersettings.cpp
denoiserplugin.cpp denoiserplugin.cpp
denoiserworker.cpp denoiserworker.cpp
denoiserwebapiadapter.cpp denoiserwebapiadapter.cpp
nvidiaaudioeffects.cpp
vst3effect.cpp
) )
set(denoiser_HEADERS set(denoiser_HEADERS
@ -14,6 +23,8 @@ set(denoiser_HEADERS
denoiserplugin.h denoiserplugin.h
denoiserworker.h denoiserworker.h
denoiserwebapiadapter.h denoiserwebapiadapter.h
nvidiaaudioeffects.h
vst3effect.h
) )
include_directories( include_directories(
@ -56,6 +67,8 @@ endif()
target_link_libraries(${TARGET_NAME} PRIVATE target_link_libraries(${TARGET_NAME} PRIVATE
Qt::Core Qt::Core
${CMAKE_DL_LIBS}
${VST3_COREFOUNDATION_FRAMEWORK}
${TARGET_LIB} ${TARGET_LIB}
sdrbase sdrbase
${TARGET_LIB_GUI} ${TARGET_LIB_GUI}
@ -64,6 +77,22 @@ target_link_libraries(${TARGET_NAME} PRIVATE
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})
if(NOT SERVER_MODE)
add_executable(sdrangel-vst3-scan vst3scan.cpp vst3effect.cpp)
target_link_libraries(sdrangel-vst3-scan PRIVATE Qt::Core ${CMAKE_DL_LIBS} ${VST3_COREFOUNDATION_FRAMEWORK})
if(WIN32)
set(VST3_SCAN_RUNTIME_DIR "${SDRANGEL_BINARY_BIN_DIR}")
else()
set(VST3_SCAN_RUNTIME_DIR "${CMAKE_BINARY_DIR}")
endif()
set_target_properties(sdrangel-vst3-scan PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${VST3_SCAN_RUNTIME_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${VST3_SCAN_RUNTIME_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${VST3_SCAN_RUNTIME_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${VST3_SCAN_RUNTIME_DIR}")
install(TARGETS sdrangel-vst3-scan DESTINATION ${INSTALL_BIN_DIR})
endif()
# Install debug symbols # Install debug symbols
if (WIN32) if (WIN32)
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}> CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} ) install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}> CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} )

441
plugins/feature/denoiser/denoiser.cpp

@ -19,6 +19,8 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QBuffer> #include <QBuffer>
#include <QJsonDocument>
#include <QJsonObject>
#include "SWGFeatureSettings.h" #include "SWGFeatureSettings.h"
#include "SWGFeatureActions.h" #include "SWGFeatureActions.h"
@ -31,6 +33,7 @@
#include "maincore.h" #include "maincore.h"
#include "denoiserworker.h" #include "denoiserworker.h"
#include "vst3effect.h"
#include "denoiser.h" #include "denoiser.h"
MESSAGE_CLASS_DEFINITION(Denoiser::MsgConfigureDenoiser, Message) MESSAGE_CLASS_DEFINITION(Denoiser::MsgConfigureDenoiser, Message)
@ -39,6 +42,37 @@ MESSAGE_CLASS_DEFINITION(Denoiser::MsgReportChannels, Message)
MESSAGE_CLASS_DEFINITION(Denoiser::MsgSelectChannel, Message) MESSAGE_CLASS_DEFINITION(Denoiser::MsgSelectChannel, Message)
MESSAGE_CLASS_DEFINITION(Denoiser::MsgReportSampleRate, Message) MESSAGE_CLASS_DEFINITION(Denoiser::MsgReportSampleRate, Message)
namespace {
QString vst3ParametersJson(const QMap<quint32, double>& values)
{
QJsonObject object;
for (auto it = values.cbegin(); it != values.cend(); ++it) {
object.insert(QString::number(it.key()), it.value());
}
return QString::fromUtf8(QJsonDocument(object).toJson(QJsonDocument::Compact));
}
QMap<quint32, double> parseVst3Parameters(const QString& json)
{
QMap<quint32, double> values;
const QJsonObject object = QJsonDocument::fromJson(json.toUtf8()).object();
for (auto it = object.begin(); it != object.end(); ++it)
{
bool validId = false;
const quint32 id = it.key().toUInt(&validId);
const double value = it.value().toDouble(-1.0);
if (validId && value >= 0.0 && value <= 1.0) values.insert(id, value);
}
return values;
}
}
const char* const Denoiser::m_featureIdURI = "sdrangel.feature.denoiser"; const char* const Denoiser::m_featureIdURI = "sdrangel.feature.denoiser";
const char* const Denoiser::m_featureId = "Denoiser"; const char* const Denoiser::m_featureId = "Denoiser";
@ -49,7 +83,8 @@ Denoiser::Denoiser(WebAPIAdapterInterface *webAPIAdapterInterface) :
m_worker(nullptr), m_worker(nullptr),
m_availableChannelOrFeatureHandler(DenoiserSettings::m_channelURIs), m_availableChannelOrFeatureHandler(DenoiserSettings::m_channelURIs),
m_selectedChannel(nullptr), m_selectedChannel(nullptr),
m_dataPipe(nullptr) m_dataPipe(nullptr),
m_sampleRate(0)
{ {
qDebug("Denoiser::Denoiser: webAPIAdapterInterface: %p", webAPIAdapterInterface); qDebug("Denoiser::Denoiser: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId); setObjectName(m_featureId);
@ -101,6 +136,8 @@ void Denoiser::start()
return; return;
} }
useDefaultSampleRate();
qDebug("Denoiser::start"); qDebug("Denoiser::start");
m_thread = new QThread(); m_thread = new QThread();
m_worker = new DenoiserWorker(); m_worker = new DenoiserWorker();
@ -126,6 +163,7 @@ void Denoiser::start()
); );
m_worker->setMessageQueueToFeature(getInputMessageQueue()); m_worker->setMessageQueueToFeature(getInputMessageQueue());
m_worker->setDemodProducer(this);
m_worker->startWork(); m_worker->startWork();
setState(StRunning); setState(StRunning);
m_thread->start(); m_thread->start();
@ -152,6 +190,7 @@ void Denoiser::start()
m_running = true; m_running = true;
configureVst3();
} }
void Denoiser::stop() void Denoiser::stop()
@ -164,6 +203,8 @@ void Denoiser::stop()
qDebug("Denoiser::stop"); qDebug("Denoiser::stop");
m_running = false; m_running = false;
m_worker->setVst3Effect(nullptr);
m_vst3Effect.reset();
if (m_dataPipe) if (m_dataPipe)
{ {
@ -189,7 +230,7 @@ double Denoiser::getMagSqAvg() const
bool Denoiser::handleMessage(const Message& cmd) bool Denoiser::handleMessage(const Message& cmd)
{ {
if (MsgConfigureDenoiser::match(cmd)) if (MsgConfigureDenoiser::match(cmd))
{ {
MsgConfigureDenoiser& cfg = (MsgConfigureDenoiser&) cmd; MsgConfigureDenoiser& cfg = (MsgConfigureDenoiser&) cmd;
qDebug() << "Denoiser::handleMessage: MsgConfigureDenoiser"; qDebug() << "Denoiser::handleMessage: MsgConfigureDenoiser";
@ -197,6 +238,32 @@ bool Denoiser::handleMessage(const Message& cmd)
return true; return true;
} }
else if (DenoiserWorker::MsgReportNvidiaStatus::match(cmd))
{
const auto& report = static_cast<const DenoiserWorker::MsgReportNvidiaStatus&>(cmd);
if (m_running && m_settings.m_enableDenoiser &&
m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Nvidia)
{
if (report.getError().isEmpty()) {
m_state = StRunning;
} else {
m_errorMessage = report.getError();
m_state = StError;
}
}
return true;
}
else if (DenoiserWorker::MsgReportVst3Status::match(cmd))
{
const auto& report = static_cast<const DenoiserWorker::MsgReportVst3Status&>(cmd);
if (m_running && m_settings.m_enableDenoiser &&
m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Vst3)
{
m_errorMessage = report.getError();
m_state = StError;
}
return true;
}
else if (MsgStartStop::match(cmd)) else if (MsgStartStop::match(cmd))
{ {
MsgStartStop& cfg = (MsgStartStop&) cmd; MsgStartStop& cfg = (MsgStartStop&) cmd;
@ -213,42 +280,40 @@ bool Denoiser::handleMessage(const Message& cmd)
else if (MsgSelectChannel::match(cmd)) else if (MsgSelectChannel::match(cmd))
{ {
MsgSelectChannel& cfg = (MsgSelectChannel&) cmd; MsgSelectChannel& cfg = (MsgSelectChannel&) cmd;
ChannelAPI *selectedChannel = cfg.getChannel(); QObject *selectedChannel = cfg.getChannel();
if (!selectedChannel) {
return true;
}
qDebug("Denoiser::handleMessage: MsgSelectChannel: %p %s", qDebug("Denoiser::handleMessage: MsgSelectChannel: %p %s",
selectedChannel, qPrintable(selectedChannel->objectName())); selectedChannel, qPrintable(selectedChannel->objectName()));
setChannel(selectedChannel); setChannel(selectedChannel);
MainCore::MsgChannelDemodQuery *msg = MainCore::MsgChannelDemodQuery::create(); if (m_selectedChannel == selectedChannel) {
selectedChannel->getInputMessageQueue()->push(msg); querySelectedSource();
}
return true; return true;
} }
else if (MainCore::MsgChannelDemodQuery::match(cmd))
{
reportDemodSampleRate();
return true;
}
else if (MainCore::MsgChannelDemodReport::match(cmd)) else if (MainCore::MsgChannelDemodReport::match(cmd))
{ {
qDebug() << "Denoiser::handleMessage: MainCore::MsgChannelDemodReport"; qDebug() << "Denoiser::handleMessage: MainCore::MsgChannelDemodReport";
MainCore::MsgChannelDemodReport& report = (MainCore::MsgChannelDemodReport&) cmd; MainCore::MsgChannelDemodReport& report = (MainCore::MsgChannelDemodReport&) cmd;
if (report.getChannelAPI() == m_selectedChannel) if (report.getChannelAPI() == m_selectedChannel) {
{ applyReportedSampleRate(report.getSampleRate());
m_sampleRate = report.getSampleRate(); }
if (m_running) {
m_worker->applySampleRate(m_sampleRate);
}
if (m_dataPipe)
{
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
if (fifo) {
fifo->setSize(2*m_sampleRate);
}
}
if (getMessageQueueToGUI()) return true;
{ }
MsgReportSampleRate *msg = MsgReportSampleRate::create(m_sampleRate); else if (MainCore::MsgFeatureDemodReport::match(cmd))
getMessageQueueToGUI()->push(msg); {
} const auto& report = static_cast<const MainCore::MsgFeatureDemodReport&>(cmd);
if (report.getFeature() == m_selectedChannel) {
applyReportedSampleRate(report.getSampleRate());
} }
return true; return true;
@ -303,24 +368,189 @@ void Denoiser::applySettings(const DenoiserSettings& settings, const QList<QStri
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
} }
const auto previousParameters = m_settings.m_vst3Parameters;
if (force) { if (force) {
m_settings = settings; m_settings = settings;
} else { } else {
m_settings.applySettings(settingsKeys, settings); m_settings.applySettings(settingsKeys, settings);
} }
if (force || settingsKeys.contains("selectedSource")) {
restoreSelectedSource();
}
if (m_running && m_state == StError &&
(force || settingsKeys.contains("denoiserType") || settingsKeys.contains("enableDenoiser") ||
settingsKeys.contains("nvidiaIntensity") || settingsKeys.contains("nvidiaVad")))
{
m_state = StRunning;
}
if (m_running && (force || settingsKeys.contains("denoiserType") ||
settingsKeys.contains("enableDenoiser") ||
settingsKeys.contains("vst3ModulePath") || settingsKeys.contains("vst3ClassId") ||
settingsKeys.contains("vst3State")))
{
configureVst3();
}
else if (m_vst3Effect && settingsKeys.contains("vst3Parameters"))
{
for (auto it = m_settings.m_vst3Parameters.cbegin(); it != m_settings.m_vst3Parameters.cend(); ++it) {
if (!previousParameters.contains(it.key()) || previousParameters.value(it.key()) != it.value()) {
m_vst3Effect->setParameter(it.key(), it.value());
}
}
}
}
QVector<Vst3ParameterInfo> Denoiser::vst3Parameters() const
{
return m_vst3Effect ? m_vst3Effect->parameters() : QVector<Vst3ParameterInfo>();
}
bool Denoiser::hasVst3Effect() const
{
return m_vst3Effect != nullptr;
}
QString Denoiser::vst3ParameterText(quint32 id, double value) const
{
return m_vst3Effect ? m_vst3Effect->parameterText(id, value) : QString::number(value, 'f', 3);
}
void Denoiser::configureVst3()
{
if (!m_worker) {
return;
}
m_worker->setVst3Effect(nullptr);
m_vst3Effect.reset();
if (!m_running || !m_settings.m_enableDenoiser ||
m_settings.m_denoiserType != DenoiserSettings::DenoiserType::DenoiserType_Vst3)
{
return;
}
if (m_sampleRate <= 0) {
return;
}
if (m_settings.m_vst3ModulePath.isEmpty() || m_settings.m_vst3ClassId.size() != 16)
{
m_errorMessage = QStringLiteral("Select a VST3 audio effect");
m_state = StError;
return;
}
auto effect = std::make_unique<Vst3Effect>();
QString error;
if (!effect->open(m_settings.m_vst3ModulePath, m_settings.m_vst3ClassId, m_sampleRate, 2, error, m_settings.m_vst3State))
{
m_errorMessage = QStringLiteral("VST3: %1. Audio is passing through.").arg(error);
m_state = StError;
qWarning() << m_errorMessage;
return;
}
for (auto it = m_settings.m_vst3Parameters.cbegin(); it != m_settings.m_vst3Parameters.cend(); ++it) {
effect->setParameter(it.key(), it.value());
}
m_worker->setVst3Effect(effect.get());
m_vst3Effect = std::move(effect);
if (m_state == StError) {
m_state = StRunning;
}
}
void Denoiser::useDefaultSampleRate()
{
if (!m_selectedChannel || m_sampleRate > 0) {
return;
}
m_sampleRate = 48000;
if (m_dataPipe)
{
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
if (fifo) {
fifo->setSize(2 * m_sampleRate);
}
}
if (getMessageQueueToGUI()) {
getMessageQueueToGUI()->push(MsgReportSampleRate::create(m_sampleRate));
}
reportDemodSampleRate();
}
void Denoiser::applyReportedSampleRate(int sampleRate)
{
if (sampleRate <= 0) return;
const bool sampleRateChanged = m_sampleRate != sampleRate;
m_sampleRate = sampleRate;
if (m_running && (sampleRateChanged || !m_vst3Effect ||
m_settings.m_denoiserType != DenoiserSettings::DenoiserType::DenoiserType_Vst3))
{
m_worker->applySampleRate(m_sampleRate);
configureVst3();
if (sampleRateChanged && m_state == StError &&
m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Nvidia)
{
m_state = StRunning;
}
}
if (m_dataPipe)
{
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
if (fifo) fifo->setSize(2 * m_sampleRate);
}
if (getMessageQueueToGUI()) {
getMessageQueueToGUI()->push(MsgReportSampleRate::create(m_sampleRate));
}
if (sampleRateChanged) reportDemodSampleRate();
}
void Denoiser::reportDemodSampleRate()
{
QList<ObjectPipe*> pipes;
MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes);
for (const auto& pipe : pipes)
{
MessageQueue *queue = qobject_cast<MessageQueue*>(pipe->m_element);
if (queue) {
queue->push(MainCore::MsgFeatureDemodReport::create(this, m_sampleRate));
}
}
} }
void Denoiser::channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo) void Denoiser::channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo)
{ {
m_availableChannels = m_availableChannelOrFeatureHandler.getAvailableChannelOrFeatureList(); m_availableChannels.clear();
for (const auto& source : m_availableChannelOrFeatureHandler.getAvailableChannelOrFeatureList()) {
if (source.m_object != this) {
m_availableChannels.append(source);
}
}
for (int i = 0; i < renameFrom.size() && i < renameTo.size(); ++i)
{
if (m_settings.m_selectedSource == renameFrom.at(i)) {
m_settings.m_selectedSource = renameTo.at(i);
}
}
if (!m_settings.m_selectedSource.isEmpty()) {
restoreSelectedSource();
}
notifyUpdate(renameFrom, renameTo); notifyUpdate(renameFrom, renameTo);
} }
void Denoiser::notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo) void Denoiser::notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo, bool autoSelect)
{ {
if (getMessageQueueToGUI()) if (getMessageQueueToGUI())
{ {
MsgReportChannels *msg = MsgReportChannels::create(renameFrom, renameTo); MsgReportChannels *msg = MsgReportChannels::create(renameFrom, renameTo, m_selectedChannel, autoSelect);
msg->getAvailableChannels() = m_availableChannels; msg->getAvailableChannels() = m_availableChannels;
getMessageQueueToGUI()->push(msg); getMessageQueueToGUI()->push(msg);
} }
@ -332,18 +562,86 @@ void Denoiser::getAvailableChannelsReport()
} }
void Denoiser::setChannel(ChannelAPI *selectedChannel) void Denoiser::querySelectedSource()
{ {
if ((selectedChannel == m_selectedChannel) || (m_availableChannels.indexOfObject(selectedChannel) == -1)) { if (auto *channel = qobject_cast<ChannelAPI*>(m_selectedChannel)) {
channel->getInputMessageQueue()->push(MainCore::MsgChannelDemodQuery::create());
} else if (auto *feature = qobject_cast<Feature*>(m_selectedChannel)) {
feature->getInputMessageQueue()->push(MainCore::MsgChannelDemodQuery::create());
}
}
void Denoiser::restoreSelectedSource()
{
if (m_settings.m_selectedSource.isEmpty())
{
setChannel(nullptr);
return; return;
} }
const int index = m_availableChannels.indexOfLongId(m_settings.m_selectedSource);
if (index < 0)
{
setChannel(nullptr, true);
return;
}
QObject *source = m_availableChannels.at(index).m_object;
if (source != m_selectedChannel)
{
setChannel(source);
if (source == m_selectedChannel)
{
querySelectedSource();
}
else
{
const int currentIndex = m_availableChannels.indexOfObject(m_selectedChannel);
m_settings.m_selectedSource = currentIndex >= 0 ? m_availableChannels.at(currentIndex).getLongId() : QString();
}
}
}
void Denoiser::setChannel(QObject *selectedChannel, bool preserveSavedSource)
{
if (selectedChannel == m_selectedChannel) {
return;
}
const int selectedIndex = selectedChannel ? m_availableChannels.indexOfObject(selectedChannel) : -1;
if (selectedChannel && selectedIndex < 0) {
return;
}
QObject *upstream = selectedChannel;
while (auto *denoiser = qobject_cast<Denoiser*>(upstream))
{
if (denoiser == this)
{
qWarning() << "Denoiser: rejecting a cyclic denoiser connection";
notifyUpdate(QStringList{}, QStringList{}, false);
return;
}
upstream = denoiser->m_selectedChannel;
}
m_sampleRate = 0;
if (m_running)
{
m_worker->setVst3Effect(nullptr);
m_vst3Effect.reset();
m_worker->applySampleRate(0);
}
if (getMessageQueueToGUI()) {
getMessageQueueToGUI()->push(MsgReportSampleRate::create(0));
}
MainCore *mainCore = MainCore::instance(); MainCore *mainCore = MainCore::instance();
if (m_selectedChannel) if (m_selectedChannel)
{ {
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod"); ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element); DataFifo *fifo = pipe ? qobject_cast<DataFifo*>(pipe->m_element) : nullptr;
if ((fifo) && m_running) if ((fifo) && m_running)
{ {
@ -363,6 +661,17 @@ void Denoiser::setChannel(ChannelAPI *selectedChannel)
} }
} }
m_dataPipe = nullptr;
m_selectedChannel = nullptr;
if (!selectedChannel)
{
if (!preserveSavedSource) {
m_settings.m_selectedSource.clear();
}
return;
}
m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod"); m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod");
connect(m_dataPipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleDataPipeToBeDeleted(int, QObject*))); connect(m_dataPipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleDataPipeToBeDeleted(int, QObject*)));
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element); DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
@ -397,6 +706,13 @@ void Denoiser::setChannel(ChannelAPI *selectedChannel)
} }
m_selectedChannel = selectedChannel; m_selectedChannel = selectedChannel;
m_settings.m_selectedSource = m_availableChannels.at(selectedIndex).getLongId();
useDefaultSampleRate();
if (m_running)
{
m_worker->applySampleRate(m_sampleRate);
configureVst3();
}
} }
int Denoiser::webapiRun(bool run, int Denoiser::webapiRun(bool run,
@ -452,6 +768,12 @@ void Denoiser::webapiFormatFeatureSettings(
{ {
response.getDenoiserSettings()->setDenoiserType(static_cast<int>(settings.m_denoiserType)); response.getDenoiserSettings()->setDenoiserType(static_cast<int>(settings.m_denoiserType));
response.getDenoiserSettings()->setEnableDenoiser(settings.m_enableDenoiser ? 1 : 0); response.getDenoiserSettings()->setEnableDenoiser(settings.m_enableDenoiser ? 1 : 0);
response.getDenoiserSettings()->setNvidiaIntensity(settings.m_nvidiaIntensity);
response.getDenoiserSettings()->setNvidiaVad(settings.m_nvidiaVad ? 1 : 0);
*response.getDenoiserSettings()->getVst3ModulePath() = settings.m_vst3ModulePath;
*response.getDenoiserSettings()->getVst3ClassId() = QString::fromLatin1(settings.m_vst3ClassId.toHex());
*response.getDenoiserSettings()->getVst3Parameters() = vst3ParametersJson(settings.m_vst3Parameters);
*response.getDenoiserSettings()->getVst3State() = QString::fromLatin1(settings.m_vst3State.toBase64());
response.getDenoiserSettings()->setAudioMute(settings.m_audioMute ? 1 : 0); response.getDenoiserSettings()->setAudioMute(settings.m_audioMute ? 1 : 0);
response.getDenoiserSettings()->setVolumeTenths(settings.m_volumeTenths); response.getDenoiserSettings()->setVolumeTenths(settings.m_volumeTenths);
if (response.getDenoiserSettings()->getAudioDeviceName()) { if (response.getDenoiserSettings()->getAudioDeviceName()) {
@ -506,12 +828,34 @@ void Denoiser::webapiUpdateFeatureSettings(
const QStringList& featureSettingsKeys, const QStringList& featureSettingsKeys,
SWGSDRangel::SWGFeatureSettings& response) SWGSDRangel::SWGFeatureSettings& response)
{ {
if (featureSettingsKeys.contains("denoiserType")) { if (featureSettingsKeys.contains("denoiserType"))
settings.m_denoiserType = static_cast<DenoiserSettings::DenoiserType>(response.getDenoiserSettings()->getDenoiserType()); {
const int type = response.getDenoiserSettings()->getDenoiserType();
if (type >= 0 && type <= 3) {
settings.m_denoiserType = static_cast<DenoiserSettings::DenoiserType>(type);
}
} }
if (featureSettingsKeys.contains("enableDenoiser")) { if (featureSettingsKeys.contains("enableDenoiser")) {
settings.m_enableDenoiser = response.getDenoiserSettings()->getEnableDenoiser() != 0; settings.m_enableDenoiser = response.getDenoiserSettings()->getEnableDenoiser() != 0;
} }
if (featureSettingsKeys.contains("nvidiaIntensity")) {
settings.m_nvidiaIntensity = qBound(0, response.getDenoiserSettings()->getNvidiaIntensity(), 100);
}
if (featureSettingsKeys.contains("nvidiaVad")) {
settings.m_nvidiaVad = response.getDenoiserSettings()->getNvidiaVad() != 0;
}
if (featureSettingsKeys.contains("vst3ModulePath") && response.getDenoiserSettings()->getVst3ModulePath()) {
settings.m_vst3ModulePath = *response.getDenoiserSettings()->getVst3ModulePath();
}
if (featureSettingsKeys.contains("vst3ClassId") && response.getDenoiserSettings()->getVst3ClassId()) {
settings.m_vst3ClassId = QByteArray::fromHex(response.getDenoiserSettings()->getVst3ClassId()->toLatin1());
}
if (featureSettingsKeys.contains("vst3Parameters") && response.getDenoiserSettings()->getVst3Parameters()) {
settings.m_vst3Parameters = parseVst3Parameters(*response.getDenoiserSettings()->getVst3Parameters());
}
if (featureSettingsKeys.contains("vst3State") && response.getDenoiserSettings()->getVst3State()) {
settings.m_vst3State = QByteArray::fromBase64(response.getDenoiserSettings()->getVst3State()->toLatin1());
}
if (featureSettingsKeys.contains("audioMute")) { if (featureSettingsKeys.contains("audioMute")) {
settings.m_audioMute = response.getDenoiserSettings()->getAudioMute() != 0; settings.m_audioMute = response.getDenoiserSettings()->getAudioMute() != 0;
} }
@ -585,6 +929,24 @@ void Denoiser::webapiReverseSendSettings(const QList<QString>& featureSettingsKe
if (featureSettingsKeys.contains("enableDenoiser") || force) { if (featureSettingsKeys.contains("enableDenoiser") || force) {
swgDenoiserSettings->setEnableDenoiser(settings.m_enableDenoiser ? 1 : 0); swgDenoiserSettings->setEnableDenoiser(settings.m_enableDenoiser ? 1 : 0);
} }
if (featureSettingsKeys.contains("nvidiaIntensity") || force) {
swgDenoiserSettings->setNvidiaIntensity(settings.m_nvidiaIntensity);
}
if (featureSettingsKeys.contains("nvidiaVad") || force) {
swgDenoiserSettings->setNvidiaVad(settings.m_nvidiaVad ? 1 : 0);
}
if (featureSettingsKeys.contains("vst3ModulePath") || force) {
swgDenoiserSettings->setVst3ModulePath(new QString(settings.m_vst3ModulePath));
}
if (featureSettingsKeys.contains("vst3ClassId") || force) {
swgDenoiserSettings->setVst3ClassId(new QString(QString::fromLatin1(settings.m_vst3ClassId.toHex())));
}
if (featureSettingsKeys.contains("vst3Parameters") || force) {
swgDenoiserSettings->setVst3Parameters(new QString(vst3ParametersJson(settings.m_vst3Parameters)));
}
if (featureSettingsKeys.contains("vst3State") || force) {
swgDenoiserSettings->setVst3State(new QString(QString::fromLatin1(settings.m_vst3State.toBase64())));
}
if (featureSettingsKeys.contains("audioMute") || force) { if (featureSettingsKeys.contains("audioMute") || force) {
swgDenoiserSettings->setAudioMute(settings.m_audioMute ? 1 : 0); swgDenoiserSettings->setAudioMute(settings.m_audioMute ? 1 : 0);
} }
@ -680,6 +1042,17 @@ void Denoiser::handleDataPipeToBeDeleted(int reason, QObject *object)
} }
m_selectedChannel = nullptr; m_selectedChannel = nullptr;
m_dataPipe = nullptr;
m_sampleRate = 0;
if (m_running)
{
m_worker->setVst3Effect(nullptr);
m_vst3Effect.reset();
m_worker->applySampleRate(0);
}
if (getMessageQueueToGUI()) {
getMessageQueueToGUI()->push(MsgReportSampleRate::create(0));
}
} }
} }

43
plugins/feature/denoiser/denoiser.h

@ -21,15 +21,18 @@
#include <QHash> #include <QHash>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QRecursiveMutex> #include <QRecursiveMutex>
#include <memory>
#include "feature/feature.h" #include "feature/feature.h"
#include "util/message.h" #include "util/message.h"
#include "availablechannelorfeaturehandler.h" #include "availablechannelorfeaturehandler.h"
#include "denoisersettings.h" #include "denoisersettings.h"
#include "vst3effect.h"
class WebAPIAdapterInterface; class WebAPIAdapterInterface;
class DenoiserWorker; class DenoiserWorker;
class Vst3Effect;
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
class QThread; class QThread;
@ -94,20 +97,28 @@ public:
AvailableChannelOrFeatureList& getAvailableChannels() { return m_availableChannels; } AvailableChannelOrFeatureList& getAvailableChannels() { return m_availableChannels; }
const QStringList& getRenameFrom() const { return m_renameFrom; } const QStringList& getRenameFrom() const { return m_renameFrom; }
const QStringList& getRenameTo() const { return m_renameTo; } const QStringList& getRenameTo() const { return m_renameTo; }
QObject *getSelectedChannel() const { return m_selectedChannel; }
bool getAutoSelect() const { return m_autoSelect; }
static MsgReportChannels* create(const QStringList& renameFrom, const QStringList& renameTo) { static MsgReportChannels* create(const QStringList& renameFrom, const QStringList& renameTo,
return new MsgReportChannels(renameFrom, renameTo); QObject *selectedChannel, bool autoSelect) {
return new MsgReportChannels(renameFrom, renameTo, selectedChannel, autoSelect);
} }
private: private:
AvailableChannelOrFeatureList m_availableChannels; AvailableChannelOrFeatureList m_availableChannels;
QStringList m_renameFrom; QStringList m_renameFrom;
QStringList m_renameTo; QStringList m_renameTo;
QObject *m_selectedChannel;
bool m_autoSelect;
MsgReportChannels(const QStringList& renameFrom, const QStringList& renameTo) : MsgReportChannels(const QStringList& renameFrom, const QStringList& renameTo,
QObject *selectedChannel, bool autoSelect) :
Message(), Message(),
m_renameFrom(renameFrom), m_renameFrom(renameFrom),
m_renameTo(renameTo) m_renameTo(renameTo),
m_selectedChannel(selectedChannel),
m_autoSelect(autoSelect)
{} {}
}; };
@ -115,15 +126,15 @@ public:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
ChannelAPI *getChannel() { return m_channel; } QObject *getChannel() { return m_channel; }
static MsgSelectChannel* create(ChannelAPI *channel) { static MsgSelectChannel* create(QObject *channel) {
return new MsgSelectChannel(channel); return new MsgSelectChannel(channel);
} }
protected: protected:
ChannelAPI *m_channel; QObject *m_channel;
MsgSelectChannel(ChannelAPI *channel) : MsgSelectChannel(QObject *channel) :
Message(), Message(),
m_channel(channel) m_channel(channel)
{ } { }
@ -191,6 +202,9 @@ public:
void getAvailableChannelsReport(); void getAvailableChannelsReport();
void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; }
QVector<Vst3ParameterInfo> vst3Parameters() const;
bool hasVst3Effect() const;
QString vst3ParameterText(quint32 id, double value) const;
static const char* const m_featureIdURI; static const char* const m_featureIdURI;
static const char* const m_featureId; static const char* const m_featureId;
@ -201,9 +215,10 @@ private:
bool m_running; bool m_running;
DenoiserWorker *m_worker; DenoiserWorker *m_worker;
DenoiserSettings m_settings; DenoiserSettings m_settings;
std::unique_ptr<Vst3Effect> m_vst3Effect;
AvailableChannelOrFeatureList m_availableChannels; AvailableChannelOrFeatureList m_availableChannels;
AvailableChannelOrFeatureHandler m_availableChannelOrFeatureHandler; AvailableChannelOrFeatureHandler m_availableChannelOrFeatureHandler;
ChannelAPI *m_selectedChannel; QObject *m_selectedChannel;
ObjectPipe *m_dataPipe; ObjectPipe *m_dataPipe;
int m_sampleRate; int m_sampleRate;
QObject *m_levelMeter = nullptr; QObject *m_levelMeter = nullptr;
@ -214,8 +229,14 @@ private:
void start(); void start();
void stop(); void stop();
void applySettings(const DenoiserSettings& settings, const QList<QString>& settingsKeys, bool force = false); void applySettings(const DenoiserSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo); void configureVst3();
void setChannel(ChannelAPI *selectedChannel); void useDefaultSampleRate();
void applyReportedSampleRate(int sampleRate);
void reportDemodSampleRate();
void notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo, bool autoSelect = true);
void querySelectedSource();
void restoreSelectedSource();
void setChannel(QObject *selectedChannel, bool preserveSavedSource = false);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DenoiserSettings& settings, bool force); void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DenoiserSettings& settings, bool force);
private slots: private slots:

517
plugins/feature/denoiser/denoisergui.cpp

@ -17,6 +17,22 @@
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo>
#include <QSignalBlocker>
#include <QCoreApplication>
#include <QDir>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess>
#include <QPointer>
#include <QDialog>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSlider>
#include <QLabel>
#include <QScreen>
#include "feature/featureuiset.h" #include "feature/featureuiset.h"
#include "gui/basicfeaturesettingsdialog.h" #include "gui/basicfeaturesettingsdialog.h"
@ -47,6 +63,7 @@ void DenoiserGUI::resetToDefaults()
{ {
m_settings.resetToDefaults(); m_settings.resetToDefaults();
displaySettings(); displaySettings();
updateChannelList(true);
applySettings(true); applySettings(true);
} }
@ -61,6 +78,7 @@ bool DenoiserGUI::deserialize(const QByteArray& data)
{ {
m_feature->setWorkspaceIndex(m_settings.m_workspaceIndex); m_feature->setWorkspaceIndex(m_settings.m_workspaceIndex);
displaySettings(); displaySettings();
updateChannelList(true);
applySettings(true); applySettings(true);
return true; return true;
} }
@ -84,9 +102,18 @@ bool DenoiserGUI::handleMessage(const Message& message)
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings()); m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
} }
const auto requestedType = m_settings.m_denoiserType;
blockApplySettings(true); blockApplySettings(true);
displaySettings(); displaySettings();
blockApplySettings(false); blockApplySettings(false);
if (cfg.getForce() || cfg.getSettingsKeys().contains("selectedSource")) {
updateChannelList(true);
}
if (m_settings.m_denoiserType != requestedType)
{
m_settingsKeys.append("denoiserType");
applySettings();
}
return true; return true;
} }
@ -95,7 +122,14 @@ bool DenoiserGUI::handleMessage(const Message& message)
qDebug("DenoiserGUI::handleMessage: Denoiser::MsgReportChannels"); qDebug("DenoiserGUI::handleMessage: Denoiser::MsgReportChannels");
Denoiser::MsgReportChannels& report = (Denoiser::MsgReportChannels&) message; Denoiser::MsgReportChannels& report = (Denoiser::MsgReportChannels&) message;
m_availableChannels = report.getAvailableChannels(); m_availableChannels = report.getAvailableChannels();
updateChannelList(); m_selectedChannel = report.getSelectedChannel();
for (int i = 0; i < report.getRenameFrom().size() && i < report.getRenameTo().size(); ++i)
{
if (m_settings.m_selectedSource == report.getRenameFrom().at(i)) {
m_settings.m_selectedSource = report.getRenameTo().at(i);
}
}
updateChannelList(report.getAutoSelect());
return true; return true;
} }
@ -142,7 +176,7 @@ DenoiserGUI::DenoiserGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Featu
ui(new Ui::DenoiserGUI), ui(new Ui::DenoiserGUI),
m_pluginAPI(pluginAPI), m_pluginAPI(pluginAPI),
m_featureUISet(featureUISet), m_featureUISet(featureUISet),
m_sampleRate(48000), m_sampleRate(0),
m_doApplySettings(true), m_doApplySettings(true),
m_selectedChannel(nullptr) m_selectedChannel(nullptr)
{ {
@ -151,6 +185,14 @@ DenoiserGUI::DenoiserGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Featu
m_helpURL = "plugins/feature/denoiser/readme.md"; m_helpURL = "plugins/feature/denoiser/readme.md";
RollupContents *rollupContents = getRollupContents(); RollupContents *rollupContents = getRollupContents();
ui->setupUi(rollupContents); ui->setupUi(rollupContents);
using DenoiserType = DenoiserSettings::DenoiserType;
ui->denoiserType->setItemData(0, static_cast<int>(DenoiserType::DenoiserType_None));
ui->denoiserType->setItemData(1, static_cast<int>(DenoiserType::DenoiserType_RNnoise));
ui->denoiserType->setItemData(2, static_cast<int>(DenoiserType::DenoiserType_Nvidia));
ui->denoiserType->setItemData(3, static_cast<int>(DenoiserType::DenoiserType_Vst3));
#if !defined(Q_OS_WIN) && !defined(Q_OS_LINUX)
ui->denoiserType->removeItem(static_cast<int>(DenoiserSettings::DenoiserType::DenoiserType_Nvidia));
#endif
rollupContents->arrangeRollups(); rollupContents->arrangeRollups();
connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
@ -183,6 +225,14 @@ DenoiserGUI::DenoiserGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Featu
DenoiserGUI::~DenoiserGUI() DenoiserGUI::~DenoiserGUI()
{ {
if (m_vst3ScanProcess)
{
QProcess *process = m_vst3ScanProcess;
m_vst3ScanProcess = nullptr;
QObject::disconnect(process, nullptr, this, nullptr);
process->kill();
process->waitForFinished(1000);
}
delete ui; delete ui;
} }
@ -206,7 +256,18 @@ void DenoiserGUI::displaySettings()
ui->record->setChecked(m_settings.m_recordToFile); ui->record->setChecked(m_settings.m_recordToFile);
ui->fileNameText->setText(m_settings.m_fileRecordName); ui->fileNameText->setText(m_settings.m_fileRecordName);
ui->showFileDialog->setEnabled(!m_settings.m_recordToFile); ui->showFileDialog->setEnabled(!m_settings.m_recordToFile);
ui->denoiserType->setCurrentIndex(static_cast<int>(m_settings.m_denoiserType)); int typeIndex = ui->denoiserType->findData(static_cast<int>(m_settings.m_denoiserType));
if (typeIndex < 0)
{
m_settings.m_denoiserType = DenoiserSettings::DenoiserType::DenoiserType_RNnoise;
typeIndex = ui->denoiserType->findData(static_cast<int>(m_settings.m_denoiserType));
}
ui->denoiserType->setCurrentIndex(typeIndex);
updateControls();
displayVst3Selection();
ui->nvidiaIntensity->setValue(m_settings.m_nvidiaIntensity);
ui->nvidiaIntensityText->setText(QStringLiteral("%1%").arg(m_settings.m_nvidiaIntensity));
ui->nvidiaVad->setChecked(m_settings.m_nvidiaVad);
ui->enable->setChecked(m_settings.m_enableDenoiser); ui->enable->setChecked(m_settings.m_enableDenoiser);
ui->audioMute->setChecked(m_settings.m_audioMute); ui->audioMute->setChecked(m_settings.m_audioMute);
ui->volume->setValue(m_settings.m_volumeTenths); ui->volume->setValue(m_settings.m_volumeTenths);
@ -218,36 +279,56 @@ void DenoiserGUI::displaySettings()
void DenoiserGUI::displaySampleRate(int sampleRate) void DenoiserGUI::displaySampleRate(int sampleRate)
{ {
if (sampleRate <= 0)
{
ui->sinkSampleRateText->setText(tr("-- kS/s"));
ui->sinkSampleRateText->setToolTip(tr("Waiting for the selected channel's sample rate"));
return;
}
QString s = QString::number(sampleRate/1000.0, 'f', 1); QString s = QString::number(sampleRate/1000.0, 'f', 1);
ui->sinkSampleRateText->setText(tr("%1 kS/s").arg(s)); ui->sinkSampleRateText->setText(tr("%1 kS/s").arg(s));
ui->sinkSampleRateText->setToolTip(QString());
} }
void DenoiserGUI::updateChannelList() void DenoiserGUI::updateChannelList(bool autoSelect)
{ {
ui->channels->blockSignals(true);
ui->channels->clear();
AvailableChannelOrFeatureList::const_iterator it = m_availableChannels.begin();
int selectedItem = -1;
for (int i = 0; it != m_availableChannels.end(); ++it, i++)
{ {
ui->channels->addItem(it->getLongId()); const QSignalBlocker blocker(ui->channels);
ui->channels->clear();
if (it->m_object == m_selectedChannel) { for (const auto& source : m_availableChannels) {
selectedItem = i; ui->channels->addItem(source.getLongId());
} }
}
ui->channels->blockSignals(false); int selectedItem = -1;
if (autoSelect)
if (m_availableChannels.size() > 0) {
{ if (!m_settings.m_selectedSource.isEmpty())
if (selectedItem >= 0) { {
ui->channels->setCurrentIndex(selectedItem); selectedItem = m_availableChannels.indexOfLongId(m_settings.m_selectedSource);
} else { }
ui->channels->setCurrentIndex(0); else
{
selectedItem = m_availableChannels.indexOfObject(m_selectedChannel);
if (selectedItem < 0 && !m_availableChannels.isEmpty()) {
selectedItem = 0;
}
}
} }
else
{
selectedItem = m_availableChannels.indexOfObject(m_selectedChannel);
if (selectedItem < 0) {
m_settings.m_selectedSource.clear();
}
}
ui->channels->setCurrentIndex(selectedItem);
}
// Adding the first item selects it while signals are blocked. Send the
// selection explicitly so the feature registers its data and rate pipes.
if (ui->channels->currentIndex() >= 0) {
on_channels_currentIndexChanged(ui->channels->currentIndex());
} }
} }
@ -296,6 +377,9 @@ void DenoiserGUI::on_startStop_toggled(bool checked)
{ {
if (m_doApplySettings) if (m_doApplySettings)
{ {
if (checked && !m_vst3ScanAttempted) {
scanVst3Plugins({}, true);
}
Denoiser::MsgStartStop *message = Denoiser::MsgStartStop::create(checked); Denoiser::MsgStartStop *message = Denoiser::MsgStartStop::create(checked);
m_denoiser->getInputMessageQueue()->push(message); m_denoiser->getInputMessageQueue()->push(message);
@ -309,7 +393,8 @@ void DenoiserGUI::on_channels_currentIndexChanged(int index)
{ {
if ((index >= 0) && (index < m_availableChannels.size())) if ((index >= 0) && (index < m_availableChannels.size()))
{ {
m_selectedChannel = qobject_cast<ChannelAPI*>(m_availableChannels[index].m_object); m_selectedChannel = m_availableChannels[index].m_object;
m_settings.m_selectedSource = m_availableChannels[index].getLongId();
Denoiser::MsgSelectChannel *msg = Denoiser::MsgSelectChannel::create(m_selectedChannel); Denoiser::MsgSelectChannel *msg = Denoiser::MsgSelectChannel::create(m_selectedChannel);
m_denoiser->getInputMessageQueue()->push(msg); m_denoiser->getInputMessageQueue()->push(msg);
} }
@ -360,11 +445,381 @@ void DenoiserGUI::on_showFileDialog_clicked(bool checked)
void DenoiserGUI::on_denoiserType_currentIndexChanged(int index) void DenoiserGUI::on_denoiserType_currentIndexChanged(int index)
{ {
m_settings.m_denoiserType = static_cast<DenoiserSettings::DenoiserType>(index); if (index < 0) {
return;
}
m_settings.m_denoiserType = static_cast<DenoiserSettings::DenoiserType>(ui->denoiserType->itemData(index).toInt());
if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Vst3 && !m_vst3ScanAttempted) {
scanVst3Plugins({}, true);
}
updateControls();
m_settingsKeys.append("denoiserType"); m_settingsKeys.append("denoiserType");
applySettings(); applySettings();
} }
void DenoiserGUI::updateControls()
{
RollupContents *rollups = getRollupContents();
const int previousContentHeight = rollups->arrangeRollups();
const bool showNvidia = m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Nvidia;
ui->nvidiaIntensityLabel->setVisible(showNvidia);
ui->nvidiaIntensity->setVisible(showNvidia);
ui->nvidiaIntensityText->setVisible(showNvidia);
ui->nvidiaVad->setVisible(showNvidia);
const bool showVst3 = m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Vst3;
ui->vst3Plugin->setVisible(showVst3);
ui->vst3Refresh->setVisible(showVst3);
ui->vst3Browse->setVisible(showVst3);
ui->vst3Parameters->setVisible(showVst3);
ui->settingsContainer->layout()->invalidate();
ui->settingsContainer->layout()->activate();
const int contentHeight = rollups->arrangeRollups();
layout()->activate();
sizeToContents();
if (isVisible() && !isMaximized()) {
resize(qMax(width(), minimumWidth()), qMax(height() + contentHeight - previousContentHeight, minimumHeight()));
}
}
void DenoiserGUI::displayVst3Selection()
{
const QSignalBlocker blocker(ui->vst3Plugin);
ui->vst3Plugin->clear();
int selected = -1;
for (const Vst3PluginInfo& plugin : m_vst3Plugins)
{
const int index = ui->vst3Plugin->count();
ui->vst3Plugin->addItem(plugin.name);
ui->vst3Plugin->setItemData(index, plugin.modulePath, Qt::ToolTipRole);
if (plugin.modulePath == m_settings.m_vst3ModulePath && plugin.classId == m_settings.m_vst3ClassId) {
selected = index;
}
}
if (selected < 0 && !m_settings.m_vst3ModulePath.isEmpty())
{
selected = ui->vst3Plugin->count();
ui->vst3Plugin->addItem(QFileInfo(m_settings.m_vst3ModulePath).fileName() + tr(" (saved)"));
ui->vst3Plugin->setItemData(selected, m_settings.m_vst3ModulePath, Qt::ToolTipRole);
}
if (selected >= 0) {
ui->vst3Plugin->setCurrentIndex(selected);
} else {
ui->vst3Plugin->setCurrentIndex(-1);
}
}
void DenoiserGUI::scanVst3Plugins(const QStringList& paths, bool automatic)
{
if (m_vst3ScanProcess) {
return;
}
if (paths.isEmpty()) {
m_vst3ScanAttempted = true;
}
auto *process = new QProcess(this);
m_vst3ScanProcess = process;
ui->vst3Refresh->setText(tr("Scanning..."));
ui->vst3Refresh->setToolTip(QString());
ui->vst3Refresh->setEnabled(false);
ui->vst3Browse->setEnabled(false);
const QString scanner = QDir(QCoreApplication::applicationDirPath()).filePath(
#ifdef Q_OS_WIN
QStringLiteral("sdrangel-vst3-scan.exe")
#else
QStringLiteral("sdrangel-vst3-scan")
#endif
);
process->setProgram(scanner);
process->setArguments(paths);
connect(process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this,
[this, process, automatic](int exitCode, QProcess::ExitStatus status) {
if (m_vst3ScanProcess != process) return;
const QJsonDocument document = QJsonDocument::fromJson(process->readAllStandardOutput());
if (status != QProcess::NormalExit || exitCode != 0 || !document.isArray())
{
const QString error = tr("The VST3 scanner failed. A plugin may have crashed during discovery.");
if (automatic) {
ui->vst3Refresh->setToolTip(error);
} else {
QMessageBox::warning(this, tr("VST3 scan"), error);
}
displayVst3Selection();
}
else
{
for (const QJsonValue& value : document.array())
{
const QJsonObject object = value.toObject();
Vst3PluginInfo plugin;
plugin.modulePath = object.value(QStringLiteral("path")).toString();
plugin.classId = QByteArray::fromHex(object.value(QStringLiteral("id")).toString().toLatin1());
plugin.name = object.value(QStringLiteral("name")).toString();
if (plugin.modulePath.isEmpty() || plugin.classId.size() != 16) continue;
bool duplicate = false;
for (const Vst3PluginInfo& known : m_vst3Plugins)
{
if (known.modulePath == plugin.modulePath && known.classId == plugin.classId)
{
duplicate = true;
break;
}
}
if (!duplicate) {
m_vst3Plugins.append(plugin);
}
}
displayVst3Selection();
if (m_vst3Plugins.isEmpty())
{
const QString message = tr("No VST3 audio effects were found.");
if (automatic) {
ui->vst3Refresh->setToolTip(message);
} else {
QMessageBox::information(this, tr("VST3 effects"), message);
}
}
}
ui->vst3Refresh->setText(tr("Scan"));
ui->vst3Refresh->setEnabled(true);
ui->vst3Browse->setEnabled(true);
m_vst3ScanProcess = nullptr;
process->deleteLater();
});
connect(process, &QProcess::errorOccurred, this, [this, process, automatic](QProcess::ProcessError error) {
if (error != QProcess::FailedToStart || m_vst3ScanProcess != process) {
return;
}
const QString message = tr("Could not launch the VST3 scanner: %1").arg(process->errorString());
if (automatic) {
ui->vst3Refresh->setToolTip(message);
} else {
QMessageBox::warning(this, tr("VST3 scan"), message);
}
displayVst3Selection();
ui->vst3Refresh->setText(tr("Scan"));
ui->vst3Refresh->setEnabled(true);
ui->vst3Browse->setEnabled(true);
m_vst3ScanProcess = nullptr;
process->deleteLater();
});
process->start();
QPointer<QProcess> guarded(process);
QTimer::singleShot(300000, this, [guarded]() {
if (guarded && guarded->state() != QProcess::NotRunning) guarded->kill();
});
}
void DenoiserGUI::on_vst3Plugin_currentIndexChanged(int index)
{
if (index < 0 || index >= m_vst3Plugins.size()) {
return;
}
const Vst3PluginInfo& plugin = m_vst3Plugins[index];
m_settings.m_vst3ModulePath = plugin.modulePath;
m_settings.m_vst3ClassId = plugin.classId;
m_settings.m_vst3Parameters.clear();
m_settings.m_vst3State.clear();
m_settingsKeys.append("vst3ModulePath");
m_settingsKeys.append("vst3ClassId");
m_settingsKeys.append("vst3Parameters");
m_settingsKeys.append("vst3State");
applySettings();
}
void DenoiserGUI::on_vst3Refresh_clicked()
{
m_vst3Plugins.clear();
scanVst3Plugins();
}
void DenoiserGUI::on_vst3Browse_clicked()
{
#ifdef Q_OS_WIN
const QString path = QFileDialog::getOpenFileName(this, tr("Select VST3 effect"), QString(), tr("VST3 effects (*.vst3)"));
#else
const QString path = QFileDialog::getExistingDirectory(this, tr("Select VST3 bundle"));
#endif
if (!path.isEmpty()) {
scanVst3Plugins({path});
}
}
void DenoiserGUI::on_vst3Parameters_clicked()
{
if (m_settings.m_vst3ModulePath.isEmpty() || m_settings.m_vst3ClassId.size() != 16)
{
QMessageBox::information(this, tr("VST3 parameters"),
tr("Select a VST3 effect from the list first."));
return;
}
// Keep the editor instance independent of the audio worker. Audio format or
// channel changes can then recreate the processing instance safely.
auto parameterEffect = std::make_unique<Vst3Effect>();
QString error;
if (!parameterEffect->open(m_settings.m_vst3ModulePath, m_settings.m_vst3ClassId,
m_sampleRate > 0 ? m_sampleRate : 48000, 2, error, m_settings.m_vst3State))
{
QMessageBox::warning(this, tr("VST3 parameters"),
tr("Could not load the selected VST3 effect: %1").arg(error));
return;
}
for (auto it = m_settings.m_vst3Parameters.cbegin(); it != m_settings.m_vst3Parameters.cend(); ++it) {
parameterEffect->setParameter(it.key(), it.value());
}
parameterEffect->setParameterEditCallback([this](quint32 id, double value) {
if (m_settings.m_vst3Parameters.value(id, -1.0) == value) {
return;
}
m_settings.m_vst3Parameters.insert(id, value);
m_settingsKeys.append("vst3Parameters");
applySettings();
});
QDialog dialog(this);
dialog.setWindowTitle(tr("VST3 parameters"));
auto *outer = new QVBoxLayout(&dialog);
if (!m_denoiser->hasVst3Effect())
{
auto *notice = new QLabel(tr("Live processing was unavailable when this dialog opened. Changes are saved and applied when the effect loads."), &dialog);
notice->setWordWrap(true);
outer->addWidget(notice);
}
QString editorError;
auto *nativeScroll = new QScrollArea(&dialog);
nativeScroll->setWidgetResizable(false);
if (QWidget *editor = parameterEffect->createEditorWidget(nativeScroll->viewport(), editorError))
{
nativeScroll->setWidget(editor);
outer->addWidget(nativeScroll);
if (QScreen *screen = dialog.screen())
{
const QRect available = screen->availableGeometry();
dialog.resize(qMin(editor->width() + 36, available.width() - 80),
qMin(editor->height() + 64, available.height() - 80));
}
else
{
dialog.adjustSize();
}
dialog.exec();
saveVst3State(*parameterEffect);
return;
}
delete nativeScroll;
const QVector<Vst3ParameterInfo> parameters = parameterEffect->parameters();
bool hasEditableParameter = false;
for (const Vst3ParameterInfo& parameter : parameters)
{
if (!parameter.readOnly && !parameter.hidden)
{
hasEditableParameter = true;
break;
}
}
if (!hasEditableParameter)
{
QMessageBox::information(this, tr("VST3 parameters"),
tr("This VST3 effect has no available editor or editable parameters. %1").arg(editorError));
return;
}
dialog.resize(440, 500);
auto *scroll = new QScrollArea(&dialog);
scroll->setWidgetResizable(true);
outer->addWidget(scroll);
auto *content = new QWidget(scroll);
auto *layout = new QVBoxLayout(content);
for (const Vst3ParameterInfo& parameter : parameters)
{
if (parameter.readOnly || parameter.hidden) {
continue;
}
auto *row = new QWidget(content);
auto *rowLayout = new QHBoxLayout(row);
auto *name = new QLabel(parameter.name, row);
name->setMinimumWidth(130);
auto *slider = new QSlider(Qt::Horizontal, row);
const int maximum = parameter.steps > 0 ? qMin(parameter.steps, 10000) : 1000;
slider->setRange(0, maximum);
const double value = m_settings.m_vst3Parameters.value(parameter.id, parameter.currentValue);
slider->setValue(qRound(value * maximum));
auto *valueLabel = new QLabel(parameterEffect->parameterText(parameter.id, value), row);
valueLabel->setMinimumWidth(70);
valueLabel->setMaximumWidth(120);
rowLayout->addWidget(name);
rowLayout->addWidget(slider, 1);
rowLayout->addWidget(valueLabel);
layout->addWidget(row);
connect(slider, &QSlider::valueChanged, &dialog, [this, parameter, maximum, valueLabel, effect = parameterEffect.get()](int raw) {
const double normalized = static_cast<double>(raw) / maximum;
effect->setParameter(parameter.id, normalized);
valueLabel->setText(effect->parameterText(parameter.id, normalized));
m_settings.m_vst3Parameters.insert(parameter.id, normalized);
m_settingsKeys.append("vst3Parameters");
applySettings();
});
}
layout->addStretch();
scroll->setWidget(content);
dialog.exec();
saveVst3State(*parameterEffect);
}
void DenoiserGUI::saveVst3State(Vst3Effect& effect)
{
QString error;
const QByteArray state = effect.state(error);
if (state.isEmpty())
{
qWarning() << "DenoiserGUI::saveVst3State:" << error;
return;
}
// Editor changes such as presets may bypass performEdit, so refresh the saved
// parameter values. Otherwise they would override the state when it is restored.
bool parametersChanged = false;
for (auto it = m_settings.m_vst3Parameters.begin(); it != m_settings.m_vst3Parameters.end(); ++it)
{
const double value = effect.parameterValue(it.key());
if (value >= 0.0 && value != it.value())
{
it.value() = value;
parametersChanged = true;
}
}
if (state == m_settings.m_vst3State && !parametersChanged) {
return;
}
m_settings.m_vst3State = state;
m_settingsKeys.append("vst3State");
if (parametersChanged) {
m_settingsKeys.append("vst3Parameters");
}
applySettings();
}
void DenoiserGUI::on_nvidiaIntensity_valueChanged(int value)
{
ui->nvidiaIntensityText->setText(QStringLiteral("%1%").arg(value));
if (ui->nvidiaIntensity->isSliderDown() || m_settings.m_nvidiaIntensity == value) {
return;
}
m_settings.m_nvidiaIntensity = value;
m_settingsKeys.append("nvidiaIntensity");
applySettings();
}
void DenoiserGUI::on_nvidiaVad_toggled(bool checked)
{
m_settings.m_nvidiaVad = checked;
m_settingsKeys.append("nvidiaVad");
applySettings();
}
void DenoiserGUI::on_enable_toggled(bool checked) void DenoiserGUI::on_enable_toggled(bool checked)
{ {
m_settings.m_enableDenoiser = checked; m_settings.m_enableDenoiser = checked;
@ -415,6 +870,9 @@ void DenoiserGUI::tick()
void DenoiserGUI::updateFeatureState() void DenoiserGUI::updateFeatureState()
{ {
updateStartStopButton(ui->startStop); updateStartStopButton(ui->startStop);
if (m_denoiser->getState() == Feature::StRunning && !m_vst3ScanAttempted) {
scanVst3Plugins({}, true);
}
} }
void DenoiserGUI::displayNRenabled() void DenoiserGUI::displayNRenabled()
@ -445,6 +903,15 @@ void DenoiserGUI::makeUIConnections()
QObject::connect(ui->record, &ButtonSwitch::toggled, this, &DenoiserGUI::on_record_toggled); QObject::connect(ui->record, &ButtonSwitch::toggled, this, &DenoiserGUI::on_record_toggled);
QObject::connect(ui->showFileDialog, &QPushButton::clicked, this, &DenoiserGUI::on_showFileDialog_clicked); QObject::connect(ui->showFileDialog, &QPushButton::clicked, this, &DenoiserGUI::on_showFileDialog_clicked);
QObject::connect(ui->denoiserType, qOverload<int>(&QComboBox::currentIndexChanged), this, &DenoiserGUI::on_denoiserType_currentIndexChanged); QObject::connect(ui->denoiserType, qOverload<int>(&QComboBox::currentIndexChanged), this, &DenoiserGUI::on_denoiserType_currentIndexChanged);
QObject::connect(ui->nvidiaIntensity, &QSlider::valueChanged, this, &DenoiserGUI::on_nvidiaIntensity_valueChanged);
QObject::connect(ui->nvidiaIntensity, &QSlider::sliderReleased, this, [this]() {
on_nvidiaIntensity_valueChanged(ui->nvidiaIntensity->value());
});
QObject::connect(ui->nvidiaVad, &QCheckBox::toggled, this, &DenoiserGUI::on_nvidiaVad_toggled);
QObject::connect(ui->vst3Plugin, qOverload<int>(&QComboBox::currentIndexChanged), this, &DenoiserGUI::on_vst3Plugin_currentIndexChanged);
QObject::connect(ui->vst3Refresh, &QPushButton::clicked, this, &DenoiserGUI::on_vst3Refresh_clicked);
QObject::connect(ui->vst3Browse, &QPushButton::clicked, this, &DenoiserGUI::on_vst3Browse_clicked);
QObject::connect(ui->vst3Parameters, &QPushButton::clicked, this, &DenoiserGUI::on_vst3Parameters_clicked);
QObject::connect(ui->enable, &ButtonSwitch::toggled, this, &DenoiserGUI::on_enable_toggled); QObject::connect(ui->enable, &ButtonSwitch::toggled, this, &DenoiserGUI::on_enable_toggled);
QObject::connect(ui->audioMute, &ButtonSwitch::toggled, this, &DenoiserGUI::on_audioMute_toggled); QObject::connect(ui->audioMute, &ButtonSwitch::toggled, this, &DenoiserGUI::on_audioMute_toggled);
QObject::connect(ui->volume, &QDial::valueChanged, this, &DenoiserGUI::on_volume_valueChanged); QObject::connect(ui->volume, &QDial::valueChanged, this, &DenoiserGUI::on_volume_valueChanged);

19
plugins/feature/denoiser/denoisergui.h

@ -27,11 +27,13 @@
#include "settings/rollupstate.h" #include "settings/rollupstate.h"
#include "denoisersettings.h" #include "denoisersettings.h"
#include "vst3effect.h"
class PluginAPI; class PluginAPI;
class FeatureUISet; class FeatureUISet;
class Denoiser; class Denoiser;
class Feature; class Feature;
class QProcess;
namespace Ui { namespace Ui {
class DenoiserGUI; class DenoiserGUI;
@ -65,8 +67,11 @@ private:
Denoiser* m_denoiser; Denoiser* m_denoiser;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
AvailableChannelOrFeatureList m_availableChannels; AvailableChannelOrFeatureList m_availableChannels;
ChannelAPI *m_selectedChannel; QObject *m_selectedChannel;
MovingAverageUtil<double, double, 40> m_channelPowerAvg; MovingAverageUtil<double, double, 40> m_channelPowerAvg;
QVector<Vst3PluginInfo> m_vst3Plugins;
QProcess *m_vst3ScanProcess = nullptr;
bool m_vst3ScanAttempted = false;
explicit DenoiserGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr); explicit DenoiserGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);
virtual ~DenoiserGUI(); virtual ~DenoiserGUI();
@ -76,7 +81,11 @@ private:
void displaySettings(); void displaySettings();
void displaySampleRate(int sampleRate); void displaySampleRate(int sampleRate);
void displayNRenabled(); void displayNRenabled();
void updateChannelList(); void updateControls();
void displayVst3Selection();
void saveVst3State(Vst3Effect& effect);
void scanVst3Plugins(const QStringList& paths = {}, bool automatic = false);
void updateChannelList(bool autoSelect);
bool handleMessage(const Message& message); bool handleMessage(const Message& message);
void makeUIConnections(); void makeUIConnections();
@ -90,6 +99,12 @@ private slots:
void on_record_toggled(bool checked); void on_record_toggled(bool checked);
void on_showFileDialog_clicked(bool checked); void on_showFileDialog_clicked(bool checked);
void on_denoiserType_currentIndexChanged(int index); void on_denoiserType_currentIndexChanged(int index);
void on_nvidiaIntensity_valueChanged(int value);
void on_nvidiaVad_toggled(bool checked);
void on_vst3Plugin_currentIndexChanged(int index);
void on_vst3Refresh_clicked();
void on_vst3Browse_clicked();
void on_vst3Parameters_clicked();
void on_enable_toggled(bool checked); void on_enable_toggled(bool checked);
void on_audioMute_toggled(bool checked); void on_audioMute_toggled(bool checked);
void on_volume_valueChanged(int value); void on_volume_valueChanged(int value);

158
plugins/feature/denoiser/denoisergui.ui

@ -93,8 +93,11 @@
</item> </item>
<item> <item>
<widget class="QLabel" name="channelsLabel"> <widget class="QLabel" name="channelsLabel">
<property name="toolTip">
<string>Audio source channel or feature</string>
</property>
<property name="text"> <property name="text">
<string>Chan</string> <string>Source</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -137,14 +140,14 @@
<string>00000.0 kS/s</string> <string>00000.0 kS/s</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -166,13 +169,13 @@
<string>Channel power</string> <string>Channel power</string>
</property> </property>
<property name="layoutDirection"> <property name="layoutDirection">
<enum>Qt::LeftToRight</enum> <enum>Qt::LayoutDirection::LeftToRight</enum>
</property> </property>
<property name="text"> <property name="text">
<string>-100.0 dB</string> <string>-100.0 dB</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -201,6 +204,16 @@
<string>RNnoise</string> <string>RNnoise</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>NVIDIA Noise Removal</string>
</property>
</item>
<item>
<property name="text">
<string>VST3 Effect</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
@ -227,7 +240,7 @@
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -257,10 +270,125 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="nvidiaControlsLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="nvidiaIntensityLabel">
<property name="text">
<string>Strength</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="nvidiaIntensity">
<property name="toolTip">
<string>Noise removal strength: lower values preserve more weak speech</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nvidiaIntensityText">
<property name="text">
<string>100%</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="nvidiaVad">
<property name="toolTip">
<string>Voice activity detection: may suppress weak or misclassified speech</string>
</property>
<property name="text">
<string>VAD</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="vst3ControlsLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="vst3Plugin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Selected VST3 audio effect</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="vst3Refresh">
<property name="toolTip">
<string>Scan installed VST3 effects</string>
</property>
<property name="text">
<string>Scan</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="vst3Browse">
<property name="toolTip">
<string>Select a VST3 module outside standard plugin folders</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="vst3Parameters">
<property name="toolTip">
<string>Edit the effect's parameters</string>
</property>
<property name="text">
<string>Params</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -310,7 +438,7 @@
<string>1.0</string> <string>1.0</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -338,7 +466,7 @@
<item> <item>
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -402,7 +530,7 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -412,17 +540,17 @@
</widget> </widget>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
<customwidget> <customwidget>
<class>RollupContents</class> <class>RollupContents</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>gui/rollupcontents.h</header> <header>gui/rollupcontents.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
<customwidget> <customwidget>
<class>LevelMeterVU</class> <class>LevelMeterVU</class>
<extends>QWidget</extends> <extends>QWidget</extends>

83
plugins/feature/denoiser/denoisersettings.cpp

@ -20,6 +20,9 @@
#include "audio/audiodevicemanager.h" #include "audio/audiodevicemanager.h"
#include "denoisersettings.h" #include "denoisersettings.h"
#include <QtGlobal>
#include <QJsonDocument>
#include <QJsonObject>
const QStringList DenoiserSettings::m_channelURIs = { const QStringList DenoiserSettings::m_channelURIs = {
QStringLiteral("sdrangel.channel.amdemod"), QStringLiteral("sdrangel.channel.amdemod"),
@ -31,6 +34,7 @@ const QStringList DenoiserSettings::m_channelURIs = {
QStringLiteral("sdrangel.channel.ssbdemod"), QStringLiteral("sdrangel.channel.ssbdemod"),
QStringLiteral("sdrangel.channel.wfmdemod"), QStringLiteral("sdrangel.channel.wfmdemod"),
QStringLiteral("sdrangel.channel.wdsprx"), QStringLiteral("sdrangel.channel.wdsprx"),
QStringLiteral("sdrangel.feature.denoiser"),
}; };
DenoiserSettings::DenoiserSettings() : DenoiserSettings::DenoiserSettings() :
@ -42,10 +46,17 @@ DenoiserSettings::DenoiserSettings() :
void DenoiserSettings::resetToDefaults() void DenoiserSettings::resetToDefaults()
{ {
m_denoiserType = DenoiserType::DenoiserType_RNnoise; m_denoiserType = DenoiserType::DenoiserType_RNnoise;
m_selectedSource.clear();
m_title = "Denoiser"; m_title = "Denoiser";
m_enableDenoiser = true; m_enableDenoiser = true;
m_audioMute = false; m_audioMute = false;
m_volumeTenths = 10; m_volumeTenths = 10;
m_nvidiaIntensity = 100;
m_nvidiaVad = false;
m_vst3ModulePath.clear();
m_vst3ClassId.clear();
m_vst3Parameters.clear();
m_vst3State.clear();
m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName; m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName;
m_rgbColor = 0xffd700; // gold m_rgbColor = 0xffd700; // gold
m_useReverseAPI = false; m_useReverseAPI = false;
@ -84,6 +95,17 @@ QByteArray DenoiserSettings::serialize() const
s.writeString(15, m_audioDeviceName); s.writeString(15, m_audioDeviceName);
s.writeBool(16, m_enableDenoiser); s.writeBool(16, m_enableDenoiser);
s.writeS32(17, m_volumeTenths); s.writeS32(17, m_volumeTenths);
s.writeS32(18, m_nvidiaIntensity);
s.writeBool(19, m_nvidiaVad);
s.writeString(20, m_vst3ModulePath);
s.writeBlob(21, m_vst3ClassId);
QJsonObject parameters;
for (auto it = m_vst3Parameters.cbegin(); it != m_vst3Parameters.cend(); ++it) {
parameters.insert(QString::number(it.key()), it.value());
}
s.writeBlob(22, QJsonDocument(parameters).toJson(QJsonDocument::Compact));
s.writeString(23, m_selectedSource);
s.writeBlob(24, m_vst3State);
return s.final(); return s.final();
} }
@ -105,7 +127,7 @@ bool DenoiserSettings::deserialize(const QByteArray& data)
uint32_t utmp; uint32_t utmp;
d.readS32(1, &itmp, 1); d.readS32(1, &itmp, 1);
m_denoiserType = static_cast<DenoiserType>(itmp); m_denoiserType = static_cast<DenoiserType>(itmp >= 0 && itmp <= 3 ? itmp : 1);
d.readString(2, &m_title, "Denoiser"); d.readString(2, &m_title, "Denoiser");
d.readU32(3, &m_rgbColor, 0xffd700); // gold d.readU32(3, &m_rgbColor, 0xffd700); // gold
d.readBool(4, &m_useReverseAPI, false); d.readBool(4, &m_useReverseAPI, false);
@ -137,6 +159,26 @@ bool DenoiserSettings::deserialize(const QByteArray& data)
d.readString(15, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName); d.readString(15, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName);
d.readBool(16, &m_enableDenoiser, true); d.readBool(16, &m_enableDenoiser, true);
d.readS32(17, &m_volumeTenths, 10); d.readS32(17, &m_volumeTenths, 10);
d.readS32(18, &m_nvidiaIntensity, 100);
m_nvidiaIntensity = qBound(0, m_nvidiaIntensity, 100);
d.readBool(19, &m_nvidiaVad, false);
d.readString(20, &m_vst3ModulePath, "");
d.readBlob(21, &m_vst3ClassId);
bytetmp.clear();
d.readBlob(22, &bytetmp);
m_vst3Parameters.clear();
const QJsonObject parameters = QJsonDocument::fromJson(bytetmp).object();
for (auto it = parameters.begin(); it != parameters.end(); ++it)
{
bool validId = false;
const quint32 id = it.key().toUInt(&validId);
const double value = it.value().toDouble(-1.0);
if (validId && value >= 0.0 && value <= 1.0) {
m_vst3Parameters.insert(id, value);
}
}
d.readString(23, &m_selectedSource, "");
d.readBlob(24, &m_vst3State);
return true; return true;
} }
@ -149,6 +191,9 @@ bool DenoiserSettings::deserialize(const QByteArray& data)
void DenoiserSettings::applySettings(const QStringList& settingsKeys, const DenoiserSettings& settings) void DenoiserSettings::applySettings(const QStringList& settingsKeys, const DenoiserSettings& settings)
{ {
if (settingsKeys.contains("selectedSource")) {
m_selectedSource = settings.m_selectedSource;
}
if (settingsKeys.contains("denoiserType")) { if (settingsKeys.contains("denoiserType")) {
m_denoiserType = settings.m_denoiserType; m_denoiserType = settings.m_denoiserType;
} }
@ -161,6 +206,24 @@ void DenoiserSettings::applySettings(const QStringList& settingsKeys, const Deno
if (settingsKeys.contains("volumeTenths")) { if (settingsKeys.contains("volumeTenths")) {
m_volumeTenths = settings.m_volumeTenths; m_volumeTenths = settings.m_volumeTenths;
} }
if (settingsKeys.contains("nvidiaIntensity")) {
m_nvidiaIntensity = qBound(0, settings.m_nvidiaIntensity, 100);
}
if (settingsKeys.contains("nvidiaVad")) {
m_nvidiaVad = settings.m_nvidiaVad;
}
if (settingsKeys.contains("vst3ModulePath")) {
m_vst3ModulePath = settings.m_vst3ModulePath;
}
if (settingsKeys.contains("vst3ClassId")) {
m_vst3ClassId = settings.m_vst3ClassId;
}
if (settingsKeys.contains("vst3Parameters")) {
m_vst3Parameters = settings.m_vst3Parameters;
}
if (settingsKeys.contains("vst3State")) {
m_vst3State = settings.m_vst3State;
}
if (settingsKeys.contains("audioDeviceName")) { if (settingsKeys.contains("audioDeviceName")) {
m_audioDeviceName = settings.m_audioDeviceName; m_audioDeviceName = settings.m_audioDeviceName;
} }
@ -200,6 +263,9 @@ QString DenoiserSettings::getDebugString(const QStringList& settingsKeys, bool f
{ {
QString debugString; QString debugString;
if (settingsKeys.contains("selectedSource") || force) {
debugString += QString("Selected source: %1 ").arg(m_selectedSource);
}
if (settingsKeys.contains("denoiserType") || force) { if (settingsKeys.contains("denoiserType") || force) {
debugString += QString("DenoiserType: %1 ").arg(static_cast<qint32>(m_denoiserType)); debugString += QString("DenoiserType: %1 ").arg(static_cast<qint32>(m_denoiserType));
} }
@ -212,6 +278,21 @@ QString DenoiserSettings::getDebugString(const QStringList& settingsKeys, bool f
if (settingsKeys.contains("volumeTenths") || force) { if (settingsKeys.contains("volumeTenths") || force) {
debugString += QString("Volume : %1 ").arg(m_volumeTenths/10.0); debugString += QString("Volume : %1 ").arg(m_volumeTenths/10.0);
} }
if (settingsKeys.contains("nvidiaIntensity") || force) {
debugString += QString("NVIDIA intensity: %1%% ").arg(m_nvidiaIntensity);
}
if (settingsKeys.contains("nvidiaVad") || force) {
debugString += QString("NVIDIA VAD: %1 ").arg(m_nvidiaVad ? "true" : "false");
}
if (settingsKeys.contains("vst3ModulePath") || force) {
debugString += QString("VST3 module: %1 ").arg(m_vst3ModulePath);
}
if (settingsKeys.contains("vst3ClassId") || force) {
debugString += QString("VST3 class: %1 ").arg(QString::fromLatin1(m_vst3ClassId.toHex()));
}
if (settingsKeys.contains("vst3State") || force) {
debugString += QString("VST3 state: %1 bytes ").arg(m_vst3State.size());
}
if (settingsKeys.contains("audioDeviceName") || force) { if (settingsKeys.contains("audioDeviceName") || force) {
debugString += QString("Audio Device Name: %1 ").arg(m_audioDeviceName); debugString += QString("Audio Device Name: %1 ").arg(m_audioDeviceName);
} }

10
plugins/feature/denoiser/denoisersettings.h

@ -20,6 +20,7 @@
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QMap>
class Serializable; class Serializable;
@ -29,12 +30,21 @@ struct DenoiserSettings
{ {
DenoiserType_None = 0, DenoiserType_None = 0,
DenoiserType_RNnoise = 1, DenoiserType_RNnoise = 1,
DenoiserType_Nvidia = 2,
DenoiserType_Vst3 = 3,
}; };
DenoiserType m_denoiserType; DenoiserType m_denoiserType;
QString m_selectedSource;
bool m_enableDenoiser; bool m_enableDenoiser;
bool m_audioMute; bool m_audioMute;
int m_volumeTenths; int m_volumeTenths;
int m_nvidiaIntensity;
bool m_nvidiaVad;
QString m_vst3ModulePath;
QByteArray m_vst3ClassId;
QMap<quint32, double> m_vst3Parameters;
QByteArray m_vst3State; //!< Opaque plugin state from Vst3Effect::state()
QString m_audioDeviceName; QString m_audioDeviceName;
QString m_title; QString m_title;
quint32 m_rgbColor; quint32 m_rgbColor;

344
plugins/feature/denoiser/denoiserworker.cpp

@ -18,28 +18,44 @@
#include "dsp/wavfilerecord.h" #include "dsp/wavfilerecord.h"
#include "audio/audiodevicemanager.h" #include "audio/audiodevicemanager.h"
#include "dsp/dspengine.h" #include "dsp/dspengine.h"
#include "pipes/datapipes.h"
#include "maincore.h"
#include "rnnoise.h" #include "rnnoise.h"
#include <algorithm>
#include <cmath>
#include "denoiserworker.h" #include "denoiserworker.h"
#include "vst3effect.h"
const int DenoiserWorker::m_levelNbSamples = 480; // 10 ms at 48 kHz const int DenoiserWorker::m_levelNbSamples = 480; // 10 ms at 48 kHz
MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgConfigureDenoiserWorker, Message) MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgConfigureDenoiserWorker, Message)
MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgConnectFifo, Message) MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgConnectFifo, Message)
MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgReportNvidiaStatus, Message)
MESSAGE_CLASS_DEFINITION(DenoiserWorker::MsgReportVst3Status, Message)
DenoiserWorker::DenoiserWorker(QObject *parent) : DenoiserWorker::DenoiserWorker(QObject *parent) :
QObject(parent), QObject(parent),
m_dataFifo(nullptr), m_dataFifo(nullptr),
m_demodProducer(nullptr),
m_sinkSampleRate(0), m_sinkSampleRate(0),
m_msgQueueToFeature(nullptr), m_msgQueueToFeature(nullptr),
m_magsq(0.0), m_magsq(0.0),
m_sampleBufferSize(0),
m_channelPowerAvg(), m_channelPowerAvg(),
m_wavFileRecord(nullptr), m_wavFileRecord(nullptr),
m_recordSilenceNbSamples(0), m_recordSilenceNbSamples(0),
m_recordSilenceCount(0), m_recordSilenceCount(0),
m_nbBytes(0), m_nbBytes(0),
m_rnnoiseFill(0) m_rnnoiseFill(0),
m_nvidiaFill(0),
m_nvidiaInitAttempted(false),
m_nvidiaReady(false),
m_nvidiaResetPending(false),
m_nvidiaStatusReported(false),
m_nvidiaGeneration(0),
m_vst3Effect(nullptr),
m_vst3Fill(0),
m_vst3FailureReported(false)
{ {
m_audioBuffer.resize(4800); m_audioBuffer.resize(4800);
m_audioBufferFill = 0; m_audioBufferFill = 0;
@ -53,6 +69,7 @@ DenoiserWorker::~DenoiserWorker()
m_inputMessageQueue.clear(); m_inputMessageQueue.clear();
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(getAudioFifo()); DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(getAudioFifo());
rnnoise_destroy(m_rnnoiseState); rnnoise_destroy(m_rnnoiseState);
m_nvidiaDenoiser.shutdown();
} }
void DenoiserWorker::reset() void DenoiserWorker::reset()
@ -106,24 +123,56 @@ void DenoiserWorker::feedPart(
m_nbBytes = nbBytes; m_nbBytes = nbBytes;
int countSamples = (end - begin) / nbBytes; int countSamples = (end - begin) / nbBytes;
if (countSamples > m_sampleBufferSize) m_sampleBuffer.clear();
{ m_sampleBuffer.reserve(countSamples);
m_sampleBuffer.resize(countSamples);
m_sampleBufferSize = countSamples;
}
for (int i = 0; i < countSamples; i++) { for (int i = 0; i < countSamples; i++) {
processSample(dataType, begin, i); processSample(dataType, begin, i);
} }
flushAudio();
if (m_settings.m_recordToFile && m_wavFileRecord) if (m_settings.m_recordToFile && m_wavFileRecord)
{ {
for (const auto& sample : m_sampleBuffer) { for (const auto& sample : m_sampleBuffer) {
writeSampleToFile(sample); writeSampleToFile(sample);
} }
}
m_sampleBuffer.clear();
}
void DenoiserWorker::flushAudio()
{
if (m_audioBufferFill == 0) return;
if (m_demodProducer)
{
QList<ObjectPipe*> pipes;
MainCore::instance()->getDataPipes().getDataPipes(m_demodProducer, "demod", pipes);
const auto *data = reinterpret_cast<const quint8*>(m_audioBuffer.data());
const unsigned int byteCount = static_cast<unsigned int>(m_audioBufferFill * sizeof(AudioSample));
for (const auto& pipe : pipes)
{
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element);
if (fifo) {
fifo->write(data, byteCount, DataFifo::DataTypeCI16);
}
}
}
if (m_settings.m_audioMute) {
std::fill_n(m_audioBuffer.begin(), m_audioBufferFill, AudioSample{0, 0});
}
m_sampleBuffer.clear(); const std::size_t written = m_audioFifo.write(reinterpret_cast<const quint8*>(m_audioBuffer.data()), m_audioBufferFill);
if (written != m_audioBufferFill)
{
qDebug("DenoiserWorker::flushAudio: %lu/%lu audio samples written", written, m_audioBufferFill);
m_audioFifo.clear();
} }
m_audioBufferFill = 0;
} }
void DenoiserWorker::writeSampleToFile(const Sample& sample) void DenoiserWorker::writeSampleToFile(const Sample& sample)
@ -271,8 +320,12 @@ void DenoiserWorker::applySettings(const DenoiserSettings& settings, const QStri
// TODO: handle sample rate change // TODO: handle sample rate change
} }
if (settingsKeys.contains("enableDenoiser") || settingsKeys.contains("denoiserType") || force) { if (settingsKeys.contains("enableDenoiser") || settingsKeys.contains("denoiserType") ||
settingsKeys.contains("nvidiaIntensity") ||
settingsKeys.contains("nvidiaVad") || force)
{
m_rnnoiseFill = 0; m_rnnoiseFill = 0;
resetNvidia();
} }
if (force) { if (force) {
@ -280,12 +333,35 @@ void DenoiserWorker::applySettings(const DenoiserSettings& settings, const QStri
} else { } else {
m_settings.applySettings(settingsKeys, settings); m_settings.applySettings(settingsKeys, settings);
} }
if (force || settingsKeys.contains("denoiserType") || settingsKeys.contains("vst3ModulePath") ||
settingsKeys.contains("vst3ClassId") || settingsKeys.contains("enableDenoiser"))
{
m_vst3Fill = 0;
m_vst3FailureReported = false;
}
// applySettings runs on the worker thread. Release the CUDA effect as soon as
// this backend is no longer in use, even if no more NVIDIA samples arrive.
if (m_nvidiaResetPending && (!m_settings.m_enableDenoiser ||
m_settings.m_denoiserType != DenoiserSettings::DenoiserType::DenoiserType_Nvidia))
{
m_nvidiaDenoiser.shutdown();
m_nvidiaResetPending = false;
}
} }
void DenoiserWorker::applySampleRate(int sampleRate) void DenoiserWorker::applySampleRate(int sampleRate)
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if (m_sinkSampleRate == sampleRate) {
return;
}
m_sinkSampleRate = sampleRate; m_sinkSampleRate = sampleRate;
resetNvidia();
m_vst3Fill = 0;
m_vst3FailureReported = false;
if (m_wavFileRecord) if (m_wavFileRecord)
{ {
@ -297,8 +373,82 @@ void DenoiserWorker::applySampleRate(int sampleRate)
} }
} }
void DenoiserWorker::setVst3Effect(Vst3Effect *effect)
{
QMutexLocker mutexLocker(&m_mutex);
m_vst3Effect = effect;
m_vst3Fill = 0;
m_vst3FailureReported = false;
}
void DenoiserWorker::resetNvidia()
{
// Caller holds m_mutex. The model itself is released on the worker thread.
m_nvidiaFill = 0;
m_nvidiaInitAttempted = false;
m_nvidiaReady = false;
m_nvidiaResetPending = true;
m_nvidiaStatusReported = false;
++m_nvidiaGeneration;
}
void DenoiserWorker::prepareNvidia()
{
int sampleRate;
float intensity;
bool vad;
quint32 generation;
{
QMutexLocker mutexLocker(&m_mutex);
if (m_nvidiaInitAttempted || !m_settings.m_enableDenoiser ||
m_settings.m_denoiserType != DenoiserSettings::DenoiserType::DenoiserType_Nvidia) {
return;
}
if (m_nvidiaResetPending)
{
m_nvidiaDenoiser.shutdown();
m_nvidiaResetPending = false;
}
m_nvidiaInitAttempted = true;
sampleRate = m_sinkSampleRate;
intensity = qBound(0, m_settings.m_nvidiaIntensity, 100) / 100.0f;
vad = m_settings.m_nvidiaVad;
generation = m_nvidiaGeneration;
}
// Loading the model can take seconds. Do it without m_mutex so the feature
// thread is not blocked by applySampleRate() or setVst3Effect() meanwhile.
// m_nvidiaDenoiser is only used on this thread, as NVIDIA requires.
QString error;
bool ready = false;
if (sampleRate != 48000) {
error = QStringLiteral("NVIDIA Noise Removal requires 48 kHz input; got %1 Hz.").arg(sampleRate);
} else {
ready = m_nvidiaDenoiser.initialize(error, intensity, vad);
}
QMutexLocker mutexLocker(&m_mutex);
if (generation != m_nvidiaGeneration) {
return; // Settings or rate changed while loading; reset and retry on the next data.
}
m_nvidiaReady = ready;
if (!ready) {
reportNvidiaError(error + QStringLiteral(" Audio is passing through."));
}
}
void DenoiserWorker::handleData() void DenoiserWorker::handleData()
{ {
prepareNvidia();
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0)) while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
@ -347,11 +497,14 @@ void DenoiserWorker::processSample(
m_magsq = re*re; m_magsq = re*re;
m_channelPowerAvg(m_magsq); m_channelPowerAvg(m_magsq);
if ((!m_settings.m_enableDenoiser || m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_None) && !m_settings.m_audioMute) { if (!m_settings.m_enableDenoiser || m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_None) {
processI16DenoiserNone(samplefp); processI16DenoiserNone(samplefp);
} } else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_RNnoise) {
else if ((m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_RNnoise) && !m_settings.m_audioMute) {
processI16DenoiserRNNoise(samplefp); processI16DenoiserRNNoise(samplefp);
} else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Nvidia) {
processNvidiaSample(samplefp);
} else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Vst3) {
processVst3Sample(samplefp, samplefp);
} }
} }
break; break;
@ -366,11 +519,14 @@ void DenoiserWorker::processSample(
m_magsq = re*re + im*im; m_magsq = re*re + im*im;
m_channelPowerAvg(m_magsq); m_channelPowerAvg(m_magsq);
if ((!m_settings.m_enableDenoiser || m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_None) && !m_settings.m_audioMute) { if (!m_settings.m_enableDenoiser || m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_None) {
processCI16DenoiserNone(samplefpRe, samplefpIm); processCI16DenoiserNone(samplefpRe, samplefpIm);
} } else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_RNnoise) {
else if ((m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_RNnoise) && !m_settings.m_audioMute) {
processCI16DenoiserRNNoise(samplefpRe, samplefpIm); processCI16DenoiserRNNoise(samplefpRe, samplefpIm);
} else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Nvidia) {
processNvidiaSample((samplefpRe + samplefpIm) / 2.0);
} else if (m_settings.m_denoiserType == DenoiserSettings::DenoiserType::DenoiserType_Vst3) {
processVst3Sample(samplefpRe, samplefpIm);
} }
} }
break; break;
@ -389,15 +545,7 @@ void DenoiserWorker::processI16DenoiserNone(const double& samplefp)
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
{ {
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); flushAudio();
if (res != m_audioBufferFill)
{
qDebug("DenoiserWorker::processSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}
m_audioBufferFill = 0;
} }
} }
@ -428,15 +576,7 @@ void DenoiserWorker::processI16DenoiserRNNoise(const double& samplefp)
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
{ {
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); flushAudio();
if (res != m_audioBufferFill)
{
qDebug("DenoiserWorker::processSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}
m_audioBufferFill = 0;
} }
} }
@ -444,6 +584,124 @@ void DenoiserWorker::processI16DenoiserRNNoise(const double& samplefp)
} }
} }
void DenoiserWorker::processNvidiaSample(const double& samplefp)
{
if (m_nvidiaResetPending)
{
m_nvidiaDenoiser.shutdown();
m_nvidiaResetPending = false;
}
// NvAFX_Run uses mono, normalized floating point audio in 10 ms frames.
m_nvidiaIn[m_nvidiaFill++] = static_cast<float>(std::max(-1.0, std::min(1.0, samplefp / 32768.0)));
if (m_nvidiaFill < m_nvidiaFrameSize) {
return;
}
// The model is loaded by prepareNvidia() outside m_mutex; pass through until it is ready.
bool processed = false;
if (m_nvidiaReady)
{
QString error;
processed = m_nvidiaDenoiser.process(m_nvidiaIn, m_nvidiaOut, error);
if (!processed)
{
m_nvidiaReady = false;
reportNvidiaError(error + QStringLiteral(" Audio is passing through."));
}
}
if (processed && !m_nvidiaStatusReported)
{
if (m_msgQueueToFeature) {
m_msgQueueToFeature->push(MsgReportNvidiaStatus::create(QString()));
}
m_nvidiaStatusReported = true;
}
for (int j = 0; j < m_nvidiaFrameSize; ++j)
{
const double normalized = processed && std::isfinite(m_nvidiaOut[j]) ? m_nvidiaOut[j] : m_nvidiaIn[j];
const double sample = std::max(-32768.0, std::min(32767.0, normalized * 32768.0));
const int16_t audioSample = static_cast<int16_t>(sample);
if (m_channelPowerAvg.asDouble() > 1e-4) {
m_sampleBuffer.push_back(Sample(static_cast<FixReal>(audioSample) * (SDR_RX_SAMP_SZ == 24 ? 256 : 1), 0));
}
m_audioBuffer[m_audioBufferFill].l = audioSample;
m_audioBuffer[m_audioBufferFill].r = audioSample;
++m_audioBufferFill;
if (m_audioBufferFill >= m_audioBuffer.size())
{
flushAudio();
}
}
m_nvidiaFill = 0;
}
void DenoiserWorker::reportNvidiaError(const QString& error)
{
qWarning() << "DenoiserWorker:" << error;
m_nvidiaStatusReported = false;
if (m_msgQueueToFeature) {
m_msgQueueToFeature->push(MsgReportNvidiaStatus::create(error));
}
}
void DenoiserWorker::processVst3Sample(double left, double right)
{
const int i = m_vst3Fill++;
m_vst3Input[0][i] = static_cast<float>(std::max(-1.0, std::min(1.0, left / 32768.0)));
m_vst3Input[1][i] = static_cast<float>(std::max(-1.0, std::min(1.0, right / 32768.0)));
if (m_vst3Fill != m_vst3BlockSize) {
return;
}
bool processed = false;
if (m_vst3Effect)
{
QString error;
processed = m_vst3Effect->process(m_vst3Input[0], m_vst3Input[1],
m_vst3Output[0], m_vst3Output[1], m_vst3BlockSize, error);
if (!processed && !m_vst3FailureReported)
{
qWarning() << "DenoiserWorker:" << error;
if (m_msgQueueToFeature)
{
m_msgQueueToFeature->push(MsgReportVst3Status::create(
QStringLiteral("VST3: %1. Audio is passing through.").arg(error)));
}
m_vst3FailureReported = true;
}
}
for (int j = 0; j < m_vst3BlockSize; ++j)
{
const float l = processed && std::isfinite(m_vst3Output[0][j]) ? m_vst3Output[0][j] : m_vst3Input[0][j];
const float r = processed && std::isfinite(m_vst3Output[1][j]) ? m_vst3Output[1][j] : m_vst3Input[1][j];
const int16_t leftSample = static_cast<int16_t>(std::max(-32768.0f, std::min(32767.0f, l * 32768.0f)));
const int16_t rightSample = static_cast<int16_t>(std::max(-32768.0f, std::min(32767.0f, r * 32768.0f)));
if (m_channelPowerAvg.asDouble() > 1e-4)
{
const int scale = SDR_RX_SAMP_SZ == 24 ? 256 : 1;
m_sampleBuffer.push_back(Sample(static_cast<FixReal>(leftSample) * scale,
static_cast<FixReal>(rightSample) * scale));
}
m_audioBuffer[m_audioBufferFill].l = leftSample;
m_audioBuffer[m_audioBufferFill].r = rightSample;
if (++m_audioBufferFill >= m_audioBuffer.size())
{
flushAudio();
}
}
m_vst3Fill = 0;
}
void DenoiserWorker::processCI16DenoiserNone(const double& samplefpRe, const double& samplefpIm) void DenoiserWorker::processCI16DenoiserNone(const double& samplefpRe, const double& samplefpIm)
{ {
if (m_channelPowerAvg.asDouble() > 1e-4) { // -40 dB threshold if (m_channelPowerAvg.asDouble() > 1e-4) { // -40 dB threshold
@ -456,15 +714,7 @@ void DenoiserWorker::processCI16DenoiserNone(const double& samplefpRe, const dou
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
{ {
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); flushAudio();
if (res != m_audioBufferFill)
{
qDebug("DenoiserWorker::processSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}
m_audioBufferFill = 0;
} }
} }
@ -497,15 +747,7 @@ void DenoiserWorker::processCI16DenoiserRNNoise(const double& samplefpRe, const
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
{ {
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); flushAudio();
if (res != m_audioBufferFill)
{
qDebug("DenoiserWorker::processSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}
m_audioBufferFill = 0;
} }
} }

58
plugins/feature/denoiser/denoiserworker.h

@ -30,8 +30,10 @@
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "denoisersettings.h" #include "denoisersettings.h"
#include "nvidiaaudioeffects.h"
class WavFileRecord; class WavFileRecord;
class Vst3Effect;
struct DenoiseState; struct DenoiseState;
class DenoiserWorker : public QObject { class DenoiserWorker : public QObject {
@ -77,6 +79,33 @@ public:
{ } { }
}; };
class MsgReportNvidiaStatus : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QString& getError() const { return m_error; }
static MsgReportNvidiaStatus* create(const QString& error) {
return new MsgReportNvidiaStatus(error);
}
private:
QString m_error;
explicit MsgReportNvidiaStatus(const QString& error) : Message(), m_error(error) {}
};
class MsgReportVst3Status : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QString& getError() const { return m_error; }
static MsgReportVst3Status* create(const QString& error) {
return new MsgReportVst3Status(error);
}
private:
QString m_error;
explicit MsgReportVst3Status(const QString& error) :
Message(),
m_error(error)
{}
};
explicit DenoiserWorker(QObject *parent = nullptr); explicit DenoiserWorker(QObject *parent = nullptr);
~DenoiserWorker() override; ~DenoiserWorker() override;
void reset(); void reset();
@ -84,8 +113,10 @@ public:
void stopWork(); void stopWork();
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
void setMessageQueueToFeature(MessageQueue *messageQueue) { m_msgQueueToFeature = messageQueue; } void setMessageQueueToFeature(MessageQueue *messageQueue) { m_msgQueueToFeature = messageQueue; }
void setDemodProducer(QObject *producer) { m_demodProducer = producer; }
void applySampleRate(int sampleRate); void applySampleRate(int sampleRate);
void applySettings(const DenoiserSettings& settings, const QStringList& settingsKeys, bool force = false); void applySettings(const DenoiserSettings& settings, const QStringList& settingsKeys, bool force = false);
void setVst3Effect(Vst3Effect *effect);
double getMagSq() const { return m_magsq; } double getMagSq() const { return m_magsq; }
double getMagSqAvg() const { return (double) m_channelPowerAvg; } double getMagSqAvg() const { return (double) m_channelPowerAvg; }
void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const
@ -105,14 +136,17 @@ signals:
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples); void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
private: private:
static constexpr int m_nvidiaFrameSize = 480;
static constexpr int m_vst3BlockSize = 512;
DataFifo *m_dataFifo; DataFifo *m_dataFifo;
QObject *m_demodProducer;
int m_sinkSampleRate; int m_sinkSampleRate;
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
MessageQueue *m_msgQueueToFeature; //!< Queue to report channel change to main feature object MessageQueue *m_msgQueueToFeature; //!< Queue to report channel change to main feature object
DenoiserSettings m_settings; DenoiserSettings m_settings;
double m_magsq; double m_magsq;
SampleVector m_sampleBuffer; SampleVector m_sampleBuffer;
int m_sampleBufferSize;
MovingAverageUtil<double, double, 480> m_channelPowerAvg; MovingAverageUtil<double, double, 480> m_channelPowerAvg;
WavFileRecord* m_wavFileRecord; WavFileRecord* m_wavFileRecord;
int m_recordSilenceNbSamples; int m_recordSilenceNbSamples;
@ -126,6 +160,22 @@ private:
float m_rnnoiseOut[480]; float m_rnnoiseOut[480];
int m_rnnoiseFill; int m_rnnoiseFill;
NvidiaAudioEffects m_nvidiaDenoiser;
alignas(64) float m_nvidiaIn[m_nvidiaFrameSize];
alignas(64) float m_nvidiaOut[m_nvidiaFrameSize];
int m_nvidiaFill;
bool m_nvidiaInitAttempted;
bool m_nvidiaReady;
bool m_nvidiaResetPending;
bool m_nvidiaStatusReported;
quint32 m_nvidiaGeneration; //!< Incremented on any change that invalidates a model load
Vst3Effect *m_vst3Effect;
float m_vst3Input[2][m_vst3BlockSize];
float m_vst3Output[2][m_vst3BlockSize];
int m_vst3Fill;
bool m_vst3FailureReported;
quint32 m_levelCalcCount = 0; quint32 m_levelCalcCount = 0;
qreal m_rmsLevel; qreal m_rmsLevel;
qreal m_peakLevelOut; qreal m_peakLevelOut;
@ -145,6 +195,7 @@ private:
bool handleMessage(const Message& cmd); bool handleMessage(const Message& cmd);
void writeSampleToFile(const Sample& sample); void writeSampleToFile(const Sample& sample);
void flushAudio();
void processSample( void processSample(
DataFifo::DataType dataType, DataFifo::DataType dataType,
const QByteArray::const_iterator& begin, const QByteArray::const_iterator& begin,
@ -154,6 +205,11 @@ private:
void processI16DenoiserRNNoise(const double& samplefp); void processI16DenoiserRNNoise(const double& samplefp);
void processCI16DenoiserNone(const double& samplefpRe, const double& samplefpIm); void processCI16DenoiserNone(const double& samplefpRe, const double& samplefpIm);
void processCI16DenoiserRNNoise(const double& samplefpRe, const double& samplefpIm); void processCI16DenoiserRNNoise(const double& samplefpRe, const double& samplefpIm);
void processNvidiaSample(const double& samplefp);
void processVst3Sample(double left, double right);
void reportNvidiaError(const QString& error);
void resetNvidia();
void prepareNvidia();
void calculateLevel(const Real& sample); void calculateLevel(const Real& sample);
private slots: private slots:

302
plugins/feature/denoiser/nvidiaaudioeffects.cpp

@ -0,0 +1,302 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDir>
#include <QFileInfo>
#include <QByteArray>
#include <QFile>
#include <QLibrary>
#include <QThread>
#include <cstring>
#ifdef Q_OS_WIN
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif
#include "nvidiaaudioeffects.h"
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
struct NvidiaAudioEffects::Impl
{
using CreateEffect = int (*)(const char *, void **);
using DestroyEffect = int (*)(void *);
using SetString = int (*)(void *, const char *, const char *);
using SetU32 = int (*)(void *, const char *, unsigned int);
using SetFloat = int (*)(void *, const char *, float);
using GetU32 = int (*)(void *, const char *, unsigned int *);
using Load = int (*)(void *);
using Run = int (*)(void *, const float **, float **, unsigned int, unsigned int);
QLibrary library;
void *effect = nullptr;
QByteArray modelPath;
Qt::HANDLE threadId = nullptr;
DestroyEffect destroyEffect = nullptr;
Run run = nullptr;
};
#else
struct NvidiaAudioEffects::Impl {};
#endif
NvidiaAudioEffects::NvidiaAudioEffects() :
m_impl(nullptr)
{
}
NvidiaAudioEffects::~NvidiaAudioEffects()
{
shutdown();
}
bool NvidiaAudioEffects::initialize(QString& error, float intensityRatio, bool enableVad)
{
shutdown();
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
QString sdkDir = qEnvironmentVariable("NVAFX_SDK_DIR");
#ifdef Q_OS_WIN
if (sdkDir.isEmpty()) {
sdkDir = QDir(qEnvironmentVariable("ProgramFiles")).filePath("NVIDIA Corporation/NVIDIA Audio Effects SDK");
}
const QString libraryPath = QDir(sdkDir).filePath("NVAudioEffects.dll");
const QString modelPath = QDir(sdkDir).filePath("models/denoiser_48k.trtpkg");
#else
if (sdkDir.isEmpty()) {
sdkDir = qEnvironmentVariable("AFX_SDK_ROOT");
}
if (sdkDir.isEmpty()) {
error = QStringLiteral("Set NVAFX_SDK_DIR to the Linux Audio Effects SDK root");
return false;
}
const QString libraryPath = QDir(sdkDir).filePath("nvafx/lib/libnv_audiofx.so");
QString modelPath = qEnvironmentVariable("NVAFX_MODEL_PATH");
if (modelPath.isEmpty())
{
// Packages contain GPU-specific models. Pick one only if unambiguous.
QStringList models;
for (const QString& feature : {QStringLiteral("denoiser"), QStringLiteral("nvafxdenoiser")})
{
const QDir modelDir(QDir(sdkDir).filePath(QStringLiteral("features/%1/models").arg(feature)));
for (const QString& gpuDir : modelDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
const QString path = modelDir.filePath(gpuDir + QStringLiteral("/denoiser_48k.trtpkg"));
if (QFileInfo(path).isFile()) {
models.append(path);
}
}
}
if (models.size() == 1) {
modelPath = models.first();
} else {
error = QStringLiteral("Set NVAFX_MODEL_PATH to this GPU's denoiser_48k.trtpkg (found %1 models)").arg(models.size());
return false;
}
}
#endif
if (!QFileInfo(libraryPath).isFile() || !QFileInfo(modelPath).isFile())
{
error = QStringLiteral("NVIDIA Audio Effects library or 48 kHz model was not found: %1, %2").arg(libraryPath, modelPath);
return false;
}
m_impl = new Impl;
m_impl->modelPath = QFile::encodeName(QDir::toNativeSeparators(modelPath));
m_impl->library.setFileName(QFileInfo(libraryPath).absoluteFilePath());
#ifdef Q_OS_WIN
// QLibrary's ordinary load cannot find this SDK's adjacent DLL dependencies.
// Load once with the SDK directory in the dependency search path, then let
// QLibrary acquire and own its own reference to the already loaded DLL.
HMODULE bootstrap = LoadLibraryExW(reinterpret_cast<LPCWSTR>(QDir::toNativeSeparators(libraryPath).utf16()),
nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
if (!bootstrap)
{
error = QStringLiteral("Could not load NVIDIA Audio Effects DLL (Windows error %1)").arg(GetLastError());
shutdown();
return false;
}
#endif
const bool loaded = m_impl->library.load();
#ifdef Q_OS_WIN
FreeLibrary(bootstrap);
#endif
if (!loaded)
{
error = QStringLiteral("Could not load NVIDIA Audio Effects library: %1").arg(m_impl->library.errorString());
shutdown();
return false;
}
m_impl->threadId = QThread::currentThreadId();
const auto resolve = [this](const char *name) { return m_impl->library.resolve(name); };
const auto createEffect = reinterpret_cast<Impl::CreateEffect>(resolve("NvAFX_CreateEffect"));
m_impl->destroyEffect = reinterpret_cast<Impl::DestroyEffect>(resolve("NvAFX_DestroyEffect"));
const auto setString = reinterpret_cast<Impl::SetString>(resolve("NvAFX_SetString"));
const auto setU32 = reinterpret_cast<Impl::SetU32>(resolve("NvAFX_SetU32"));
const auto setFloat = reinterpret_cast<Impl::SetFloat>(resolve("NvAFX_SetFloat"));
const auto getU32 = reinterpret_cast<Impl::GetU32>(resolve("NvAFX_GetU32"));
const auto load = reinterpret_cast<Impl::Load>(resolve("NvAFX_Load"));
m_impl->run = reinterpret_cast<Impl::Run>(resolve("NvAFX_Run"));
if (!createEffect || !m_impl->destroyEffect || !setString || !setU32 || !setFloat || !getU32 || !load || !m_impl->run)
{
error = QStringLiteral("NVIDIA Audio Effects library is missing required functions");
shutdown();
return false;
}
int status = createEffect("denoiser", &m_impl->effect);
if (status == 0) {
status = setU32(m_impl->effect, "input_sample_rate", 48000);
}
if (status == 0) {
status = setFloat(m_impl->effect, "intensity_ratio", qBound(0.0f, intensityRatio, 1.0f));
}
if (status == 0) {
status = setU32(m_impl->effect, "enable_vad", enableVad ? 1U : 0U);
}
#ifdef Q_OS_LINUX
if (status == 0) {
status = setU32(m_impl->effect, "num_streams", 1);
}
if (status == 0) {
status = setU32(m_impl->effect, "num_samples_per_input_frame", 480);
}
#endif
if (status == 0) {
status = setString(m_impl->effect, "model_path", m_impl->modelPath.constData());
}
if (status == 0) {
status = load(m_impl->effect);
}
unsigned int frameSize = 0;
unsigned int outputFrameSize = 0;
unsigned int inputChannels = 0;
unsigned int outputChannels = 0;
unsigned int outputSampleRate = 0;
#ifdef Q_OS_LINUX
const char *inputFrameSelector = "num_samples_per_input_frame";
const char *outputFrameSelector = "num_samples_per_output_frame";
#else
const char *inputFrameSelector = "num_input_samples_per_frame";
const char *outputFrameSelector = "num_output_samples_per_frame";
#endif
if (status == 0) {
status = getU32(m_impl->effect, inputFrameSelector, &frameSize);
}
if (status == 0) {
status = getU32(m_impl->effect, outputFrameSelector, &outputFrameSize);
}
if (status == 0) {
status = getU32(m_impl->effect, "num_input_channels", &inputChannels);
}
if (status == 0) {
status = getU32(m_impl->effect, "num_output_channels", &outputChannels);
}
if (status == 0) {
status = getU32(m_impl->effect, "output_sample_rate", &outputSampleRate);
}
if (status != 0 || frameSize != 480 || outputFrameSize != 480 || inputChannels != 1 || outputChannels != 1 || outputSampleRate != 48000)
{
error = QStringLiteral("NVIDIA denoiser initialization failed (status %1, frames %2/%3, channels %4/%5, output rate %6)")
.arg(status).arg(frameSize).arg(outputFrameSize).arg(inputChannels).arg(outputChannels).arg(outputSampleRate);
shutdown();
return false;
}
return true;
#else
error = QStringLiteral("NVIDIA Audio Effects is available only on Windows and Linux");
return false;
#endif
}
void NvidiaAudioEffects::shutdown()
{
if (!m_impl) {
return;
}
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
if (m_impl->effect && m_impl->destroyEffect) {
m_impl->destroyEffect(m_impl->effect);
}
if (m_impl->library.isLoaded()) {
m_impl->library.unload();
}
#endif
delete m_impl;
m_impl = nullptr;
}
bool NvidiaAudioEffects::process(const float *input, float *output, QString& error)
{
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
if (!m_impl || !m_impl->effect) {
error = QStringLiteral("NVIDIA denoiser is not initialized");
return false;
}
if (QThread::currentThreadId() != m_impl->threadId) {
error = QStringLiteral("NVIDIA denoiser was called from a different thread than it was initialized on");
return false;
}
// Keep the caller's input intact for failure passthrough.
std::memcpy(output, input, 480 * sizeof(float));
#ifdef Q_OS_WIN
// The installed Windows runtime processes the buffer in place, as in OBS.
const float *inputs[] = {output};
#else
const float *inputs[] = {input};
#endif
float *outputs[] = {output};
const int status = m_impl->run(m_impl->effect, inputs, outputs, 480, 1);
if (status != 0)
{
error = QStringLiteral("NVIDIA denoiser processing failed (status %1)").arg(status);
shutdown();
return false;
}
return true;
#else
Q_UNUSED(input)
Q_UNUSED(output)
error = QStringLiteral("NVIDIA Audio Effects is available only on Windows and Linux");
return false;
#endif
}

41
plugins/feature/denoiser/nvidiaaudioeffects.h

@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FEATURE_DENOISER_NVIDIAAUDIOEFFECTS_H_
#define INCLUDE_FEATURE_DENOISER_NVIDIAAUDIOEFFECTS_H_
#include <QString>
// Loads the user-installed NVIDIA Audio Effects redistributable at runtime.
// No NVIDIA headers or binaries are required.
class NvidiaAudioEffects
{
public:
NvidiaAudioEffects();
~NvidiaAudioEffects();
bool initialize(QString& error, float intensityRatio, bool enableVad);
void shutdown();
bool process(const float *input, float *output, QString& error);
private:
struct Impl;
Impl *m_impl;
};
#endif

73
plugins/feature/denoiser/readme.md

@ -1,19 +1,27 @@
<h1>Demoiser</h1> <h1>Denoiser</h1>
<h2>Introduction</h2> <h2>Introduction</h2>
This audio denoiser plugin can be used to reduce or remove noise from audio. For now it only implements the RNNoise noise reduction (more details next) This feature can process demodulated audio with RNNoise, NVIDIA Noise Removal,
or an installed VST3 audio effect, such as a [denoiser](https://github.com/werman/noise-suppression-for-voice)
or [EQ](https://www.manda-audio.com/products.php).
It connects to the "demod" stream of Rx channels similarly to the Demod analyzer plugin. Hence it covers: It connects to the "demod" stream of RX channels or features similarly to the Demod Analyzer plugin.
It also outputs its processed stereo audio on a "demod" stream, so another Denoiser or Demod Analyzer can use it as an input.
Supported sources include:
- AM demodulator - AM demodulator
- Broadcast FM demodulator - Broadcast FM demodulator
- DAB demodulator
- DSD demodulator
- NFM demodulator - NFM demodulator
- SSB demodulator - SSB demodulator
- WFM demodulator - WFM demodulator
- WDSP plugin (multimode) - WDSP plugin (multimode)
- Another Denoiser feature
The following noise reduction schemes are covered. It can be selected via the (6) combo box: The processing mode is selected with the (6) combo box:
<h3>RNNoise</h3> <h3>RNNoise</h3>
@ -23,6 +31,49 @@ The noise reduction is based on a mix of DSP functions and a recursive neural ne
You will find all the details about RNnoise here: https://jmvalin.ca/demo/rnnoise/ You will find all the details about RNnoise here: https://jmvalin.ca/demo/rnnoise/
<h3>NVIDIA Noise Removal</h3>
On Windows, this option uses the NVIDIA Audio Effects SDK redistributable installed separately from NVIDIA Broadcast.
Install the redistributable for your RTX GPU from [NVIDIA's Broadcast SDK resources](https://www.nvidia.com/en-us/geforce/broadcasting/broadcast-sdk/resources/).
The feature looks in `NVAFX_SDK_DIR` if set, otherwise in `%ProgramFiles%\NVIDIA Corporation\NVIDIA Audio Effects SDK`.
SDRangel does not include NVIDIA binaries or models.
On Linux, install the [NVIDIA Audio Effects SDK core and Denoiser feature package](https://docs.nvidia.com/maxine/afx/latest/LinuxAFXSDK/InstallTheAFXSDK.html).
Set `NVAFX_SDK_DIR` to the extracted SDK root (or use `AFX_SDK_ROOT`). Put the SDK's `nvafx/lib`,
Denoiser feature `lib`, and `external/cuda/lib` directories on `LD_LIBRARY_PATH` before starting SDRangel.
The feature selects `features/denoiser/models/sm_*/denoiser_48k.trtpkg` automatically when exactly one GPU-specific model is installed; otherwise set `NVAFX_MODEL_PATH` to the model for your GPU.
NVIDIA officially supports the Linux SDK for its listed server GPUs; consumer GeForce cards are outside that support list.
NVIDIA Noise Removal is not available on macOS.
Set the demodulated audio stream to 48 kS/s. The SDK's 48 kHz speech denoiser receives mono audio; stereo input is mixed to mono.
If the SDK, model, or supported GPU is unavailable, the feature passes audio through and reports the reason in the feature's error status and SDRangel log.
NVIDIA's model is trained for speech, so tones, music, and weak radio signals may be suppressed.
When NVIDIA Noise Removal is selected, **Strength** controls the intensity ratio from 0% (passthrough) to 100% (strongest suppression).
If weak speech is being removed, try 30–50% and adjust by ear. **VAD** enables voice activity detection, which can mute frames classified as non-speech; leave it off when receiving weak or distorted voices.
Changes to these controls reload the NVIDIA model briefly. Neither setting can guarantee preservation of speech that the model classifies as noise.
<h3>VST3 Audio Effects</h3>
Select **VST3 Effect** to scan automatically for effects in the standard VST3 folders on Windows, Linux, or macOS.
Denoiser also scans when the feature starts; use **Scan** to refresh the list after installing a plugin.
On macOS the folders include the user, system, and network Audio/Plug-ins/VST3 folders, plus the app's Contents/VST3 folder.
The scanner runs in a separate process so a plugin that fails during discovery cannot crash SDRangel.
The **...** button lets you select a module outside those folders.
Select an effect from the list and start the feature.
**Params** opens the effect's own editor when available, or a slider dialog for its editable parameters.
Changes to exposed parameters are saved with the Denoiser settings.
When **Params** is closed, the effect's complete state (including editor settings and presets that are not exposed as parameters) is also saved, and the running effect is reloaded with it.
The effect runs at the selected channel's sample rate when reported, and otherwise assumes 48 kS/s.
The host accepts effects with one main mono or stereo audio input and output.
Effects that require other layouts or host services may report an error; in that case audio passes through.
**Params** tries the native editor on Windows, macOS, and Linux when Qt uses X11. If the editor cannot attach, it uses the slider dialog.
Editor changes that a plugin does not expose as parameters are only heard once **Params** is closed.
<h3>Notes</h3>
Please note the following points: Please note the following points:
- Audio sample rate must be 48 kS/s (check 4) - Audio sample rate must be 48 kS/s (check 4)
@ -40,17 +91,17 @@ Please note the following points:
This button starts or stops the plugin This button starts or stops the plugin
<h3>2: Channel selection</h3> <h3>2: Source selection</h3>
Use this combo to select which channel to use for display. Channel is selected at start time and upon change. You may use button (3) to force association with the channel if necessary. Use this combo to select an Rx channel or Feature as the audio source. The selection takes effect at start time and upon change. You may use button (3) to force association with the source if necessary.
<h3>3: (Re)apply channel selection</h3> <h3>3: (Re)apply source selection</h3>
Applies or re-applies channel association (2) so that the channel gets effectively (re)connected to the denoiser. Normally it should not be necessary to use it. Applies or re-applies source association (2) so that the source gets effectively (re)connected to the denoiser. Normally it should not be necessary to use it.
<h3>4: Input sample rate</h3> <h3>4: Input sample rate</h3>
This is the input audio stream sample rate and for RNNoise it should always be 48 kS/s This is the input audio stream sample rate. RNNoise and NVIDIA Noise Removal require 48 kS/s.
<h3>5: Input power</h4> <h3>5: Input power</h4>
@ -62,10 +113,12 @@ Selects the noise reduction scheme
- **None**: No noise reduction (passthrough) - **None**: No noise reduction (passthrough)
- **RNnoise**: RNNoise (see introduction) - **RNnoise**: RNNoise (see introduction)
- **NVIDIA Noise Removal**: NVIDIA Audio Effects SDK speech denoiser
- **VST3 Effect**: An installed VST3 audio effect
<h3>7: Noise reduction enable</h3> <h3>7: Noise reduction enable</h3>
Enable or disable noise reduction. When disabled it just passes audio through Enable or disable noise reduction or VST3 effect. When disabled it just passes audio through.
<h3>8: Audio mute and device selection</h3> <h3>8: Audio mute and device selection</h3>

27
plugins/feature/denoiser/vst3/LICENSE.txt

@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// LICENSE
// (c) 2025, Steinberg Media Technologies GmbH, All Rights Reserved
//-----------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Steinberg Media Technologies nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------

3777
plugins/feature/denoiser/vst3/vst3_c_api.h

File diff suppressed because it is too large Load Diff

1415
plugins/feature/denoiser/vst3effect.cpp

File diff suppressed because it is too large Load Diff

87
plugins/feature/denoiser/vst3effect.h

@ -0,0 +1,87 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FEATURE_DENOISER_VST3EFFECT_H_
#define INCLUDE_FEATURE_DENOISER_VST3EFFECT_H_
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QVector>
#include <QtGlobal>
#include <functional>
#include <memory>
class QWidget;
struct Vst3PluginInfo
{
QString modulePath;
QByteArray classId; // The factory's 16-byte platform-specific class ID.
QString name;
};
struct Vst3ParameterInfo
{
quint32 id;
QString name;
double defaultValue;
double currentValue;
int steps;
bool readOnly;
bool hidden;
};
// Owns one audio effect. Construct, configure and destroy on the feature thread;
// only process() is called by the audio worker while the instance is active.
class Vst3Effect
{
public:
Vst3Effect();
~Vst3Effect();
static QVector<Vst3PluginInfo> discover(const QStringList& extraPaths = {});
static QStringList modulePaths(const QStringList& extraPaths = {});
// state is a blob from state(); it is ignored if it belongs to a different class.
bool open(const QString& modulePath, const QByteArray& classId, int sampleRate,
int sourceChannels, QString& error, const QByteArray& state = QByteArray());
bool process(const float *left, const float *right, float *outLeft, float *outRight,
int count, QString& error);
void close();
unsigned int latencySamples() const;
QVector<Vst3ParameterInfo> parameters() const;
double parameterValue(quint32 id) const;
// Not safe while another thread calls process(); flushes queued parameter changes.
QByteArray state(QString& error);
bool setState(const QByteArray& state, QString& error);
bool setParameter(quint32 id, double value);
QString parameterText(quint32 id, double value) const;
void setParameterEditCallback(std::function<void(quint32, double)> callback);
#ifdef QT_WIDGETS_LIB
QWidget *createEditorWidget(QWidget *parent, QString& error);
#endif
private:
#ifdef QT_WIDGETS_LIB
class EditorWidget;
#endif
struct Impl;
std::unique_ptr<Impl> m_impl;
};
#endif

83
plugins/feature/denoiser/vst3scan.cpp

@ -0,0 +1,83 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QCoreApplication>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess>
#include <cstdio>
#include "vst3effect.h"
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QStringList paths = app.arguments().mid(1);
const bool probe = !paths.isEmpty() && paths.first() == QStringLiteral("--probe");
if (probe) {
paths.removeFirst();
}
QJsonArray plugins;
if (probe)
{
for (const Vst3PluginInfo& plugin : Vst3Effect::discover(paths))
{
QJsonObject object;
object.insert(QStringLiteral("path"), plugin.modulePath);
object.insert(QStringLiteral("id"), QString::fromLatin1(plugin.classId.toHex()));
object.insert(QStringLiteral("name"), plugin.name);
plugins.append(object);
}
}
else
{
for (const QString& path : Vst3Effect::modulePaths(paths))
{
QProcess child;
child.setProgram(app.applicationFilePath());
child.setArguments({QStringLiteral("--probe"), path});
child.start();
if (!child.waitForStarted(5000)) {
continue;
}
if (!child.waitForFinished(60000))
{
child.kill();
child.waitForFinished(5000);
continue;
}
if (child.exitStatus() != QProcess::NormalExit || child.exitCode() != 0)
continue;
const QJsonDocument result = QJsonDocument::fromJson(child.readAllStandardOutput());
if (!result.isArray()) {
continue;
}
for (const QJsonValue& value : result.array()) {
plugins.append(value);
}
}
}
const QByteArray json = QJsonDocument(plugins).toJson(QJsonDocument::Compact);
std::fwrite(json.constData(), 1, static_cast<size_t>(json.size()), stdout);
return 0;
}

1
sdrbase/maincore.cpp

@ -64,6 +64,7 @@ MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteFeature, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelReport, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelReport, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelSettings, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelSettings, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelDemodReport, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelDemodReport, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgFeatureDemodReport, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelDemodQuery, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgChannelDemodQuery, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgMoveDeviceUIToWorkspace, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgMoveDeviceUIToWorkspace, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgArrangeWorkspace, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgArrangeWorkspace, Message)

22
sdrbase/maincore.h

@ -565,6 +565,28 @@ public:
{ } { }
}; };
class SDRBASE_API MsgFeatureDemodReport : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QObject *getFeature() const { return m_feature; }
int getSampleRate() const { return m_sampleRate; }
static MsgFeatureDemodReport* create(const QObject *feature, int sampleRate) {
return new MsgFeatureDemodReport(feature, sampleRate);
}
private:
const QObject *m_feature;
int m_sampleRate;
MsgFeatureDemodReport(const QObject *feature, int sampleRate) :
Message(),
m_feature(feature),
m_sampleRate(sampleRate)
{ }
};
class SDRBASE_API MsgChannelSettings : public Message { class SDRBASE_API MsgChannelSettings : public Message {
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION

25
sdrbase/resources/webapi/doc/swagger/include/Denoiser.yaml

@ -9,6 +9,8 @@ DenoiserSettings:
Denoiser type Denoiser type
* 0 - none * 0 - none
* 1 - RNnoise * 1 - RNnoise
* 2 - NVIDIA Noise Removal
* 3 - VST3 audio effect
enableDenoiser: enableDenoiser:
type: integer type: integer
minimum: 0 minimum: 0
@ -17,6 +19,29 @@ DenoiserSettings:
Enable denoiser Enable denoiser
* 1 - enable * 1 - enable
* 0 - disable * 0 - disable
nvidiaIntensity:
type: integer
minimum: 0
maximum: 100
description: NVIDIA Noise Removal strength in percent
nvidiaVad:
type: integer
description: >
NVIDIA voice activity detection
* 1 - enable
* 0 - disable
vst3ModulePath:
type: string
description: Absolute path to the selected VST3 module or bundle
vst3ClassId:
type: string
description: 16-byte VST3 processor class ID encoded as hexadecimal
vst3Parameters:
type: string
description: JSON object mapping numeric VST3 parameter IDs to normalized values from 0 to 1
vst3State:
type: string
description: Opaque VST3 component and controller state, base64 encoded
volumeTenths: volumeTenths:
type: integer type: integer
description: > description: >

25
swagger/sdrangel/api/swagger/include/Denoiser.yaml

@ -9,6 +9,8 @@ DenoiserSettings:
Denoiser type Denoiser type
* 0 - none * 0 - none
* 1 - RNnoise * 1 - RNnoise
* 2 - NVIDIA Noise Removal
* 3 - VST3 audio effect
enableDenoiser: enableDenoiser:
type: integer type: integer
minimum: 0 minimum: 0
@ -17,6 +19,29 @@ DenoiserSettings:
Enable denoiser Enable denoiser
* 1 - enable * 1 - enable
* 0 - disable * 0 - disable
nvidiaIntensity:
type: integer
minimum: 0
maximum: 100
description: NVIDIA Noise Removal strength in percent
nvidiaVad:
type: integer
description: >
NVIDIA voice activity detection
* 1 - enable
* 0 - disable
vst3ModulePath:
type: string
description: Absolute path to the selected VST3 module or bundle
vst3ClassId:
type: string
description: 16-byte VST3 processor class ID encoded as hexadecimal
vst3Parameters:
type: string
description: JSON object mapping numeric VST3 parameter IDs to normalized values from 0 to 1
vst3State:
type: string
description: Opaque VST3 component and controller state, base64 encoded
volumeTenths: volumeTenths:
type: integer type: integer
description: > description: >

110
swagger/sdrangel/code/qt5/client/SWGDenoiserSettings.cpp

@ -32,6 +32,18 @@ SWGDenoiserSettings::SWGDenoiserSettings() {
m_denoiser_type_isSet = false; m_denoiser_type_isSet = false;
enable_denoiser = 0; enable_denoiser = 0;
m_enable_denoiser_isSet = false; m_enable_denoiser_isSet = false;
nvidia_intensity = 0;
m_nvidia_intensity_isSet = false;
nvidia_vad = 0;
m_nvidia_vad_isSet = false;
vst3_module_path = nullptr;
m_vst3_module_path_isSet = false;
vst3_class_id = nullptr;
m_vst3_class_id_isSet = false;
vst3_parameters = nullptr;
m_vst3_parameters_isSet = false;
vst3_state = nullptr;
m_vst3_state_isSet = false;
volume_tenths = 0; volume_tenths = 0;
m_volume_tenths_isSet = false; m_volume_tenths_isSet = false;
audio_device_name = nullptr; audio_device_name = nullptr;
@ -70,6 +82,18 @@ SWGDenoiserSettings::init() {
m_denoiser_type_isSet = false; m_denoiser_type_isSet = false;
enable_denoiser = 0; enable_denoiser = 0;
m_enable_denoiser_isSet = false; m_enable_denoiser_isSet = false;
nvidia_intensity = 0;
m_nvidia_intensity_isSet = false;
nvidia_vad = 0;
m_nvidia_vad_isSet = false;
vst3_module_path = new QString("");
m_vst3_module_path_isSet = false;
vst3_class_id = new QString("");
m_vst3_class_id_isSet = false;
vst3_parameters = new QString("");
m_vst3_parameters_isSet = false;
vst3_state = new QString("");
m_vst3_state_isSet = false;
volume_tenths = 0; volume_tenths = 0;
m_volume_tenths_isSet = false; m_volume_tenths_isSet = false;
audio_device_name = new QString(""); audio_device_name = new QString("");
@ -101,6 +125,11 @@ SWGDenoiserSettings::init() {
void void
SWGDenoiserSettings::cleanup() { SWGDenoiserSettings::cleanup() {
if(vst3_module_path != nullptr) delete vst3_module_path;
if(vst3_class_id != nullptr) delete vst3_class_id;
if(vst3_parameters != nullptr) delete vst3_parameters;
if(vst3_state != nullptr) delete vst3_state;
if(audio_device_name != nullptr) { if(audio_device_name != nullptr) {
@ -142,6 +171,14 @@ SWGDenoiserSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&enable_denoiser, pJson["enableDenoiser"], "qint32", ""); ::SWGSDRangel::setValue(&enable_denoiser, pJson["enableDenoiser"], "qint32", "");
::SWGSDRangel::setValue(&nvidia_intensity, pJson["nvidiaIntensity"], "qint32", "");
::SWGSDRangel::setValue(&nvidia_vad, pJson["nvidiaVad"], "qint32", "");
::SWGSDRangel::setValue(&vst3_module_path, pJson["vst3ModulePath"], "QString", "QString");
::SWGSDRangel::setValue(&vst3_class_id, pJson["vst3ClassId"], "QString", "QString");
::SWGSDRangel::setValue(&vst3_parameters, pJson["vst3Parameters"], "QString", "QString");
::SWGSDRangel::setValue(&vst3_state, pJson["vst3State"], "QString", "QString");
::SWGSDRangel::setValue(&volume_tenths, pJson["volumeTenths"], "qint32", ""); ::SWGSDRangel::setValue(&volume_tenths, pJson["volumeTenths"], "qint32", "");
::SWGSDRangel::setValue(&audio_device_name, pJson["audioDeviceName"], "QString", "QString"); ::SWGSDRangel::setValue(&audio_device_name, pJson["audioDeviceName"], "QString", "QString");
@ -190,6 +227,24 @@ SWGDenoiserSettings::asJsonObject() {
if(m_enable_denoiser_isSet){ if(m_enable_denoiser_isSet){
obj->insert("enableDenoiser", QJsonValue(enable_denoiser)); obj->insert("enableDenoiser", QJsonValue(enable_denoiser));
} }
if(m_nvidia_intensity_isSet){
obj->insert("nvidiaIntensity", QJsonValue(nvidia_intensity));
}
if(m_nvidia_vad_isSet){
obj->insert("nvidiaVad", QJsonValue(nvidia_vad));
}
if(vst3_module_path != nullptr && *vst3_module_path != QString("")){
toJsonValue(QString("vst3ModulePath"), vst3_module_path, obj, QString("QString"));
}
if(vst3_class_id != nullptr && *vst3_class_id != QString("")){
toJsonValue(QString("vst3ClassId"), vst3_class_id, obj, QString("QString"));
}
if(vst3_parameters != nullptr && *vst3_parameters != QString("")){
toJsonValue(QString("vst3Parameters"), vst3_parameters, obj, QString("QString"));
}
if(vst3_state != nullptr && *vst3_state != QString("")){
toJsonValue(QString("vst3State"), vst3_state, obj, QString("QString"));
}
if(m_volume_tenths_isSet){ if(m_volume_tenths_isSet){
obj->insert("volumeTenths", QJsonValue(volume_tenths)); obj->insert("volumeTenths", QJsonValue(volume_tenths));
} }
@ -253,6 +308,51 @@ SWGDenoiserSettings::setEnableDenoiser(qint32 enable_denoiser) {
this->m_enable_denoiser_isSet = true; this->m_enable_denoiser_isSet = true;
} }
qint32
SWGDenoiserSettings::getNvidiaIntensity() {
return nvidia_intensity;
}
void
SWGDenoiserSettings::setNvidiaIntensity(qint32 nvidia_intensity) {
this->nvidia_intensity = nvidia_intensity;
this->m_nvidia_intensity_isSet = true;
}
qint32
SWGDenoiserSettings::getNvidiaVad() {
return nvidia_vad;
}
void
SWGDenoiserSettings::setNvidiaVad(qint32 nvidia_vad) {
this->nvidia_vad = nvidia_vad;
this->m_nvidia_vad_isSet = true;
}
QString* SWGDenoiserSettings::getVst3ModulePath() { return vst3_module_path; }
void SWGDenoiserSettings::setVst3ModulePath(QString* value) {
if (vst3_module_path != value) delete vst3_module_path;
vst3_module_path = value;
m_vst3_module_path_isSet = true;
}
QString* SWGDenoiserSettings::getVst3ClassId() { return vst3_class_id; }
void SWGDenoiserSettings::setVst3ClassId(QString* value) {
if (vst3_class_id != value) delete vst3_class_id;
vst3_class_id = value;
m_vst3_class_id_isSet = true;
}
QString* SWGDenoiserSettings::getVst3Parameters() { return vst3_parameters; }
void SWGDenoiserSettings::setVst3Parameters(QString* value) {
if (vst3_parameters != value) delete vst3_parameters;
vst3_parameters = value;
m_vst3_parameters_isSet = true;
}
QString* SWGDenoiserSettings::getVst3State() { return vst3_state; }
void SWGDenoiserSettings::setVst3State(QString* value) {
if (vst3_state != value) delete vst3_state;
vst3_state = value;
m_vst3_state_isSet = true;
}
qint32 qint32
SWGDenoiserSettings::getVolumeTenths() { SWGDenoiserSettings::getVolumeTenths() {
return volume_tenths; return volume_tenths;
@ -394,6 +494,15 @@ SWGDenoiserSettings::isSet(){
if(m_enable_denoiser_isSet){ if(m_enable_denoiser_isSet){
isObjectUpdated = true; break; isObjectUpdated = true; break;
} }
if(m_nvidia_intensity_isSet){
isObjectUpdated = true; break;
}
if(m_nvidia_vad_isSet){
isObjectUpdated = true; break;
}
if(m_vst3_module_path_isSet || m_vst3_class_id_isSet || m_vst3_parameters_isSet || m_vst3_state_isSet){
isObjectUpdated = true; break;
}
if(m_volume_tenths_isSet){ if(m_volume_tenths_isSet){
isObjectUpdated = true; break; isObjectUpdated = true; break;
} }
@ -437,4 +546,3 @@ SWGDenoiserSettings::isSet(){
return isObjectUpdated; return isObjectUpdated;
} }
} }

32
swagger/sdrangel/code/qt5/client/SWGDenoiserSettings.h

@ -49,6 +49,22 @@ public:
qint32 getEnableDenoiser(); qint32 getEnableDenoiser();
void setEnableDenoiser(qint32 enable_denoiser); void setEnableDenoiser(qint32 enable_denoiser);
qint32 getNvidiaIntensity();
void setNvidiaIntensity(qint32 nvidia_intensity);
qint32 getNvidiaVad();
void setNvidiaVad(qint32 nvidia_vad);
QString* getVst3ModulePath();
void setVst3ModulePath(QString* vst3_module_path);
QString* getVst3ClassId();
void setVst3ClassId(QString* vst3_class_id);
QString* getVst3Parameters();
void setVst3Parameters(QString* vst3_parameters);
QString* getVst3State();
void setVst3State(QString* vst3_state);
qint32 getVolumeTenths(); qint32 getVolumeTenths();
void setVolumeTenths(qint32 volume_tenths); void setVolumeTenths(qint32 volume_tenths);
@ -98,6 +114,22 @@ private:
qint32 enable_denoiser; qint32 enable_denoiser;
bool m_enable_denoiser_isSet; bool m_enable_denoiser_isSet;
qint32 nvidia_intensity;
bool m_nvidia_intensity_isSet;
qint32 nvidia_vad;
bool m_nvidia_vad_isSet;
QString* vst3_module_path;
bool m_vst3_module_path_isSet;
QString* vst3_class_id;
bool m_vst3_class_id_isSet;
QString* vst3_parameters;
bool m_vst3_parameters_isSet;
QString* vst3_state;
bool m_vst3_state_isSet;
qint32 volume_tenths; qint32 volume_tenths;
bool m_volume_tenths_isSet; bool m_volume_tenths_isSet;

Loading…
Cancel
Save