Model Loading API
-
namespace nam
Typedefs
-
using ConfigParserFunction = std::function<std::unique_ptr<ModelConfig>(const nlohmann::json&, double)>
Function type for parsing a ModelConfig from JSON.
Functions
-
void verify_config_version(const std::string version)
Verify that the config version is supported by this plugin version.
- Parameters:
version – Config version string to verify
-
std::unique_ptr<DSP> get_dsp_legacy(const std::filesystem::path dirname)
Legacy loader for directory-style DSPs.
Loads models from a directory structure (older format).
- Parameters:
dirname – Path to the directory containing the model
- Returns:
Unique pointer to a DSP object
-
std::unique_ptr<DSP> get_dsp(const std::filesystem::path config_filename)
Get NAM from a .nam file at the provided location.
- Parameters:
config_filename – Path to the .nam model file
- Returns:
Unique pointer to a DSP object
-
std::unique_ptr<DSP> get_dsp(const std::filesystem::path config_filename, dspData &returnedConfig)
Get NAM from a .nam file and store its configuration.
Creates an instance of DSP and also returns a dspData struct that holds the data of the model.
- Parameters:
config_filename – Path to the .nam model file
returnedConfig – Output parameter that will be filled with the model data
- Returns:
Unique pointer to a DSP object
-
std::unique_ptr<DSP> get_dsp(const nlohmann::json &config, dspData &returnedConfig)
Get NAM from a provided configuration JSON object.
- Parameters:
config – JSON configuration object
returnedConfig – Output parameter that will be filled with the model data
- Returns:
Unique pointer to a DSP object
-
std::unique_ptr<DSP> get_dsp(const nlohmann::json &config)
Get NAM from a provided configuration JSON object (convenience overload)
- Parameters:
config – JSON configuration object
- Returns:
Unique pointer to a DSP object
-
double get_sample_rate_from_nam_file(const nlohmann::json &j)
Get sample rate from a .nam file.
- Parameters:
j – JSON object from the .nam file
- Returns:
Sample rate in Hz, or -1 if not known (really old .nam files)
-
std::unique_ptr<DSP> create_dsp(std::unique_ptr<ModelConfig> config, std::vector<float> weights, const ModelMetadata &metadata)
Construct a DSP object from a typed config, weights, and metadata.
This is the single construction path used by both JSON and binary loaders. Handles construction, metadata application, and prewarm.
- Parameters:
config – Architecture-specific configuration (abstract base)
weights – Model weights (taken by value to allow move for WaveNet)
metadata – Model metadata (version, sample rate, loudness, levels)
- Returns:
Unique pointer to a DSP object
-
std::unique_ptr<ModelConfig> parse_model_config_json(const std::string &architecture, const nlohmann::json &config, double sample_rate)
Parse a ModelConfig from a JSON architecture name and config block.
- Parameters:
architecture – Architecture name string (e.g., “WaveNet”, “LSTM”)
config – JSON config block for this architecture
sample_rate – Expected sample rate from metadata
- Returns:
unique_ptr<ModelConfig>
Variables
-
const std::string LATEST_FULLY_SUPPORTED_NAM_FILE_VERSION = "0.7.0"
-
const std::string EARLIEST_SUPPORTED_NAM_FILE_VERSION = "0.5.0"
-
class Buffer : public nam::DSP
- #include <dsp.h>
Base class for DSP models that require input buffering This class is deprecated and will be removed in a future version.
Class where an input buffer is kept so that long-time effects can be captured. (e.g. conv nets or impulse responses, where we need history that’s longer than the sample buffer that’s coming in.)
Subclassed by nam::Linear, nam::convnet::ConvNet
Public Functions
-
Buffer(const int in_channels, const int out_channels, const int receptive_field, const double expected_sample_rate = -1.0)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
receptive_field – Size of the receptive field (buffer size needed)
expected_sample_rate – Expected sample rate in Hz (-1.0 if unknown)
-
Buffer(const int in_channels, const int out_channels, const int receptive_field, const double expected_sample_rate = -1.0)
-
struct ConfigParserHelper
- #include <model_config.h>
Auto-registration helper for config parsers.
Create a static instance to register a config parser at program startup.
Public Functions
-
inline ConfigParserHelper(const std::string &name, ConfigParserFunction func)
-
inline ConfigParserHelper(const std::string &name, ConfigParserFunction func)
-
class ConfigParserRegistry
- #include <model_config.h>
Singleton registry mapping architecture names to config parser functions.
Both built-in and external architectures register here. There is one construction path for all architectures.
Public Functions
-
inline void registerParser(const std::string &name, ConfigParserFunction func)
Register a config parser for an architecture.
- Parameters:
name – Architecture name (e.g., “WaveNet”, “LSTM”)
func – Parser function that returns a unique_ptr<ModelConfig>
- Throws:
std::runtime_error – If the name is already registered
-
inline bool has(const std::string &name) const
Check whether an architecture name is registered.
-
inline std::unique_ptr<ModelConfig> parse(const std::string &name, const nlohmann::json &config, double sampleRate) const
Parse a ModelConfig from an architecture name, JSON config, and sample rate.
- Throws:
std::runtime_error – If no parser is registered for the given name
Public Static Functions
-
static inline ConfigParserRegistry &instance()
-
inline void registerParser(const std::string &name, ConfigParserFunction func)
-
class Conv1D
- #include <conv1d.h>
1D dilated convolution layer
Implements a 1D convolution with support for dilation and grouped convolution. Uses a ring buffer to maintain input history for efficient processing of sequential audio frames.
Public Functions
-
inline Conv1D()
Default constructor.
Initializes with dilation=1 and groups=1. Use set_size_() to configure.
-
inline Conv1D(const int in_channels, const int out_channels, const int kernel_size, const int bias, const int dilation, const int groups = 1)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
kernel_size – Size of the convolution kernel
bias – Whether to use bias (1 for true, 0 for false)
dilation – Dilation factor for the convolution
groups – Number of groups for grouped convolution (default: 1)
-
void set_weights_(std::vector<float>::iterator &weights)
Set the parameters (weights) of this module.
- Parameters:
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation, const int groups = 1)
Set the size parameters of the convolution.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
kernel_size – Size of the convolution kernel
do_bias – Whether to use bias
_dilation – Dilation factor for the convolution
groups – Number of groups for grouped convolution
-
void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int _dilation, const bool do_bias, const int groups, std::vector<float>::iterator &weights)
Set size and weights in one call.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
kernel_size – Size of the convolution kernel
_dilation – Dilation factor for the convolution
do_bias – Whether to use bias
groups – Number of groups for grouped convolution
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
void SetMaxBufferSize(const int maxBufferSize)
Reset the ring buffer and pre-allocate output buffer.
- Parameters:
maxBufferSize – Maximum buffer size for output buffer and to size ring buffer
-
inline Eigen::MatrixXf &GetOutput()
Get the entire internal output buffer.
This is intended for internal wiring between layers; callers should treat the buffer as pre-allocated storage and only consider the first num_frames columns valid for a given processing call. Slice with .leftCols(num_frames) as needed.
- Returns:
Reference to the output buffer
-
inline const Eigen::MatrixXf &GetOutput() const
Get the entire internal output buffer (const version)
- Returns:
Const reference to the output buffer
-
void Process(const Eigen::MatrixXf &input, const int num_frames)
Process input and write to internal output buffer.
- Parameters:
input – Input matrix (channels x num_frames)
num_frames – Number of frames to process
-
void process_(const Eigen::MatrixXf &input, Eigen::MatrixXf &output, const long i_start, const long ncols, const long j_start) const
Process from input to output (legacy method, kept for compatibility)
Rightmost indices of input go from i_start for ncols, Indices on output go from j_start (to j_start + ncols - i_start).
- Parameters:
input – Input matrix
output – Output matrix
i_start – Starting index in input
ncols – Number of columns to process
j_start – Starting index in output
-
long get_in_channels() const
Get the number of input channels.
- Returns:
Number of input channels
-
long get_kernel_size() const
Get the kernel size.
- Returns:
Kernel size
-
long get_num_weights() const
Get the total number of weights.
- Returns:
Total number of weight parameters
-
long get_out_channels() const
Get the number of output channels.
- Returns:
Number of output channels
-
inline int get_dilation() const
Get the dilation factor.
- Returns:
Dilation factor
-
inline bool has_bias() const
Check if bias is used.
- Returns:
true if bias is present, false otherwise
-
inline Conv1D()
-
class Conv1x1
- #include <dsp.h>
1x1 convolution (really just a fully-connected linear layer operating per-sample)
Performs a pointwise convolution, which is equivalent to a fully connected layer applied independently to each time step. Supports grouped convolution for efficiency.
Public Functions
-
Conv1x1(const int in_channels, const int out_channels, const bool _bias, const int groups = 1)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
_bias – Whether to use bias
groups – Number of groups for grouped convolution (default: 1)
-
inline Eigen::MatrixXf &GetOutput()
Get the entire internal output buffer.
This is intended for internal wiring between layers/arrays; callers should treat the buffer as pre-allocated storage and only consider the first num_frames columns valid for a given processing call. Slice with .leftCols(num_frames) as needed.
- Returns:
Reference to the output buffer
-
inline const Eigen::MatrixXf &GetOutput() const
Get the entire internal output buffer (const version)
- Returns:
Const reference to the output buffer
-
void SetMaxBufferSize(const int maxBufferSize)
Resize the output buffer to handle maxBufferSize frames.
- Parameters:
maxBufferSize – Maximum number of frames to process in a single call
-
void set_weights_(std::vector<float>::iterator &weights)
Set the parameters (weights) of this module.
- Parameters:
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
inline Eigen::MatrixXf process(const Eigen::MatrixXf &input) const
Process input and return output matrix.
- Parameters:
input – Input matrix (channels x num_frames) or (channels,)
- Returns:
Output matrix (channels x num_frames) or (channels,), respectively
-
Eigen::MatrixXf process(const Eigen::MatrixXf &input, const int num_frames) const
Process input and return output matrix.
- Parameters:
input – Input matrix (channels x num_frames)
num_frames – Number of frames to process
- Returns:
Output matrix (channels x num_frames)
-
void process_(const Eigen::Ref<const Eigen::MatrixXf> &input, const int num_frames)
Process input and store output to pre-allocated buffer.
Uses Eigen::Ref to accept matrices and block expressions without creating temporaries (real-time safe). Access output via GetOutput().
- Parameters:
input – Input matrix (channels x num_frames)
num_frames – Number of frames to process
-
long get_out_channels() const
-
long get_in_channels() const
-
Conv1x1(const int in_channels, const int out_channels, const bool _bias, const int groups = 1)
-
class DSP
- #include <dsp.h>
Base class for all DSP models.
DSP provides the common interface for all neural network-based audio processing models. It handles:
Input/output channel management
Sample rate tracking
Level management (input/output levels and loudness)
Prewarm functionality for settling initial conditions
Buffer size management
Subclasses should override process() to implement the actual processing algorithm.
Subclassed by nam::Buffer, nam::container::ContainerModel, nam::lstm::LSTM
Public Functions
-
DSP(const int in_channels, const int out_channels, const double expected_sample_rate)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
expected_sample_rate – Expected sample rate in Hz (-1.0 if unknown)
-
virtual ~DSP() = default
Virtual destructor.
-
virtual void prewarm()
Prewarm the model to settle initial conditions.
This can be somewhat expensive, so should not be called during real-time audio processing. Important: don’t expect the model to be outputting zeroes after this. Neural networks don’t know that there’s anything special about “zero”, and forcing this gets rid of some possibilities (e.g. models that “are noisy”).
-
virtual void process(NAM_SAMPLE **input, NAM_SAMPLE **output, const int num_frames)
Process audio frames.
- Parameters:
input – Input audio buffers. Double pointer where the first pointer indexes channels and the second indexes frames: input[channel][frame]
output – Output audio buffers. Same structure as input.
num_frames – Number of frames to process
-
inline double GetExpectedSampleRate() const
Get the expected sample rate.
- Returns:
Expected sample rate in Hz (-1.0 if unknown)
-
inline int NumInputChannels() const
Get the number of input channels.
- Returns:
Number of input channels
-
inline int NumOutputChannels() const
Get the number of output channels.
- Returns:
Number of output channels
-
double GetInputLevel()
Get the input level.
Input level is in dBu RMS, corresponding to 0 dBFS peak for a 1 kHz sine wave. You should call HasInputLevel() first to be safe. Note: input level is assumed global over all inputs.
- Returns:
Input level in dBu
-
double GetLoudness() const
Get how loud this model’s output is, in dB, if a “typical” input is processed.
This can be used to normalize the output level of the object.
Throws a std::runtime_error if the model doesn’t know how loud it is. Note: loudness is assumed global over all outputs.
- Throws:
std::runtime_error – If the model doesn’t know its loudness
- Returns:
Loudness in dB
-
double GetOutputLevel()
Get the output level.
Output level is in dBu RMS, corresponding to 0 dBFS peak for a 1 kHz sine wave. You should call HasOutputLevel() first to be safe. Note: output level is assumed global over all outputs.
- Returns:
Output level in dBu
-
bool HasInputLevel()
Check if this model knows its input level.
Note: input level is assumed global over all inputs.
- Returns:
true if input level is known, false otherwise
-
inline bool HasLoudness() const
Check if the model knows how loud it is.
- Returns:
true if loudness is known, false otherwise
-
bool HasOutputLevel()
Check if this model knows its output level.
Note: output level is assumed global over all outputs.
- Returns:
true if output level is known, false otherwise
-
virtual void Reset(const double sampleRate, const int maxBufferSize)
General function for resetting the DSP unit.
This doesn’t call prewarm(). If you want to do that, then you might want to use ResetAndPrewarm(). See https://github.com/sdatkinson/NeuralAmpModelerCore/issues/96 for the reasoning.
- Parameters:
sampleRate – Current sample rate
maxBufferSize – Maximum buffer size to process
-
inline void ResetAndPrewarm(const double sampleRate, const int maxBufferSize)
Reset the DSP unit, then prewarm.
- Parameters:
sampleRate – Current sample rate
maxBufferSize – Maximum buffer size to process
-
void SetInputLevel(const double inputLevel)
Set the input level.
- Parameters:
inputLevel – Input level in dBu
-
void SetLoudness(const double loudness)
Set the loudness.
This is usually defined to be the loudness to a standardized input. The trainer has its own, but you can always use this to define it a different way if you like yours better. Note: loudness is assumed global over all outputs.
- Parameters:
loudness – Loudness in dB
-
void SetOutputLevel(const double outputLevel)
Set the output level.
- Parameters:
outputLevel – Output level in dBu
Friends
- friend class wavenet::WaveNet
-
struct dspData
- #include <dsp.h>
Data structure for a DSP object.
Contains all information needed to instantiate and configure a DSP model.
Public Members
-
std::string version
Data version. Follows conventions established in trainer code.
-
std::string architecture
High-level architecture. Supported: “ConvNet”, “LSTM”, “Linear”, “WaveNet”.
-
nlohmann::json config
Model configuration JSON.
-
nlohmann::json metadata
Model metadata JSON.
-
std::vector<float> weights
Model weights.
-
double expected_sample_rate
Expected sample rate in Hz.
Most NAM models implicitly assume data at some sample rate. Use -1.0 for “I don’t know”.
-
std::string version
-
class FiLM
- #include <film.h>
Feature-wise Linear Modulation (FiLM)
Given an input (input_dim x num_frames) and a condition (condition_dim x num_frames), compute: scale, shift = Conv1x1(condition) split across channels (top/bottom half, respectively) output = input * scale + shift (elementwise)
FiLM applies per-channel scaling and optional shifting based on conditioning input, allowing the model to adapt its behavior based on external signals.
Public Functions
-
inline FiLM(const int condition_dim, const int input_dim, const bool shift, const int groups = 1)
Constructor.
- Parameters:
condition_dim – Size of the conditioning input
input_dim – Size of the input to be modulated
shift – Whether to apply both scale and shift (true) or only scale (false)
groups – Number of groups for grouped convolution in the condition-to-scale-shift submodule (default: 1)
-
inline Eigen::MatrixXf &GetOutput()
Get the entire internal output buffer.
This is intended for internal wiring between layers; callers should treat the buffer as pre-allocated storage and only consider the first num_frames columns valid for a given processing call. Slice with .leftCols(num_frames) as needed.
- Returns:
Reference to the output buffer
-
inline const Eigen::MatrixXf &GetOutput() const
Get the entire internal output buffer (const version)
- Returns:
Const reference to the output buffer
-
inline void SetMaxBufferSize(const int maxBufferSize)
Resize buffers to handle maxBufferSize frames.
- Parameters:
maxBufferSize – Maximum number of frames to process in a single call
-
inline void set_weights_(std::vector<float>::iterator &weights)
Set the parameters (weights) of this module.
- Parameters:
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
inline long get_condition_dim() const
Get the condition dimension.
- Returns:
Size of the conditioning input
-
inline long get_input_dim() const
Get the input dimension.
- Returns:
Size of the input to be modulated
-
inline void Process(const Eigen::Ref<const Eigen::MatrixXf> &input, const Eigen::Ref<const Eigen::MatrixXf> &condition, const int num_frames)
Process input with conditioning.
Writes (input_dim x num_frames) into internal output buffer; access via GetOutput(). Uses Eigen::Ref to accept matrices and block expressions without creating temporaries (real-time safe).
- Parameters:
input – Input matrix (input_dim x num_frames)
condition – Conditioning matrix (condition_dim x num_frames)
num_frames – Number of frames to process
-
inline void Process_(Eigen::Ref<Eigen::MatrixXf> input, const Eigen::Ref<const Eigen::MatrixXf> &condition, const int num_frames)
Process input with conditioning (in-place)
Uses Eigen::Ref to accept matrices and block expressions without creating temporaries (real-time safe). Modifies the input matrix directly.
- Parameters:
input – Input matrix (input_dim x num_frames), will be modified in-place
condition – Conditioning matrix (condition_dim x num_frames)
num_frames – Number of frames to process
-
inline FiLM(const int condition_dim, const int input_dim, const bool shift, const int groups = 1)
-
class IVersionSupportChecker
- #include <get_dsp.h>
-
class Linear : public nam::Buffer
- #include <dsp.h>
Basic linear model.
Implements a simple linear convolution, (i.e. an impulse response).
Public Functions
-
Linear(const int in_channels, const int out_channels, const int receptive_field, const bool _bias, const std::vector<float> &weights, const double expected_sample_rate = -1.0)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
receptive_field – Size of the impulse response
_bias – Whether to use bias
weights – Model weights (impulse response coefficients)
expected_sample_rate – Expected sample rate in Hz (-1.0 if unknown)
-
virtual void process(NAM_SAMPLE **input, NAM_SAMPLE **output, const int num_frames) override
Process audio frames.
- Parameters:
input – Input audio buffers
output – Output audio buffers
num_frames – Number of frames to process
-
Linear(const int in_channels, const int out_channels, const int receptive_field, const bool _bias, const std::vector<float> &weights, const double expected_sample_rate = -1.0)
-
class ModelConfig
- #include <model_config.h>
Abstract base class for architecture-specific configuration.
Each architecture defines a concrete config struct that inherits from this and implements create() to construct the DSP object.
Subclassed by nam::container::ContainerConfig, nam::convnet::ConvNetConfig, nam::factory::FactoryConfig, nam::linear::LinearConfig, nam::lstm::LSTMConfig
Public Functions
-
virtual ~ModelConfig() = default
-
virtual ~ModelConfig() = default
-
struct ModelMetadata
- #include <model_config.h>
Metadata common to all model formats.
-
class RingBuffer
- #include <ring_buffer.h>
Ring buffer for managing Eigen::MatrixXf buffers with write/read pointers.
Provides efficient circular buffer functionality for maintaining input history in convolutional layers. Automatically handles buffer wrapping when needed.
Public Functions
-
inline RingBuffer()
Default constructor.
-
void Reset(const int channels, const int max_buffer_size)
Initialize/resize storage.
- Parameters:
channels – Number of channels (rows in the storage matrix)
max_buffer_size – Maximum amount that will be written or read at once
-
void Write(const Eigen::MatrixXf &input, const int num_frames)
Write new data at write pointer.
NOTE: This function expects a full, pre-allocated, column-major MatrixXf covering the entire valid buffer range. Callers should not pass Block expressions (e.g. .leftCols()) across the API boundary; instead, pass the full buffer and slice inside the callee. This avoids Eigen evaluating Blocks into temporaries (which would allocate) when binding to MatrixXf.
- Parameters:
input – Input matrix (channels x num_frames)
num_frames – Number of frames to write
-
Eigen::Block<Eigen::MatrixXf> Read(const int num_frames, const long lookback = 0)
Read data with optional lookback.
- Parameters:
num_frames – Number of frames to read
lookback – Number of frames to look back from write pointer (default 0)
- Returns:
Block reference to the storage data
-
void Advance(const int num_frames)
Advance write pointer.
- Parameters:
num_frames – Number of frames to advance
-
inline int GetMaxBufferSize() const
Get max buffer size (the value passed to Reset())
- Returns:
Maximum buffer size
-
inline int GetChannels() const
Get number of channels (rows)
- Returns:
Number of channels
-
inline void SetMaxLookback(const long max_lookback)
Set the max lookback (maximum history needed when rewinding)
- Parameters:
max_lookback – Maximum lookback distance
-
inline RingBuffer()
-
class SlimmableModel
- #include <slimmable.h>
Interface for models that support dynamic size reduction.
Models implementing this interface can reduce their computational cost at the expense of quality. The interpretation of the size parameter is model-specific (e.g., selecting a sub-model, pruning channels, etc.).
Subclassed by nam::container::ContainerModel
-
class Version
- #include <get_dsp.h>
-
namespace activations
Enums
-
enum class ActivationType
Values:
-
enumerator Tanh
-
enumerator Hardtanh
-
enumerator Fasttanh
-
enumerator ReLU
-
enumerator LeakyReLU
-
enumerator PReLU
-
enumerator Sigmoid
-
enumerator SiLU
-
enumerator Hardswish
-
enumerator LeakyHardtanh
-
enumerator Softsign
-
enumerator Tanh
Functions
-
inline float relu(float x)
-
inline float sigmoid(float x)
-
inline float hard_tanh(float x)
-
inline float leaky_hardtanh(float x, float min_val, float max_val, float min_slope, float max_slope)
-
inline float fast_tanh(const float x)
-
inline float fast_sigmoid(const float x)
-
inline float leaky_relu(float x, float negative_slope)
-
inline float leaky_relu(float x)
-
inline float swish(float x)
-
inline float hardswish(float x)
-
inline float softsign(float x)
-
class Activation
- #include <activations.h>
Subclassed by nam::activations::ActivationFastTanh, nam::activations::ActivationHardSwish, nam::activations::ActivationHardTanh, nam::activations::ActivationIdentity, nam::activations::ActivationLeakyHardTanh, nam::activations::ActivationLeakyReLU, nam::activations::ActivationPReLU, nam::activations::ActivationReLU, nam::activations::ActivationSigmoid, nam::activations::ActivationSoftsign, nam::activations::ActivationSwish, nam::activations::ActivationTanh, nam::activations::FastLUTActivation, nam::gating_activations::IdentityActivation
Public Types
-
using Ptr = std::shared_ptr<Activation>
Public Functions
-
Activation() = default
-
virtual ~Activation() = default
-
inline virtual void apply(Eigen::MatrixXf &matrix)
-
inline virtual void apply(Eigen::Block<Eigen::MatrixXf> block)
-
inline virtual void apply(Eigen::Block<Eigen::MatrixXf, -1, -1, true> block)
-
virtual void apply(float *data, long size) = 0
Public Static Functions
-
static Ptr get_activation(const std::string name)
-
static Ptr get_activation(const ActivationConfig &config)
-
static Ptr get_activation(const nlohmann::json &activation_config)
-
static void enable_fast_tanh()
-
static void disable_fast_tanh()
-
static void enable_lut(std::string function_name, float min, float max, std::size_t n_points)
-
static void disable_lut(std::string function_name)
Public Static Attributes
-
static bool using_fast_tanh
-
using Ptr = std::shared_ptr<Activation>
-
struct ActivationConfig
- #include <activations.h>
Public Members
-
ActivationType type
-
std::optional<float> negative_slope
-
std::optional<std::vector<float>> negative_slopes
-
std::optional<float> min_val
-
std::optional<float> max_val
-
std::optional<float> min_slope
-
std::optional<float> max_slope
Public Static Functions
-
static ActivationConfig simple(ActivationType t)
-
static ActivationConfig from_json(const nlohmann::json &j)
-
ActivationType type
-
class ActivationFastTanh : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationHardSwish : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationHardTanh : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationIdentity : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
ActivationIdentity() = default
-
~ActivationIdentity() = default
-
inline virtual void apply(float *data, long size) override
-
ActivationIdentity() = default
-
class ActivationLeakyHardTanh : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
ActivationLeakyHardTanh() = default
-
inline ActivationLeakyHardTanh(float min_val_, float max_val_, float min_slope_, float max_slope_)
-
inline virtual void apply(float *data, long size) override
-
ActivationLeakyHardTanh() = default
-
class ActivationLeakyReLU : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
ActivationLeakyReLU() = default
-
inline ActivationLeakyReLU(float ns)
-
inline virtual void apply(float *data, long size) override
-
ActivationLeakyReLU() = default
-
class ActivationPReLU : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
ActivationPReLU() = default
-
inline ActivationPReLU(float ns)
-
inline ActivationPReLU(std::vector<float> ns)
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(Eigen::MatrixXf &matrix) override
-
ActivationPReLU() = default
-
class ActivationReLU : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationSigmoid : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationSoftsign : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationSwish : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class ActivationTanh : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline virtual void apply(float *data, long size) override
-
inline virtual void apply(float *data, long size) override
-
class FastLUTActivation : public nam::activations::Activation
- #include <activations.h>
Public Functions
-
inline FastLUTActivation(float min_x, float max_x, std::size_t size, std::function<float(float)> f)
-
inline float lookup(float x) const
-
inline virtual void apply(float *data, long size) override
-
inline FastLUTActivation(float min_x, float max_x, std::size_t size, std::function<float(float)> f)
-
enum class ActivationType
-
namespace container
Functions
-
std::unique_ptr<ModelConfig> create_config(const nlohmann::json &config, double sampleRate)
-
struct ContainerConfig : public nam::ModelConfig
- #include <container.h>
Public Functions
-
class ContainerModel : public nam::DSP, public nam::SlimmableModel
- #include <container.h>
A container model that holds multiple submodels at different sizes.
SetSlimmableSize selects the active submodel based on the max_value thresholds. Each submodel covers values up to (but not including) its max_value. The last submodel is the fallback for values at or above the last threshold.
Public Functions
-
ContainerModel(std::vector<Submodel> submodels, const double expected_sample_rate)
Constructor.
- Parameters:
submodels – Vector of submodels sorted by max_value ascending
expected_sample_rate – Expected sample rate in Hz
-
virtual void process(NAM_SAMPLE **input, NAM_SAMPLE **output, const int num_frames) override
Process audio frames.
- Parameters:
input – Input audio buffers. Double pointer where the first pointer indexes channels and the second indexes frames: input[channel][frame]
output – Output audio buffers. Same structure as input.
num_frames – Number of frames to process
-
virtual void prewarm() override
Prewarm the model to settle initial conditions.
This can be somewhat expensive, so should not be called during real-time audio processing. Important: don’t expect the model to be outputting zeroes after this. Neural networks don’t know that there’s anything special about “zero”, and forcing this gets rid of some possibilities (e.g. models that “are noisy”).
-
virtual void Reset(const double sampleRate, const int maxBufferSize) override
General function for resetting the DSP unit.
This doesn’t call prewarm(). If you want to do that, then you might want to use ResetAndPrewarm(). See https://github.com/sdatkinson/NeuralAmpModelerCore/issues/96 for the reasoning.
- Parameters:
sampleRate – Current sample rate
maxBufferSize – Maximum buffer size to process
-
virtual void SetSlimmableSize(const double val) override
Set the slimmable size of the model.
Thread-safe Not real-time safe
- Parameters:
val – Value between 0.0 (minimum size) and 1.0 (maximum size)
-
ContainerModel(std::vector<Submodel> submodels, const double expected_sample_rate)
-
struct Submodel
- #include <container.h>
-
std::unique_ptr<ModelConfig> create_config(const nlohmann::json &config, double sampleRate)
-
namespace convnet
Functions
-
ConvNetConfig parse_config_json(const nlohmann::json &config)
Parse ConvNet configuration from JSON.
- Parameters:
config – JSON configuration object
- Returns:
-
std::unique_ptr<ModelConfig> create_config(const nlohmann::json &config, double sampleRate)
Config parser for ConfigParserRegistry.
-
class _Head
- #include <convnet.h>
Public Functions
-
inline _Head()
-
_Head(const int in_channels, const int out_channels, std::vector<float>::iterator &weights)
-
void process_(const Eigen::MatrixXf &input, Eigen::MatrixXf &output, const long i_start, const long i_end) const
-
inline _Head()
-
class BatchNorm
- #include <convnet.h>
Batch normalization layer.
In production mode, so really just an elementwise affine layer. Applies: y = (x - mean) / sqrt(variance + eps) * weight + bias which simplifies to: y = scale * x + loc
Public Functions
-
inline BatchNorm()
Default constructor.
-
BatchNorm(const int dim, std::vector<float>::iterator &weights)
Constructor with weights.
- Parameters:
dim – Dimension of the input
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
void process_(Eigen::MatrixXf &input, const long i_start, const long i_end) const
Process input in-place.
- Parameters:
input – Input matrix to process
i_start – Start index
i_end – End index
-
inline BatchNorm()
-
class ConvNet : public nam::Buffer
- #include <convnet.h>
Convolutional neural network model.
A ConvNet consists of multiple ConvNetBlocks with increasing dilation factors, followed by a head layer that produces the final output.
Public Functions
-
ConvNet(const int in_channels, const int out_channels, const int channels, const std::vector<int> &dilations, const bool batchnorm, const activations::ActivationConfig &activation_config, std::vector<float> &weights, const double expected_sample_rate = -1.0, const int groups = 1)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
channels – Number of channels in the hidden layers
dilations – Vector of dilation factors, one per block
batchnorm – Whether to use batch normalization
activation_config – Activation function configuration
weights – Model weights vector
expected_sample_rate – Expected sample rate in Hz (-1.0 if unknown)
groups – Number of groups for grouped convolution
-
~ConvNet() = default
Destructor.
-
virtual void process(NAM_SAMPLE **input, NAM_SAMPLE **output, const int num_frames) override
Process audio frames.
- Parameters:
input – Input audio buffers
output – Output audio buffers
num_frames – Number of frames to process
-
virtual void SetMaxBufferSize(const int maxBufferSize) override
Resize all buffers to handle maxBufferSize frames.
- Parameters:
maxBufferSize – Maximum number of frames to process in a single call
-
ConvNet(const int in_channels, const int out_channels, const int channels, const std::vector<int> &dilations, const bool batchnorm, const activations::ActivationConfig &activation_config, std::vector<float> &weights, const double expected_sample_rate = -1.0, const int groups = 1)
-
class ConvNetBlock
- #include <convnet.h>
A single block in a ConvNet.
Consists of a dilated convolution, optional batch normalization, and activation.
Public Functions
-
inline ConvNetBlock()
Default constructor.
-
void set_weights_(const int in_channels, const int out_channels, const int _dilation, const bool batchnorm, const activations::ActivationConfig &activation_config, const int groups, std::vector<float>::iterator &weights)
Set the parameters (weights) of this block.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
_dilation – Dilation factor for the convolution
batchnorm – Whether to use batch normalization
activation_config – Activation function configuration
groups – Number of groups for grouped convolution
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
void SetMaxBufferSize(const int maxBufferSize)
Resize buffers to handle maxBufferSize frames.
- Parameters:
maxBufferSize – Maximum number of frames to process in a single call
-
void Process(const Eigen::MatrixXf &input, const int num_frames)
Process input matrix directly (new API, similar to WaveNet)
- Parameters:
input – Input matrix (channels x num_frames)
num_frames – Number of frames to process
-
void process_(const Eigen::MatrixXf &input, Eigen::MatrixXf &output, const long i_start, const long i_end)
Process input (legacy method for compatibility, uses indices)
- Parameters:
input – Input matrix
output – Output matrix
i_start – Start index in input
i_end – End index in input
-
Eigen::Block<Eigen::MatrixXf> GetOutput(const int num_frames)
Get output from last Process() call.
- Parameters:
num_frames – Number of frames to return
- Returns:
Block reference to the output
-
long get_out_channels() const
Get the number of output channels.
- Returns:
Number of output channels
Public Members
-
Conv1D conv
The dilated convolution layer.
-
inline ConvNetBlock()
-
struct ConvNetConfig : public nam::ModelConfig
- #include <convnet.h>
Configuration for a ConvNet model.
Public Functions
Public Members
-
int channels
-
std::vector<int> dilations
-
bool batchnorm
-
activations::ActivationConfig activation
-
int groups
-
int in_channels
-
int out_channels
-
int channels
-
ConvNetConfig parse_config_json(const nlohmann::json &config)
-
namespace factory
Typedefs
-
class FactoryConfig : public nam::ModelConfig
- #include <registry.h>
ModelConfig wrapper around a legacy FactoryFunction.
Stores the factory function, JSON config, and sample rate so that create() can delegate to the factory. This allows external code that registers a FactoryFunction to work transparently with ConfigParserRegistry.
Public Functions
-
inline FactoryConfig(FactoryFunction factory, nlohmann::json config, double sampleRate)
-
inline virtual std::unique_ptr<DSP> create(std::vector<float> weights, double sampleRate) override
Construct a DSP object from this configuration.
- Parameters:
weights – Model weights (taken by value to allow move for WaveNet)
sampleRate – Expected sample rate in Hz
- Returns:
Unique pointer to a DSP object
-
inline FactoryConfig(FactoryFunction factory, nlohmann::json config, double sampleRate)
-
struct Helper
- #include <registry.h>
Registration helper for factories (external code compatibility)
Wraps a FactoryFunction into a ConfigParserRegistry entry via FactoryConfig. Use this to register external architectures. Create a static instance to automatically register a factory when the program starts.
Public Functions
-
inline Helper(const std::string &name, FactoryFunction factory)
- Parameters:
name – Architecture name
factory – Factory function
-
inline Helper(const std::string &name, FactoryFunction factory)
-
class FactoryConfig : public nam::ModelConfig
-
namespace gating_activations
-
class BlendingActivation
- #include <gating_activations.h>
Public Functions
-
inline BlendingActivation(activations::Activation::Ptr input_act, activations::Activation::Ptr blend_act, int input_channels = 1)
Constructor for BlendingActivation.
- Parameters:
input_act – Activation function for input channels
blend_act – Activation function for blending channels
input_channels – Number of input channels
-
~BlendingActivation() = default
-
template<typename InputDerived, typename OutputDerived>
inline void apply(const Eigen::MatrixBase<InputDerived> &input, Eigen::MatrixBase<OutputDerived> &output) Apply blending activation to input matrix.
- Parameters:
input – Input matrix with shape (input_channels + blend_channels) x num_samples
output – Output matrix with shape input_channels x num_samples
-
inline int get_input_channels() const
Get the total number of input channels required.
-
inline int get_output_channels() const
Get the number of output channels.
-
inline BlendingActivation(activations::Activation::Ptr input_act, activations::Activation::Ptr blend_act, int input_channels = 1)
-
class GatingActivation
- #include <gating_activations.h>
Public Functions
-
inline GatingActivation(activations::Activation::Ptr input_act, activations::Activation::Ptr gating_act, int input_channels = 1)
Constructor for GatingActivation.
- Parameters:
input_act – Activation function for input channels
gating_act – Activation function for gating channels
input_channels – Number of input channels (default: 1)
gating_channels – Number of gating channels (default: 1)
-
~GatingActivation() = default
-
template<typename InputDerived, typename OutputDerived>
inline void apply(const Eigen::MatrixBase<InputDerived> &input, Eigen::MatrixBase<OutputDerived> &output) Apply gating activation to input matrix.
- Parameters:
input – Input matrix with shape (input_channels + gating_channels) x num_samples
output – Output matrix with shape input_channels x num_samples
-
inline int get_input_channels() const
Get the total number of input channels required.
-
inline int get_output_channels() const
Get the number of output channels.
-
inline GatingActivation(activations::Activation::Ptr input_act, activations::Activation::Ptr gating_act, int input_channels = 1)
-
class IdentityActivation : public nam::activations::Activation
- #include <gating_activations.h>
Public Functions
-
IdentityActivation() = default
-
~IdentityActivation() = default
-
IdentityActivation() = default
-
class BlendingActivation
-
namespace linear
Functions
-
LinearConfig parse_config_json(const nlohmann::json &config)
Parse Linear configuration from JSON.
- Parameters:
config – JSON configuration object
- Returns:
-
std::unique_ptr<ModelConfig> create_config(const nlohmann::json &config, double sampleRate)
Config parser for ConfigParserRegistry.
- Parameters:
config – JSON configuration object
sampleRate – Expected sample rate in Hz
- Returns:
unique_ptr<ModelConfig> wrapping a LinearConfig
-
struct LinearConfig : public nam::ModelConfig
- #include <dsp.h>
Configuration for a Linear model.
Public Functions
-
LinearConfig parse_config_json(const nlohmann::json &config)
-
namespace lstm
Functions
-
LSTMConfig parse_config_json(const nlohmann::json &config)
Parse LSTM configuration from JSON.
- Parameters:
config – JSON configuration object
- Returns:
-
std::unique_ptr<ModelConfig> create_config(const nlohmann::json &config, double sampleRate)
Config parser for ConfigParserRegistry.
-
class LSTM : public nam::DSP
- #include <lstm.h>
A multi-layer LSTM model.
A multi-layer LSTM processes audio frame-by-frame, maintaining hidden states across layers. Each layer processes the hidden state from the previous layer as input.
Public Functions
-
LSTM(const int in_channels, const int out_channels, const int num_layers, const int input_size, const int hidden_size, std::vector<float> &weights, const double expected_sample_rate = -1.0)
Constructor.
- Parameters:
in_channels – Number of input channels
out_channels – Number of output channels
num_layers – Number of LSTM layers
input_size – Size of the input to each LSTM cell
hidden_size – Size of the hidden state in each LSTM cell
weights – Model weights vector
expected_sample_rate – Expected sample rate in Hz (-1.0 if unknown)
-
~LSTM() = default
Destructor.
-
virtual void process(NAM_SAMPLE **input, NAM_SAMPLE **output, const int num_frames) override
Process audio frames.
- Parameters:
input – Input audio buffers
output – Output audio buffers
num_frames – Number of frames to process
-
LSTM(const int in_channels, const int out_channels, const int num_layers, const int input_size, const int hidden_size, std::vector<float> &weights, const double expected_sample_rate = -1.0)
-
class LSTMCell
- #include <lstm.h>
A single LSTM cell.
Public Functions
-
LSTMCell(const int input_size, const int hidden_size, std::vector<float>::iterator &weights)
Constructor.
- Parameters:
input_size – Size of the input vector
hidden_size – Size of the hidden state
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
Get the current hidden state.
- Returns:
Hidden state vector
-
void process_(const Eigen::VectorXf &x)
Process a single input vector.
- Parameters:
x – Input vector
-
LSTMCell(const int input_size, const int hidden_size, std::vector<float>::iterator &weights)
-
struct LSTMConfig : public nam::ModelConfig
- #include <lstm.h>
Configuration for an LSTM model.
Public Functions
-
LSTMConfig parse_config_json(const nlohmann::json &config)
-
namespace util
Functions
-
std::string lowercase(const std::string &s)
Convert a string to lowercase.
- Parameters:
s – Input string
- Returns:
Lowercase version of the input string
-
std::string lowercase(const std::string &s)
-
namespace wavenet
-
using ConfigParserFunction = std::function<std::unique_ptr<ModelConfig>(const nlohmann::json&, double)>