Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient pre-warming using multiple-sample buffers #112

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions NAM/dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ void nam::DSP::prewarm()
if (prewarmSamples == 0)
return;

NAM_SAMPLE sample = 0;
NAM_SAMPLE* sample_ptr = &sample;
const size_t bufferSize = std::max(mMaxBufferSize, 1);
std::vector<NAM_SAMPLE> inputBuffer, outputBuffer;
inputBuffer.resize(bufferSize);
outputBuffer.resize(bufferSize);
for (auto it = inputBuffer.begin(); it != inputBuffer.end(); ++it)
{
(*it) = (NAM_SAMPLE)0.0;
}

// pre-warm the model for a model-specific number of samples
for (long i = 0; i < prewarmSamples; i++)
NAM_SAMPLE* inputPtr = inputBuffer.data();
NAM_SAMPLE* outputPtr = outputBuffer.data();
int samplesProcessed = 0;
while (samplesProcessed < prewarmSamples)
{
this->process(sample_ptr, sample_ptr, 1);
sample = 0;
this->process(inputPtr, outputPtr, bufferSize);
samplesProcessed += bufferSize;
}
}

Expand Down
8 changes: 4 additions & 4 deletions tools/benchmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ int main(int argc, char* argv[])
exit(1);
}

auto t1 = high_resolution_clock::now();

size_t bufferSize = AUDIO_BUFFER_SIZE;
model->Reset(model->GetExpectedSampleRate(), bufferSize);
Expand All @@ -49,17 +48,18 @@ int main(int argc, char* argv[])
{
inputBuffer[i] = 0.0;
}
// Run once outside to trigger any pre-allocation
model->process(inputBuffer, outputBuffer, AUDIO_BUFFER_SIZE);

std::cout << "Running benchmark\n";

auto t1 = high_resolution_clock::now();
for (size_t i = 0; i < numBuffers; i++)
{
model->process(inputBuffer, outputBuffer, AUDIO_BUFFER_SIZE);
}

auto t2 = high_resolution_clock::now();
std::cout << "Finished\n";

auto t2 = high_resolution_clock::now();

/* Getting number of milliseconds as an integer. */
auto ms_int = duration_cast<milliseconds>(t2 - t1);
Expand Down
Loading