Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you'd like to work on an [existing Issue](https://github.com/sdatkinson/Neura
I would like to ask that you please try to give me a timeline for your work--I'd hate to have you duplicate work if I know that I'm going to e.g. get to it today and beat you to the punch.

## Testing
The model sample-rate adapter has standalone regression tests that do not require a plugin SDK:
The sample-rate adapter and cabinet loader have standalone regression tests that do not require a plugin SDK:

```bash
cmake -S tests -B build-tests -DCMAKE_BUILD_TYPE=Release
Expand Down
211 changes: 106 additions & 105 deletions NeuralAmpModeler/NeuralAmpModeler.cpp

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions NeuralAmpModeler/NeuralAmpModeler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#pragma once

#include "../AudioDSPTools/dsp/ImpulseResponse.h"
#include "../AudioDSPTools/dsp/NoiseGate.h"
#include "../AudioDSPTools/dsp/dsp.h"
#include "../AudioDSPTools/dsp/wav.h"
#include "ResamplingNAM.h"

#include "Colors.h"
Expand Down Expand Up @@ -39,7 +37,7 @@ enum EParams
// The rest is fine though.
kNoiseGateActive,
kEQActive,
kIRToggle,
kCabToggle,
// Input calibration
kCalibrateInput,
kInputCalibrationLevel,
Expand All @@ -53,7 +51,7 @@ const int numKnobs = 6;
enum ECtrlTags
{
kCtrlTagModelFileBrowser = 0,
kCtrlTagIRFileBrowser,
kCtrlTagCabFileBrowser,
kCtrlTagInputMeter,
kCtrlTagOutputMeter,
kCtrlTagSettingsBox,
Expand All @@ -70,12 +68,12 @@ enum EMsgTags
{
// These tags are used from UI -> DSP
kMsgTagClearModel = 0,
kMsgTagClearIR,
kMsgTagClearCab,
kMsgTagHighlightColor,
// The following tags are from DSP -> UI
kMsgTagLoadFailed,
kMsgTagLoadedModel,
kMsgTagLoadedIR,
kMsgTagLoadedCab,
kNumMsgTags
};

Expand Down Expand Up @@ -117,10 +115,9 @@ class NeuralAmpModeler final : public iplug::Plugin
// Loads a NAM model and stores it to mStagedNAM
// Returns an empty string on success, or an error message on failure.
std::string _StageModel(const WDL_String& dspFile);
// Loads an IR and stores it to mStagedIR.
// Return status code so that error messages can be relayed if
// it wasn't successful.
dsp::wav::LoadReturnCode _StageIR(const WDL_String& irPath);
// Loads a WAV or NAM cab and stores it to mStagedCab.
// Returns an empty string on success, or an error message on failure.
std::string _StageCab(const WDL_String& cabPath);

bool _HaveModel() const { return this->mModel != nullptr; };
// Prepare the input & output buffers
Expand All @@ -136,8 +133,8 @@ class NeuralAmpModeler final : public iplug::Plugin
// :param nChansOut: Out to external
void _ProcessOutput(iplug::sample** inputs, iplug::sample** outputs, const size_t nFrames, const size_t nChansIn,
const size_t nChansOut);
// Resetting for models and IRs, called by OnReset
void _ResetModelAndIR(const double sampleRate, const int maxBlockSize);
// Resetting for the model and cab, called by OnReset
void _ResetModelAndCab(const double sampleRate, const int maxBlockSize);

void _SetInputGain();
void _SetOutputGain();
Expand All @@ -153,8 +150,8 @@ class NeuralAmpModeler final : public iplug::Plugin
// Update all controls that depend on a model
void _UpdateControlsFromModel();

// Make sure that the latency is reported correctly.
void _UpdateLatency();
// Report latency and tail length to the host.
void _UpdateLatencyAndTail();

// Update level meters
// Called within ProcessBlock().
Expand All @@ -168,6 +165,8 @@ class NeuralAmpModeler final : public iplug::Plugin
std::vector<std::vector<iplug::sample>> mInputArray;
// Output from NAM
std::vector<std::vector<iplug::sample>> mOutputArray;
// Separate cab output avoids requiring NAM architectures to support in-place processing.
std::vector<iplug::sample> mCabinetOutput;
// Pointer versions
iplug::sample** mInputPointers = nullptr;
iplug::sample** mOutputPointers = nullptr;
Expand All @@ -181,29 +180,31 @@ class NeuralAmpModeler final : public iplug::Plugin
dsp::noise_gate::Gain mNoiseGateGain;
// The model actually being used:
std::unique_ptr<ResamplingNAM> mModel;
// And the IR
std::unique_ptr<dsp::ImpulseResponse> mIR;
// The cabinet, loaded from a WAV impulse response or NAM model.
std::unique_ptr<ResamplingNAM> mCab;
bool mCabIsWav = false;
// Manages switching what DSP is being used.
std::unique_ptr<ResamplingNAM> mStagedModel;
std::unique_ptr<dsp::ImpulseResponse> mStagedIR;
std::unique_ptr<ResamplingNAM> mStagedCab;
bool mStagedCabIsWav = false;
// Flags to take away the modules at a safe time.
std::atomic<bool> mShouldRemoveModel = false;
std::atomic<bool> mShouldRemoveIR = false;
std::atomic<bool> mShouldRemoveCab = false;

std::atomic<bool> mNewModelLoadedInDSP = false;
std::atomic<bool> mModelCleared = false;

// Tone stack modules
std::unique_ptr<dsp::tone_stack::AbstractToneStack> mToneStack;

// Post-IR filters
// Post-cab filters
recursive_linear_filter::HighPass mHighPass;
// recursive_linear_filter::LowPass mLowPass;

// Path to model's config.json or model.nam
WDL_String mNAMPath;
// Path to IR (.wav file)
WDL_String mIRPath;
// Path to the cab (.wav or .nam file). Keep IRPath in serialized state for compatibility.
WDL_String mCabPath;

WDL_String mHighLightColor{PluginColors::NAM_THEMECOLOR.ToColorCode()};

Expand Down
46 changes: 45 additions & 1 deletion NeuralAmpModeler/NeuralAmpModelerControls.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include <cmath> // std::round
#include <cctype>
#include <cstdio> // FILE, fclose
#include <filesystem>
#include <sstream> // std::stringstream
#include <unordered_map> // std::unordered_map
#include "IControls.h"
Expand Down Expand Up @@ -296,6 +298,48 @@ class NAMFileBrowserControl : public IDirBrowseControlBase

void Draw(IGraphics& g) override { g.DrawFittedBitmap(mBitmap, mRECT); }

void SetupMenu()
{
if (std::strcmp(mExtension.Get(), "wav nam") != 0)
{
IDirBrowseControlBase::SetupMenu();
return;
}

// This iPlug2 version scans only one extension. Populate the cab's flat directory menu locally so the file
// picker, popup menu, and previous/next buttons all see both supported formats.
mFiles.Empty(true);
mItems.Empty(false);
mMainMenu.Clear();
mSelectedItemIndex = -1;
for (int pathIndex = 0; pathIndex < mPaths.GetSize(); ++pathIndex)
{
std::error_code error;
const auto directory = std::filesystem::u8path(mPaths.Get(pathIndex)->Get());
for (std::filesystem::directory_iterator entry(directory, error), end; !error && entry != end;
entry.increment(error))
{
const auto& path = entry->path();
const auto name = path.filename().u8string();
std::error_code fileError;
auto extension = path.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
if (name.empty() || name[0] == '.' || !entry->is_regular_file(fileError)
|| (extension != ".wav" && extension != ".nam"))
continue;
const auto label = path.stem().u8string();
auto* item = new IPopupMenu::Item(
reinterpret_cast<const char*>(label.c_str()), IPopupMenu::Item::kNoFlags, mFiles.GetSize());
mMainMenu.AddItem(item, -2 /* sort alphabetically */);
const auto fullPath = path.u8string();
mFiles.Add(new WDL_String(reinterpret_cast<const char*>(fullPath.c_str())));
}
}
for (int i = 0; i < mMainMenu.NItems(); ++i)
mItems.Add(mMainMenu.GetItem(i));
}

void OnPopupMenuSelection(IPopupMenu* pSelectedMenu, int valIdx) override
{
if (pSelectedMenu)
Expand Down Expand Up @@ -455,7 +499,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
}
break;
case kMsgTagLoadedModel:
case kMsgTagLoadedIR:
case kMsgTagLoadedCab:
{
WDL_String fileName, directory;
fileName.Set(reinterpret_cast<const char*>(pData));
Expand Down
15 changes: 11 additions & 4 deletions NeuralAmpModeler/ResamplingNAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <cmath>
#include <functional>
#include <limits>
#include <memory>
#include <stdexcept>
#include <utility>
Expand Down Expand Up @@ -65,10 +66,6 @@ class ResamplingNAM : public nam::DSP
SetOutputLevel(mEncapsulated->GetOutputLevel());
}

// NOTE: prewarm samples doesn't mean anything--we can prewarm the encapsulated model as it likes and be good to
// go.
// _prewarm_samples = 0;

// And be ready
int maxBlockSize = 2048; // Conservative
Reset(expected_sample_rate, maxBlockSize);
Expand All @@ -78,6 +75,16 @@ class ResamplingNAM : public nam::DSP

void prewarm() override { mEncapsulated->prewarm(); };

// Report the encapsulated model's history length in host-rate samples.
int GetPrewarmSamples() override
{
double samples = mEncapsulated->GetPrewarmSamples();
if (NeedToResample())
samples *= GetExpectedSampleRate() / GetEncapsulatedSampleRate();
return static_cast<int>(std::clamp(std::ceil(samples), 0.0,
static_cast<double>(std::numeric_limits<int>::max())));
}

void process(NAM_SAMPLE** input, NAM_SAMPLE** output, const int num_frames) override
{
if (num_frames > mMaxExternalBlockSize)
Expand Down
8 changes: 4 additions & 4 deletions NeuralAmpModeler/Unserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ void NeuralAmpModeler::_UnserializeApplyConfig(nlohmann::json& config)
LEAVE_PARAMS_MUTEX

mNAMPath.Set(static_cast<std::string>(config["NAMPath"]).c_str());
mIRPath.Set(static_cast<std::string>(config["IRPath"]).c_str());
mCabPath.Set(static_cast<std::string>(config["IRPath"]).c_str());

if (mNAMPath.GetLength())
{
_StageModel(mNAMPath);
}
if (mIRPath.GetLength())
if (mCabPath.GetLength())
{
_StageIR(mIRPath);
_StageCab(mCabPath);
}
}

// Unserialize NAM Path, IR path, then named keys
// Unserialize model path, cab path, then named keys
int _UnserializePathsAndExpectedKeys(const iplug::IByteChunk& chunk, int startPos, nlohmann::json& config,
std::vector<std::string>& paramNames)
{
Expand Down
4 changes: 0 additions & 4 deletions NeuralAmpModeler/projects/NeuralAmpModeler-aax.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,8 @@
<ClCompile Include="..\..\iPlug2\IPlug\IPlugProcessor.cpp" />
<ClCompile Include="..\..\iPlug2\IPlug\IPlugTimer.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\dsp.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\ImpulseResponse.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\NoiseGate.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\RecursiveLinearFilter.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\wav.cpp" />
<ClCompile Include="..\NeuralAmpModeler.cpp" />
<ClCompile Include="..\..\NeuralAmpModelerCore\NAM\activations.cpp" />
<ClCompile Include="..\..\NeuralAmpModelerCore\NAM\conv1d.cpp" />
Expand Down Expand Up @@ -523,7 +521,6 @@
<ClInclude Include="..\..\iPlug2\IPlug\IPlug_include_in_plug_hdr.h" />
<ClInclude Include="..\..\iPlug2\IPlug\IPlug_include_in_plug_src.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\dsp.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\ImpulseResponse.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\NoiseGate.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\RecursiveLinearFilter.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\Resample.h" />
Expand All @@ -533,7 +530,6 @@
<ClInclude Include="..\..\AudioDSPTools\dsp\ResamplingContainer\Dependencies\WDL\wdltypes.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\ResamplingContainer\ResamplingContainer.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\version.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\wav.h" />
<ClInclude Include="..\Colors.h" />
<ClInclude Include="..\config.h" />
<ClInclude Include="..\NeuralAmpModeler.h" />
Expand Down
12 changes: 0 additions & 12 deletions NeuralAmpModeler/projects/NeuralAmpModeler-aax.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,12 @@
<ClCompile Include="..\AudioDSPTools\dsp\dsp.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\ImpulseResponse.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\NoiseGate.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\RecursiveLinearFilter.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\wav.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\ToneStack.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -273,9 +267,6 @@
<ClInclude Include="..\AudioDSPTools\dsp\dsp.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\ImpulseResponse.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\NoiseGate.h">
<Filter>dsp</Filter>
</ClInclude>
Expand All @@ -288,9 +279,6 @@
<ClInclude Include="..\AudioDSPTools\dsp\version.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\wav.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\..\iPlug2\IPlug\Extras\NonIntegerResampler.h">
<Filter>IPlug\Extras</Filter>
</ClInclude>
Expand Down
4 changes: 0 additions & 4 deletions NeuralAmpModeler/projects/NeuralAmpModeler-app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@
<ClInclude Include="..\..\iPlug2\IPlug\IPlug_include_in_plug_hdr.h" />
<ClInclude Include="..\..\iPlug2\IPlug\IPlug_include_in_plug_src.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\dsp.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\ImpulseResponse.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\NoiseGate.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\RecursiveLinearFilter.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\Resample.h" />
Expand All @@ -330,7 +329,6 @@
<ClInclude Include="..\..\AudioDSPTools\dsp\ResamplingContainer\Dependencies\WDL\wdltypes.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\ResamplingContainer\ResamplingContainer.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\version.h" />
<ClInclude Include="..\..\AudioDSPTools\dsp\wav.h" />
<ClInclude Include="..\Colors.h" />
<ClInclude Include="..\NeuralAmpModeler.h" />
<ClInclude Include="..\NeuralAmpModelerControls.h" />
Expand Down Expand Up @@ -399,10 +397,8 @@
<ClCompile Include="..\..\iPlug2\IPlug\IPlugProcessor.cpp" />
<ClCompile Include="..\..\iPlug2\IPlug\IPlugTimer.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\dsp.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\ImpulseResponse.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\NoiseGate.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\RecursiveLinearFilter.cpp" />
<ClCompile Include="..\..\AudioDSPTools\dsp\wav.cpp" />
<ClCompile Include="..\NeuralAmpModeler.cpp" />
<ClCompile Include="..\..\NeuralAmpModelerCore\NAM\activations.cpp" />
<ClCompile Include="..\..\NeuralAmpModelerCore\NAM\conv1d.cpp" />
Expand Down
12 changes: 0 additions & 12 deletions NeuralAmpModeler/projects/NeuralAmpModeler-app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,12 @@
<ClCompile Include="..\AudioDSPTools\dsp\dsp.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\ImpulseResponse.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\NoiseGate.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\RecursiveLinearFilter.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\AudioDSPTools\dsp\wav.cpp">
<Filter>dsp</Filter>
</ClCompile>
<ClCompile Include="..\ToneStack.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -321,9 +315,6 @@
<ClInclude Include="..\AudioDSPTools\dsp\dsp.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\ImpulseResponse.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\NoiseGate.h">
<Filter>dsp</Filter>
</ClInclude>
Expand All @@ -336,9 +327,6 @@
<ClInclude Include="..\AudioDSPTools\dsp\version.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\AudioDSPTools\dsp\wav.h">
<Filter>dsp</Filter>
</ClInclude>
<ClInclude Include="..\..\iPlug2\IPlug\Extras\NonIntegerResampler.h">
<Filter>IPlug\Extras</Filter>
</ClInclude>
Expand Down
Loading
Loading