sdatkinson / NeuralAmpModelerPlugin

Plugin for Neural Amp Modeler
MIT License
1.82k stars 118 forks source link

[BUG] Plugin crashes after about an hour when resampling #447

Closed nappies closed 2 months ago

nappies commented 3 months ago

The latest version of the plugin 0.7.8 vst 3 causes a clean installed Reaper to crash as in the screenshot below. The crash occurs exactly after an hour when resampling is turned on. The crash was tested on 3 different computers with different versions of Windows 10.

Steps to reproduce the behavior:

Install clean portable reaper latest version. Set Samplerate - 44100 Set Buffers - 8x 256 Make sure that the Project Sample Rate is 44100. In the audio settings, uncheck "close audio device when stopped and ...."

Load the Vst NAM plugin onto the track. Load profile with frequency 48000 so that the message Resampling to 48000 appears. Set the timer on your phone for exactly 1 hour. Watch the Reaper's Crash in an hour!!

Screenshot bug

Desktop :

bjarkihall commented 3 months ago

I get the same message ("Runtime Error! This application has requested the runtime to terminate it in an unusual way. Please contact the application's support team for more information.") on Windows 11, Reaper 7.11, NAM 0.7.8 VST3, Audio Interface Audiobox USB 96. Buffer size doesn't seem to matter and I'm not sure if it's exactly 1 hour or not but I hope it helps to confirm this is happening on others and it's not only bound to Win10. Let me know if I can provide further information.

sdatkinson commented 3 months ago

I've been able to reproduce the issue myself.

My guess was that the latency in the resamplers' latency is just a bit too close that floating-point rounding just barely puts it over and it needs one more sample than is available.

Adding an extra sample of buffer to both resamplers appears to have fixed it (been running for over an hour; gonna let it run for a while and see).

sdatkinson commented 3 months ago

Scratch that--just died 😅

I'll have to look closer.

sdatkinson commented 2 months ago

The root cause may be that the second resampler is unable to pop enough samples. The exception being thrown seems to be this one; I caught an exception in the debugger and see nFrames=128 but populated2=127.

This may be because of the floating-point arithmetic getting off after a while (an hour is 173M samples...maybe that's enough?); a solution may be to handle the phase calculation internally as a rational number. It's bad if it can't fill the needed output buffer, but a quick fix would be to fill any gap samples with the last sample--super-hacky, but at least it'll only be a 1-sample blip once every hour, which isn't the worst thing in the world.

So at least that's a quick fix and a better one that can get worked on in the meantime.

Made https://github.com/sdatkinson/AudioDSPTools/issues/13 for the fix in the library; this issue can get closed when a fix is in.

bjarkihall commented 2 months ago

Thanks, I can confirm that the issue has been fixed in version 0.7.9, it's been running all evening without any issues (window in foreground/background, even logging out for more than an hour and back in).