Skip to content

Commit

Permalink
Merge branch 'develop' into simpler-file-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd authored Sep 27, 2020
2 parents f41ae6d + b655837 commit a68d856
Show file tree
Hide file tree
Showing 72 changed files with 3,314 additions and 1,675 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ dist: bionic
cache:
directories:
- vst/download/
# macOS Homebrew
- $HOME/Library/Caches/Homebrew
- /usr/local/Homebrew

jobs:
include:
Expand Down Expand Up @@ -48,6 +51,11 @@ jobs:
install: .travis/install_osx.sh
script: .travis/script_osx.sh
after_success: .travis/prepare_osx.sh
before_cache:
- brew cleanup
# Credit https://discourse.brew.sh/t/best-practice-for-homebrew-on-travis-brew-update-is-5min-to-build-time/5215/9
# Cache only .git files under "/usr/local/Homebrew" so "brew update" does not take 5min every build
- find /usr/local/Homebrew \! -regex ".+\.git.+" -delete

- name: "MOD devices arm"
env:
Expand Down
1 change: 1 addition & 0 deletions .travis/install_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -ex

sudo ln -s /usr/local /opt/local
brew cask uninstall --force java
brew update
brew upgrade cmake
brew install python || brew link --overwrite python
Expand Down
134 changes: 134 additions & 0 deletions benchmarks/BM_pan_arm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// 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 "Panning.h"
#include "simd/Common.h"
#include <benchmark/benchmark.h>
#include <random>
#include <absl/algorithm/container.h>
#include "absl/types/span.h"
#include <arm_neon.h>

#include <jsl/allocator>
template <class T, std::size_t A = 16>
using aligned_vector = std::vector<T, jsl::aligned_allocator<T, A>>;

// 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 = lroundPositive(pan * (panSize - 1));
return panData[index];
}

void panScalar(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 panSIMD(const float* panEnvelope, float* leftBuffer, float* rightBuffer, unsigned size) noexcept
{
const auto sentinel = panEnvelope + size;
int32_t indices[4];
while (panEnvelope < sentinel) {
float32x4_t mmPan = vld1q_f32(panEnvelope);
mmPan = vaddq_f32(mmPan, vdupq_n_f32(1.0f));
mmPan = vmulq_n_f32(mmPan, 0.5f * panSize);
mmPan = vaddq_f32(mmPan, vdupq_n_f32(0.5f));
mmPan = vminq_f32(mmPan, vdupq_n_f32(panSize));
mmPan = vmaxq_f32(mmPan, vdupq_n_f32(0.0f));
int32x4_t mmIdx = vcvtq_s32_f32(mmPan);
vst1q_s32(indices, mmIdx);

leftBuffer[0] *= panData[indices[0]];
rightBuffer[0] *= panData[panSize - indices[0] - 1];
leftBuffer[1] *= panData[indices[1]];
rightBuffer[1] *= panData[panSize - indices[1]- 1];
leftBuffer[2] *= panData[indices[2]];
rightBuffer[2] *= panData[panSize - indices[2]- 1];
leftBuffer[3] *= panData[indices[3]];
rightBuffer[3] *= panData[panSize - indices[3]- 1];

incrementAll<4>(panEnvelope, leftBuffer, rightBuffer);
}
}

class PanFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state) {
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { -1.0f, 1.0f };
pan.resize(state.range(0));
right.resize(state.range(0));
left.resize(state.range(0));

if (!willAlign<16>(pan.data(), left.data(), right.data()))
std::cout << "Will not align!" << '\n';
absl::c_generate(pan, [&]() { return dist(gen); });
absl::c_generate(left, [&]() { return dist(gen); });
absl::c_generate(right, [&]() { return dist(gen); });
}

void TearDown(const ::benchmark::State& /* state */) {

}

aligned_vector<float> pan;
aligned_vector<float> right;
aligned_vector<float> left;
};

BENCHMARK_DEFINE_F(PanFixture, PanScalar)(benchmark::State& state) {
for (auto _ : state)
{
panScalar(pan.data(), left.data(), right.data(), state.range(0));
}
}

BENCHMARK_DEFINE_F(PanFixture, PanSIMD)(benchmark::State& state) {
for (auto _ : state)
{
panSIMD(pan.data(), left.data(), right.data(), state.range(0));
}
}

BENCHMARK_DEFINE_F(PanFixture, PanSfizz)(benchmark::State& state) {
for (auto _ : state)
{
sfz::pan(pan.data(), left.data(), right.data(), state.range(0));
}
}

// Register the function as a benchmark
BENCHMARK_REGISTER_F(PanFixture, PanScalar)->RangeMultiplier(4)->Range((1 << 4), (1 << 12));
BENCHMARK_REGISTER_F(PanFixture, PanSIMD)->RangeMultiplier(4)->Range((1 << 4), (1 << 12));
BENCHMARK_REGISTER_F(PanFixture, PanSfizz)->RangeMultiplier(4)->Range((1 << 4), (1 << 12));
BENCHMARK_MAIN();
6 changes: 6 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ if (TARGET bm_resample)
add_dependencies(sfizz_benchmarks bm_resample)
endif()

if (SFIZZ_SYSTEM_PROCESSOR MATCHES "armv7l")
sfizz_add_benchmark(bm_pan_arm BM_pan_arm.cpp ../src/sfizz/Panning.cpp)
target_link_libraries(bm_pan_arm PRIVATE sfizz-jsl)
add_dependencies(sfizz_benchmarks bm_pan_arm)
endif()

configure_file("sample.wav" "${CMAKE_BINARY_DIR}/benchmarks/sample1.wav" COPYONLY)
configure_file("sample.wav" "${CMAKE_BINARY_DIR}/benchmarks/sample2.wav" COPYONLY)
configure_file("sample.wav" "${CMAKE_BINARY_DIR}/benchmarks/sample3.wav" COPYONLY)
Expand Down
7 changes: 7 additions & 0 deletions cmake/SfizzConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Werror=return-type)
if (SFIZZ_SYSTEM_PROCESSOR MATCHES "^(i.86|x86_64)$")
add_compile_options(-msse2)
elseif(SFIZZ_SYSTEM_PROCESSOR MATCHES "^(arm.*)$")
add_compile_options(-mfpu=neon)
add_compile_options(-mfloat-abi=hard)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -76,6 +79,10 @@ endfunction()
# The sndfile library
add_library(sfizz-sndfile INTERFACE)

# The jsl utility library for C++
add_library(sfizz-jsl INTERFACE)
target_include_directories(sfizz-jsl INTERFACE "external/jsl/include")

if (SFIZZ_USE_VCPKG OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
find_package(SndFile CONFIG REQUIRED)
find_path(SNDFILE_INCLUDE_DIR sndfile.hh)
Expand Down
1 change: 1 addition & 0 deletions cmake/SfizzSIMDSourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ macro(sfizz_add_simd_sources SOURCES_VAR PREFIX)

list (APPEND ${SOURCES_VAR}
${PREFIX}/sfizz/SIMDHelpers.cpp
${PREFIX}/sfizz/simd/HelpersNEON.cpp
${PREFIX}/sfizz/simd/HelpersSSE.cpp
${PREFIX}/sfizz/simd/HelpersAVX.cpp)

Expand Down
6 changes: 3 additions & 3 deletions cmake/VSTConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ if(NOT VST3_PACKAGE_ARCHITECTURE)
else()
set(VST3_PACKAGE_ARCHITECTURE "i386")
endif()
elseif(VST3_SYSTEM_PROCESSOR MATCHES "^(armv7l)$")
set(VST3_PACKAGE_ARCHITECTURE "armv7l")
elseif(VST3_SYSTEM_PROCESSOR MATCHES "^(armv[0-9]+)")
string(REGEX REPLACE "^(armv[0-9]+).*$" "\\1hl" VST3_PACKAGE_ARCHITECTURE "${VST3_SYSTEM_PROCESSOR}")
elseif(VST3_SYSTEM_PROCESSOR MATCHES "^(aarch64)$")
set(VST3_PACKAGE_ARCHITECTURE "aarch64")
set(VST3_PACKAGE_ARCHITECTURE "aarch64")
else()
message(FATAL_ERROR "We don't know this architecture for VST3: ${VST3_SYSTEM_PROCESSOR}.")
endif()
Expand Down
Loading

0 comments on commit a68d856

Please sign in to comment.