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;
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<SCBufferView*>(parameter::lookupParam("Source Buffer", mParams).getBuffer());
resynth = static_cast<SCBufferView*>(parameter::lookupParam("Resynthesis Buffer", mParams).getBuffer());
dict = static_cast<SCBufferView*>(parameter::lookupParam("Dictionary Buffer", mParams).getBuffer());
act = static_cast<SCBufferView*>(parameter::lookupParam("Activation Buffer", mParams).getBuffer());
src = static_cast<SCBufferView*>(parameter::lookupParam("src", nmf.getParams()).getBuffer());
resynth = static_cast<SCBufferView*>(parameter::lookupParam("resynthbuf", nmf.getParams()).getBuffer());
dict = static_cast<SCBufferView*>(parameter::lookupParam("filterbuf", nmf.getParams()).getBuffer());
act = static_cast<SCBufferView*>(parameter::lookupParam("envbuf", nmf.getParams()).getBuffer());
return true;
}
@ -104,9 +104,12 @@ namespace fluid {
}
bool postComplete(World* w) { return true; }
std::vector<parameter::Instance>& parameters()
{
return nmf.getParams();
}
private:
NMFClient nmf;
NMFClient::ProcessModel mModel;
SCBufferView* src;
SCBufferView* resynth;

@ -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<size_t>(frames),static_cast<size_t>(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<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
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
{
if(valid())
@ -110,9 +125,12 @@ namespace sc{
SndBuf* thisThing = static_cast<SndBuf*>(this);
float* oldData = thisThing->data;
mRank = rank;
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));
//
// static_cast<FluidTensorView<float,2>&>(*this) = std::move(v);
@ -145,10 +163,9 @@ namespace sc{
NRTCommandBase(NRTCommandBase&) = delete;
NRTCommandBase& operator=(NRTCommandBase&) = delete;
NRTCommandBase(std::vector<param_type> 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<param_type> mParams;
// std::vector<param_type> mParams;
};
//This wraps a class instance in a function call to pass to SC
template<typename NRT_Plug>
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<parameter::Instance> params = NRT_Plug::client_type::newParameterSet();
for (auto&& p: params)
// std::vector<parameter::Instance> 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

Loading…
Cancel
Save