From 8ade50a3ac988cacb4a0211d9864ebee632b009f Mon Sep 17 00:00:00 2001 From: "Robin E.R. Davies" Date: Tue, 21 Apr 2026 00:36:13 -0400 Subject: [PATCH] Resurrect pipedalProfilePlugin, and amd64 benchmarks. --- .vscode/launch.json | 33 ++++++++++++++++++- src/Lv2Pedalboard.cpp | 3 ++ src/WebServerConfig.cpp | 1 + src/profilePluginMain.cpp | 67 +++++++++++++++++++++++++++++++++------ todo.txt | 17 ++++++++++ 5 files changed, 110 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d459cd3..ccadb2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -328,6 +328,37 @@ "ignoreFailures": true } ] - } + }, + { + "name": "(gdb) pipedalProfilePlugin", + "type": "cppdbg", + "request": "launch", + // Resolved by CMake Tools: + "program": "${command:cmake.launchTargetPath}", + "args": [ + "--no-profile", + "--preset-file", "/home/robin/Downloads/NAM Profiling.piPreset", + "--seconds", "100", + "-w" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "PATH", + "value": "$PATH:${command:cmake.launchTargetDirectory}" + } + ], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + ] } \ No newline at end of file diff --git a/src/Lv2Pedalboard.cpp b/src/Lv2Pedalboard.cpp index 9006c56..1d3aa45 100644 --- a/src/Lv2Pedalboard.cpp +++ b/src/Lv2Pedalboard.cpp @@ -546,6 +546,9 @@ bool Lv2Pedalboard::Run(float **inputBuffers, float **outputBuffers, uint32_t sa float volume = outputVolume.Tick(); for (size_t c = 0; c < this->pedalboardOutputBuffers.size(); ++c) { + if (outputBuffers[c] == nullptr) { + break; + } outputBuffers[c][i] = this->pedalboardOutputBuffers[c][i] * volume; } } diff --git a/src/WebServerConfig.cpp b/src/WebServerConfig.cpp index 9a977a2..9681552 100644 --- a/src/WebServerConfig.cpp +++ b/src/WebServerConfig.cpp @@ -18,6 +18,7 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "WebServerConfig.hpp" +#include "PresetBundle.hpp" #include "WebServer.hpp" #include #include diff --git a/src/profilePluginMain.cpp b/src/profilePluginMain.cpp index 7c04c20..cd8c629 100644 --- a/src/profilePluginMain.cpp +++ b/src/profilePluginMain.cpp @@ -7,6 +7,7 @@ #include #include #include "ss.hpp" +#include "PresetBundle.hpp" // apt install google-perftools #include @@ -78,6 +79,22 @@ private: std::unique_ptr thread; WriterRingbuffer &writerRingbuffer; }; + +static bool IsZipFile(const std::filesystem::path &path) +{ + std::ifstream f(path); + if (!f.is_open()) + return false; + + char c[4]; + memset(c, 0, sizeof(c)); + + f >> c[0] >> c[1] >> c[2] >> c[3]; + + // official file header according to PKware documetnation. + return c[0] == 0x50 && c[1] == 0x4B && c[2] == 0x03 && c[3] == 0x04; +} + struct ProfileOptions { std::string presetName; @@ -127,6 +144,7 @@ void profilePlugin(const ProfileOptions &profileOptions) if (profileOptions.presetName.length() != 0) { + PresetIndex presetIndex; model.GetPresets(&presetIndex); @@ -149,26 +167,50 @@ void profilePlugin(const ProfileOptions &profileOptions) } else if (profileOptions.presetFileName.length() != 0) { - std::ifstream f(profileOptions.presetFileName); - if (!f.is_open()) + std::filesystem::path filePath = profileOptions.presetFileName; + + if (IsZipFile(filePath)) { - throw std::runtime_error(SS("Unable to load preset file " << profileOptions.presetFileName << ".")); - } - try - { - json_reader reader(f); + auto presetReader = PresetBundleReader::LoadPresetsFile(model, filePath); + presetReader->ExtractMediaFiles(); + + std::stringstream ss(presetReader->GetPresetJson()); + json_reader reader(ss); + BankFile bankFile; reader.read(&bankFile); + if (bankFile.presets().size() != 1) { throw new std::runtime_error(SS("Invalid preset file. Expection one preset, but " << bankFile.presets().size() << " presets were found.")); } Pedalboard pedalboard = (bankFile.presets()[0]->preset()); - model.SetPedalboard(-1,pedalboard); + model.SetPedalboard(-1, pedalboard); } - catch (const std::exception &e) + else { - throw std::runtime_error(SS("Invalid file format: " << profileOptions.presetFileName << ". " << e.what() )); + + std::ifstream f(profileOptions.presetFileName); + if (!f.is_open()) + { + throw std::runtime_error(SS("Unable to load preset file " << profileOptions.presetFileName << ".")); + } + try + { + json_reader reader(f); + BankFile bankFile; + reader.read(&bankFile); + if (bankFile.presets().size() != 1) + { + throw new std::runtime_error(SS("Invalid preset file. Expection one preset, but " << bankFile.presets().size() << " presets were found.")); + } + Pedalboard pedalboard = (bankFile.presets()[0]->preset()); + model.SetPedalboard(-1, pedalboard); + } + catch (const std::exception &e) + { + throw std::runtime_error(SS("Invalid file format: " << profileOptions.presetFileName << ". " << e.what())); + } } } else @@ -197,6 +239,7 @@ void profilePlugin(const ProfileOptions &profileOptions) RingBufferSink ringBufferSink(writerRingbuffer); // run once to get memory allocations in NAM and ML out of the way. + lv2Pedalboard->ResetAtomBuffers(); lv2Pedalboard->Run(inputBuffers, outputBuffers, nFrames, &ringBufferWriter); /* *** Pump the plugin for a bit if it is expected to do work on the scheduler thread when initializing */ @@ -210,6 +253,7 @@ void profilePlugin(const ProfileOptions &profileOptions) while (true) { + lv2Pedalboard->ResetAtomBuffers(); lv2Pedalboard->Run(inputBuffers, outputBuffers, nFrames, &ringBufferWriter); auto elapsed = clock::now() - waitStart; @@ -235,6 +279,7 @@ void profilePlugin(const ProfileOptions &profileOptions) size_t repetitions = static_cast(48000 * profileOptions.benchmark_seconds / nFrames); for (size_t i = 0; i < repetitions; ++i) { + lv2Pedalboard->ResetAtomBuffers(); lv2Pedalboard->Run(inputBuffers, outputBuffers, nFrames, &ringBufferWriter); } @@ -298,6 +343,8 @@ int main(int argc, char **argv) cout << "Options:" << endl; cout << " --no-profile:" << endl; cout << " do NOT generate a perf file." << endl; + cout << " --nam-core:" << endl; + cout << " Force use of NAM Core models." << endl; cout << " -p, --preset-file filename:" << endl; cout << " Load the specified preset file. " << endl; cout << " -o, --output filename:" << endl; diff --git a/todo.txt b/todo.txt index 30ca17d..67fa184 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,20 @@ +Benchmark Results: + +amd64 (Ubuntu 24.04) + + NeuralAudio x64: 5.416s + Neural Modeler Core: 7.965s + + +CPU: AMD Ryzen 7 7735HS with Radeon Graphics +OS: Ubuntu 24.04 (amd64) + +/home/robin/Downloads/NAM Test/media/NeuralAmpModels/Fender Deluxe Reverb %2765 Reissue %7c Clean %7c SM57 %2b Royer R-121 %2b Room/ + + + + + summaries for Mono audio adapaters. Check PWA on windows, edge and chrome. Make sure Pi 4 default audio device is still hidden when selecting devices!