Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .azure/azure-pipelines-alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ stages:
vmImage: 'ubuntu-24.04'
steps:
- checkout: self
submodules: true

- task: Docker@2
continueOnError: true
Expand Down Expand Up @@ -87,6 +88,7 @@ stages:
container: alpine-linux
steps:
- checkout: self
submodules: true
- task: CMake@1
displayName: 'CMake configure'
inputs:
Expand Down
3 changes: 3 additions & 0 deletions .azure/azure-pipelines-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ jobs:
vmImage: 'ubuntu-22.04'

steps:
- checkout: self
submodules: true

- script: |
set -ex
mkdir -p $(DEV)
Expand Down
4 changes: 4 additions & 0 deletions .azure/azure-pipelines-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jobs:
# brew update || brew update
# brew upgrade $PACKAGES
steps:
- checkout: self
submodules: true
- script: |
set -ex
PACKAGES="glib gobject-introspection libsndfile pkg-config jack dbus-glib pulseaudio portaudio sdl2 libomp readline"
Expand Down Expand Up @@ -163,6 +165,8 @@ jobs:
pool:
vmImage: $(imageName)
steps:
- checkout: self
submodules: true
- script: |
set -ex
brew install wget pkg-config
Expand Down
6 changes: 6 additions & 0 deletions .azure/azure-pipelines-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
pool:
vmImage: 'windows-2022'
steps:
- checkout: self
submodules: true
- task: DownloadBuildArtifacts@0
inputs:
buildType: specific
Expand Down Expand Up @@ -184,6 +186,8 @@ jobs:
pool:
vmImage: 'windows-2022'
steps:
- checkout: self
submodules: true
- script: |
@ECHO ON
mkdir d:\deps || exit -1
Expand Down Expand Up @@ -245,6 +249,8 @@ jobs:
pool:
vmImage: 'windows-2022'
steps:
- checkout: self
submodules: true
- task: DownloadBuildArtifacts@0
inputs:
buildType: specific
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Add apt-get repositories
run: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
submodules: recursive


- name: Add apt-get repositories
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: '${{ matrix.icon }} Setup MSYS2'
uses: msys2/setup-msys2@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "test/manual"]
path = test/manual
url = https://github.com/FluidSynth/testdata.git
[submodule "gcem"]
path = gcem
url = https://github.com/kthohr/gcem.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ endif ( CMAKE_SYSTEM MATCHES "OS2" )
set(CMAKE_C_STANDARD 90)

# the default C++ standard to use for all targets
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD 11)

# whether to use gnu extensions
set(CMAKE_C_EXTENSIONS ON)
Expand Down
1 change: 1 addition & 0 deletions gcem
Submodule gcem added at 012ae7
34 changes: 10 additions & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ endif ( OBOE_SUPPORT )
set ( config_SOURCES ${FluidSynth_BINARY_DIR}/config.h )

set ( libfluidsynth_SOURCES
gentables/fluid_ct2hz.cpp
gentables/fluid_cb2amp.cpp
gentables/fluid_concave.cpp
gentables/fluid_convex.cpp
gentables/fluid_pan.cpp
gentables/fluid_interp_coeff.cpp
gentables/fluid_interp_coeff_linear.cpp
gentables/fluid_interp_coeff_sinc7.cpp
gentables/ConstExprArr.hpp
utils/fluid_conv.c
utils/fluid_conv.h
utils/fluid_hash.c
Expand Down Expand Up @@ -281,6 +290,7 @@ target_include_directories ( libfluidsynth-OBJ PRIVATE
${FluidSynth_SOURCE_DIR}/src/sfloader
${FluidSynth_SOURCE_DIR}/src/bindings
${FluidSynth_SOURCE_DIR}/include
${FluidSynth_SOURCE_DIR}/gcem/include
)

if ( LIBFLUID_CPPFLAGS )
Expand Down Expand Up @@ -576,27 +586,3 @@ install(EXPORT FluidSynthTargets
NAMESPACE FluidSynth::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fluidsynth
)

# ******* Auto Generated Lookup Tables ******

include(ExternalProject)

set (GENTAB_SDIR ${CMAKE_CURRENT_SOURCE_DIR}/gentables)
set (GENTAB_BDIR ${CMAKE_CURRENT_BINARY_DIR}/gentables)

# Use external project to ensure that cmake uses the host compiler when building make_tables.exe
# To fix cross-compiling fluidsynth from Win32 to ARM (using vcpkg), we need to pass the current generator
# on to the external project, otherwise (for some unknown reason) the target compiler will be used rather
# than the host compiler.

ExternalProject_Add(gentables
DOWNLOAD_COMMAND ""
SOURCE_DIR ${GENTAB_SDIR}
BINARY_DIR ${GENTAB_BDIR}
CONFIGURE_COMMAND
"${CMAKE_COMMAND}" -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} -G "${CMAKE_GENERATOR}" -B "${GENTAB_BDIR}" "${GENTAB_SDIR}"
BUILD_COMMAND
"${CMAKE_COMMAND}" --build "${GENTAB_BDIR}"
INSTALL_COMMAND ${GENTAB_BDIR}/make_tables.exe "${FluidSynth_BINARY_DIR}/"
)
add_dependencies(libfluidsynth-OBJ gentables)
36 changes: 0 additions & 36 deletions src/gentables/CMakeLists.txt

This file was deleted.

59 changes: 59 additions & 0 deletions src/gentables/ConstExprArr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

#pragma once

#include "fluidsynth_priv.h"


struct IsBoundary
{
// Checks whether N is a multiple of 10
static constexpr bool chunk10(int N)
{
return (N >= 0) && (N % 10 == 0);
}
};

// === Recursive Template Struct: ConstExprArr_impl ===
// This struct recursively instantiates itself, decrementing N and accumulating template parameters
// in Rest... Each instantiation pushes N onto the Rest... pack, so eventually the values are
// collected as 1, 2, ..., N-1, N in Rest..., until we reach N = 0.
template<typename F, bool NisMult10, int N, int... Rest> struct ConstExprArr_impl
{
static constexpr auto &value = ConstExprArr_impl<F, IsBoundary::chunk10(N - 1), N - 1, N, Rest...>::value;
};

// === Partial Specialization for N==0 ===
// When N == 0, this specialization is used.
// It defines a static constant array value containing the values as calculated by the functor.
// At this point, Rest... actually contains all previous N values, so the array will be { 0, 1, 2, ..., N }
template<typename F, int... Rest> struct ConstExprArr_impl<F, true, 0, Rest...>
{
static constexpr fluid_real_t value[] = { F::calc(0), F::calc(Rest)... };
};

// === Partial Specialization whenever N is positive and a multiple of 10 ===
// The sole purpose of this specialization is to allow compilation with MSVC. MSVC has a hard-coded
// recursive template instantiation limit of 500. By chunking the recursion in steps of 10 whenever
// N is a multiple of 10, we drastically reduce the template recursion depth, allowing the code to
// compile for MSVC.
template<typename F, int N, int... Rest> struct ConstExprArr_impl<F, true, N, Rest...>
{
static constexpr auto &value =
ConstExprArr_impl<F, IsBoundary::chunk10(N - 10), N - 10, N - 9, N - 8, N - 7, N - 6, N - 5, N - 4, N - 3, N - 2, N - 1, N, Rest...>::value;
};

// Out-of-class Definition of the Static Array (needed for linkage)
template<typename F, int... Rest> constexpr fluid_real_t ConstExprArr_impl<F, true, 0, Rest...>::value[];

template<typename F, int N> struct ConstExprArr
{
static_assert(N > 0, "N must be greater 0");

// invokes the Recursive Template Struct
// N-1 because we want to exclude the last element, i.e. only from 0 to N-1
static constexpr auto &value = ConstExprArr_impl<F, IsBoundary::chunk10(N - 1), N - 1>::value;

ConstExprArr() = delete;
ConstExprArr(const ConstExprArr &) = delete;
ConstExprArr(ConstExprArr &&) = delete;
};
22 changes: 22 additions & 0 deletions src/gentables/fluid_cb2amp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#include "utils/fluid_conv_tables.h"
#include "gentables/ConstExprArr.hpp"

#include "gcem.hpp"

struct Cb2AmpFunctor
{
static constexpr fluid_real_t calc(int i)
{
/* centibels to amplitude conversion
* Note: SF2.01 section 8.1.3: Initial attenuation range is
* between 0 and 144 dB. Therefore a negative attenuation is
* not allowed.
*/
return gcem::pow(10.0L, static_cast<fluid_real_t>(i) / -200.0L);
}
};

extern "C" const constexpr auto fluid_cb2amp_tab_cpp = ConstExprArr<Cb2AmpFunctor, FLUID_CB_AMP_SIZE>::value;

extern "C" const fluid_real_t *const fluid_cb2amp_tab = fluid_cb2amp_tab_cpp;
24 changes: 24 additions & 0 deletions src/gentables/fluid_concave.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include "utils/fluid_conv_tables.h"
#include "gentables/ConstExprArr.hpp"

#include "gcem.hpp"

struct ConcaveFunctor
{
/* There seems to be an error in the specs. The equations are
implemented according to the pictures on SF2.01 page 73. */
static constexpr fluid_real_t calc(int i)
{
return ((i == 0)
? 0
: ((i == FLUID_VEL_CB_SIZE - 1)
? 1
: ((-200.0L * 2 / FLUID_PEAK_ATTENUATION) * gcem::log(((FLUID_VEL_CB_SIZE - 1) - i) / (FLUID_VEL_CB_SIZE - 1.0L)) / GCEM_LOG_10)
));
}
};

extern "C" const constexpr auto fluid_concave_tab_cpp = ConstExprArr<ConcaveFunctor, FLUID_VEL_CB_SIZE>::value;

extern "C" const fluid_real_t *const fluid_concave_tab = fluid_concave_tab_cpp;
24 changes: 24 additions & 0 deletions src/gentables/fluid_convex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include "utils/fluid_conv_tables.h"
#include "gentables/ConstExprArr.hpp"

#include "gcem.hpp"

struct ConvexFunctor
{
/* There seems to be an error in the specs. The equations are
implemented according to the pictures on SF2.01 page 73. */
static constexpr fluid_real_t calc(int i)
{
return ((i == 0)
? 0
: ((i == FLUID_VEL_CB_SIZE - 1)
? 1
: (1.0L - ((-200.0L * 2 / FLUID_PEAK_ATTENUATION) * gcem::log(i / (FLUID_VEL_CB_SIZE - 1.0L)) / GCEM_LOG_10))
));
}
};

extern "C" const constexpr auto fluid_convex_tab_cpp = ConstExprArr<ConvexFunctor, FLUID_VEL_CB_SIZE>::value;

extern "C" const fluid_real_t *const fluid_convex_tab = fluid_convex_tab_cpp;
20 changes: 20 additions & 0 deletions src/gentables/fluid_ct2hz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include "utils/fluid_conv_tables.h"
#include "gentables/ConstExprArr.hpp"

#include "gcem.hpp"

struct Ct2HzFunctor
{
static constexpr fluid_real_t calc(int i)
{
// 6,875 is just a factor that we already multiply into the lookup table to save
// that multiplication in fluid_ct2hz_real()
// 6.875 Hz because 440Hz / 2^6
return 6.875 * gcem::pow(2.0, static_cast<fluid_real_t>(i) / 1200.0);
}
};

extern "C" const constexpr auto fluid_ct2hz_tab_cpp = ConstExprArr<Ct2HzFunctor, FLUID_CENTS_HZ_SIZE>::value;

extern "C" const fluid_real_t *const fluid_ct2hz_tab = fluid_ct2hz_tab_cpp;
Loading
Loading