commit 4174e3d6eb35b84705ad7e7165208be359686bc4
parent 3374247b61319135b059d3b3336798ec00e68018
Author: Steven Atkinson <steven@atkinson.mn>
Date: Fri, 28 Jul 2023 22:17:16 -0700
Resample IR if sample rate changes (#352)
* Resample IR if sample rate changes
* Resample IR if sample rate changes
Diffstat:
2 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp
@@ -371,6 +371,8 @@ void NeuralAmpModeler::OnReset()
mInputSender.Reset(sampleRate);
mOutputSender.Reset(sampleRate);
mCheckSampleRateWarning = true;
+ // If there is a model or IR loaded, they need to be checked for resampling.
+ _ResampleModelAndIR();
}
void NeuralAmpModeler::OnIdle()
@@ -494,20 +496,6 @@ void NeuralAmpModeler::_AllocateIOPointers(const size_t nChans)
void NeuralAmpModeler::_ApplyDSPStaging()
{
- // Move things from staged to live
- if (mStagedModel != nullptr)
- {
- // Move from staged to active DSP
- mModel = std::move(mStagedModel);
- mStagedModel = nullptr;
- mNewModelLoadedInDSP = true;
- mCheckSampleRateWarning = true;
- }
- if (mStagedIR != nullptr)
- {
- mIR = std::move(mStagedIR);
- mStagedIR = nullptr;
- }
// Remove marked modules
if (mShouldRemoveModel)
{
@@ -522,6 +510,20 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mIRPath.Set("");
mShouldRemoveIR = false;
}
+ // Move things from staged to live
+ if (mStagedModel != nullptr)
+ {
+ // Move from staged to active DSP
+ mModel = std::move(mStagedModel);
+ mStagedModel = nullptr;
+ mNewModelLoadedInDSP = true;
+ mCheckSampleRateWarning = true;
+ }
+ if (mStagedIR != nullptr)
+ {
+ mIR = std::move(mStagedIR);
+ mStagedIR = nullptr;
+ }
}
void NeuralAmpModeler::_CheckSampleRateWarning()
@@ -570,6 +572,29 @@ void NeuralAmpModeler::_FallbackDSP(iplug::sample** inputs, iplug::sample** outp
mOutputArray[c][s] = mInputArray[c][s];
}
+void NeuralAmpModeler::_ResampleModelAndIR()
+{
+ const auto sampleRate = GetSampleRate();
+ // Model
+ // TODO
+
+ // IR
+ if (mStagedIR != nullptr) {
+ const double irSampleRate = mStagedIR->GetSampleRate();
+ if (irSampleRate != sampleRate) {
+ const auto irData = mStagedIR->GetData();
+ mStagedIR = std::make_unique<dsp::ImpulseResponse>(irData, sampleRate);
+ }
+ }
+ else if (mIR != nullptr) {
+ const double irSampleRate = mIR->GetSampleRate();
+ if (irSampleRate != sampleRate) {
+ const auto irData = mIR->GetData();
+ mStagedIR = std::make_unique<dsp::ImpulseResponse>(irData, sampleRate);
+ }
+ }
+}
+
std::string NeuralAmpModeler::_StageModel(const WDL_String& modelPath)
{
WDL_String previousNAMPath = mNAMPath;
diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h
@@ -126,6 +126,8 @@ private:
// :param nChansOut: Out to external
void _ProcessOutput(iplug::sample** inputs, iplug::sample** outputs, const size_t nFrames, const size_t nChansIn,
const size_t nChansOut);
+ // Checks the loaded model and IR against the current sample rate and resamples them if needed
+ void _ResampleModelAndIR();
// Update level meters
// Called within ProcessBlock().