[FEATURE] Options to disable prewarming during .Reset()#285
Conversation
…AmpModelerCore into 270-no-prewarm
|
I've got this wired up in NeuralAmpModelerPlugin and have verified that I'm not visiting the prewarm routine more than once when changing models, regardless of whether the slim knob is set to 0 or 1. So I'm feeling pretty good about this as a solution. Code coming later in NeuralAmpModelerPlugin to demonstrate, but it's basically a no-prewarm context in |
|
Here's the method: std::string NeuralAmpModeler::_StageModel(const WDL_String& modelPath)
{
WDL_String previousNAMPath = mNAMPath;
try
{
auto dspPath = std::filesystem::u8path(modelPath.Get());
std::unique_ptr<ResamplingNAM> temp = nullptr;
{
nam::ScopedPrewarmOnResetDefault scoped_prewarm_default(false);
std::unique_ptr<nam::DSP> model = nam::get_dsp(dspPath);
// Check that the model has 1 input and 1 output channel
if (model->NumInputChannels() != 1)
{
throw std::runtime_error("Model must have 1 input channel, but has "
+ std::to_string(model->NumInputChannels()));
}
if (model->NumOutputChannels() != 1)
{
throw std::runtime_error("Model must have 1 output channel, but has "
+ std::to_string(model->NumOutputChannels()));
}
temp = std::make_unique<ResamplingNAM>(std::move(model), GetSampleRate());
if (nam::SlimmableModel* slimmable = temp->GetSlimmableModel())
{
slimmable->SetSlimmableSize(GetParam(kSlim)->Value());
}
}
temp->SetPrewarmOnReset(true);
temp->Reset(GetSampleRate(), GetBlockSize());
mStagedModel = std::move(temp);
mNAMPath = modelPath;
SendControlMsgFromDelegate(kCtrlTagModelFileBrowser, kMsgTagLoadedModel, mNAMPath.GetLength(), mNAMPath.Get());
}
catch (std::runtime_error& e)
{
SendControlMsgFromDelegate(kCtrlTagModelFileBrowser, kMsgTagLoadFailed);
if (mStagedModel != nullptr)
{
mStagedModel = nullptr;
}
mNAMPath = previousNAMPath;
std::cerr << "Failed to read DSP module" << std::endl;
std::cerr << e.what() << std::endl;
return e.what();
}
return "";
} |
|
cc @mikeoliphant if you want to have a look before I merge this. |
|
So a thread-local flag? Seems like that should be enough to prevent the possibility of inter-plugin crosstalk. |
Description
Resolves #270
DSP::SetPrewarmOnReset()to toggle whether reset triggers prewarming. Default to true to avoid mistakes; folks can usefalseto optimize their code (with care!).ScopedPrewarmOnResetDefaultallows setting a context default before constructing DSP instances in case they call Reset internally during their constructor.gPrewarmOnResetDefaultis used to determine whether DSP instances prewarm on reset.Checklist