working with 3 output types!

nix
Pierre Alexandre Tremblay 7 years ago
parent 138eb5e473
commit 08e0d285da

@ -27,15 +27,15 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
size_t windowSize = msg->geti();
size_t hopSize = msg->geti();
SndBuf* dstBuf;
size_t dstFrameCount;
size_t dstChanCount;
if (dstBufNum == -1 && dictBufNum == -1 && actBufNum == -1) {
Print("fdNMF is not happy because there are no output buffer specified.\n");
return;
}
SndBuf *dstBuf, *dictBuf, *actBuf;
size_t dstFrameCount, dictFrameCount, actFrameCount;
size_t dstChanCount, dictChanCount, actChanCount;
// check sanity of audio destination buffer
if (dstBufNum != -1){
if (dstBufNum >= world->mNumSndBufs){
@ -64,6 +64,62 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
}
}
// check sanity of dictionary destination buffer
if (dictBufNum != -1){
if (dictBufNum >= world->mNumSndBufs){
Print("fdNMF is not happy because the destination buffer does not exist.\n");
return;
}
dictBuf = world->mSndBufs + dictBufNum;
if (srcBuf->data == dictBuf->data){
Print("fdNMF is not happy because the destination buffer is the same as the source buffer.\n");
return;
}
dictFrameCount = dictBuf->frames;
dictChanCount = dictBuf->channels;
if (dictChanCount < rank) {
Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return;
}
if (dictFrameCount < (fftSize / 2 + 1)) {
Print("fdNMF is not happy because the destination buffer shorter than the source buffer.\n");
return;
}
}
// check sanity of activations destination buffer
if (actBufNum != -1){
if (actBufNum >= world->mNumSndBufs){
Print("fdNMF is not happy because the destination buffer does not exist.\n");
return;
}
actBuf = world->mSndBufs + actBufNum;
if (srcBuf->data == actBuf->data){
Print("fdNMF is not happy because the destination buffer is the same as the source buffer.\n");
return;
}
actFrameCount = actBuf->frames;
actChanCount = actBuf->channels;
if (actChanCount < rank) {
Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return;
}
if (actFrameCount < (srcFrameCount / hopSize + 1)) {
Print("fdNMF is not happy because the destination buffer shorter than the source buffer.\n");
return;
}
}
// make fuildtensorviewers of the SC interleaved input buffer
FluidTensorView<float,2> in_view ({0,{srcFrameCount, srcChanCount}},srcBuf->data);
@ -78,7 +134,8 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
FluidTensor<double,1> audio_in(in_view.col(j));
//Process, with resynthesis
nmf.process(audio_in,true);
//Copy output
//Copy audio outputs if they are requested
if (dstBufNum != -1){
FluidTensorView<float,2> out_view ({0,{dstFrameCount, dstChanCount}},dstBuf->data);
@ -87,6 +144,24 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
out_view.col(i) = nmf.source(i);
}
}
//Copy dictionaries if they are requested
if (dictBufNum != -1){
FluidTensorView<float,2> out_view ({0,{dictFrameCount, dictChanCount}},dictBuf->data);
for (int i = 0; i < rank; ++i)
{
out_view.col(i) = nmf.dictionary(i);
}
}
//Copy activations if they are requested
if (actBufNum != -1){
FluidTensorView<float,2> out_view ({0,{actFrameCount, actChanCount}},actBuf->data);
for (int i = 0; i < rank; ++i)
{
out_view.col(i) = nmf.activation(i);
}
}
}
}

@ -4,37 +4,55 @@ s.reboot
b = Buffer.read(s,"/Users/pa/Documents/documents@hudd/research/projects/fluid corpus navigation/research/denoise_stn/sources/01-mix.wav");
b.play;
(
c = Buffer.alloc(s,b.numFrames,5);
x = Buffer.alloc(s,b.numFrames,5);
y = Buffer.alloc(s,b.numFrames,5);
x = Buffer.alloc(s,(1024 / 2 +1),5);
y = Buffer.alloc(s,(b.numFrames / 256 + 1) ,5);
)
d = Main.elapsedTime; b.fdNMF(c, x, y, 5, 100, 1024,1024,256,{e = Main.elapsedTime; (e-d).postln})
d = Main.elapsedTime; b.fdNMF(c, x, nil, 5, 100, 1024,1024,256,{e = Main.elapsedTime; (e-d).postln})
//look at the dictionaries and activations
x.plot; y.plot;
//null test of the sum of sources
{(PlayBuf.ar(5,c.bufnum,doneAction:2).sum)+(-1*PlayBuf.ar(1,b.bufnum,doneAction:2))}.play
// play around
{Splay.ar(PlayBuf.ar(5,c.bufnum,doneAction:2))}.play
//play a single source
{PlayBuf.ar(5,c.bufnum,doneAction:2)[0].dup}.play
//play noise through a filter
(
{
var chain;
chain = FFT(LocalBuf(1024), WhiteNoise.ar());
chain = chain.pvcollect(1024, {|mag, phase, index|
[mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[0]];
});
IFFT(chain);
}.play
)
////////////////////////////
// test for osc clutter
SynthDef(\testcontrol, { arg fader = 0.5;
Out.ar(0, Pulse.ar(MouseX.kr(-1).exprange(100,400), fader,0.1));
}).send(s);
x = Synth(\testcontrol);
y = {GrainBuf.ar(2,Impulse.ar(MouseX.kr(2,20)),MouseX.kr(1,0.1),b.bufnum,1,MouseY.kr(),2,LFNoise0.kr(20),-1,512,0.5)}.play;
//play noise through an activation
{WhiteNoise.ar(BufRd.kr(5,y.bufnum,Phasor.ar(1,1/256,0,(b.numFrames / 256 + 1)),0,1)[0])}.play
z = {[0,BufRd.ar(1, b.bufnum, Phasor.ar(0, 2 , 0, BufFrames.kr(b.bufnum)),0)]}.play;
x.set(\fader, 0.05)
x.set(\fader, 0.5)
//play noise through both activation and filter
(
{
var chain;
chain = FFT(LocalBuf(1024), WhiteNoise.ar(BufRd.kr(5,y.bufnum,Phasor.ar(1,1/256,0,(b.numFrames / 256 + 1)),0,1)[0]),0.25);
x.free; y.free; z.free;
chain = chain.pvcollect(1024, {|mag, phase, index|
[mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[0]];
});
// starting the buffer reading synths before is no issue, but cannot start accessing/playing them during the computing (lock?)
IFFT(chain);
}.play
)

Loading…
Cancel
Save