Skip to content

Commit 540fd59

Browse files
authored
Update NeuralAmpModelerCore (#493)
* Update NeuralAmpModelerCore Remove finalize_() * Update NeuralAmpModelerCore * Format, update core * ResetAndPrewarm in ResamplingNAM
1 parent 83fa931 commit 540fd59

File tree

3 files changed

+2
-41
lines changed

3 files changed

+2
-41
lines changed

NeuralAmpModeler/NeuralAmpModeler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ void NeuralAmpModeler::ProcessBlock(iplug::sample** inputs, iplug::sample** outp
306306
// TODO multi-channel processing; Issue
307307
// Make sure it's multi-threaded or else this won't perform well!
308308
mModel->process(triggerOutput[0], mOutputPointers[0], nFrames);
309-
mModel->finalize_(nFrames);
310309
// Normalize loudness
311310
if (GetParam(kOutNorm)->Value())
312311
{

NeuralAmpModeler/NeuralAmpModeler.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class ResamplingNAM : public nam::DSP
9696
// Assign the encapsulated object's processing function to this object's member so that the resampler can use it:
9797
auto ProcessBlockFunc = [&](NAM_SAMPLE** input, NAM_SAMPLE** output, int numFrames) {
9898
mEncapsulated->process(input[0], output[0], numFrames);
99-
mEncapsulated->finalize_(numFrames);
10099
};
101100
mBlockProcessFunc = ProcessBlockFunc;
102101

@@ -120,40 +119,18 @@ class ResamplingNAM : public nam::DSP
120119

121120
void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames) override
122121
{
123-
if (!mFinalized)
124-
throw std::runtime_error("Processing was called before the last block was finalized!");
125122
if (num_frames > mMaxExternalBlockSize)
126123
// We can afford to be careful
127124
throw std::runtime_error("More frames were provided than the max expected!");
128125

129126
if (!NeedToResample())
130127
{
131128
mEncapsulated->process(input, output, num_frames);
132-
mEncapsulated->finalize_(num_frames);
133129
}
134130
else
135131
{
136132
mResampler.ProcessBlock(&input, &output, num_frames, mBlockProcessFunc);
137133
}
138-
139-
// Prepare for external call to .finalize_()
140-
lastNumExternalFramesProcessed = num_frames;
141-
mFinalized = false;
142-
};
143-
144-
void finalize_(const int num_frames) override
145-
{
146-
if (mFinalized)
147-
throw std::runtime_error("Call to ResamplingNAM.finalize_() when the object is already in a finalized state!");
148-
if (num_frames != lastNumExternalFramesProcessed)
149-
throw std::runtime_error(
150-
"finalize_() called on ResamplingNAM with a different number of frames from what was just processed. Something "
151-
"is probably going wrong.");
152-
153-
// We don't actually do anything--it was taken care of during BlockProcessFunc()!
154-
155-
// prepare for next call to `.process()`
156-
mFinalized = true;
157134
};
158135

159136
int GetLatency() const { return NeedToResample() ? mResampler.GetLatency() : 0; };
@@ -168,14 +145,7 @@ class ResamplingNAM : public nam::DSP
168145
// Stolen some code from the resampler; it'd be nice to have these exposed as methods? :)
169146
const double mUpRatio = sampleRate / GetEncapsulatedSampleRate();
170147
const auto maxEncapsulatedBlockSize = static_cast<int>(std::ceil(static_cast<double>(maxBlockSize) / mUpRatio));
171-
std::vector<NAM_SAMPLE> input, output;
172-
for (int i = 0; i < maxEncapsulatedBlockSize; i++)
173-
input.push_back((NAM_SAMPLE)0.0);
174-
output.resize(maxEncapsulatedBlockSize); // Doesn't matter what's in here
175-
mEncapsulated->process(input.data(), output.data(), maxEncapsulatedBlockSize);
176-
mEncapsulated->finalize_(maxEncapsulatedBlockSize);
177-
178-
mFinalized = true; // prepare for `.process()`
148+
mEncapsulated->ResetAndPrewarm(sampleRate, maxEncapsulatedBlockSize);
179149
};
180150

181151
// So that we can let the world know if we're resampling (useful for debugging)
@@ -185,20 +155,12 @@ class ResamplingNAM : public nam::DSP
185155
bool NeedToResample() const { return GetExpectedSampleRate() != GetEncapsulatedSampleRate(); };
186156
// The encapsulated NAM
187157
std::unique_ptr<nam::DSP> mEncapsulated;
188-
// The processing for NAM is a little weird--there's a call to .finalize_() that's expected.
189-
// This flag makes sure that the NAM sees alternating instances of .process() and .finalize_()
190-
// A value of `true` means that we expect the ResamplingNAM object to see .process() next;
191-
// `false` means we expect .finalize_() next.
192-
bool mFinalized = true;
193158

194159
// The resampling wrapper
195160
dsp::ResamplingContainer<NAM_SAMPLE, 1, 12> mResampler;
196161

197162
// Used to check that we don't get too large a block to process.
198163
int mMaxExternalBlockSize = 0;
199-
// Keep track of how many frames were processed so that we can be sure that finalize_() is being used correctly.
200-
// This is kind of hacky, but I'm not sure I want to rethink the core right now.
201-
int lastNumExternalFramesProcessed = -1;
202164

203165
// This function is defined to conform to the interface expected by the iPlug2 resampler.
204166
std::function<void(NAM_SAMPLE**, NAM_SAMPLE**, int)> mBlockProcessFunc;

0 commit comments

Comments
 (0)