From cebf9060e1195d6888099e2566932725e6c1f548 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 31 May 2020 10:31:03 +0200 Subject: [PATCH] Move panning into its own file and outside of SIMD --- benchmarks/BM_pan.cpp | 68 ---------------------- benchmarks/BM_widthPos.cpp | 80 -------------------------- benchmarks/CMakeLists.txt | 2 - dpf.mk | 1 + scripts/run_clang_tidy.sh | 1 + src/CMakeLists.txt | 1 + src/sfizz/MathHelpers.h | 1 + src/sfizz/Panning.cpp | 58 +++++++++++++++++++ src/sfizz/Panning.h | 47 ++++++++++++++++ src/sfizz/SIMDHelpers.h | 109 ------------------------------------ src/sfizz/SIMDSSE.cpp | 79 -------------------------- src/sfizz/SfzHelpers.cpp | 14 +++-- src/sfizz/Voice.cpp | 9 +-- src/sfizz/effects/Width.cpp | 6 +- tests/DemoStereo.cpp | 6 +- tests/SIMDHelpersT.cpp | 13 +++-- 16 files changed, 136 insertions(+), 359 deletions(-) delete mode 100644 benchmarks/BM_pan.cpp delete mode 100644 benchmarks/BM_widthPos.cpp create mode 100644 src/sfizz/Panning.cpp create mode 100644 src/sfizz/Panning.h diff --git a/benchmarks/BM_pan.cpp b/benchmarks/BM_pan.cpp deleted file mode 100644 index e08b447e..00000000 --- a/benchmarks/BM_pan.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include "Config.h" -#include "ScopedFTZ.h" -#include "absl/types/span.h" - -class PanArray : public benchmark::Fixture { -public: - void SetUp(const ::benchmark::State& state) { - std::random_device rd { }; - std::mt19937 gen { rd() }; - std::uniform_real_distribution dist { 0.001f, 1.0f }; - pan = std::vector(state.range(0)); - left = std::vector(state.range(0)); - right = std::vector(state.range(0)); - std::generate(pan.begin(), pan.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(state.range(0)); - temp2 = std::vector(state.range(0)); - span1 = absl::MakeSpan(temp1); - span2 = absl::MakeSpan(temp2); - } - - void TearDown(const ::benchmark::State& /* state */) { - - } - - std::vector pan; - std::vector left; - std::vector right; - std::vector temp1; - std::vector temp2; - absl::Span span1; - absl::Span span2; -}; - - -BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) { - ScopedFTZ ftz; - for (auto _ : state) - { - sfz::pan(pan, absl::MakeSpan(left), absl::MakeSpan(right)); - } -} - -BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) { - ScopedFTZ ftz; - for (auto _ : state) - { - sfz::pan(pan, absl::MakeSpan(left), absl::MakeSpan(right)); - } -} - -BENCHMARK_REGISTER_F(PanArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 12); -BENCHMARK_REGISTER_F(PanArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12); -BENCHMARK_MAIN(); diff --git a/benchmarks/BM_widthPos.cpp b/benchmarks/BM_widthPos.cpp deleted file mode 100644 index 1ab9fa7d..00000000 --- a/benchmarks/BM_widthPos.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#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 dist { 0.001f, 1.0f }; - width = std::vector(state.range(0)); - position = std::vector(state.range(0)); - left = std::vector(state.range(0)); - right = std::vector(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(state.range(0)); - temp2 = std::vector(state.range(0)); - temp3 = std::vector(state.range(0)); - span1 = absl::MakeSpan(temp1); - span2 = absl::MakeSpan(temp2); - span3 = absl::MakeSpan(temp3); - } - - void TearDown(const ::benchmark::State& /* state */) { - - } - - std::vector width; - std::vector position; - std::vector left; - std::vector right; - std::vector temp1; - std::vector temp2; - std::vector temp3; - absl::Span span1; - absl::Span span2; - absl::Span span3; -}; - -BENCHMARK_DEFINE_F(WidthPosArray, Scalar)(benchmark::State& state) { - ScopedFTZ ftz; - const auto leftBuffer = absl::MakeSpan(left); - const auto rightBuffer = absl::MakeSpan(right); - for (auto _ : state) - { - sfz::width(width, leftBuffer, rightBuffer); - sfz::pan(position, leftBuffer, rightBuffer); - } -} - -BENCHMARK_DEFINE_F(WidthPosArray, SIMD)(benchmark::State& state) { - ScopedFTZ ftz; - const auto leftBuffer = absl::MakeSpan(left); - const auto rightBuffer = absl::MakeSpan(right); - for (auto _ : state) - { - sfz::width(width, leftBuffer, rightBuffer); - sfz::pan(position, leftBuffer, rightBuffer); - } -} - -BENCHMARK_REGISTER_F(WidthPosArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 12); -BENCHMARK_REGISTER_F(WidthPosArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12); -BENCHMARK_MAIN(); diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 0fa42459..0e44d964 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -50,12 +50,10 @@ sfizz_add_benchmark(bm_multiplyAdd BM_multiplyAdd.cpp) sfizz_add_benchmark(bm_multiplyAddFixedGain BM_multiplyAddFixedGain.cpp) sfizz_add_benchmark(bm_subtract BM_subtract.cpp) sfizz_add_benchmark(bm_copy BM_copy.cpp) -sfizz_add_benchmark(bm_pan BM_pan.cpp) sfizz_add_benchmark(bm_mean BM_mean.cpp) sfizz_add_benchmark(bm_meanSquared BM_meanSquared.cpp) sfizz_add_benchmark(bm_cumsum BM_cumsum.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_pointerIterationOrOffsets BM_pointerIterationOrOffsets.cpp) sfizz_add_benchmark(bm_maps BM_maps.cpp) diff --git a/dpf.mk b/dpf.mk index c02c2f0e..a2734283 100644 --- a/dpf.mk +++ b/dpf.mk @@ -85,6 +85,7 @@ SFIZZ_SOURCES = \ src/sfizz/OpcodeCleanup.cpp \ src/sfizz/Opcode.cpp \ src/sfizz/Oversampler.cpp \ + src/sfizz/Panning.cpp \ src/sfizz/Parser.cpp \ src/sfizz/parser/Parser.cpp \ src/sfizz/parser/ParserPrivate.cpp \ diff --git a/scripts/run_clang_tidy.sh b/scripts/run_clang_tidy.sh index a58587b8..6c1f6f8a 100755 --- a/scripts/run_clang_tidy.sh +++ b/scripts/run_clang_tidy.sh @@ -13,6 +13,7 @@ clang-tidy \ src/sfizz/Opcode.cpp \ src/sfizz/Oversampler.cpp \ src/sfizz/Parser.cpp \ + src/sfizz/Panning.cpp \ src/sfizz/sfizz.cpp \ src/sfizz/Region.cpp \ src/sfizz/SfzHelpers.cpp \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0307417f..a75f96db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ set (SFIZZ_SOURCES sfizz/Wavetables.cpp sfizz/Tuning.cpp sfizz/RTSemaphore.cpp + sfizz/Panning.cpp sfizz/Effects.cpp sfizz/effects/Nothing.cpp sfizz/effects/Filter.cpp diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index 3bb10f67..cf30c79a 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -9,6 +9,7 @@ * @brief Contains math helper functions and math constants */ #pragma once +#include "Debug.h" #include "Config.h" #include "Macros.h" #include "SIMDConfig.h" diff --git a/src/sfizz/Panning.cpp b/src/sfizz/Panning.cpp new file mode 100644 index 00000000..bdafebd8 --- /dev/null +++ b/src/sfizz/Panning.cpp @@ -0,0 +1,58 @@ +#include "Panning.h" +#include + +namespace sfz +{ +// Number of elements in the table, odd for equal volume at center +constexpr int panSize = 4095; + +// Table of pan values for the left channel, extra element for safety +static const auto panData = []() +{ + std::array pan; + int i = 0; + + for (; i < panSize; ++i) + pan[i] = std::cos(i * (piTwo() / (panSize - 1))); + + for (; i < static_cast(pan.size()); ++i) + pan[i] = pan[panSize - 1]; + + return pan; +}(); + +float panLookup(float pan) +{ + // reduce range, round to nearest + int index = static_cast(0.5f + pan * (panSize - 1)); + return panData[index]; +} + +void pan(const float* panEnvelope, float* leftBuffer, float* rightBuffer, unsigned size) noexcept +{ + const auto sentinel = panEnvelope + size; + while (panEnvelope < sentinel) { + auto p =(*panEnvelope + 1.0f) * 0.5f; + p = clamp(p, 0.0f, 1.0f); + *leftBuffer *= panLookup(p); + *rightBuffer *= panLookup(1 - p); + incrementAll(panEnvelope, leftBuffer, rightBuffer); + } +} + +void width(const float* widthEnvelope, float* leftBuffer, float* rightBuffer, unsigned size) noexcept +{ + const auto sentinel = widthEnvelope + size; + while (widthEnvelope < sentinel) { + float w = (*widthEnvelope + 1.0f) * 0.5f; + w = clamp(w, 0.0f, 1.0f); + const auto coeff1 = panLookup(w); + const auto coeff2 = panLookup(1 - w); + const auto l = *leftBuffer; + const auto r = *rightBuffer; + *leftBuffer = l * coeff2 + r * coeff1; + *rightBuffer = l * coeff1 + r * coeff2; + incrementAll(widthEnvelope, leftBuffer, rightBuffer); + } +} +} diff --git a/src/sfizz/Panning.h b/src/sfizz/Panning.h new file mode 100644 index 00000000..75d31ea4 --- /dev/null +++ b/src/sfizz/Panning.h @@ -0,0 +1,47 @@ +#pragma once +#include "absl/types/span.h" +#include "MathHelpers.h" + +namespace sfz +{ + +/** + * @brief Lookup a value from the pan table + * + * @param pan + * @return float + */ +float panLookup(float pan); + +/** + * @brief Pans a mono signal left or right + * + * @param panEnvelope + * @param leftBuffer + * @param rightBuffer + * @param size + */ +void pan(const float* panEnvelope, float* leftBuffer, float* rightBuffer, unsigned size) noexcept; +inline void pan(absl::Span panEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept +{ + CHECK_SPAN_SIZES(panEnvelope, leftBuffer, rightBuffer); + pan(panEnvelope.data(), leftBuffer.data(), rightBuffer.data(), minSpanSize(panEnvelope, leftBuffer, rightBuffer)); +} + +/** + * @brief Controls the width of a stereo signal, setting it to mono when width = 0 and inverting the channels + * when width = -1. Width = 1 has no effect. + * + * @param widthEnvelope + * @param leftBuffer + * @param rightBuffer + * @param size + */ +void width(const float* widthEnvelope, float* leftBuffer, float* rightBuffer, unsigned size) noexcept; +inline void width(absl::Span widthEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept +{ + CHECK_SPAN_SIZES(widthEnvelope, leftBuffer, rightBuffer); + width(widthEnvelope.data(), leftBuffer.data(), rightBuffer.data(), minSpanSize(widthEnvelope, leftBuffer, rightBuffer)); +} + +} diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index aef54af6..1f2ab5e3 100644 --- a/src/sfizz/SIMDHelpers.h +++ b/src/sfizz/SIMDHelpers.h @@ -525,115 +525,6 @@ void copy(absl::Span input, absl::Span output) noexcept copy(input.data(), output.data(), minSpanSize(input, output)); } -namespace _internals { - // Number of elements in the table, odd for equal volume at center - constexpr int panSize = 4095; - - // Table of pan values for the left channel, extra element for safety - const auto panData = []() - { - std::array pan; - int i = 0; - - for (; i < panSize; ++i) - pan[i] = std::cos(i * (piTwo() / (panSize - 1))); - - for (; i < static_cast(pan.size()); ++i) - pan[i] = pan[panSize - 1]; - - return pan; - }(); - - template - inline T panLookup(T pan) - { - // reduce range, round to nearest - int index = static_cast(T{0.5} + pan * (panSize - 1)); - return panData[index]; - } - - template - inline void snippetPan(T pan, T& left, T& right) - { - pan = (pan + T{1.0}) * T{0.5}; - pan = clamp(pan, 0, 1); - left *= panLookup(pan); - right *= panLookup(1 - pan); - } - - template - inline void snippetWidth(T width, T& left, T& right) - { - T w = (width + T{1.0}) * T{0.5}; - w = clamp(w, 0, 1); - const auto coeff1 = panLookup(w); - const auto coeff2 = panLookup(1 - w); - const auto l = left; - const auto r = right; - left = l * coeff2 + r * coeff1; - right = l * coeff1 + r * coeff2; - } -} - -/** - * @brief Pans a mono signal left or right - * - * The output size will be the minimum of the pan envelope span and left and right buffer span sizes. - * - * @tparam T the underlying type - * @tparam SIMD use the SIMD version or the scalar version - * @param panEnvelope - * @param leftBuffer - * @param rightBuffer - */ -template -void pan(absl::Span panEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept -{ - CHECK(leftBuffer.size() >= panEnvelope.size()); - CHECK(rightBuffer.size() >= panEnvelope.size()); - auto* pan = panEnvelope.begin(); - auto* left = leftBuffer.begin(); - auto* right = rightBuffer.begin(); - auto* sentinel = pan + min(panEnvelope.size(), leftBuffer.size(), rightBuffer.size()); - while (pan < sentinel) { - _internals::snippetPan(*pan, *left, *right); - incrementAll(pan, left, right); - } -} - -template <> -void pan(absl::Span panEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept; - -/** - * @brief Controls the width of a stereo signal, setting it to mono when width = 0 and inverting the channels - * when width = -1. Width = 1 has no effect. - * - * The output size will be the minimum of the width envelope span and left and right buffer span sizes. - * - * @tparam T the underlying type - * @tparam SIMD use the SIMD version or the scalar version - * @param panEnvelope - * @param leftBuffer - * @param rightBuffer - */ -template -void width(absl::Span widthEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept -{ - CHECK(leftBuffer.size() >= widthEnvelope.size()); - CHECK(rightBuffer.size() >= widthEnvelope.size()); - auto* width = widthEnvelope.begin(); - auto* left = leftBuffer.begin(); - auto* right = rightBuffer.begin(); - auto* sentinel = width + min(widthEnvelope.size(), leftBuffer.size(), rightBuffer.size()); - while (width < sentinel) { - _internals::snippetWidth(*width, *left, *right); - incrementAll(width, left, right); - } -} - -template <> -void width(absl::Span widthEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept; - /** * @brief Computes the mean of a span * diff --git a/src/sfizz/SIMDSSE.cpp b/src/sfizz/SIMDSSE.cpp index da6a734b..f20938b7 100644 --- a/src/sfizz/SIMDSSE.cpp +++ b/src/sfizz/SIMDSSE.cpp @@ -16,85 +16,6 @@ constexpr uintptr_t TypeAlignment = 4; -template <> -void sfz::pan(absl::Span panEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept -{ - CHECK(leftBuffer.size() >= panEnvelope.size()); - CHECK(rightBuffer.size() >= panEnvelope.size()); - auto* pan = panEnvelope.begin(); - auto* left = leftBuffer.begin(); - auto* right = rightBuffer.begin(); - auto* sentinel = pan + min(panEnvelope.size(), leftBuffer.size(), rightBuffer.size()); - const auto* lastAligned = prevAligned(sentinel); - - while (unaligned(pan, left, right) && pan < lastAligned) { - _internals::snippetPan(*pan, *left, *right); - incrementAll(pan, left, right); - } - - const auto mmOne = _mm_set_ps1(1.0f); - const auto mmPiFour = _mm_set_ps1(piFour()); - __m128 mmCos; - __m128 mmSin; - while (pan < lastAligned) { - auto mmPan = _mm_load_ps(pan); - mmPan = _mm_add_ps(mmOne, mmPan); - mmPan = _mm_mul_ps(mmPan, mmPiFour); - sincos_ps(mmPan, &mmSin, &mmCos); - auto mmLeft = _mm_mul_ps(mmCos, _mm_load_ps(left)); - auto mmRight = _mm_mul_ps(mmSin, _mm_load_ps(right)); - _mm_store_ps(left, mmLeft); - _mm_store_ps(right, mmRight); - incrementAll(pan, left, right); - } - - while (pan < sentinel){ - _internals::snippetPan(*pan, *left, *right); - incrementAll(pan, left, right); - } -} - -template <> -void sfz::width(absl::Span widthEnvelope, absl::Span leftBuffer, absl::Span rightBuffer) noexcept -{ - CHECK(leftBuffer.size() >= widthEnvelope.size()); - CHECK(rightBuffer.size() >= widthEnvelope.size()); - auto* width = widthEnvelope.begin(); - auto* left = leftBuffer.begin(); - auto* right = rightBuffer.begin(); - auto* sentinel = width + min(widthEnvelope.size(), leftBuffer.size(), rightBuffer.size()); - const auto* lastAligned = prevAligned(sentinel); - - while (unaligned(width, left, right) && width < lastAligned) { - _internals::snippetWidth(*width, *left, *right); - incrementAll(width, left, right); - } - - const auto mmPiFour = _mm_set_ps1(piFour()); - __m128 mmCos; - __m128 mmSin; - while (width < lastAligned) { - auto mmWidth = _mm_load_ps(width); - mmWidth = _mm_mul_ps(mmWidth, mmPiFour); - sincos_ps(mmWidth, &mmSin, &mmCos); - auto mmCosPlusSine = _mm_add_ps(mmCos, mmSin); - auto mmCosMinusSine = _mm_sub_ps(mmCos, mmSin); - auto mmLeft = _mm_load_ps(left); - auto mmRight = _mm_load_ps(right); - auto mmTemp = _mm_mul_ps(mmCosMinusSine, mmRight); - mmRight = _mm_add_ps(_mm_mul_ps(mmCosMinusSine, mmLeft), _mm_mul_ps(mmCosPlusSine, mmRight)); - mmLeft = _mm_add_ps(_mm_mul_ps(mmCosPlusSine, mmLeft), mmTemp); - _mm_store_ps(left, mmLeft); - _mm_store_ps(right, mmRight); - incrementAll(width, left, right); - } - - while (width < sentinel){ - _internals::snippetWidth(*width, *left, *right); - incrementAll(width, left, right); - } -} - template <> float sfz::mean(absl::Span vector) noexcept { diff --git a/src/sfizz/SfzHelpers.cpp b/src/sfizz/SfzHelpers.cpp index 435ae30d..92d64cfa 100644 --- a/src/sfizz/SfzHelpers.cpp +++ b/src/sfizz/SfzHelpers.cpp @@ -7,7 +7,9 @@ #include "SfzHelpers.h" #include "StringViewHelpers.h" -absl::optional sfz::readNoteValue(const absl::string_view& value) +namespace sfz{ + +absl::optional readNoteValue(const absl::string_view& value) { switch(hash(value)) { @@ -153,7 +155,7 @@ absl::optional sfz::readNoteValue(const absl::string_view& value) } } -bool sfz::findHeader(absl::string_view& source, absl::string_view& header, absl::string_view& members) +bool findHeader(absl::string_view& source, absl::string_view& header, absl::string_view& members) { auto openHeader = source.find("<"); if (openHeader == absl::string_view::npos) @@ -176,7 +178,7 @@ bool sfz::findHeader(absl::string_view& source, absl::string_view& header, absl: return true; } -bool sfz::findOpcode(absl::string_view& source, absl::string_view& opcode, absl::string_view& value) +bool findOpcode(absl::string_view& source, absl::string_view& opcode, absl::string_view& value) { auto opcodeEnd = source.find("="); if (opcodeEnd == absl::string_view::npos) @@ -203,7 +205,7 @@ bool sfz::findOpcode(absl::string_view& source, absl::string_view& opcode, absl: } -bool sfz::findDefine(absl::string_view line, absl::string_view& variable, absl::string_view& value) +bool findDefine(absl::string_view line, absl::string_view& variable, absl::string_view& value) { const auto defPosition = line.find("#define"); if (defPosition == absl::string_view::npos) @@ -229,7 +231,7 @@ bool sfz::findDefine(absl::string_view line, absl::string_view& variable, absl:: return true; } -bool sfz::findInclude(absl::string_view line, std::string& path) +bool findInclude(absl::string_view line, std::string& path) { const auto defPosition = line.find("#include"); if (defPosition == absl::string_view::npos) @@ -246,3 +248,5 @@ bool sfz::findInclude(absl::string_view line, std::string& path) path = std::string(line.substr(pathStart + 1, pathEnd - pathStart - 1)); return true; } + +} diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index adca60c1..597b986b 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -10,6 +10,7 @@ #include "ModifierHelpers.h" #include "MathHelpers.h" #include "SIMDHelpers.h" +#include "Panning.h" #include "SfzHelpers.h" #include "Interpolators.h" #include "absl/algorithm/container.h" @@ -363,7 +364,7 @@ void sfz::Voice::panStageMono(AudioSpan buffer) noexcept linearModifier(resources, *tempSpan, mod, normalizePercents); add(*tempSpan, *modulationSpan); } - pan(*modulationSpan, leftBuffer, rightBuffer); + pan(*modulationSpan, leftBuffer, rightBuffer); } void sfz::Voice::panStageStereo(AudioSpan buffer) noexcept @@ -384,7 +385,7 @@ void sfz::Voice::panStageStereo(AudioSpan buffer) noexcept linearModifier(resources, *tempSpan, mod, normalizePercents); add(*tempSpan, *modulationSpan); } - pan(*modulationSpan, leftBuffer, rightBuffer); + pan(*modulationSpan, leftBuffer, rightBuffer); // Apply the width/position process fill(*modulationSpan, region->width); @@ -392,14 +393,14 @@ void sfz::Voice::panStageStereo(AudioSpan buffer) noexcept linearModifier(resources, *tempSpan, mod, normalizePercents); add(*tempSpan, *modulationSpan); } - width(*modulationSpan, leftBuffer, rightBuffer); + width(*modulationSpan, leftBuffer, rightBuffer); fill(*modulationSpan, region->position); for (const auto& mod : region->positionCC) { linearModifier(resources, *tempSpan, mod, normalizePercents); add(*tempSpan, *modulationSpan); } - pan(*modulationSpan, leftBuffer, rightBuffer); + pan(*modulationSpan, leftBuffer, rightBuffer); } void sfz::Voice::filterStageMono(AudioSpan buffer) noexcept diff --git a/src/sfizz/effects/Width.cpp b/src/sfizz/effects/Width.cpp index 8c3893ff..f07a9025 100644 --- a/src/sfizz/effects/Width.cpp +++ b/src/sfizz/effects/Width.cpp @@ -16,7 +16,7 @@ #include "Width.h" #include "Opcode.h" -#include "SIMDHelpers.h" +#include "Panning.h" #include "absl/memory/memory.h" namespace sfz { @@ -53,8 +53,8 @@ namespace fx { const float r = input2[i]; const float w = clamp((widths[i] + 100.0f) * 0.005f, 0.0f, 1.0f); - const float coeff1 = _internals::panLookup(w); - const float coeff2 = _internals::panLookup(1.0f - w); + const float coeff1 = panLookup(w); + const float coeff2 = panLookup(1.0f - w); output1[i] = l * coeff2 + r * coeff1; output2[i] = l * coeff1 + r * coeff2; diff --git a/tests/DemoStereo.cpp b/tests/DemoStereo.cpp index 2ef1558c..64bc1b97 100644 --- a/tests/DemoStereo.cpp +++ b/tests/DemoStereo.cpp @@ -4,7 +4,7 @@ // 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 "sfizz/SIMDHelpers.h" +#include "sfizz/Panning.h" #include "ui_DemoStereo.h" #include #include @@ -160,8 +160,8 @@ int DemoApp::processAudio(jack_nframes_t nframes, void *cbdata) std::fill(positionEnvelope.begin(), positionEnvelope.end(), self->fPan * 0.01f); using namespace sfz; - width(widthEnvelope, leftBuffer, rightBuffer); - pan(positionEnvelope, leftBuffer, rightBuffer); + width(widthEnvelope, leftBuffer, rightBuffer); + pan(positionEnvelope, leftBuffer, rightBuffer); return 0; } diff --git a/tests/SIMDHelpersT.cpp b/tests/SIMDHelpersT.cpp index d4d3c437..fd545249 100644 --- a/tests/SIMDHelpersT.cpp +++ b/tests/SIMDHelpersT.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "sfizz/SIMDHelpers.h" +#include "sfizz/Panning.h" #include "catch2/catch.hpp" #include #include @@ -729,21 +730,21 @@ TEST_CASE("[Helpers] Pan Scalar") SECTION("Pan = 0") { std::array pan { 0.0f }; - sfz::pan(pan, left, right); + sfz::pan(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 pan { 1.0f }; - sfz::pan(pan, left, right); + sfz::pan(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 pan { -1.0f }; - sfz::pan(pan, left, right); + sfz::pan(pan, left, right); REQUIRE(left[0] == Approx(1.0f).margin(0.001f)); REQUIRE(right[0] == Approx(0.0f).margin(0.001f)); } @@ -758,21 +759,21 @@ TEST_CASE("[Helpers] Width Scalar") SECTION("width = 1") { std::array width { 1.0f }; - sfz::width(width, left, right); + sfz::width(width, left, right); REQUIRE(left[0] == Approx(1.0f).margin(0.001f)); REQUIRE(right[0] == Approx(1.0f).margin(0.001f)); } SECTION("width = 0") { std::array width { 0.0f }; - sfz::width(width, left, right); + sfz::width(width, left, right); REQUIRE(left[0] == Approx(1.414f).margin(0.001f)); REQUIRE(right[0] == Approx(1.414f).margin(0.001f)); } SECTION("width = -1") { std::array width { -1.0f }; - sfz::width(width, left, right); + sfz::width(width, left, right); REQUIRE(left[0] == Approx(1.0f).margin(0.001f)); REQUIRE(right[0] == Approx(1.0f).margin(0.001f)); }