fdNRTBase, fdNMF: Changes to parameter instance ownership; implement offsets in frames and channels

nix
Owen Green 7 years ago
parent ebaa6ae63e
commit 035e1833ce

@ -70,21 +70,21 @@ namespace fluid {
bool parametersOk; bool parametersOk;
NMFClient::ProcessModel processModel; NMFClient::ProcessModel processModel;
std::string whatHappened;//this will give us a message to pass back if param check fails 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) if(!parametersOk)
{ {
Print("fdNMF: %s \n", whatHappened.c_str()); Print("fdNMF: %s \n", whatHappened.c_str());
return false; return false;
} }
//Now, we can proceed //Now, we can proceed
NMFClient nmf(processModel);
nmf.process(); nmf.process(processModel);
mModel = processModel; mModel = processModel;
src = static_cast<SCBufferView*>(parameter::lookupParam("Source Buffer", mParams).getBuffer()); src = static_cast<SCBufferView*>(parameter::lookupParam("src", nmf.getParams()).getBuffer());
resynth = static_cast<SCBufferView*>(parameter::lookupParam("Resynthesis Buffer", mParams).getBuffer()); resynth = static_cast<SCBufferView*>(parameter::lookupParam("resynthbuf", nmf.getParams()).getBuffer());
dict = static_cast<SCBufferView*>(parameter::lookupParam("Dictionary Buffer", mParams).getBuffer()); dict = static_cast<SCBufferView*>(parameter::lookupParam("filterbuf", nmf.getParams()).getBuffer());
act = static_cast<SCBufferView*>(parameter::lookupParam("Activation Buffer", mParams).getBuffer()); act = static_cast<SCBufferView*>(parameter::lookupParam("envbuf", nmf.getParams()).getBuffer());
return true; return true;
} }
@ -104,9 +104,12 @@ namespace fluid {
} }
bool postComplete(World* w) { return true; } bool postComplete(World* w) { return true; }
std::vector<parameter::Instance>& parameters()
{
return nmf.getParams();
}
private: private:
NMFClient nmf;
NMFClient::ProcessModel mModel; NMFClient::ProcessModel mModel;
SCBufferView* src; SCBufferView* src;
SCBufferView* resynth; SCBufferView* resynth;

@ -24,7 +24,7 @@ namespace sc{
NRTBuf(World* world,long bufnum): NRTBuf(World* world,long bufnum):
NRTBuf(*World_GetNRTBuf(world,bufnum)) NRTBuf(*World_GetNRTBuf(world,bufnum))
{ {
if(!this->samplerate)
this->samplerate = world->mFullRate.mSampleRate; this->samplerate = world->mFullRate.mSampleRate;
} }
@ -55,7 +55,11 @@ namespace sc{
NRTBuf(world,bufnum), NRTBuf(world,bufnum),
// BufferAdaptor({0,{static_cast<size_t>(frames),static_cast<size_t>(channels)}},NRTBuf::data), // BufferAdaptor({0,{static_cast<size_t>(frames),static_cast<size_t>(channels)}},NRTBuf::data),
mBufnum(bufnum), mWorld(world) mBufnum(bufnum), mWorld(world)
{} {
mChans = this->channels;
mFrames = this->frames;
}
~SCBufferView() = default; ~SCBufferView() = default;
@ -74,18 +78,29 @@ namespace sc{
return (mBufnum >=0 && mBufnum < mWorld->mNumSndBufs); return (mBufnum >=0 && mBufnum < mWorld->mNumSndBufs);
} }
FluidTensorView<float,1> samps(size_t channel, size_t rankIdx = 1) override FluidTensorView<float,1> samps(size_t channel, size_t rankIdx = 0) override
{ {
FluidTensorView<float,2> v{this->data,0, static_cast<size_t>(this->frames), static_cast<size_t>(this->channels)}; FluidTensorView<float,2> v{this->data,0, static_cast<size_t>(mFrames),static_cast<size_t>(mChans * mRank)};
return v.col(rankIdx + channel * (this->channels - 1)); return v.col(rankIdx + channel * mRank );
} }
//Return a view of all the data //Return a view of all the data
FluidTensorView<float,2> samps() override FluidTensorView<float,2> samps() override
{ {
return {this->data,0, static_cast<size_t>(this->frames), static_cast<size_t>(this->channels)}; return {this->data,0, static_cast<size_t>(mFrames), static_cast<size_t>(mChans * mRank)};
}
//Return a 2D chunk
FluidTensorView<float,2> samps(size_t offset, size_t nframes, size_t chanoffset, size_t chans) override
{
FluidTensorView<float,2> v{this->data,0, static_cast<size_t>(mFrames), static_cast<size_t>(mChans * mRank)};
return v(fluid::slice(offset,nframes), fluid::slice(chanoffset,chans));
} }
size_t numSamps() const override size_t numSamps() const override
{ {
if(valid()) if(valid())
@ -110,9 +125,12 @@ namespace sc{
SndBuf* thisThing = static_cast<SndBuf*>(this); SndBuf* thisThing = static_cast<SndBuf*>(this);
float* oldData = thisThing->data; float* oldData = thisThing->data;
mRank = rank;
mWorld->ft->fBufAlloc(this, channels * rank, frames, this->samplerate); mWorld->ft->fBufAlloc(this, channels * rank, frames, this->samplerate);
mFrames = this->frames;
mChans = this->channels / mRank;
// FluidTensorView<float,2> v= FluidTensorView<float,2>(NRTBuf::data,0,static_cast<size_t>(frames),static_cast<size_t>(channels * rank)); // FluidTensorView<float,2> v= FluidTensorView<float,2>(NRTBuf::data,0,static_cast<size_t>(frames),static_cast<size_t>(channels * rank));
// //
// static_cast<FluidTensorView<float,2>&>(*this) = std::move(v); // static_cast<FluidTensorView<float,2>&>(*this) = std::move(v);
@ -145,10 +163,9 @@ namespace sc{
NRTCommandBase(NRTCommandBase&) = delete; NRTCommandBase(NRTCommandBase&) = delete;
NRTCommandBase& operator=(NRTCommandBase&) = delete; NRTCommandBase& operator=(NRTCommandBase&) = delete;
NRTCommandBase(std::vector<param_type> params, NRTCommandBase(void* inUserData)
void* inUserData):
// mWorld(inWorld),mReplyAddr(replyAddr), mCompletionMsgData(completionMsgData), mCompletionMsgSize(completionMsgSize), // mWorld(inWorld),mReplyAddr(replyAddr), mCompletionMsgData(completionMsgData), mCompletionMsgSize(completionMsgSize),
mParams(params)
{} {}
~NRTCommandBase() = default; ~NRTCommandBase() = default;
@ -179,16 +196,19 @@ namespace sc{
void *cmdData; void *cmdData;
char* mCompletionMsgData; char* mCompletionMsgData;
size_t mCompletionMsgSize; size_t mCompletionMsgSize;
std::vector<param_type> mParams; // std::vector<param_type> mParams;
}; };
//This wraps a class instance in a function call to pass to SC //This wraps a class instance in a function call to pass to SC
template<typename NRT_Plug> template<typename NRT_Plug>
void command(World *inWorld, void* inUserData, struct sc_msg_iter *args, void *replyAddr) 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 //Iterate over parameter descriptions associated with this client object, fill with data from language side
std::vector<parameter::Instance> params = NRT_Plug::client_type::newParameterSet(); // std::vector<parameter::Instance> params = NRT_Plug::client_type::newParameterSet();
for (auto&& p: params) for (auto&& p: cmd->parameters())
{ {
switch(p.getDescriptor().getType()) switch(p.getDescriptor().getType())
{ {
@ -228,7 +248,7 @@ namespace sc{
args->getb(completionMsgData,completionMsgSize); args->getb(completionMsgData,completionMsgSize);
} }
//Make a new pointer for our plugin, and set it going //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); cmd->runCommand(inWorld, replyAddr, completionMsgData, completionMsgSize);
} }
} //namespace sc } //namespace sc

Loading…
Cancel
Save