[FEATURE] Support models variable sample rate - #333
Merged
sdatkinson merged 5 commits intoSep 18, 2026
Merged
Conversation
sdatkinson
deleted the
332-feature-support-models-variable-sample-rate
branch
September 18, 2026 19:56
dfernandes83
added a commit
to dfernandes83/NeuralAmpModelerCore
that referenced
this pull request
Sep 21, 2026
Brings in NAM Core 0.6.0 from sdatkinson/NeuralAmpModelerCore: - models with variable sample rate (sdatkinson#333): Linear reports SupportsArbitrarySampleRate() and resamples in Reset() - 1-to-n and n-to-1 channel configurations in Linear models (sdatkinson#335, breaking: a Linear model now needs one kernel per output/input path) - Linear models instantiated from .wav files through get_dsp() (sdatkinson#337) - version bump to 0.6.0 (sdatkinson#336) Conflicts: - NAM/get_dsp.cpp: kept all three includes (<algorithm> and <cctype> from upstream, <cmath> from our validation code). - NAM/linear.cpp: took upstream's rewritten direct-convolution loop. Our side only had a static_cast to silence an MSVC conversion warning in the code that upstream replaced. Consumers now have to compile NAM/wav.cpp too: get_dsp.cpp calls nam::detail::load_wav_ir().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #332
Summary
Adds an explicit capability check for models that support arbitrary processing sample rates and implements that support for
Linearmodels.For example, a linear model trained at 48 kHz can now be reset to another processing rate, such as 44.1 or 96 kHz. Its impulse response is resampled during
Reset(), and subsequent calls toprocess()use the adapted coefficients. The model continues to report 48 kHz as its training rate.Public API
Adds the following virtual method to
DSP:Linearoverrides it to returntrue. Other model architectures retain the default behavior.Hosts can query this capability when deciding whether a model can process at the host’s sample rate or requires external sample-rate conversion. Supporting models are configured through the existing
Reset(sampleRate, maxBufferSize)interface.The documentation for
GetExpectedSampleRate()now identifies it as the model’s training sample rate, which is not necessarily its only supported processing rate. Resetting a model does not change this metadata. This might be cleaned up in a later breaking version bump.Linear model sample-rate adaptation
Linearretains a separate copy of its original trained impulse response. Every reset derives the active coefficients from that original response, preventing interpolation errors from accumulating across successive rate changes.When the processing rate differs from the known training rate:
Resetting to the training rate restores the original coefficients without interpolation.
Both direct and FFT convolution use the adapted response. Automatic implementation selection is reevaluated using the resampled response length, allowing a rate change to switch the selected convolution engine.
Reset and processing behavior
Reset rebuilds the convolution state and clears input history and pending FFT work, including when resetting to the same processing rate. This prevents audio buffered before the reset from appearing afterward.
Input and output buffers are prepared during reset so processing within the advertised maximum buffer size does not allocate, including the first processing call when prewarming is disabled. Resampling and FFT preparation happen outside
process(); callers must perform reset outside the audio callback.Invalid processing rates, including nonpositive and nonfinite values, are rejected. Oversized resampled responses and input buffers are also checked.
Compatibility and limitations
Models whose training rate is unknown (
-1.0) retain their original coefficients because a conversion ratio cannot be determined.Linearis conservative and does not advertise the architecture’s arbitrary-rate capability in this case.Other architectures retain their existing processing behavior.
Cubic interpolation approximates the original impulse response and is not a band-limited resampler. Accuracy can degrade near Nyquist and when downsampling; this limitation is documented.
Tests and verification
Added regression coverage for:
Verification completed:
NAM_SAMPLE_FLOAT.