Move panning into its own file and outside of SIMD
This commit is contained in:
parent
190e7085de
commit
cebf9060e1
16 changed files with 136 additions and 359 deletions
|
|
@ -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 <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 PanArray : 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 };
|
|
||||||
pan = std::vector<float>(state.range(0));
|
|
||||||
left = std::vector<float>(state.range(0));
|
|
||||||
right = std::vector<float>(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<float>(state.range(0));
|
|
||||||
temp2 = std::vector<float>(state.range(0));
|
|
||||||
span1 = absl::MakeSpan(temp1);
|
|
||||||
span2 = absl::MakeSpan(temp2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown(const ::benchmark::State& /* state */) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<float> pan;
|
|
||||||
std::vector<float> left;
|
|
||||||
std::vector<float> right;
|
|
||||||
std::vector<float> temp1;
|
|
||||||
std::vector<float> temp2;
|
|
||||||
absl::Span<float> span1;
|
|
||||||
absl::Span<float> span2;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
BENCHMARK_DEFINE_F(PanArray, Scalar)(benchmark::State& state) {
|
|
||||||
ScopedFTZ ftz;
|
|
||||||
for (auto _ : state)
|
|
||||||
{
|
|
||||||
sfz::pan<float, false>(pan, absl::MakeSpan(left), absl::MakeSpan(right));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BENCHMARK_DEFINE_F(PanArray, SIMD)(benchmark::State& state) {
|
|
||||||
ScopedFTZ ftz;
|
|
||||||
for (auto _ : state)
|
|
||||||
{
|
|
||||||
sfz::pan<float, true>(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();
|
|
||||||
|
|
@ -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 <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 */) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
const auto leftBuffer = absl::MakeSpan(left);
|
|
||||||
const auto rightBuffer = absl::MakeSpan(right);
|
|
||||||
for (auto _ : state)
|
|
||||||
{
|
|
||||||
sfz::width<float, false>(width, leftBuffer, rightBuffer);
|
|
||||||
sfz::pan<float, false>(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<float, true>(width, leftBuffer, rightBuffer);
|
|
||||||
sfz::pan<float, true>(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();
|
|
||||||
|
|
@ -50,12 +50,10 @@ sfizz_add_benchmark(bm_multiplyAdd BM_multiplyAdd.cpp)
|
||||||
sfizz_add_benchmark(bm_multiplyAddFixedGain BM_multiplyAddFixedGain.cpp)
|
sfizz_add_benchmark(bm_multiplyAddFixedGain BM_multiplyAddFixedGain.cpp)
|
||||||
sfizz_add_benchmark(bm_subtract BM_subtract.cpp)
|
sfizz_add_benchmark(bm_subtract BM_subtract.cpp)
|
||||||
sfizz_add_benchmark(bm_copy BM_copy.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_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)
|
||||||
sfizz_add_benchmark(bm_maps BM_maps.cpp)
|
sfizz_add_benchmark(bm_maps BM_maps.cpp)
|
||||||
|
|
|
||||||
1
dpf.mk
1
dpf.mk
|
|
@ -85,6 +85,7 @@ SFIZZ_SOURCES = \
|
||||||
src/sfizz/OpcodeCleanup.cpp \
|
src/sfizz/OpcodeCleanup.cpp \
|
||||||
src/sfizz/Opcode.cpp \
|
src/sfizz/Opcode.cpp \
|
||||||
src/sfizz/Oversampler.cpp \
|
src/sfizz/Oversampler.cpp \
|
||||||
|
src/sfizz/Panning.cpp \
|
||||||
src/sfizz/Parser.cpp \
|
src/sfizz/Parser.cpp \
|
||||||
src/sfizz/parser/Parser.cpp \
|
src/sfizz/parser/Parser.cpp \
|
||||||
src/sfizz/parser/ParserPrivate.cpp \
|
src/sfizz/parser/ParserPrivate.cpp \
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ clang-tidy \
|
||||||
src/sfizz/Opcode.cpp \
|
src/sfizz/Opcode.cpp \
|
||||||
src/sfizz/Oversampler.cpp \
|
src/sfizz/Oversampler.cpp \
|
||||||
src/sfizz/Parser.cpp \
|
src/sfizz/Parser.cpp \
|
||||||
|
src/sfizz/Panning.cpp \
|
||||||
src/sfizz/sfizz.cpp \
|
src/sfizz/sfizz.cpp \
|
||||||
src/sfizz/Region.cpp \
|
src/sfizz/Region.cpp \
|
||||||
src/sfizz/SfzHelpers.cpp \
|
src/sfizz/SfzHelpers.cpp \
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ set (SFIZZ_SOURCES
|
||||||
sfizz/Wavetables.cpp
|
sfizz/Wavetables.cpp
|
||||||
sfizz/Tuning.cpp
|
sfizz/Tuning.cpp
|
||||||
sfizz/RTSemaphore.cpp
|
sfizz/RTSemaphore.cpp
|
||||||
|
sfizz/Panning.cpp
|
||||||
sfizz/Effects.cpp
|
sfizz/Effects.cpp
|
||||||
sfizz/effects/Nothing.cpp
|
sfizz/effects/Nothing.cpp
|
||||||
sfizz/effects/Filter.cpp
|
sfizz/effects/Filter.cpp
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
* @brief Contains math helper functions and math constants
|
* @brief Contains math helper functions and math constants
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Debug.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Macros.h"
|
#include "Macros.h"
|
||||||
#include "SIMDConfig.h"
|
#include "SIMDConfig.h"
|
||||||
|
|
|
||||||
58
src/sfizz/Panning.cpp
Normal file
58
src/sfizz/Panning.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "Panning.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
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<float, panSize + 1> pan;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (; i < panSize; ++i)
|
||||||
|
pan[i] = std::cos(i * (piTwo<double>() / (panSize - 1)));
|
||||||
|
|
||||||
|
for (; i < static_cast<int>(pan.size()); ++i)
|
||||||
|
pan[i] = pan[panSize - 1];
|
||||||
|
|
||||||
|
return pan;
|
||||||
|
}();
|
||||||
|
|
||||||
|
float panLookup(float pan)
|
||||||
|
{
|
||||||
|
// reduce range, round to nearest
|
||||||
|
int index = static_cast<int>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/sfizz/Panning.h
Normal file
47
src/sfizz/Panning.h
Normal file
|
|
@ -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<const float> panEnvelope, absl::Span<float> leftBuffer, absl::Span<float> 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<const float> widthEnvelope, absl::Span<float> leftBuffer, absl::Span<float> rightBuffer) noexcept
|
||||||
|
{
|
||||||
|
CHECK_SPAN_SIZES(widthEnvelope, leftBuffer, rightBuffer);
|
||||||
|
width(widthEnvelope.data(), leftBuffer.data(), rightBuffer.data(), minSpanSize(widthEnvelope, leftBuffer, rightBuffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -525,115 +525,6 @@ void copy(absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||||
copy<T>(input.data(), output.data(), minSpanSize(input, output));
|
copy<T>(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<float, panSize + 1> pan;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (; i < panSize; ++i)
|
|
||||||
pan[i] = std::cos(i * (piTwo<double>() / (panSize - 1)));
|
|
||||||
|
|
||||||
for (; i < static_cast<int>(pan.size()); ++i)
|
|
||||||
pan[i] = pan[panSize - 1];
|
|
||||||
|
|
||||||
return pan;
|
|
||||||
}();
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline T panLookup(T pan)
|
|
||||||
{
|
|
||||||
// reduce range, round to nearest
|
|
||||||
int index = static_cast<int>(T{0.5} + pan * (panSize - 1));
|
|
||||||
return panData[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void snippetPan(T pan, T& left, T& right)
|
|
||||||
{
|
|
||||||
pan = (pan + T{1.0}) * T{0.5};
|
|
||||||
pan = clamp<T>(pan, 0, 1);
|
|
||||||
left *= panLookup(pan);
|
|
||||||
right *= panLookup(1 - pan);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void snippetWidth(T width, T& left, T& right)
|
|
||||||
{
|
|
||||||
T w = (width + T{1.0}) * T{0.5};
|
|
||||||
w = clamp<T>(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 <class T, bool SIMD = SIMDConfig::pan>
|
|
||||||
void pan(absl::Span<const T> panEnvelope, absl::Span<T> leftBuffer, absl::Span<T> 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<float, true>(absl::Span<const float> panEnvelope, absl::Span<float> leftBuffer, absl::Span<float> 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 <class T, bool SIMD = SIMDConfig::pan>
|
|
||||||
void width(absl::Span<const T> widthEnvelope, absl::Span<T> leftBuffer, absl::Span<T> 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<float, true>(absl::Span<const float> widthEnvelope, absl::Span<float> leftBuffer, absl::Span<float> rightBuffer) noexcept;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Computes the mean of a span
|
* @brief Computes the mean of a span
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -16,85 +16,6 @@
|
||||||
|
|
||||||
constexpr uintptr_t TypeAlignment = 4;
|
constexpr uintptr_t TypeAlignment = 4;
|
||||||
|
|
||||||
template <>
|
|
||||||
void sfz::pan<float, true>(absl::Span<const float> panEnvelope, absl::Span<float> leftBuffer, absl::Span<float> 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<float>());
|
|
||||||
__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<TypeAlignment>(pan, left, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (pan < sentinel){
|
|
||||||
_internals::snippetPan(*pan, *left, *right);
|
|
||||||
incrementAll(pan, left, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
void sfz::width<float, true>(absl::Span<const float> widthEnvelope, absl::Span<float> leftBuffer, absl::Span<float> 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<float>());
|
|
||||||
__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<TypeAlignment>(width, left, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (width < sentinel){
|
|
||||||
_internals::snippetWidth(*width, *left, *right);
|
|
||||||
incrementAll(width, left, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
float sfz::mean<float, true>(absl::Span<const float> vector) noexcept
|
float sfz::mean<float, true>(absl::Span<const float> vector) noexcept
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@
|
||||||
#include "SfzHelpers.h"
|
#include "SfzHelpers.h"
|
||||||
#include "StringViewHelpers.h"
|
#include "StringViewHelpers.h"
|
||||||
|
|
||||||
absl::optional<uint8_t> sfz::readNoteValue(const absl::string_view& value)
|
namespace sfz{
|
||||||
|
|
||||||
|
absl::optional<uint8_t> readNoteValue(const absl::string_view& value)
|
||||||
{
|
{
|
||||||
switch(hash(value))
|
switch(hash(value))
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +155,7 @@ absl::optional<uint8_t> 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("<");
|
auto openHeader = source.find("<");
|
||||||
if (openHeader == absl::string_view::npos)
|
if (openHeader == absl::string_view::npos)
|
||||||
|
|
@ -176,7 +178,7 @@ bool sfz::findHeader(absl::string_view& source, absl::string_view& header, absl:
|
||||||
return true;
|
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("=");
|
auto opcodeEnd = source.find("=");
|
||||||
if (opcodeEnd == absl::string_view::npos)
|
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");
|
const auto defPosition = line.find("#define");
|
||||||
if (defPosition == absl::string_view::npos)
|
if (defPosition == absl::string_view::npos)
|
||||||
|
|
@ -229,7 +231,7 @@ bool sfz::findDefine(absl::string_view line, absl::string_view& variable, absl::
|
||||||
return true;
|
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");
|
const auto defPosition = line.find("#include");
|
||||||
if (defPosition == absl::string_view::npos)
|
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));
|
path = std::string(line.substr(pathStart + 1, pathEnd - pathStart - 1));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "ModifierHelpers.h"
|
#include "ModifierHelpers.h"
|
||||||
#include "MathHelpers.h"
|
#include "MathHelpers.h"
|
||||||
#include "SIMDHelpers.h"
|
#include "SIMDHelpers.h"
|
||||||
|
#include "Panning.h"
|
||||||
#include "SfzHelpers.h"
|
#include "SfzHelpers.h"
|
||||||
#include "Interpolators.h"
|
#include "Interpolators.h"
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
|
|
@ -363,7 +364,7 @@ void sfz::Voice::panStageMono(AudioSpan<float> buffer) noexcept
|
||||||
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
||||||
add<float>(*tempSpan, *modulationSpan);
|
add<float>(*tempSpan, *modulationSpan);
|
||||||
}
|
}
|
||||||
pan<float>(*modulationSpan, leftBuffer, rightBuffer);
|
pan(*modulationSpan, leftBuffer, rightBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::panStageStereo(AudioSpan<float> buffer) noexcept
|
void sfz::Voice::panStageStereo(AudioSpan<float> buffer) noexcept
|
||||||
|
|
@ -384,7 +385,7 @@ void sfz::Voice::panStageStereo(AudioSpan<float> buffer) noexcept
|
||||||
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
||||||
add<float>(*tempSpan, *modulationSpan);
|
add<float>(*tempSpan, *modulationSpan);
|
||||||
}
|
}
|
||||||
pan<float>(*modulationSpan, leftBuffer, rightBuffer);
|
pan(*modulationSpan, leftBuffer, rightBuffer);
|
||||||
|
|
||||||
// Apply the width/position process
|
// Apply the width/position process
|
||||||
fill(*modulationSpan, region->width);
|
fill(*modulationSpan, region->width);
|
||||||
|
|
@ -392,14 +393,14 @@ void sfz::Voice::panStageStereo(AudioSpan<float> buffer) noexcept
|
||||||
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
||||||
add<float>(*tempSpan, *modulationSpan);
|
add<float>(*tempSpan, *modulationSpan);
|
||||||
}
|
}
|
||||||
width<float>(*modulationSpan, leftBuffer, rightBuffer);
|
width(*modulationSpan, leftBuffer, rightBuffer);
|
||||||
|
|
||||||
fill(*modulationSpan, region->position);
|
fill(*modulationSpan, region->position);
|
||||||
for (const auto& mod : region->positionCC) {
|
for (const auto& mod : region->positionCC) {
|
||||||
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
linearModifier(resources, *tempSpan, mod, normalizePercents<float>);
|
||||||
add<float>(*tempSpan, *modulationSpan);
|
add<float>(*tempSpan, *modulationSpan);
|
||||||
}
|
}
|
||||||
pan<float>(*modulationSpan, leftBuffer, rightBuffer);
|
pan(*modulationSpan, leftBuffer, rightBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::filterStageMono(AudioSpan<float> buffer) noexcept
|
void sfz::Voice::filterStageMono(AudioSpan<float> buffer) noexcept
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "Width.h"
|
#include "Width.h"
|
||||||
#include "Opcode.h"
|
#include "Opcode.h"
|
||||||
#include "SIMDHelpers.h"
|
#include "Panning.h"
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
|
||||||
namespace sfz {
|
namespace sfz {
|
||||||
|
|
@ -53,8 +53,8 @@ namespace fx {
|
||||||
const float r = input2[i];
|
const float r = input2[i];
|
||||||
|
|
||||||
const float w = clamp((widths[i] + 100.0f) * 0.005f, 0.0f, 1.0f);
|
const float w = clamp((widths[i] + 100.0f) * 0.005f, 0.0f, 1.0f);
|
||||||
const float coeff1 = _internals::panLookup(w);
|
const float coeff1 = panLookup(w);
|
||||||
const float coeff2 = _internals::panLookup(1.0f - w);
|
const float coeff2 = panLookup(1.0f - w);
|
||||||
|
|
||||||
output1[i] = l * coeff2 + r * coeff1;
|
output1[i] = l * coeff2 + r * coeff1;
|
||||||
output2[i] = l * coeff1 + r * coeff2;
|
output2[i] = l * coeff1 + r * coeff2;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
// license. You should have receive a LICENSE.md file along with the code.
|
// 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
|
// 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 "ui_DemoStereo.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
@ -160,8 +160,8 @@ int DemoApp::processAudio(jack_nframes_t nframes, void *cbdata)
|
||||||
std::fill(positionEnvelope.begin(), positionEnvelope.end(), self->fPan * 0.01f);
|
std::fill(positionEnvelope.begin(), positionEnvelope.end(), self->fPan * 0.01f);
|
||||||
|
|
||||||
using namespace sfz;
|
using namespace sfz;
|
||||||
width<float>(widthEnvelope, leftBuffer, rightBuffer);
|
width(widthEnvelope, leftBuffer, rightBuffer);
|
||||||
pan<float>(positionEnvelope, leftBuffer, rightBuffer);
|
pan(positionEnvelope, leftBuffer, rightBuffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
#include "sfizz/SIMDHelpers.h"
|
#include "sfizz/SIMDHelpers.h"
|
||||||
|
#include "sfizz/Panning.h"
|
||||||
#include "catch2/catch.hpp"
|
#include "catch2/catch.hpp"
|
||||||
#include <absl/algorithm/container.h>
|
#include <absl/algorithm/container.h>
|
||||||
#include <absl/types/span.h>
|
#include <absl/types/span.h>
|
||||||
|
|
@ -729,21 +730,21 @@ TEST_CASE("[Helpers] Pan Scalar")
|
||||||
SECTION("Pan = 0")
|
SECTION("Pan = 0")
|
||||||
{
|
{
|
||||||
std::array<float, 1> pan { 0.0f };
|
std::array<float, 1> pan { 0.0f };
|
||||||
sfz::pan<float, false>(pan, left, right);
|
sfz::pan(pan, left, right);
|
||||||
REQUIRE(left[0] == Approx(0.70711f).margin(0.001f));
|
REQUIRE(left[0] == Approx(0.70711f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(0.70711f).margin(0.001f));
|
REQUIRE(right[0] == Approx(0.70711f).margin(0.001f));
|
||||||
}
|
}
|
||||||
SECTION("Pan = 1")
|
SECTION("Pan = 1")
|
||||||
{
|
{
|
||||||
std::array<float, 1> pan { 1.0f };
|
std::array<float, 1> pan { 1.0f };
|
||||||
sfz::pan<float, false>(pan, left, right);
|
sfz::pan(pan, left, right);
|
||||||
REQUIRE(left[0] == Approx(0.0f).margin(0.001f));
|
REQUIRE(left[0] == Approx(0.0f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
||||||
}
|
}
|
||||||
SECTION("Pan = -1")
|
SECTION("Pan = -1")
|
||||||
{
|
{
|
||||||
std::array<float, 1> pan { -1.0f };
|
std::array<float, 1> pan { -1.0f };
|
||||||
sfz::pan<float, false>(pan, left, right);
|
sfz::pan(pan, left, right);
|
||||||
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(0.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")
|
SECTION("width = 1")
|
||||||
{
|
{
|
||||||
std::array<float, 1> width { 1.0f };
|
std::array<float, 1> width { 1.0f };
|
||||||
sfz::width<float, false>(width, left, right);
|
sfz::width(width, left, right);
|
||||||
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
||||||
}
|
}
|
||||||
SECTION("width = 0")
|
SECTION("width = 0")
|
||||||
{
|
{
|
||||||
std::array<float, 1> width { 0.0f };
|
std::array<float, 1> width { 0.0f };
|
||||||
sfz::width<float, false>(width, left, right);
|
sfz::width(width, left, right);
|
||||||
REQUIRE(left[0] == Approx(1.414f).margin(0.001f));
|
REQUIRE(left[0] == Approx(1.414f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(1.414f).margin(0.001f));
|
REQUIRE(right[0] == Approx(1.414f).margin(0.001f));
|
||||||
}
|
}
|
||||||
SECTION("width = -1")
|
SECTION("width = -1")
|
||||||
{
|
{
|
||||||
std::array<float, 1> width { -1.0f };
|
std::array<float, 1> width { -1.0f };
|
||||||
sfz::width<float, false>(width, left, right);
|
sfz::width(width, left, right);
|
||||||
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(left[0] == Approx(1.0f).margin(0.001f));
|
||||||
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
REQUIRE(right[0] == Approx(1.0f).margin(0.001f));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue