From ebfab8e311a6bdfbd679e1d426bc6f95a31b6d31 Mon Sep 17 00:00:00 2001 From: Owen Green Date: Thu, 18 Oct 2018 22:04:11 +0100 Subject: [PATCH] Add FluidNMFMatch --- src/FluidNMFMatch/CMakeLists.txt | 20 +++++ src/FluidNMFMatch/FluidNMFMatch.cpp | 135 ++++++++++++++++++++++++++++ src/FluidNMFMatch/test.scd | 21 +++++ 3 files changed, 176 insertions(+) create mode 100755 src/FluidNMFMatch/CMakeLists.txt create mode 100644 src/FluidNMFMatch/FluidNMFMatch.cpp create mode 100644 src/FluidNMFMatch/test.scd diff --git a/src/FluidNMFMatch/CMakeLists.txt b/src/FluidNMFMatch/CMakeLists.txt new file mode 100755 index 0000000..3693881 --- /dev/null +++ b/src/FluidNMFMatch/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.3) +get_filename_component(PLUGIN ${CMAKE_CURRENT_LIST_DIR} NAME_WE) +message("Configuring ${PLUGIN}") +set(FILENAME ${PLUGIN}.cpp) + +add_library( + ${PLUGIN} + MODULE + ${FILENAME} +) + +target_include_directories( + ${PLUGIN} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../include +) + +target_link_libraries( + ${PLUGIN} PRIVATE FLUID_DECOMPOSITION +) + +include(${CMAKE_CURRENT_LIST_DIR}/../../scripts/target_post.cmake) diff --git a/src/FluidNMFMatch/FluidNMFMatch.cpp b/src/FluidNMFMatch/FluidNMFMatch.cpp new file mode 100644 index 0000000..bab6c84 --- /dev/null +++ b/src/FluidNMFMatch/FluidNMFMatch.cpp @@ -0,0 +1,135 @@ + +// A tool from the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899) + +#include "SC_PlugIn.hpp" +#include "data/FluidTensor.hpp" +#include "fdNRTBase.hpp" +#include "clients/rt/NMFMatch.hpp" + + + +static InterfaceTable *ft; +namespace fluid { +namespace nmf{ + class FDNMFMatch: public SCUnit + { + using Client = NMFMatch; + using AudioSignalWrapper = Client::AudioSignal; + using SignalWrapper = Client::Signal; + using SignalPointer = std::unique_ptr; + using ClientPointer = std::unique_ptr; + template + using SignalArray = std::array; + using SignalVector = std::vector; + + public: + FDNMFMatch() + { + //Order of args + //psize hszie pthresh hthresh Window size, Hop size, FFT Size + + mClient = ClientPointer(new Client(65536)); + + setParams(true); + + bool isOK; + std::string feedback; + + std::tie(isOK, feedback) = mClient->sanityCheck(); + if(!isOK) + { + Print("fdNMFMatch Error: %s",feedback.c_str()); + return; + } + + mRank = parameter::lookupParam("rank", mClient->getParams()).getLong(); + + + mClient->set_host_buffer_size(bufferSize()); + mClient->reset(); + + inputSignals[0] = SignalPointer(new AudioSignalWrapper()); + + outputSignals.resize(mRank); + for(size_t i = 0; i < mRank; ++i) + outputSignals[i].reset(new Client::ScalarSignal()); + + mCalcFunc = make_calc_function(); + Unit* unit = this; + ClearUnitOutputs(unit,1); + } + + ~FDNMFMatch() {} + + private: + + void setParams(bool instantiation) + { + assert(mClient); + for(size_t i = 0; i < mClient->getParams().size(); ++i) + { + parameter::Instance& p = mClient->getParams()[i]; + if(!instantiation && p.getDescriptor().instantiation()) + continue; + switch(p.getDescriptor().getType()) + { + case parameter::Type::Long: + p.setLong(in0(i+1)); + p.checkRange(); + break; + case parameter::Type::Float: + { + p.setFloat(in0(i+1)); + p.checkRange(); + } + break; + case parameter::Type::Buffer: + { + long bufnum = static_cast(in0(i+1)); + sc::RTBufferView* currentBuf = static_cast(p.getBuffer()); + + + if(bufnum >= 0 && (currentBuf? (currentBuf->bufnum() != bufnum) : true)){ + sc::RTBufferView* buf = new sc::RTBufferView(mWorld,bufnum); + p.setBuffer(buf); + } + break; + } + default: + break; + } + } + } + + void next(int numsamples) + { + setParams(false); + const float* input = zin(0); + const float inscalar = in0(0); + inputSignals[0]->set(const_cast(input), inscalar); + for(size_t i = 0; i < mRank; ++i) + outputSignals[i]->set(out(i),out0(i)); + + mClient->do_process_noOLA(inputSignals.begin(),inputSignals.end(), outputSignals.begin(), outputSignals.end(), mWorld->mFullRate.mBufLength ,1,mRank); + for(size_t i = 0; i < mRank; ++i) + out0(i) = outputSignals[i]->next(); + } + + + + size_t mRank; + ClientPointer mClient; + SignalArray<1> inputSignals; + SignalVector outputSignals; + }; +} +} + +PluginLoad(FluidSTFTUGen) { + ft = inTable; + registerUnit(ft, "FluidNMFMatch"); +} + + + + diff --git a/src/FluidNMFMatch/test.scd b/src/FluidNMFMatch/test.scd new file mode 100644 index 0000000..6145ad1 --- /dev/null +++ b/src/FluidNMFMatch/test.scd @@ -0,0 +1,21 @@ +s.reboot; + + +( +b = Buffer.read(s,"../../release-packaging/AudioFiles/Tremblay-AaS-AcousticStrums-M.wav".resolveRelative); +c = Buffer.new(s); +x = Buffer.new(s); +) + + +( +Routine { + FluidBufNMF.process(s,b.bufnum,0,88200,0,1, c.bufnum, x.bufnum, rank:10); + s.sync; + c.query; +}.play; +) + + +{FluidNMFMatch.kr(PlayBuf.ar(1,b.bufnum),x.bufnum,10)}.play +