From 18d3544ba452e17de5c68c01cf19ab6c1c58470b Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 1 Jun 2023 11:27:06 +0100 Subject: [PATCH 01/11] initial nix flake --- flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 39 ++++++++++++++++++++++++++++++++ nix/libear.nix | 23 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/libear.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b6cf49d --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705916986, + "narHash": "sha256-iBpfltu6QvN4xMpen6jGGEb6jOqmmVQKUrXdOJ32u8w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d7f206b723e42edb09d9d753020a84b3061a79d8", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7903a76 --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "nixpkgs/nixos-23.11"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + devtools = [ + pkgs.clang-tools + pkgs.cmake-format + pkgs.nixpkgs-fmt + ]; + in + rec { + packages.xsimd = pkgs.xsimd.overrideAttrs rec { + version = "12.1.1"; + src = pkgs.fetchFromGitHub { + owner = "xtensor-stack"; + repo = "xsimd"; + rev = "12.1.1"; + sha256 = "sha256-ofUFieeRtpnzNv3Ad5oYwKWb2XcqQHoj601TIhydJyI="; + }; + }; + packages.libear = pkgs.callPackage ./nix/libear.nix { src = ./.; xsimd = packages.xsimd; }; + packages.default = packages.libear; + + packages.libear_clang = packages.libear.override { stdenv = pkgs.clangStdenv; }; + + devShells.libear = packages.libear.overrideAttrs (attrs: { + nativeBuildInputs = attrs.nativeBuildInputs ++ devtools; + }); + devShells.default = devShells.libear; + } + ); +} + diff --git a/nix/libear.nix b/nix/libear.nix new file mode 100644 index 0000000..75ed12e --- /dev/null +++ b/nix/libear.nix @@ -0,0 +1,23 @@ +{ lib, buildPackages, stdenv, cmake, src, ninja, boost, eigen, xsimd }: +let + isCross = stdenv.buildPlatform != stdenv.hostPlatform; +in +(stdenv.mkDerivation { + name = "libear"; + inherit src; + nativeBuildInputs = [ + cmake + ninja + ]; + buildInputs = [ boost eigen xsimd ]; + cmakeFlags = [ + "-DEAR_USE_INTERNAL_EIGEN=OFF" + "-DEAR_USE_INTERNAL_XSIMD=OFF" + "-DEAR_UNIT_TESTS=ON" + ] + ++ lib.optionals isCross [ + "-DCMAKE_CROSSCOMPILING_EMULATOR=${stdenv.hostPlatform.emulator buildPackages}" + ]; + + doCheck = true; +}) From b9dafab37482d7ec8f9497b451299d28a5ed113b Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:41:30 +0000 Subject: [PATCH 02/11] drop unused and unimplemented components from objects gain calculator --- src/common/channel_lock.hpp | 9 --------- src/common/screen_scale.hpp | 14 -------------- src/object_based/gain_calculator_objects.cpp | 4 ---- src/object_based/gain_calculator_objects.hpp | 8 -------- src/object_based/zone_exclusion.hpp | 9 --------- 5 files changed, 44 deletions(-) delete mode 100644 src/common/channel_lock.hpp delete mode 100644 src/common/screen_scale.hpp delete mode 100644 src/object_based/zone_exclusion.hpp diff --git a/src/common/channel_lock.hpp b/src/common/channel_lock.hpp deleted file mode 100644 index 6d530ec..0000000 --- a/src/common/channel_lock.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "ear/layout.hpp" - -namespace ear { - class ChannelLockHandler { - public: - ChannelLockHandler(Layout layout){}; - }; -} // namespace ear diff --git a/src/common/screen_scale.hpp b/src/common/screen_scale.hpp deleted file mode 100644 index 73d330b..0000000 --- a/src/common/screen_scale.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include -#include "ear/screen.hpp" - -namespace ear { - class ScreenScaleHandler { - public: - ScreenScaleHandler(boost::optional reproductionScreen) - : _reproductionScreen(reproductionScreen){}; - - private: - boost::optional _reproductionScreen; - }; -} // namespace ear diff --git a/src/object_based/gain_calculator_objects.cpp b/src/object_based/gain_calculator_objects.cpp index 4132d99..9274975 100644 --- a/src/object_based/gain_calculator_objects.cpp +++ b/src/object_based/gain_calculator_objects.cpp @@ -26,11 +26,7 @@ namespace ear { GainCalculatorObjectsImpl::GainCalculatorObjectsImpl(const Layout& layout) : _layout(layout), _pointSourcePanner(configurePolarPanner(_layout.withoutLfe())), - _screenEdgeLockHandler(ScreenEdgeLockHandler(_layout.screen())), - _screenScaleHandler(ScreenScaleHandler(_layout.screen())), - _channelLockHandler(ChannelLockHandler(_layout.withoutLfe())), _polarExtentPanner(_pointSourcePanner), - _zoneExclusionHandler(ZoneExclusionHandler(_layout.withoutLfe())), _isLfe(copy_vector(layout.isLfe())), _pvTmp(_pointSourcePanner->numberOfOutputChannels()){}; diff --git a/src/object_based/gain_calculator_objects.hpp b/src/object_based/gain_calculator_objects.hpp index cdb5922..160c2f5 100644 --- a/src/object_based/gain_calculator_objects.hpp +++ b/src/object_based/gain_calculator_objects.hpp @@ -1,16 +1,12 @@ #pragma once #include -#include "../common/channel_lock.hpp" #include "../common/point_source_panner.hpp" -#include "../common/screen_edge_lock.hpp" -#include "../common/screen_scale.hpp" #include "ear/common_types.hpp" #include "ear/helpers/output_gains.hpp" #include "ear/layout.hpp" #include "ear/metadata.hpp" #include "ear/warnings.hpp" #include "polar_extent.hpp" -#include "zone_exclusion.hpp" namespace ear { @@ -33,11 +29,7 @@ namespace ear { private: Layout _layout; std::shared_ptr _pointSourcePanner; - ScreenEdgeLockHandler _screenEdgeLockHandler; - ScreenScaleHandler _screenScaleHandler; - ChannelLockHandler _channelLockHandler; PolarExtent _polarExtentPanner; - ZoneExclusionHandler _zoneExclusionHandler; Eigen::Array _isLfe; Eigen::VectorXd _pvTmp; }; diff --git a/src/object_based/zone_exclusion.hpp b/src/object_based/zone_exclusion.hpp deleted file mode 100644 index c555692..0000000 --- a/src/object_based/zone_exclusion.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "ear/layout.hpp" - -namespace ear { - class ZoneExclusionHandler { - public: - ZoneExclusionHandler(Layout layout){}; - }; -} // namespace ear From 21334d51d1dea3d5c21b5a1d2456f21be8716c12 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:44:35 +0000 Subject: [PATCH 03/11] fix unused arguments in example --- examples/objects_gains.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/objects_gains.cpp b/examples/objects_gains.cpp index 6941a51..9472617 100644 --- a/examples/objects_gains.cpp +++ b/examples/objects_gains.cpp @@ -4,7 +4,7 @@ using namespace ear; -int main(int argc, char **argv) { +int main(int, char **) { // make the gain calculator Layout layout = getLayout("0+5+0"); GainCalculatorObjects gc(layout); From ae64acef4c0505d4922930affe469d2b285b5406 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:45:06 +0000 Subject: [PATCH 04/11] fix unused arguments in conversion --- src/conversion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conversion.cpp b/src/conversion.cpp index 024bf45..84699f1 100644 --- a/src/conversion.cpp +++ b/src/conversion.cpp @@ -261,9 +261,9 @@ namespace ear { // wrappers for OTM struct guess_cartesian_flag : public boost::static_visitor { - bool operator()(const PolarPosition &pos) const { return false; } + bool operator()(const PolarPosition &) const { return false; } - bool operator()(const CartesianPosition &pos) const { return true; } + bool operator()(const CartesianPosition &) const { return true; } }; void toPolar(ObjectsTypeMetadata &otm) { From 9df384f605b87c623fa9cc1ae5e8a2f4c6d226b1 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:45:26 +0000 Subject: [PATCH 05/11] fix unused arguments in GainCalculatorObjectsImpl --- src/object_based/gain_calculator_objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/object_based/gain_calculator_objects.cpp b/src/object_based/gain_calculator_objects.cpp index 9274975..d551cac 100644 --- a/src/object_based/gain_calculator_objects.cpp +++ b/src/object_based/gain_calculator_objects.cpp @@ -33,7 +33,7 @@ namespace ear { void GainCalculatorObjectsImpl::calculate(const ObjectsTypeMetadata& metadata, OutputGains& direct, OutputGains& diffuse, - const WarningCB& warning_cb) { + const WarningCB&) { if (metadata.cartesian) throw not_implemented("cartesian"); boost::apply_visitor(throw_if_not_implemented(), metadata.position); boost::apply_visitor(throw_if_not_implemented(), metadata.objectDivergence); From e8b43fef749f17f816d907118508e1d913a66a30 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:58:34 +0000 Subject: [PATCH 06/11] fix unused argument in AllocentricPanner --- src/common/point_source_panner.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/point_source_panner.cpp b/src/common/point_source_panner.cpp index a398c92..3cc0f67 100644 --- a/src/common/point_source_panner.cpp +++ b/src/common/point_source_panner.cpp @@ -388,8 +388,7 @@ namespace ear { return boost::none; } - boost::optional AllocentricPanner::handle( - Eigen::Vector3d position) { + boost::optional AllocentricPanner::handle(Eigen::Vector3d) { return boost::none; } From f35058f54b5acb0273edef261a0c2c52a54bd43c Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:58:55 +0000 Subject: [PATCH 07/11] fix unused variable in conversion_tests --- tests/conversion_tests.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conversion_tests.cpp b/tests/conversion_tests.cpp index 874019d..587a5eb 100644 --- a/tests/conversion_tests.cpp +++ b/tests/conversion_tests.cpp @@ -48,7 +48,6 @@ static void check_extent_equal(const ExtentParams &p1, const ExtentParams &p2) { } TEST_CASE("conversion_cartesian_polar_loop") { - double eps = 1e-6; for (double az : {0.0, -10.0, 10.0, 90.0, -90.0, 150.0, -150.0}) for (double el : {0.0, -10.0, 10.0, -45.0, 45.0, -90.0, 90.0}) for (double dist : {0.5, 1.0}) { From 38bbeb387f92edb7ffe593e11094e7492238eed7 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 15:59:48 +0000 Subject: [PATCH 08/11] fix temporary construction warning in gain_calculator_direct_speakers_tests --- tests/gain_calculator_direct_speakers_tests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/gain_calculator_direct_speakers_tests.cpp b/tests/gain_calculator_direct_speakers_tests.cpp index 9bbb626..e1712e5 100644 --- a/tests/gain_calculator_direct_speakers_tests.cpp +++ b/tests/gain_calculator_direct_speakers_tests.cpp @@ -32,10 +32,10 @@ TEST_CASE("test_speaker_label") { Layout layout = getLayout("4+5+0"); GainCalculatorDirectSpeakers p(layout); - // DirectSpeakersTypeMetadata metadata; Gains actual(layout.channels().size()); - for (const std::string& prefix : - {"", "urn:itu:bs:2051:0:speaker:", "urn:itu:bs:2051:1:speaker:"}) { + std::vector prefixes = { + "", "urn:itu:bs:2051:0:speaker:", "urn:itu:bs:2051:1:speaker:"}; + for (const std::string& prefix : prefixes) { // normal case p.calculate(tmWithLabels(std::vector{prefix + "M+000"}), actual); From a5c6b39038c527719966d8d09f10dd887fda7a59 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 16:03:25 +0000 Subject: [PATCH 09/11] fix unused variable warning in extra_pos_vertical_nominal tests these layouts have different extra virtual loudspeakers; perhaps the original author thought the +1 in 4+5+1 is overhead? this behaviour matches the EAR reference implementation --- tests/point_source_panner_tests.cpp | 44 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/tests/point_source_panner_tests.cpp b/tests/point_source_panner_tests.cpp index 0c37d5c..ab3efed 100644 --- a/tests/point_source_panner_tests.cpp +++ b/tests/point_source_panner_tests.cpp @@ -151,22 +151,36 @@ TEST_CASE("extra_pos_vertical_nominal") { REQUIRE(downmix == expectedDownmix); }; - SECTION("4+5+0/4+5+1") { - for (const std::string& layoutName : {"4+5+0", "4+5+1"}) { - Layout layout = getLayout("4+5+0").withoutLfe(); - std::tie(extraChannels, downmix) = extraPosVerticalNominal(layout); - std::vector expectedPositions = { - PolarPosition(30.0, -30.0, 1.0), PolarPosition(-30.0, -30.0, 1.0), - PolarPosition(0.0, -30.0, 1.0), PolarPosition(110.0, -30.0, 1.0), - PolarPosition(-110.0, -30.0, 1.0)}; - REQUIRE(extraChannels.size() == expectedPositions.size()); - for (size_t i = 0; i < extraChannels.size(); ++i) { - REQUIRE(extraChannels[i].polarPosition() == expectedPositions[i]); - } - Eigen::MatrixXd expectedDownmix = createDownmixMatrixFromIndices( - std::vector{0, 1, 2, 3, 4}, layout.channels().size()); - REQUIRE(downmix == expectedDownmix); + SECTION("4+5+0") { + Layout layout = getLayout("4+5+0").withoutLfe(); + std::tie(extraChannels, downmix) = extraPosVerticalNominal(layout); + std::vector expectedPositions = { + PolarPosition(30.0, -30.0, 1.0), PolarPosition(-30.0, -30.0, 1.0), + PolarPosition(0.0, -30.0, 1.0), PolarPosition(110.0, -30.0, 1.0), + PolarPosition(-110.0, -30.0, 1.0)}; + REQUIRE(extraChannels.size() == expectedPositions.size()); + for (size_t i = 0; i < extraChannels.size(); ++i) { + REQUIRE(extraChannels[i].polarPosition() == expectedPositions[i]); } + Eigen::MatrixXd expectedDownmix = createDownmixMatrixFromIndices( + std::vector{0, 1, 2, 3, 4}, layout.channels().size()); + REQUIRE(downmix == expectedDownmix); + }; + + SECTION("4+5+1") { + Layout layout = getLayout("4+5+1").withoutLfe(); + std::tie(extraChannels, downmix) = extraPosVerticalNominal(layout); + std::vector expectedPositions = { + PolarPosition(110.0, -30.0, 1.0), + PolarPosition(-110.0, -30.0, 1.0), + }; + REQUIRE(extraChannels.size() == expectedPositions.size()); + for (size_t i = 0; i < extraChannels.size(); ++i) { + REQUIRE(extraChannels[i].polarPosition() == expectedPositions[i]); + } + Eigen::MatrixXd expectedDownmix = createDownmixMatrixFromIndices( + std::vector{3, 4}, layout.channels().size()); + REQUIRE(downmix == expectedDownmix); }; SECTION("3+7+0") { From 8aee6cbfb673cd8d1e1eaa13aae91bdbf54cca64 Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Thu, 25 Jan 2024 18:48:52 +0000 Subject: [PATCH 10/11] fix missing virtual destructor in PointSourcePanner closes #56 --- src/common/point_source_panner.cpp | 2 ++ src/common/point_source_panner.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/common/point_source_panner.cpp b/src/common/point_source_panner.cpp index 3cc0f67..856a5de 100644 --- a/src/common/point_source_panner.cpp +++ b/src/common/point_source_panner.cpp @@ -224,6 +224,8 @@ namespace ear { return ret + 1; } + PointSourcePanner::~PointSourcePanner() {} + PointSourcePannerDownmix::PointSourcePannerDownmix( std::shared_ptr psp, Eigen::MatrixXd downmix) : _psp(psp), _downmix(downmix){}; diff --git a/src/common/point_source_panner.hpp b/src/common/point_source_panner.hpp index eb323b5..4914967 100644 --- a/src/common/point_source_panner.hpp +++ b/src/common/point_source_panner.hpp @@ -116,6 +116,8 @@ namespace ear { virtual boost::optional handle( Eigen::Vector3d position) = 0; virtual int numberOfOutputChannels() const = 0; + + virtual ~PointSourcePanner(); }; /** @brief Wrapper around multiple regions. From 720fe69d3dc5a61b9185fee23b0e8e60ab1ad3fc Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Fri, 26 Jan 2024 11:50:20 +0000 Subject: [PATCH 11/11] update xsimd to 12.1.1 --- submodules/xsimd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/xsimd b/submodules/xsimd index 31298c8..c1247bf 160000 --- a/submodules/xsimd +++ b/submodules/xsimd @@ -1 +1 @@ -Subproject commit 31298c883bda0f3dfcf44170f45be242deb78f1a +Subproject commit c1247bffa8fc36de7380a5cd42673a3b32f74c97