From 36f9bf0161de90f8d6c446e5100f788b95a5bee5 Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Thu, 28 Apr 2022 11:26:18 +0100 Subject: [PATCH 1/6] CMake: Centralise C++ version and set to 17 --- CMakeLists.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00e37b8f7..68029db94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ cmake_minimum_required (VERSION 3.11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + get_directory_property(hasParent PARENT_DIRECTORY) #set module path at top level so wrapper projects can easily include fluid_version script @@ -127,9 +131,6 @@ target_link_libraries( target_include_directories(HISSTools_FFT PUBLIC "${hisstools_SOURCE_DIR}") set_target_properties(HISSTools_FFT PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF POSITION_INDEPENDENT_CODE ON ) @@ -152,11 +153,6 @@ add_library( "${hisstools_SOURCE_DIR}/AudioFile/OAudioFile.cpp" ) -set_target_properties(HISSTools_AudioFile PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF -) #Fluid Decomposition header-only target add_library(FLUID_DECOMPOSITION INTERFACE) From c1a92fc7c14929361a57f18d90a76aabc4fe7efd Mon Sep 17 00:00:00 2001 From: weefuzzy Date: Thu, 28 Apr 2022 11:28:56 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Introduce=20long=20param=20type=20with=20a?= =?UTF-8?q?=20user-defined=20maximum=20+=20'primary'=20params=20=20?= =?UTF-8?q?=E2=80=93=C2=A0e.g.=20max=20coeffs=20for=20MFCC)=20=20-=20decou?= =?UTF-8?q?pling=20Max/PD=20arguments=20from=20'fixed'=20params=20?= =?UTF-8?q?=E2=80=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/clients/common/FluidBaseClient.hpp | 12 +- .../clients/common/FluidNRTClientWrapper.hpp | 8 +- .../clients/common/ParameterConstraints.hpp | 25 +++- include/clients/common/ParameterSet.hpp | 69 +++++++++- include/clients/common/ParameterTypes.hpp | 125 ++++++++++++++++-- include/clients/common/Result.hpp | 6 +- .../nrt/FluidSharedInstanceAdaptor.hpp | 6 + 7 files changed, 215 insertions(+), 36 deletions(-) diff --git a/include/clients/common/FluidBaseClient.hpp b/include/clients/common/FluidBaseClient.hpp index 5a839b821..76490e323 100644 --- a/include/clients/common/FluidBaseClient.hpp +++ b/include/clients/common/FluidBaseClient.hpp @@ -33,7 +33,8 @@ enum ProcessState { kNoProcess, kProcessing, kDone, kDoneStillProcessing }; struct ControlChannel { index count{0}; - index size{-1}; + index size{-1}; + index max{-1}; }; class FluidBaseClient @@ -47,7 +48,7 @@ class FluidBaseClient ControlChannel controlChannelsOut() const noexcept { return mControlChannelsOut; } index maxControlChannelsOut() const noexcept { - return mMaxControlChannelsOut; + return mControlChannelsOut.max > -1 ? mControlChannelsOut.max : mControlChannelsOut.size; } bool controlTrigger() const noexcept { return mControlTrigger; } index audioBuffersIn() const noexcept { return mBuffersIn; } @@ -71,10 +72,6 @@ class FluidBaseClient void audioChannelsOut(const index x) noexcept { mAudioChannelsOut = x; } void controlChannelsIn(const index x) noexcept { mControlChannelsIn = x; } void controlChannelsOut(const ControlChannel x) noexcept { mControlChannelsOut = x; } - void maxControlChannelsOut(const index x) noexcept - { - mMaxControlChannelsOut = x; - } void controlTrigger(const bool x) noexcept { mControlTrigger = x; } void audioBuffersIn(const index x) noexcept { mBuffersIn = x; } void audioBuffersOut(const index x) noexcept { mBuffersOut = x; } @@ -97,8 +94,7 @@ class FluidBaseClient index mAudioChannelsIn = 0; index mAudioChannelsOut = 0; index mControlChannelsIn = 0; - ControlChannel mControlChannelsOut {0,0}; - index mMaxControlChannelsOut = 0; + ControlChannel mControlChannelsOut {0,0,-1}; bool mControlTrigger{false}; index mBuffersIn = 0; index mBuffersOut = 0; diff --git a/include/clients/common/FluidNRTClientWrapper.hpp b/include/clients/common/FluidNRTClientWrapper.hpp index b87f75c63..8b298392b 100644 --- a/include/clients/common/FluidNRTClientWrapper.hpp +++ b/include/clients/common/FluidNRTClientWrapper.hpp @@ -528,7 +528,7 @@ struct StreamingControl { // To account for process latency we need to copy the buffers with padding std::vector inputData; - index nFeatures = client.controlChannelsOut().size; + index maxFeatures = client.maxControlChannelsOut(); // outputData.reserve(nFeatures); inputData.reserve(inputBuffers.size()); @@ -557,7 +557,7 @@ struct StreamingControl std::fill_n(std::back_inserter(inputData), inputBuffers.size(), HostMatrix(nChans, nFrames + totalPadding)); - HostMatrix outputData(nChans * nFeatures, nHops); + HostMatrix outputData(nChans * maxFeatures, nHops); double sampleRate{0}; // Copy input data for (index i = 0; i < nChans; ++i) @@ -591,7 +591,7 @@ struct StreamingControl // for (index k = 0; k < nFeatures; ++k) // outputs.emplace_back(outputData.row(k + i * nFeatures)(Slice(j, 1))); - outputs.push_back(outputData.col(j)(Slice(i * nFeatures, nFeatures))); + outputs.push_back(outputData.col(j)(Slice(i * maxFeatures, maxFeatures))); client.process(inputs, outputs, dummyContext); @@ -603,7 +603,7 @@ struct StreamingControl } BufferAdaptor::Access thisOutput(outputBuffers[0]); - + index nFeatures = client.controlChannelsOut().size; index latencyHops = client.latency() / controlRate; index keepHops = nHops - latencyHops; diff --git a/include/clients/common/ParameterConstraints.hpp b/include/clients/common/ParameterConstraints.hpp index 38bc0d6d9..0991ed729 100644 --- a/include/clients/common/ParameterConstraints.hpp +++ b/include/clients/common/ParameterConstraints.hpp @@ -35,7 +35,22 @@ struct MinImpl constexpr void clamp(U& x, Tuple& /*params*/, Descriptor& d, Result* r) const { U oldX = x; - x = std::max(x, value); + x = std::max(x, static_cast(value)); + if (r && oldX != x) + { + r->set(Result::Status::kWarning); + r->addMessage(d.template get().name, " value, ", oldX, + ", below absolute minimum ", x); + } + } + + template + constexpr void clamp(LongRuntimeMaxParam& x, Tuple& /*params*/, Descriptor& d, Result* r) const + { + index oldX = x(); + index newx = std::max(x(), value); + x.set(newx); if (r && oldX != x) { r->set(Result::Status::kWarning); @@ -75,17 +90,17 @@ struct LowerLimitImpl : public Relational { T oldV = v; - v = std::max({v, std::get(params)...}); + v = std::max({v, std::get(params).get()...}); if (r && oldV != v) { r->set(Result::Status::kWarning); std::array constraintValues{ - {std::get(params)...}}; + {std::get(params).get()...}}; index minPos = std::distance( constraintValues.begin(), std::min_element(constraintValues.begin(), constraintValues.end())); - std::array constraintNames{ + std::array constraintNames{ {d.template get().name...}}; r->addMessage(d.template get().name, " value (", oldV, ") below parameter ", constraintNames[asUnsigned(minPos)], @@ -113,7 +128,7 @@ struct UpperLimitImpl : public Relational index maxPos = std::distance( constraintValues.begin(), std::max_element(constraintValues.begin(), constraintValues.end())); - std::array constraintNames{ + std::array constraintNames{ {d.template get().name...}}; r->addMessage(d.template get().name, " value, ", oldV, ", above parameter ", constraintNames[asUnsigned(maxPos)], diff --git a/include/clients/common/ParameterSet.hpp b/include/clients/common/ParameterSet.hpp index d57b2d7ee..4df01e835 100644 --- a/include/clients/common/ParameterSet.hpp +++ b/include/clients/common/ParameterSet.hpp @@ -16,6 +16,9 @@ under the European Union’s Horizon 2020 research and innovation programme #include "../../data/FluidIndex.hpp" #include #include +#include + + namespace fluid { namespace client { @@ -29,16 +32,41 @@ class ParameterDescriptorSet; template class ParameterDescriptorSet, std::tuple> { + + + template + using tuple_element_t = typename std::tuple_element::type; + + struct IsPrimary + { + template + using apply = std::is_same>; + }; + template struct FixedParam { template - using apply = - std::is_same, typename std::tuple_element<2, T>::type>; + using apply = std::is_same, tuple_element_t<2,T>>; }; - - using IsFixed = FixedParam; - using IsMutable = FixedParam; + + struct IsFixed + { + template + using apply = std::is_same, tuple_element_t<2,T>>; + }; + + struct IsMutable + { + template + using apply = std::disjunction< + std::is_same, tuple_element_t<2,T>>, + std::is_same>>; + }; + + +// using IsFixed = FixedParam; +// using IsMutable = FixedParam; struct IsRelational { @@ -79,6 +107,9 @@ class ParameterDescriptorSet, std::tuple> // clang < 3.7: index_sequence_for doesn't work here using IndexList = std::make_index_sequence; + + using PrimaryIndexList = typename impl::FilterTupleIndices::type; + using FixedIndexList = typename impl::FilterTupleIndices::type; @@ -105,6 +136,7 @@ class ParameterDescriptorSet, std::tuple> typename impl::FilterTupleIndices::type::size(); } + static constexpr index NumPrimaryParams = PrimaryIndexList::size(); static constexpr index NumFixedParams = FixedIndexList::size(); static constexpr index NumMutableParams = MutableIndexList::size(); @@ -124,6 +156,14 @@ class ParameterDescriptorSet, std::tuple> iterateImpl(IndexList(), std::forward(args)...); } + template + void iteratePrimary(Func&& func) const + { + ForThese(mDescriptors, + [](auto& d, auto idx, auto&& f){ f(std::get<0>(d),idx); }, + PrimaryIndexList(), std::forward(func)); + } + template