diff --git a/fdNMF/fdNMF.cpp b/fdNMF/fdNMF.cpp index ce68119..75ba1f4 100644 --- a/fdNMF/fdNMF.cpp +++ b/fdNMF/fdNMF.cpp @@ -70,21 +70,21 @@ namespace fluid { bool parametersOk; NMFClient::ProcessModel processModel; std::string whatHappened;//this will give us a message to pass back if param check fails - std::tie(parametersOk,whatHappened,processModel) = NMFClient::sanityCheck(mParams); + std::tie(parametersOk,whatHappened,processModel) = nmf.sanityCheck(); if(!parametersOk) { Print("fdNMF: %s \n", whatHappened.c_str()); return false; } //Now, we can proceed - NMFClient nmf(processModel); - nmf.process(); + + nmf.process(processModel); mModel = processModel; - src = static_cast(parameter::lookupParam("Source Buffer", mParams).getBuffer()); - resynth = static_cast(parameter::lookupParam("Resynthesis Buffer", mParams).getBuffer()); - dict = static_cast(parameter::lookupParam("Dictionary Buffer", mParams).getBuffer()); - act = static_cast(parameter::lookupParam("Activation Buffer", mParams).getBuffer()); + src = static_cast(parameter::lookupParam("src", nmf.getParams()).getBuffer()); + resynth = static_cast(parameter::lookupParam("resynthbuf", nmf.getParams()).getBuffer()); + dict = static_cast(parameter::lookupParam("filterbuf", nmf.getParams()).getBuffer()); + act = static_cast(parameter::lookupParam("envbuf", nmf.getParams()).getBuffer()); return true; } @@ -104,9 +104,12 @@ namespace fluid { } bool postComplete(World* w) { return true; } - + std::vector& parameters() + { + return nmf.getParams(); + } private: - + NMFClient nmf; NMFClient::ProcessModel mModel; SCBufferView* src; SCBufferView* resynth; diff --git a/include/fdNRTBase.hpp b/include/fdNRTBase.hpp index 73b6612..0ef5cc1 100644 --- a/include/fdNRTBase.hpp +++ b/include/fdNRTBase.hpp @@ -24,8 +24,8 @@ namespace sc{ NRTBuf(World* world,long bufnum): NRTBuf(*World_GetNRTBuf(world,bufnum)) { - - this->samplerate = world->mFullRate.mSampleRate; + if(!this->samplerate) + this->samplerate = world->mFullRate.mSampleRate; } }; @@ -55,7 +55,11 @@ namespace sc{ NRTBuf(world,bufnum), // BufferAdaptor({0,{static_cast(frames),static_cast(channels)}},NRTBuf::data), mBufnum(bufnum), mWorld(world) - {} + { + mChans = this->channels; + mFrames = this->frames; + + } ~SCBufferView() = default; @@ -74,18 +78,29 @@ namespace sc{ return (mBufnum >=0 && mBufnum < mWorld->mNumSndBufs); } - FluidTensorView samps(size_t channel, size_t rankIdx = 1) override + FluidTensorView samps(size_t channel, size_t rankIdx = 0) override { - FluidTensorView v{this->data,0, static_cast(this->frames), static_cast(this->channels)}; + FluidTensorView v{this->data,0, static_cast(mFrames),static_cast(mChans * mRank)}; - return v.col(rankIdx + channel * (this->channels - 1)); + return v.col(rankIdx + channel * mRank ); } //Return a view of all the data FluidTensorView samps() override { - return {this->data,0, static_cast(this->frames), static_cast(this->channels)}; + return {this->data,0, static_cast(mFrames), static_cast(mChans * mRank)}; + } + + //Return a 2D chunk + FluidTensorView samps(size_t offset, size_t nframes, size_t chanoffset, size_t chans) override + { + FluidTensorView v{this->data,0, static_cast(mFrames), static_cast(mChans * mRank)}; + + return v(fluid::slice(offset,nframes), fluid::slice(chanoffset,chans)); + + } + size_t numSamps() const override { if(valid()) @@ -110,9 +125,12 @@ namespace sc{ SndBuf* thisThing = static_cast(this); float* oldData = thisThing->data; - + mRank = rank; mWorld->ft->fBufAlloc(this, channels * rank, frames, this->samplerate); + mFrames = this->frames; + mChans = this->channels / mRank; + // FluidTensorView v= FluidTensorView(NRTBuf::data,0,static_cast(frames),static_cast(channels * rank)); // // static_cast&>(*this) = std::move(v); @@ -145,10 +163,9 @@ namespace sc{ NRTCommandBase(NRTCommandBase&) = delete; NRTCommandBase& operator=(NRTCommandBase&) = delete; - NRTCommandBase(std::vector params, - void* inUserData): + NRTCommandBase(void* inUserData) // mWorld(inWorld),mReplyAddr(replyAddr), mCompletionMsgData(completionMsgData), mCompletionMsgSize(completionMsgSize), - mParams(params) + {} ~NRTCommandBase() = default; @@ -179,16 +196,19 @@ namespace sc{ void *cmdData; char* mCompletionMsgData; size_t mCompletionMsgSize; - std::vector mParams; +// std::vector mParams; }; //This wraps a class instance in a function call to pass to SC template void command(World *inWorld, void* inUserData, struct sc_msg_iter *args, void *replyAddr) { + + NRT_Plug* cmd = new NRT_Plug(inUserData); + //Iterate over parameter descriptions associated with this client object, fill with data from language side - std::vector params = NRT_Plug::client_type::newParameterSet(); - for (auto&& p: params) +// std::vector params = NRT_Plug::client_type::newParameterSet(); + for (auto&& p: cmd->parameters()) { switch(p.getDescriptor().getType()) { @@ -228,7 +248,7 @@ namespace sc{ args->getb(completionMsgData,completionMsgSize); } //Make a new pointer for our plugin, and set it going - NRT_Plug* cmd = new NRT_Plug(params, inUserData); + cmd->runCommand(inWorld, replyAddr, completionMsgData, completionMsgSize); } } //namespace sc