Skip to content

Commit

Permalink
Add perf test for buchla lpg
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfault1602 committed Jan 18, 2024
1 parent 78df030 commit 3f3bf94
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ readability-*,\
-readability-named-parameter,\
-readability-identifier-length,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-modernize-use-auto
-modernize-use-auto,\
-modernize-loop-convert
"
1 change: 0 additions & 1 deletion include/buchla_lpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BuchlaLPG
float sd_ = 0.f;
float so_ = 0.f;
float yo_ = 0.f;
float xo_ = 0.f;

bool non_lin_ = false;
};
Expand Down
10 changes: 5 additions & 5 deletions src/buchla_lpg.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "buchla_lpg.h"

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -38,14 +39,13 @@ int8_t sign(float x)
{
return 1;
}
else if (x < 0)

if (x < 0)
{
return -1;
}
else
{
return 0;
}

return 0;
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions tests/perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FetchContent_MakeAvailable(nanobench doctest)

add_executable(perf_tests
perf_tests.cpp
buchla_lpg_perf.cpp
basicosc_perf.cpp
phaseshaper_perf.cpp)
target_include_directories(perf_tests PRIVATE ${doctest_SOURCE_DIR}/doctest)
Expand Down
59 changes: 59 additions & 0 deletions tests/perf/buchla_lpg_perf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "doctest.h"
#include "nanobench.h"
#include <chrono>
#include <memory>

#include "basic_oscillators.h"
#include "buchla_lpg.h"

using namespace ankerl;
using namespace std::chrono_literals;

constexpr size_t kSamplerate = 96000;
constexpr size_t kOutputSize = 960;

TEST_CASE("BuchlaLPG")
{
nanobench::Bench bench;
bench.title("Buchla LPG");
// bench.relative(true);
bench.timeUnit(1ms, "ms");
bench.performanceCounters(true);

sfdsp::BasicOscillator cv;
cv.Init(kSamplerate, 4, sfdsp::OscillatorType::Square);
cv.SetDuty(0.05f);
auto cv_out = std::make_unique<float[]>(kOutputSize);
cv.ProcessBlock(cv_out.get(), kOutputSize);

constexpr float kModDepth = 8.f;
for (size_t i = 0; i < kOutputSize; ++i)
{
cv_out[i] = kModDepth / 2.f * (1.f + cv_out[i]);
}

auto audio_buffer = std::make_unique<float[]>(kOutputSize);
sfdsp::BasicOscillator audio;
audio.Init(kSamplerate, 440, sfdsp::OscillatorType::Square);
audio.ProcessBlock(audio_buffer.get(), kOutputSize);

for (size_t i = 0; i < kOutputSize; ++i)
{
audio_buffer[i] = 0.3f * audio_buffer[i];
}

sfdsp::BuchlaLPG lpg;
lpg.Init(kSamplerate);

lpg.ProcessBlock(cv_out.get(), audio_buffer.get(), audio_buffer.get(), kOutputSize);

std::unique_ptr<float[]> audio_out = std::make_unique<float[]>(kOutputSize);
constexpr size_t kBlockSize = 128;

bench.run("Buchla LPG", [&]() {
for (size_t i = 0; i < kOutputSize; i += kBlockSize)
{
lpg.ProcessBlock(cv_out.get() + i, audio_buffer.get() + i, audio_out.get() + i, kBlockSize);
}
});
}

0 comments on commit 3f3bf94

Please sign in to comment.