You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Loading certain A1 models after A2 models can cause audio crackling / dropouts #303
we discovered a hard-to-reproduce issue, where certain A1 models will not play correctly when loaded right after certain other A2 models. Re-instantiating the plugin (prepareToPlay call) will resolve the issue.
We discovered this on our own implementation of the NAM Core (which uses none of the Gateway plugin harness), and verified it on Gateway, which leads us to believe the issue lies with the NAM Core itself.
We discovered this on our own implementation of the NAM Core (which uses none of the Gateway plugin harness), and verified it on Gateway, which leads us to believe the issue lies with the NAM Core itself.
NAM Core is a DSP library; Gateway is a private fork of NeuralAmpModelerPlugin...what's the "Gateway plugin harness" that this library uses? And are you saying that this can be observed without putting this library in a plugin? Would a test that just instantiates a model a bunch of times and keep checking the predictions maybe expose the bug?
Thanks for the video & models; I'll get to them later.
We’re using the NAM core in our own plugin, where we discovered the issue. This plugin uses no code from the NeuralAmpModelerPlugin, but is a custom juce implementation around the NAM core.
We used Gateway to confirm that the issue is not in our juce plugin code, but that it happens (probably) in the NAM Core. That’s what the video shows.
Following your suggestion,
we ran the two models from the zip through a Core-only harness: no plugin code,
staged as the plugin does (get_dsp → Reset → SetSlimmableSize), at 64- and
512-frame blocks.
Swapping models doesn't change the A1 model. The A1 output was bit-identical
to a fresh load in every case:
after the A2 model ran at slim 1.0, then was destroyed;
the same at slim 0.0;
with the A2 model kept alive, its slim toggled every 50 blocks, and the A1
model processing in between.
We checked this on v0.5.3, v0.5.4 and main.
What does reproduce it is a host calling process() with more frames than
it passed to Reset(). The A2 fast path grows its buffers and plays on. The
generic WaveNet, which every A1 model uses, only asserts, so a release build
writes past its buffers. A host that under-reserves would therefore sound fine
with A2 models and corrupt the heap with the next A1 model, until prepareToPlay resets it with the real size:
sequenceDiagram
accTitle: Buffer size across an A2 to A1 model swap
accDescr: The host announces 512 frames and later calls with 1024. The A2 fast path grows itself and keeps playing. The next model, an A1 WaveNet, is reset with the stale 512, and the 1024-frame call writes past its buffers until the host prepares again with the real size.
participant H as Host
participant P as Plugin
participant A2 as A2 model (A2FastModel)
participant A1 as A1 model (WaveNet)
H->>P: prepareToPlay(48 kHz, 512)
P->>A2: Reset(48 kHz, 512)
H->>P: processBlock(1024)
P->>A2: process(1024)
Note over A2: 1024 > 512: SetMaxBufferSize(1024)<br/>(a2_fast.cpp:735-736), grows, keeps playing
Note over P: still holds 512 from prepareToPlay
P->>A1: get_dsp(), Reset(48 kHz, 512)
H->>P: processBlock(1024)
P->>A1: process(1024)
Note over A1: the assert at model.cpp:827 is compiled out<br/>1024 frames go into 512-frame buffers (from :820)
H->>P: prepareToPlay(48 kHz, 1024)
P->>A1: Reset(48 kHz, 1024)
Note over A1: fits again, which is the workaround in the report
LoadingWhat one oversized call overwrites (the zip's A1 model, reserve 64, call 128)
@benediktadams, two things would tell us whether this is your case:
Does processBlock ever get more samples than you passed to Reset?
JUCE calls maximumExpectedSamplesPerBlock "a strong hint" and asks plugins
to "program defensively in case a buggy host exceeds this value".
Does the crackling stop if you reset with a much larger size?
#340 makes WaveNet split such a call into reservation-sized chunks: no
overflow, no allocation, and the same output as the host making those calls
itself.
One thing we can't check: the open-source plugin's ResamplingNAM throws on an
oversized block. If Gateway kept that check, the Gateway reproduction points
somewhere else.
@squatchlr today while working on NeuralAmpModelerPlugin, I sort of organically encountered and resolved this in a different way. There wasn't a bug with the plugin, but I did notice that some of the logic could be made more obviously clean, and I ended up having the plugin allocate for a max buffer size of 2048 on instantiation, then do basically what you're saying if the provided buffer by the host is larger. So e.g. if the host sends a buffer of size 4096, then it internally processes two length-2048 buffers and places them as needed in the output array.
What I realized though is that this issue was better to solve at the plugin level instead of Core level because there were other audio processing pieces that would have also needed to solve the same problem separately. IMO, it's more straightforward to assert correct behavior at the low level, and handle any unruly hosts at the plugin level.
Another way to put it is that while it may be true that a plugin host might give an invalid buffer to a plugin, this library isn't itself a plugin. So I believe it simplifies the scope of concern for this DSP library to be able to assume valid use and leave possible invalid use by the host to the scope of the plugin itself instead of propagating it :)
@sdatkinson Thanks, that's a cleaner split and I agree with it. The plugin is the layer that has to absorb host behaviour anyway, and #690 does it once for the whole chain (resampler, gate, tone stack, cab) instead of model type by model type, which Core on its own couldn't do.
I read through the block handling in #690:
Staging is applied once per host block, before the chunk loop, so a model or cab swap can't land between two chunks of the same host block. Nice touch.
test_large_host_blocks is the right test: 5000-frame host blocks against short blocks at 44.1, 48 and 96 kHz, with a signal check on the final partial chunk and latency and tail compared. Because the 44.1 and 96 kHz cases resample, it also covers the inner ceil(2048 * modelRate / hostRate) size.
I also built #690 locally (macOS, Release) and ran it. Your CTest suite passes and the Steinberg validator reports 47/47. On top of that I ran a few harsher host cases against the example models (A1 standard, wavenet.nam, A2.nam, LSTM) at 48 and 44.1 kHz, each compared with the same input in short blocks:
a host that announces 256 frames and then sends 4096;
uneven blocks of 2049, 1, 4095, 2048, 3 and 2047 frames;
8192-frame blocks with an honest announcement;
6000-frame blocks with the gate and EQ on;
the sequence from this issue: an A2 model plays 1024-frame blocks after a 512 announcement, then an A1 model is loaded and gets the same.
All 34 cases match. A2 and LSTM at 48 kHz are bit-identical; the A1 WaveNet differs by at most 3.2e-6 (with the EQ on), which is below the 3.5e-6 you get from simply changing the short block sizes with no splitting at all. Happy to turn the announce-256-send-4096 and A2-to-A1 cases into a test for test_stereo_plugin if you'd like them.
Two small things on the Core side, in case they're useful. Happy to send either as a PR, or leave them with you:
Write the contract down.DSP::process() doesn't currently say that num_frames must not exceed the maxBufferSize given to Reset(). One line there would tell other Core users, like the custom JUCE wrapper in this issue, that splitting is their job.
A2's fast path still grows instead.A2FastModel::process() calls SetMaxBufferSize(num_frames) when a call is too big (a2_fast.cpp#L735-L736); on main, a submodel of example_models/A2.nam reset for 64 frames comes out of a 128-frame call resized to 128. That allocates on the audio thread, and it hides a host bug with A2 models that then shows up with the next A1 model, which is close to what this issue describes. Under the contract above it could be the same assert as the generic WaveNet.
@benediktadams, for your JUCE plugin this puts the fix on your side: Reset() with a size you'll never exceed and split larger processBlock calls into chunks of that size, as #690 does, or Reset() again whenever the host announces a new maximum. If that clears the crackling, this issue can probably be closed.
Activity
sdatkinson commentedon Jul 1, 2026
Care to clarify this?
NAM Core is a DSP library; Gateway is a private fork of NeuralAmpModelerPlugin...what's the "Gateway plugin harness" that this library uses? And are you saying that this can be observed without putting this library in a plugin? Would a test that just instantiates a model a bunch of times and keep checking the predictions maybe expose the bug?
Thanks for the video & models; I'll get to them later.
benediktadams commentedon Jul 1, 2026
Yeah sorry for the confusion.
We’re using the NAM core in our own plugin, where we discovered the issue. This plugin uses no code from the NeuralAmpModelerPlugin, but is a custom juce implementation around the NAM core.
We used Gateway to confirm that the issue is not in our juce plugin code, but that it happens (probably) in the NAM Core. That’s what the video shows.
Hope that helps
fix(thread-safety): guard the global activation registry against conc…
Split WaveNet::process() calls larger than the buffer size
squatchlr commentedon Sep 25, 2026
Following your suggestion,
we ran the two models from the zip through a Core-only harness: no plugin code,
staged as the plugin does (
get_dsp→Reset→SetSlimmableSize), at 64- and512-frame blocks.
Swapping models doesn't change the A1 model. The A1 output was bit-identical
to a fresh load in every case:
model processing in between.
We checked this on v0.5.3, v0.5.4 and
main.What does reproduce it is a host calling
process()with more frames thanit passed to
Reset(). The A2 fast path grows its buffers and plays on. Thegeneric WaveNet, which every A1 model uses, only asserts, so a release build
writes past its buffers. A host that under-reserves would therefore sound fine
with A2 models and corrupt the heap with the next A1 model, until
prepareToPlayresets it with the real size:sequenceDiagram accTitle: Buffer size across an A2 to A1 model swap accDescr: The host announces 512 frames and later calls with 1024. The A2 fast path grows itself and keeps playing. The next model, an A1 WaveNet, is reset with the stale 512, and the 1024-frame call writes past its buffers until the host prepares again with the real size. participant H as Host participant P as Plugin participant A2 as A2 model (A2FastModel) participant A1 as A1 model (WaveNet) H->>P: prepareToPlay(48 kHz, 512) P->>A2: Reset(48 kHz, 512) H->>P: processBlock(1024) P->>A2: process(1024) Note over A2: 1024 > 512: SetMaxBufferSize(1024)<br/>(a2_fast.cpp:735-736), grows, keeps playing Note over P: still holds 512 from prepareToPlay P->>A1: get_dsp(), Reset(48 kHz, 512) H->>P: processBlock(1024) P->>A1: process(1024) Note over A1: the assert at model.cpp:827 is compiled out<br/>1024 frames go into 512-frame buffers (from :820) H->>P: prepareToPlay(48 kHz, 1024) P->>A1: Reset(48 kHz, 1024) Note over A1: fits again, which is the workaround in the reportWhat one oversized call overwrites (the zip's A1 model, reserve 64, call 128)
@benediktadams, two things would tell us whether this is your case:
processBlockever get more samples than you passed toReset?JUCE calls
maximumExpectedSamplesPerBlock"a strong hint" and asks pluginsto "program defensively in case a buggy host exceeds this value".
#340 makes WaveNet split such a call into reservation-sized chunks: no
overflow, no allocation, and the same output as the host making those calls
itself.
One thing we can't check: the open-source plugin's
ResamplingNAMthrows on anoversized block. If Gateway kept that check, the Gateway reproduction points
somewhere else.
sdatkinson commentedon Nov 20, 2026
@squatchlr today while working on NeuralAmpModelerPlugin, I sort of organically encountered and resolved this in a different way. There wasn't a bug with the plugin, but I did notice that some of the logic could be made more obviously clean, and I ended up having the plugin allocate for a max buffer size of 2048 on instantiation, then do basically what you're saying if the provided buffer by the host is larger. So e.g. if the host sends a buffer of size 4096, then it internally processes two length-2048 buffers and places them as needed in the output array.
What I realized though is that this issue was better to solve at the plugin level instead of Core level because there were other audio processing pieces that would have also needed to solve the same problem separately. IMO, it's more straightforward to assert correct behavior at the low level, and handle any unruly hosts at the plugin level.
See: sdatkinson/NeuralAmpModelerPlugin#690
Another way to put it is that while it may be true that a plugin host might give an invalid buffer to a plugin, this library isn't itself a plugin. So I believe it simplifies the scope of concern for this DSP library to be able to assume valid use and leave possible invalid use by the host to the scope of the plugin itself instead of propagating it :)
Happy to hear your thoughts.
squatchlr commentedon Nov 21, 2026
@sdatkinson Thanks, that's a cleaner split and I agree with it. The plugin is the layer that has to absorb host behaviour anyway, and #690 does it once for the whole chain (resampler, gate, tone stack, cab) instead of model type by model type, which Core on its own couldn't do.
I read through the block handling in #690:
test_large_host_blocksis the right test: 5000-frame host blocks against short blocks at 44.1, 48 and 96 kHz, with a signal check on the final partial chunk and latency and tail compared. Because the 44.1 and 96 kHz cases resample, it also covers the innerceil(2048 * modelRate / hostRate)size.I also built #690 locally (macOS, Release) and ran it. Your CTest suite passes and the Steinberg validator reports 47/47. On top of that I ran a few harsher host cases against the example models (A1 standard,
wavenet.nam,A2.nam, LSTM) at 48 and 44.1 kHz, each compared with the same input in short blocks:All 34 cases match. A2 and LSTM at 48 kHz are bit-identical; the A1 WaveNet differs by at most 3.2e-6 (with the EQ on), which is below the 3.5e-6 you get from simply changing the short block sizes with no splitting at all. Happy to turn the announce-256-send-4096 and A2-to-A1 cases into a test for
test_stereo_pluginif you'd like them.Given that, I'll close #340 and #348.
Two small things on the Core side, in case they're useful. Happy to send either as a PR, or leave them with you:
DSP::process()doesn't currently say thatnum_framesmust not exceed themaxBufferSizegiven toReset(). One line there would tell other Core users, like the custom JUCE wrapper in this issue, that splitting is their job.A2FastModel::process()callsSetMaxBufferSize(num_frames)when a call is too big (a2_fast.cpp#L735-L736); onmain, a submodel ofexample_models/A2.namreset for 64 frames comes out of a 128-frame call resized to 128. That allocates on the audio thread, and it hides a host bug with A2 models that then shows up with the next A1 model, which is close to what this issue describes. Under the contract above it could be the same assert as the generic WaveNet.@benediktadams, for your JUCE plugin this puts the fix on your side:
Reset()with a size you'll never exceed and split largerprocessBlockcalls into chunks of that size, as #690 does, orReset()again whenever the host announces a new maximum. If that clears the crackling, this issue can probably be closed.