Added benchmarks and tests for width/pan
This commit is contained in:
parent
d74777280a
commit
90d680f0c3
4 changed files with 184 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "ScopedFTZ.h"
|
||||||
#include "absl/types/span.h"
|
#include "absl/types/span.h"
|
||||||
|
|
||||||
class PanArray : public benchmark::Fixture {
|
class PanArray : public benchmark::Fixture {
|
||||||
|
|
@ -47,6 +48,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) {
|
BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
for (auto _ : state)
|
for (auto _ : state)
|
||||||
{
|
{
|
||||||
sfz::pan<float, false>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
sfz::pan<float, false>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
||||||
|
|
@ -54,6 +56,7 @@ BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) {
|
BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
for (auto _ : state)
|
for (auto _ : state)
|
||||||
{
|
{
|
||||||
sfz::pan<float, true>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
sfz::pan<float, true>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
||||||
|
|
@ -61,6 +64,7 @@ BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK_DEFINE_F(PanArray, BlockOps)(benchmark::State& state) {
|
BENCHMARK_DEFINE_F(PanArray, BlockOps)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
for (auto _ : state)
|
for (auto _ : state)
|
||||||
{
|
{
|
||||||
sfz::fill<float>(span2, 1.0f);
|
sfz::fill<float>(span2, 1.0f);
|
||||||
|
|
|
||||||
120
benchmarks/BM_widthPos.cpp
Normal file
120
benchmarks/BM_widthPos.cpp
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||||
|
// license. You should have receive a LICENSE.md file along with the code.
|
||||||
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
|
#include "SIMDHelpers.h"
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <random>
|
||||||
|
#include <numeric>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include "Config.h"
|
||||||
|
#include "ScopedFTZ.h"
|
||||||
|
#include "absl/types/span.h"
|
||||||
|
|
||||||
|
class WidthPosArray : public benchmark::Fixture {
|
||||||
|
public:
|
||||||
|
void SetUp(const ::benchmark::State& state) {
|
||||||
|
std::random_device rd { };
|
||||||
|
std::mt19937 gen { rd() };
|
||||||
|
std::uniform_real_distribution<float> dist { 0.001f, 1.0f };
|
||||||
|
width = std::vector<float>(state.range(0));
|
||||||
|
position = std::vector<float>(state.range(0));
|
||||||
|
left = std::vector<float>(state.range(0));
|
||||||
|
right = std::vector<float>(state.range(0));
|
||||||
|
std::generate(width.begin(), width.end(), [&]() { return dist(gen); });
|
||||||
|
std::generate(position.begin(), position.end(), [&]() { return dist(gen); });
|
||||||
|
std::generate(right.begin(), right.end(), [&]() { return dist(gen); });
|
||||||
|
std::generate(left.begin(), left.end(), [&]() { return dist(gen); });
|
||||||
|
temp1 = std::vector<float>(state.range(0));
|
||||||
|
temp2 = std::vector<float>(state.range(0));
|
||||||
|
temp3 = std::vector<float>(state.range(0));
|
||||||
|
span1 = absl::MakeSpan(temp1);
|
||||||
|
span2 = absl::MakeSpan(temp2);
|
||||||
|
span3 = absl::MakeSpan(temp3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> width;
|
||||||
|
std::vector<float> position;
|
||||||
|
std::vector<float> left;
|
||||||
|
std::vector<float> right;
|
||||||
|
std::vector<float> temp1;
|
||||||
|
std::vector<float> temp2;
|
||||||
|
std::vector<float> temp3;
|
||||||
|
absl::Span<float> span1;
|
||||||
|
absl::Span<float> span2;
|
||||||
|
absl::Span<float> span3;
|
||||||
|
};
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(WidthPosArray, Scalar)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
auto widthPtr = width.data();
|
||||||
|
auto posPtr = position.data();
|
||||||
|
auto leftPtr = left.data();
|
||||||
|
auto rightPtr = right.data();
|
||||||
|
const auto sentinel = width.data() + width.size();
|
||||||
|
while(widthPtr < sentinel)
|
||||||
|
{
|
||||||
|
auto mid = (*leftPtr + *rightPtr) * sqrtTwoInv<float>;
|
||||||
|
auto side = (*leftPtr - *rightPtr) * sqrtTwoInv<float>;
|
||||||
|
sfz::_internals::snippetWidth(*widthPtr, mid, side);
|
||||||
|
auto midRight = mid;
|
||||||
|
sfz::_internals::snippetPan(*posPtr, mid, midRight);
|
||||||
|
*leftPtr = (mid + side) * sqrtTwoInv<float>;
|
||||||
|
*rightPtr = (midRight - side) * sqrtTwoInv<float>;
|
||||||
|
incrementAll(leftPtr, rightPtr, widthPtr, posPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(WidthPosArray, BlockOps)(benchmark::State& state) {
|
||||||
|
ScopedFTZ ftz;
|
||||||
|
const auto leftBuffer = absl::MakeSpan(left);
|
||||||
|
const auto rightBuffer = absl::MakeSpan(right);
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
const auto leftBufferCopy = span2;
|
||||||
|
sfz::copy<float>(left, leftBufferCopy);
|
||||||
|
|
||||||
|
const auto midBuffer = leftBuffer;
|
||||||
|
sfz::add<float>(rightBuffer, midBuffer);
|
||||||
|
|
||||||
|
const auto sideBuffer = rightBuffer;
|
||||||
|
sfz::applyGain<float>(-1.0f, sideBuffer);
|
||||||
|
sfz::add<float>(leftBufferCopy, sideBuffer);
|
||||||
|
|
||||||
|
sfz::applyGain<float>(sqrtTwoInv<float>, midBuffer);
|
||||||
|
sfz::applyGain<float>(sqrtTwoInv<float>, sideBuffer);
|
||||||
|
|
||||||
|
// Apply the width process
|
||||||
|
sfz::width<float>(width, midBuffer, sideBuffer);
|
||||||
|
|
||||||
|
// Copy the mid channel into another span
|
||||||
|
const auto midBufferCopy = span3;
|
||||||
|
sfz::copy<float>(midBuffer, midBufferCopy);
|
||||||
|
sfz::pan<float>(position, midBuffer, midBufferCopy);
|
||||||
|
|
||||||
|
// Rebuild left/right
|
||||||
|
// Recall that midBuffer and leftBuffer point to the same buffer
|
||||||
|
sfz::add<float>(sideBuffer, leftBuffer);
|
||||||
|
sfz::applyGain(sqrtTwoInv<float>, leftBuffer);
|
||||||
|
|
||||||
|
// Recall that sideBuffer and rightBuffer point to the same buffer
|
||||||
|
sfz::applyGain<float>(-1.0f, sideBuffer);
|
||||||
|
sfz::add<float>(midBufferCopy, sideBuffer);
|
||||||
|
sfz::applyGain(sqrtTwoInv<float>, rightBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_REGISTER_F(WidthPosArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
|
||||||
|
BENCHMARK_REGISTER_F(WidthPosArray, BlockOps)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
|
||||||
|
BENCHMARK_MAIN();
|
||||||
|
|
@ -51,6 +51,7 @@ sfizz_add_benchmark(bm_mean BM_mean.cpp)
|
||||||
sfizz_add_benchmark(bm_meanSquared BM_meanSquared.cpp)
|
sfizz_add_benchmark(bm_meanSquared BM_meanSquared.cpp)
|
||||||
sfizz_add_benchmark(bm_cumsum BM_cumsum.cpp)
|
sfizz_add_benchmark(bm_cumsum BM_cumsum.cpp)
|
||||||
sfizz_add_benchmark(bm_diff BM_diff.cpp)
|
sfizz_add_benchmark(bm_diff BM_diff.cpp)
|
||||||
|
sfizz_add_benchmark(bm_widthPos BM_widthPos.cpp)
|
||||||
sfizz_add_benchmark(bm_interpolationCast BM_interpolationCast.cpp)
|
sfizz_add_benchmark(bm_interpolationCast BM_interpolationCast.cpp)
|
||||||
sfizz_add_benchmark(bm_pointerIterationOrOffsets BM_pointerIterationOrOffsets.cpp)
|
sfizz_add_benchmark(bm_pointerIterationOrOffsets BM_pointerIterationOrOffsets.cpp)
|
||||||
|
|
||||||
|
|
@ -106,6 +107,7 @@ add_dependencies(sfizz_benchmarks
|
||||||
bm_resampleChunk
|
bm_resampleChunk
|
||||||
bm_envelopes
|
bm_envelopes
|
||||||
bm_wavfile
|
bm_wavfile
|
||||||
|
bm_widthPos
|
||||||
bm_flacfile
|
bm_flacfile
|
||||||
bm_filterModulation
|
bm_filterModulation
|
||||||
bm_filterStereoMono
|
bm_filterStereoMono
|
||||||
|
|
|
||||||
|
|
@ -756,3 +756,61 @@ TEST_CASE("[Helpers] Diff (SIMD vs Scalar)")
|
||||||
sfz::diff<float, true>(input, absl::MakeSpan(outputSIMD));
|
sfz::diff<float, true>(input, absl::MakeSpan(outputSIMD));
|
||||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Helpers] Pan Scalar")
|
||||||
|
{
|
||||||
|
std::array<float, 1> leftValue { 1.0f };
|
||||||
|
std::array<float, 1> rightValue { 1.0f };
|
||||||
|
auto left = absl::MakeSpan(leftValue);
|
||||||
|
auto right = absl::MakeSpan(rightValue);
|
||||||
|
SECTION("Pan = 0")
|
||||||
|
{
|
||||||
|
std::array<float, 1> pan { 0.0f };
|
||||||
|
sfz::pan<float, false>(pan, left, right);
|
||||||
|
REQUIRE(left[0] == Approx(0.70711f).margin(0.001f));
|
||||||
|
REQUIRE(right[0] == Approx(0.70711f).margin(0.001f));
|
||||||
|
}
|
||||||
|
SECTION("Pan = 1")
|
||||||
|
{
|
||||||
|
std::array<float, 1> pan { 1.0f };
|
||||||
|
sfz::pan<float, false>(pan, left, right);
|
||||||
|
REQUIRE(left[0] == Approx(0.0f).margin(0.001f));
|
||||||
|
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
||||||
|
}
|
||||||
|
SECTION("Pan = -1")
|
||||||
|
{
|
||||||
|
std::array<float, 1> pan { -1.0f };
|
||||||
|
sfz::pan<float, false>(pan, left, right);
|
||||||
|
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
||||||
|
REQUIRE(right[0] == Approx(0.0f).margin(0.001f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Helpers] Width Scalar")
|
||||||
|
{
|
||||||
|
std::array<float, 1> midValue { 1.0f };
|
||||||
|
std::array<float, 1> sideValue { 1.0f };
|
||||||
|
auto mid = absl::MakeSpan(midValue);
|
||||||
|
auto side = absl::MakeSpan(sideValue);
|
||||||
|
SECTION("width = 1")
|
||||||
|
{
|
||||||
|
std::array<float, 1> width { 1.0f };
|
||||||
|
sfz::width<float, false>(width, mid, side);
|
||||||
|
REQUIRE(mid[0] == Approx(0.70711f).margin(0.001f));
|
||||||
|
REQUIRE(side[0] == Approx(0.70711f).margin(0.001f));
|
||||||
|
}
|
||||||
|
SECTION("width = 0")
|
||||||
|
{
|
||||||
|
std::array<float, 1> width { 0.0f };
|
||||||
|
sfz::width<float, false>(width, mid, side);
|
||||||
|
REQUIRE(mid[0] == Approx(1.0f).margin(0.001f));
|
||||||
|
REQUIRE(side[0] == Approx(0.0f).margin(0.001f));
|
||||||
|
}
|
||||||
|
SECTION("width = -1")
|
||||||
|
{
|
||||||
|
std::array<float, 1> width { -1.0f };
|
||||||
|
sfz::width<float, false>(width, mid, side);
|
||||||
|
REQUIRE(mid[0] == Approx(0.70711f).margin(0.001f));
|
||||||
|
REQUIRE(side[0] == Approx(-0.70711f).margin(0.001f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue