diff --git a/cmake/SfizzSIMDSourceFilesCheck.cmake b/cmake/SfizzSIMDSourceFilesCheck.cmake index 1237b3bc..3c88f5b2 100644 --- a/cmake/SfizzSIMDSourceFilesCheck.cmake +++ b/cmake/SfizzSIMDSourceFilesCheck.cmake @@ -10,7 +10,7 @@ endif() # SIMD checks if (HAVE_X86INTRIN_H AND UNIX) add_compile_options (-DHAVE_X86INTRIN_H) - set (SFIZZ_SIMD_SOURCES sfizz/SIMDSSE.cpp) + set (SFIZZ_SIMD_SOURCES sfizz/SIMDSSE.cpp sfizz/OversamplerSSE.cpp) elseif (HAVE_INTRIN_H AND WIN32) add_compile_options (/DHAVE_INTRIN_H) set (SFIZZ_SIMD_SOURCES sfizz/SIMDSSE.cpp) @@ -20,9 +20,9 @@ elseif (HAVE_ARM_NEON_H AND UNIX) add_compile_options (-march=native) add_compile_options (-mtune=cortex-a53) add_compile_options (-funsafe-math-optimizations) - set (SFIZZ_SIMD_SOURCES sfizz/SIMDDummy.cpp) + set (SFIZZ_SIMD_SOURCES sfizz/SIMDDummy.cpp sfizz/OversamplerDummy.cpp) else() - set (SFIZZ_SIMD_SOURCES sfizz/SIMDDummy.cpp) + set (SFIZZ_SIMD_SOURCES sfizz/SIMDDummy.cpp sfizz/OversamplerDummy.cpp) endif() set (SFIZZ_SOURCES ${SFIZZ_SOURCES} ${SFIZZ_SIMD_SOURCES}) diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index 9176f6e0..9087d0b0 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -65,5 +65,6 @@ namespace SIMDConfig { constexpr bool sfzInterpolationCast { true }; constexpr bool mean { false }; constexpr bool meanSquared { false }; + constexpr bool upsampling { false }; } } // namespace sfz diff --git a/src/sfizz/Oversampler.h b/src/sfizz/Oversampler.h new file mode 100644 index 00000000..68953be6 --- /dev/null +++ b/src/sfizz/Oversampler.h @@ -0,0 +1,95 @@ +// Copyright (c) 2019, Paul Ferrand +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: + +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once +#include +#include "absl/types/span.h" +#include "Debug.h" +#include "Config.h" +#include "hiir/Upsampler2xFpu.h" + +namespace sfz { + +constexpr std::array coeffsStage2x { + 0.036681502163648017, + 0.13654762463195771, + 0.27463175937945411, + 0.42313861743656667, + 0.56109869787919475, + 0.67754004997416162, + 0.76974183386322659, + 0.83988962484963803, + 0.89226081800387891, + 0.9315419599631839, + 0.96209454837808395, + 0.98781637073289708 +}; + +constexpr std::array coeffsStage4x { + 0.042448989488488006, + 0.17072114107630679, + 0.39329183835224008, + 0.74569514831986694 +}; + +constexpr std::array coeffsStage8x { + 0.055748680811302048, + 0.24305119574153092, + 0.6466991311926823 +}; + +template +inline void upsample2xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2xFpu upsampler; + upsampler.set_coefs(coeffsStage2x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +} + + +template +inline void upsample4xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2xFpu upsampler; + upsampler.set_coefs(coeffsStage4x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +} + +template +inline void upsample8xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2xFpu upsampler; + upsampler.set_coefs(coeffsStage8x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +} + +template<> +inline void upsample2xStage(absl::Span input, absl::Span output); +template<> +inline void upsample4xStage(absl::Span input, absl::Span output); +template<> +inline void upsample8xStage(absl::Span input, absl::Span output); +} diff --git a/src/sfizz/OversamplerDummy.cpp b/src/sfizz/OversamplerDummy.cpp new file mode 100644 index 00000000..b92477b5 --- /dev/null +++ b/src/sfizz/OversamplerDummy.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2019, Paul Ferrand +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: + +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "Oversampler.h" + +template<> +inline void sfz::upsample2xStage(absl::Span input, absl::Span output) +{ + sfz::upsample2xStage(input, output); +} +template<> +inline void sfz::upsample4xStage(absl::Span input, absl::Span output) +{ + sfz::upsample4xStage(input, output); +} +template<> +inline void sfz::upsample8xStage(absl::Span input, absl::Span output) +{ + sfz::upsample8xStage(input, output); +} diff --git a/src/sfizz/OversamplerSSE.cpp b/src/sfizz/OversamplerSSE.cpp new file mode 100644 index 00000000..f3617a02 --- /dev/null +++ b/src/sfizz/OversamplerSSE.cpp @@ -0,0 +1,50 @@ +// Copyright (c) 2019, Paul Ferrand +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: + +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "Oversampler.h" +#include "hiir/Upsampler2x4Sse.h" + +template<> +inline void sfz::upsample2xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2x4Sse upsampler; + upsampler.set_coefs(sfz::coeffsStage2x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +} +template<> +inline void sfz::upsample4xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2x4Sse upsampler; + upsampler.set_coefs(sfz::coeffsStage4x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +} +template<> +inline void sfz::upsample8xStage(absl::Span input, absl::Span output) +{ + ASSERT(output.size() >= 2 * input.size()); + hiir::Upsampler2x4Sse upsampler; + upsampler.set_coefs(sfz::coeffsStage8x.data()); + upsampler.process_block(output.data(), input.data(), input.size()); +}