Skip to content

Commit 824df5c

Browse files
authored
Display a warning if host sample rate isn't correct for the NAM model (#331)
* Put in sample rate warning control (always on right now) * Adjust wording * Toggle disable state based on sample rate and model (hard-coded for now to 48k) * Remove warning if there's no model loaded * Check when UI open
1 parent cb01320 commit 824df5c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

NeuralAmpModeler/NeuralAmpModeler.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
148148

149149
// Misc Areas
150150
const auto helpButtonArea = mainArea.GetFromTRHC(50, 50).GetCentredInside(20, 20);
151+
const auto sampleRateWarningArea = inputMeterArea.GetFromBottom(16.f).GetTranslated(12.f, 16.f).GetFromLeft(300.f);
151152

152153
// Model loader button
153154
auto loadModelCompletionHandler = [&](const WDL_String& fileName, const WDL_String& path) {
@@ -224,6 +225,9 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
224225
pGraphics->AttachControl(new NAMMeterControl(inputMeterArea, meterBackgroundBitmap, style), kCtrlTagInputMeter);
225226
pGraphics->AttachControl(new NAMMeterControl(outputMeterArea, meterBackgroundBitmap, style), kCtrlTagOutputMeter);
226227

228+
// A warning when NAM isn't being run in the right sample rate:
229+
pGraphics->AttachControl(new NAMSampleRateWarningControl(sampleRateWarningArea), kCtrlTagSampleRateWarning);
230+
227231
// Help/about box
228232
pGraphics->AttachControl(new NAMCircleButtonControl(
229233
helpButtonArea,
@@ -355,6 +359,7 @@ void NeuralAmpModeler::OnReset()
355359
const auto sampleRate = GetSampleRate();
356360
mInputSender.Reset(sampleRate);
357361
mOutputSender.Reset(sampleRate);
362+
mCheckSampleRateWarning = true;
358363
}
359364

360365
void NeuralAmpModeler::OnIdle()
@@ -369,6 +374,10 @@ void NeuralAmpModeler::OnIdle()
369374

370375
mNewModelLoadedInDSP = false;
371376
}
377+
if (mCheckSampleRateWarning)
378+
{
379+
_CheckSampleRateWarning();
380+
}
372381
}
373382

374383
bool NeuralAmpModeler::SerializeState(IByteChunk& chunk) const
@@ -403,6 +412,7 @@ void NeuralAmpModeler::OnUIOpen()
403412
SendControlMsgFromDelegate(kCtrlTagIRFileBrowser, kMsgTagLoadedIR, mIRPath.GetLength(), mIRPath.Get());
404413
if (mModel != nullptr)
405414
GetUI()->GetControlWithTag(kCtrlTagOutNorm)->SetDisabled(!mModel->HasLoudness());
415+
mCheckSampleRateWarning = true;
406416
}
407417

408418
void NeuralAmpModeler::OnParamChangeUI(int paramIdx, EParamSource source)
@@ -480,6 +490,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
480490
mModel = std::move(mStagedModel);
481491
mStagedModel = nullptr;
482492
mNewModelLoadedInDSP = true;
493+
mCheckSampleRateWarning = true;
483494
}
484495
if (mStagedIR != nullptr)
485496
{
@@ -492,6 +503,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
492503
mModel = nullptr;
493504
mNAMPath.Set("");
494505
mShouldRemoveModel = false;
506+
mCheckSampleRateWarning = true;
495507
}
496508
if (mShouldRemoveIR)
497509
{
@@ -501,6 +513,22 @@ void NeuralAmpModeler::_ApplyDSPStaging()
501513
}
502514
}
503515

516+
void NeuralAmpModeler::_CheckSampleRateWarning()
517+
{
518+
if (auto* pGraphics = GetUI())
519+
{
520+
bool showWarning = false;
521+
if (_HaveModel())
522+
{
523+
const auto pluginSampleRate = GetSampleRate();
524+
const double namSampleRate = 48000.0; // TODO from model
525+
showWarning = pluginSampleRate != namSampleRate;
526+
}
527+
pGraphics->GetControlWithTag(kCtrlTagSampleRateWarning)->SetDisabled(!showWarning);
528+
mCheckSampleRateWarning = false;
529+
}
530+
}
531+
504532
void NeuralAmpModeler::_DeallocateIOPointers()
505533
{
506534
if (mInputPointers != nullptr)

NeuralAmpModeler/NeuralAmpModeler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum ECtrlTags
5151
kCtrlTagOutputMeter,
5252
kCtrlTagAboutBox,
5353
kCtrlTagOutNorm,
54+
kCtrlTagSampleRateWarning,
5455
kNumCtrlTags
5556
};
5657

@@ -94,6 +95,9 @@ class NeuralAmpModeler final : public iplug::Plugin
9495
// partially-instantiated.
9596
void _ApplyDSPStaging();
9697
// Deallocates mInputPointers and mOutputPointers
98+
// Check whether the sample rate is correct for the NAM model.
99+
// Adjust the warning control accordingly.
100+
void _CheckSampleRateWarning();
97101
void _DeallocateIOPointers();
98102
// Fallback that just copies inputs to outputs if mDSP doesn't hold a model.
99103
void _FallbackDSP(iplug::sample** inputs, iplug::sample** outputs, const size_t numChannels, const size_t numFrames);
@@ -154,6 +158,8 @@ class NeuralAmpModeler final : public iplug::Plugin
154158
std::atomic<bool> mShouldRemoveIR = false;
155159

156160
std::atomic<bool> mNewModelLoadedInDSP = false;
161+
// Flag to check whether the playback sample rate is correct for the model being used.
162+
std::atomic<bool> mCheckSampleRateWarning = true;
157163

158164
// Tone stack modules
159165
recursive_linear_filter::LowShelf mToneBass;

NeuralAmpModeler/NeuralAmpModelerControls.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,29 @@ class NAMMeterControl : public IVPeakAvgMeterControl<>, public IBitmapBase
430430
}
431431
};
432432

433+
const IText _WARNING_TEXT(DEFAULT_TEXT_SIZE + 3.f, COLOR_RED, "Roboto-Regular", EAlign::Near);
434+
435+
class NAMSampleRateWarningControl : public ITextControl
436+
{
437+
public:
438+
NAMSampleRateWarningControl(const IRECT& bounds)
439+
: ITextControl(bounds, "WARNING: Run NAM at sample rate 48kHz!", _WARNING_TEXT)
440+
{
441+
}
442+
void SetDisabled(bool disable) override
443+
{
444+
{
445+
mBlend.mWeight = (disable ? mDisabledBlend : mEnabledBlend);
446+
mDisabled = disable;
447+
SetDirty(false);
448+
}
449+
}
450+
451+
protected:
452+
float mDisabledBlend = 0.0f; // when this is disabled, it's completely gone.
453+
float mEnabledBlend = 1.0f; // Like normal
454+
};
455+
433456
class NAMAboutBoxControl : public IContainerBase
434457
{
435458
public:

0 commit comments

Comments
 (0)