Skip to content

Commit

Permalink
Merge pull request #856 from jpcima/build-time-optimization
Browse files Browse the repository at this point in the history
Build time optimization: resources
  • Loading branch information
jpcima authored Apr 25, 2021
2 parents f5bed98 + 508dae2 commit 954ae4c
Show file tree
Hide file tree
Showing 35 changed files with 603 additions and 295 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ for:
- ${APPVEYOR_BUILD_FOLDER}/scripts/appveyor/before_build.sh
build_script:
- cd build
- make -j2 sfizz_tests
- cmake --build . -j2 --target sfizz_tests
- tests/sfizz_tests
- make -j2
- cmake --build . -j2
after_build:
- chmod +x ${APPVEYOR_BUILD_FOLDER}/scripts/appveyor/after_build.sh
- ${APPVEYOR_BUILD_FOLDER}/scripts/appveyor/after_build.sh
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: |
sudo apt-get update && \
sudo apt-get install \
ninja-build \
libjack-jackd2-dev \
libsndfile1-dev \
libcairo2-dev \
Expand All @@ -64,7 +65,8 @@ jobs:
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
cmake "$GITHUB_WORKSPACE" -G Ninja \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DSFIZZ_JACK=ON \
-DSFIZZ_VST=ON \
-DSFIZZ_LV2_UI=ON \
Expand Down Expand Up @@ -239,7 +241,7 @@ jobs:
shell: bash
run: |
pacman -Sqyu --noconfirm
pacman -Sq --needed --noconfirm base-devel git wget mingw-w64-cmake mingw-w64-gcc mingw-w64-pkg-config mingw-w64-libsndfile
pacman -Sq --needed --noconfirm base-devel git wget ninja mingw-w64-cmake mingw-w64-gcc mingw-w64-pkg-config mingw-w64-libsndfile
- uses: actions/checkout@v2
with:
submodules: recursive
Expand All @@ -263,7 +265,7 @@ jobs:
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
i686-w64-mingw32-cmake "$GITHUB_WORKSPACE" \
i686-w64-mingw32-cmake "$GITHUB_WORKSPACE" -G Ninja \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DENABLE_LTO=OFF \
-DSFIZZ_JACK=OFF \
Expand Down Expand Up @@ -308,7 +310,7 @@ jobs:
shell: bash
run: |
pacman -Sqyu --noconfirm
pacman -Sq --needed --noconfirm base-devel git wget mingw-w64-cmake mingw-w64-gcc mingw-w64-pkg-config mingw-w64-libsndfile
pacman -Sq --needed --noconfirm base-devel git wget ninja mingw-w64-cmake mingw-w64-gcc mingw-w64-pkg-config mingw-w64-libsndfile
- uses: actions/checkout@v2
with:
submodules: recursive
Expand All @@ -332,7 +334,7 @@ jobs:
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
x86_64-w64-mingw32-cmake "$GITHUB_WORKSPACE" \
x86_64-w64-mingw32-cmake "$GITHUB_WORKSPACE" -G Ninja \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DENABLE_LTO=OFF \
-DSFIZZ_JACK=OFF \
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option_ex (SFIZZ_USE_SYSTEM_ABSEIL "Use Abseil libraries preinstalled on system"
option_ex (SFIZZ_USE_SYSTEM_SIMDE "Use SIMDe libraries preinstalled on system" OFF)
option_ex (SFIZZ_STATIC_DEPENDENCIES "Link dependencies statically" OFF)
option_ex (SFIZZ_RELEASE_ASSERTS "Forced assertions in release builds" OFF)
option_ex (SFIZZ_PROFILE_BUILD "Profile the build time" OFF)

# The fixed number of controller parameters
set(SFIZZ_NUM_CCS 512)
Expand Down
13 changes: 13 additions & 0 deletions cmake/SfizzConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(CMakeDependentOption)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(GNUWarnings)

Expand All @@ -22,6 +23,18 @@ elseif((SFIZZ_LV2_UI OR SFIZZ_VST OR SFIZZ_AU OR SFIZZ_VST2) AND CMAKE_CXX_STAND
set(CMAKE_CXX_STANDARD 14)
endif()

# Set build profiling options
if(SFIZZ_PROFILE_BUILD)
check_c_compiler_flag("-ftime-trace" SFIZZ_HAVE_CFLAG_FTIME_TRACE)
check_cxx_compiler_flag("-ftime-trace" SFIZZ_HAVE_CXXFLAG_FTIME_TRACE)
if(SFIZZ_HAVE_CFLAG_FTIME_TRACE)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-ftime-trace>")
endif()
if(SFIZZ_HAVE_CXXFLAG_FTIME_TRACE)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-ftime-trace>")
endif()
endif()

# Process sources as UTF-8
if(MSVC)
add_compile_options("/utf-8")
Expand Down
16 changes: 14 additions & 2 deletions cmake/SfizzDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,21 @@ add_library(sfizz::atomic_queue ALIAS sfizz_atomic_queue)
target_include_directories(sfizz_atomic_queue INTERFACE "external/atomic_queue/include")

# The ghc::filesystem library
add_library(sfizz_filesystem INTERFACE)
if(FALSE)
# header-only
add_library(sfizz_filesystem INTERFACE)
target_include_directories(sfizz_filesystem INTERFACE "external/filesystem/include")
else()
# static library
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/fs_std_impl.cpp" "#include <ghc/fs_std_impl.hpp>")
add_library(sfizz_filesystem_impl STATIC "${CMAKE_CURRENT_BINARY_DIR}/fs_std_impl.cpp")
target_include_directories(sfizz_filesystem_impl PUBLIC "external/filesystem/include")
#
add_library(sfizz_filesystem INTERFACE)
target_compile_definitions(sfizz_filesystem INTERFACE "GHC_FILESYSTEM_FWD")
target_link_libraries(sfizz_filesystem INTERFACE sfizz_filesystem_impl)
endif()
add_library(sfizz::filesystem ALIAS sfizz_filesystem)
target_include_directories(sfizz_filesystem INTERFACE "external/filesystem/include")

# The atomic library
add_library(sfizz_atomic INTERFACE)
Expand Down
1 change: 1 addition & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SFIZZ_SOURCES = \
src/sfizz/PowerFollower.cpp \
src/sfizz/Region.cpp \
src/sfizz/RegionSet.cpp \
src/sfizz/Resources.cpp \
src/sfizz/RTSemaphore.cpp \
src/sfizz/ScopedFTZ.cpp \
src/sfizz/sfizz.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set(SFIZZ_SOURCES
sfizz/WindowedSinc.cpp
sfizz/Interpolators.cpp
sfizz/Layer.cpp
sfizz/Resources.cpp
sfizz/modulations/ModId.cpp
sfizz/modulations/ModKey.cpp
sfizz/modulations/ModKeyHash.cpp
Expand Down Expand Up @@ -201,6 +202,7 @@ set(SFIZZ_PARSER_HEADERS
sfizz/Range.h
sfizz/Opcode.h
sfizz/parser/Parser.h
sfizz/parser/ParserListener.h
sfizz/parser/ParserPrivate.h
sfizz/parser/ParserPrivate.hpp
sfizz/SfzHelpers.h)
Expand Down
19 changes: 12 additions & 7 deletions src/sfizz/EQPool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "EQPool.h"
#include "Region.h"
#include "Resources.h"
#include "BufferPool.h"
#include "SIMDHelpers.h"
#include "utility/SwapAndPop.h"
#include <absl/algorithm/container.h>
Expand Down Expand Up @@ -31,9 +34,10 @@ void sfz::EQHolder::setup(const Region& region, unsigned eqId, float velocity)
baseBandwidth = description->bandwidth;
baseGain = description->gain + velocity * description->vel2gain;

gainTarget = resources.modMatrix.findTarget(ModKey::createNXYZ(ModId::EqGain, region.id, eqId));
bandwidthTarget = resources.modMatrix.findTarget(ModKey::createNXYZ(ModId::EqBandwidth, region.id, eqId));
frequencyTarget = resources.modMatrix.findTarget(ModKey::createNXYZ(ModId::EqFrequency, region.id, eqId));
const ModMatrix& mm = resources.getModMatrix();
gainTarget = mm.findTarget(ModKey::createNXYZ(ModId::EqGain, region.id, eqId));
bandwidthTarget = mm.findTarget(ModKey::createNXYZ(ModId::EqBandwidth, region.id, eqId));
frequencyTarget = mm.findTarget(ModKey::createNXYZ(ModId::EqFrequency, region.id, eqId));

// Disables smoothing of the parameters on the first call
prepared = false;
Expand All @@ -47,10 +51,11 @@ void sfz::EQHolder::process(const float** inputs, float** outputs, unsigned numF
return;
}

ModMatrix& mm = resources.modMatrix;
auto frequencySpan = resources.bufferPool.getBuffer(numFrames);
auto bandwidthSpan = resources.bufferPool.getBuffer(numFrames);
auto gainSpan = resources.bufferPool.getBuffer(numFrames);
ModMatrix& mm = resources.getModMatrix();
BufferPool& bufferPool = resources.getBufferPool();
auto frequencySpan = bufferPool.getBuffer(numFrames);
auto bandwidthSpan = bufferPool.getBuffer(numFrames);
auto gainSpan = bufferPool.getBuffer(numFrames);

if (!frequencySpan || !bandwidthSpan || !gainSpan)
return;
Expand Down
12 changes: 7 additions & 5 deletions src/sfizz/EQPool.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once
#include "SfzFilter.h"
#include "Region.h"
#include "Resources.h"
#include "Defaults.h"
#include "modulations/ModMatrix.h"
#include <vector>
#include <memory>

namespace sfz
{
namespace sfz {
struct Region;
class Resources;
struct EQDescription;

class EQHolder
{
Expand Down Expand Up @@ -52,4 +54,4 @@ class EQHolder
ModMatrix::TargetId bandwidthTarget;
};

}
} // namespace sfz
1 change: 1 addition & 0 deletions src/sfizz/FileMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <absl/strings/numbers.h>
#include <absl/strings/string_view.h>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
Expand Down
14 changes: 9 additions & 5 deletions src/sfizz/FilterPool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "FilterPool.h"
#include "Region.h"
#include "Resources.h"
#include "BufferPool.h"
#include "SIMDHelpers.h"
#include "utility/SwapAndPop.h"
#include <absl/algorithm/container.h>
Expand Down Expand Up @@ -42,7 +45,7 @@ void sfz::FilterHolder::setup(const Region& region, unsigned filterId, int noteN
baseGain = description->gain;
baseResonance = description->resonance;

ModMatrix& mm = resources.modMatrix;
ModMatrix& mm = resources.getModMatrix();
gainTarget = mm.findTarget(ModKey::createNXYZ(ModId::FilGain, region.id, filterId));
cutoffTarget = mm.findTarget(ModKey::createNXYZ(ModId::FilCutoff, region.id, filterId));
resonanceTarget = mm.findTarget(ModKey::createNXYZ(ModId::FilResonance, region.id, filterId));
Expand All @@ -62,10 +65,11 @@ void sfz::FilterHolder::process(const float** inputs, float** outputs, unsigned
return;
}

ModMatrix& mm = resources.modMatrix;
auto cutoffSpan = resources.bufferPool.getBuffer(numFrames);
auto resonanceSpan = resources.bufferPool.getBuffer(numFrames);
auto gainSpan = resources.bufferPool.getBuffer(numFrames);
ModMatrix& mm = resources.getModMatrix();
BufferPool& bufferPool = resources.getBufferPool();
auto cutoffSpan = bufferPool.getBuffer(numFrames);
auto resonanceSpan = bufferPool.getBuffer(numFrames);
auto gainSpan = bufferPool.getBuffer(numFrames);

if (!cutoffSpan || !resonanceSpan || !gainSpan)
return;
Expand Down
11 changes: 6 additions & 5 deletions src/sfizz/FilterPool.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once
#include "SfzFilter.h"
#include "Region.h"
#include "Resources.h"
#include "Defaults.h"
#include "modulations/ModMatrix.h"
#include <vector>
#include <memory>

namespace sfz
{
namespace sfz {
struct Region;
class Resources;
struct FilterDescription;

class FilterHolder
{
Expand Down Expand Up @@ -54,4 +55,4 @@ class FilterHolder
bool prepared { false };
};

}
} // namespace sfz
16 changes: 10 additions & 6 deletions src/sfizz/LFO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "SIMDHelpers.h"
#include "Config.h"
#include "Resources.h"
#include "BufferPool.h"
#include "BeatClock.h"
#include "MidiState.h"
#include "modulations/ModMatrix.h"
#include "modulations/ModKey.h"
#include "modulations/ModId.h"
#include <array>
Expand Down Expand Up @@ -61,7 +65,7 @@ void LFO::setSampleRate(double sampleRate)
void LFO::configure(const LFODescription* desc)
{
Impl& impl = *impl_;
ModMatrix& modMatrix = impl.resources_.modMatrix;
ModMatrix& modMatrix = impl.resources_.getModMatrix();
impl.desc_ = desc ? desc : &LFODescription::getDefault();
impl.beatsKeyId = modMatrix.findTarget(desc->beatsKey);
impl.freqKeyId = modMatrix.findTarget(desc->freqKey);
Expand All @@ -73,7 +77,7 @@ void LFO::start(unsigned triggerDelay)
Impl& impl = *impl_;
const LFODescription& desc = *impl.desc_;
const float sampleRate = impl.sampleRate_;
const MidiState& state = impl.resources_.midiState;
const MidiState& state = impl.resources_.getMidiState();

impl.subPhases_.fill(0.0f);
impl.sampleHoldMem_.fill(0.0f);
Expand Down Expand Up @@ -230,7 +234,7 @@ void LFO::process(absl::Span<float> out)
{
Impl& impl = *impl_;
const LFODescription& desc = *impl.desc_;
BufferPool& pool = impl.resources_.bufferPool;
BufferPool& pool = impl.resources_.getBufferPool();
size_t numFrames = out.size();

fill(out, 0.0f);
Expand Down Expand Up @@ -323,9 +327,9 @@ void LFO::processFadeIn(absl::Span<float> out)
void LFO::generatePhase(unsigned nth, absl::Span<float> phases)
{
Impl& impl = *impl_;
BufferPool& bufferPool = impl.resources_.bufferPool;
BeatClock& beatClock = impl.resources_.beatClock;
ModMatrix& modMatrix = impl.resources_.modMatrix;
BufferPool& bufferPool = impl.resources_.getBufferPool();
BeatClock& beatClock = impl.resources_.getBeatClock();
ModMatrix& modMatrix = impl.resources_.getModMatrix();
const LFODescription& desc = *impl.desc_;
const LFODescription::Sub& sub = desc.sub[nth];
const float samplePeriod = 1.0f / impl.sampleRate_;
Expand Down
2 changes: 1 addition & 1 deletion src/sfizz/LFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <memory>

namespace sfz {
struct Resources;
class Resources;
struct Region;

enum class LFOWave : int;
Expand Down
Loading

0 comments on commit 954ae4c

Please sign in to comment.