From 3b1d6a226b8f88f17836d60c59c9799327b1f58b Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Wed, 22 Aug 2018 10:18:42 +0100 Subject: [PATCH] now with optional process of source only if required, and more disciplined SC testing --- fdNMF.cpp | 9 +++++++-- tests.scd | 35 ++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/fdNMF.cpp b/fdNMF.cpp index 9c0b714..e5ed337 100644 --- a/fdNMF.cpp +++ b/fdNMF.cpp @@ -132,8 +132,13 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) for (int j=0;j<1;j++){ //copies and casts to double the source samples FluidTensor audio_in(in_view.col(j)); - //Process, with resynthesis - nmf.process(audio_in,true); + + //Process, with resynthesis if needs be + if (dstBufNum != -1){ + nmf.process(audio_in,true); + } else { + nmf.process(audio_in,false); + } //Copy audio outputs if they are requested if (dstBufNum != -1){ diff --git a/tests.scd b/tests.scd index a653067..50c998e 100644 --- a/tests.scd +++ b/tests.scd @@ -2,16 +2,25 @@ s.reboot //////////////////////////// // test for efficiency +( b = Buffer.read(s,"/Users/pa/Documents/documents@hudd/research/projects/fluid corpus navigation/research/denoise_stn/sources/01-mix.wav"); -b.play; +~fft_size = 2048; +~frame_size = 1024; +~hop_size = 256; +~which_rank = 0; +) ( c = Buffer.alloc(s,b.numFrames,5); -x = Buffer.alloc(s,(1024 / 2 +1),5); -y = Buffer.alloc(s,(b.numFrames / 256 + 1) ,5); +x = Buffer.alloc(s,(~fft_size / 2 +1),5); +y = Buffer.alloc(s,(b.numFrames / ~hop_size + 1) ,5); ) -d = Main.elapsedTime; b.fdNMF(c, x, y, 5, 100, 1024,1024,256,{e = Main.elapsedTime; (e-d).postln}) +// without sources +d = Main.elapsedTime; b.fdNMF(nil, x, y, 5, 100, ~fft_size,~frame_size,~hop_size,{e = Main.elapsedTime; (e-d).postln}) + +// with sources +d = Main.elapsedTime; b.fdNMF(c, x, y, 5, 100, ~fft_size,~frame_size,~hop_size,{e = Main.elapsedTime; (e-d).postln}) //look at the dictionaries and activations x.plot; y.plot; @@ -23,16 +32,16 @@ x.plot; y.plot; {Splay.ar(PlayBuf.ar(5,c.bufnum,doneAction:2))}.play //play a single source -{PlayBuf.ar(5,c.bufnum,doneAction:2)[0].dup}.play +{PlayBuf.ar(5,c.bufnum,doneAction:2)[~which_rank].dup}.play //play noise through a filter ( { var chain; - chain = FFT(LocalBuf(1024), WhiteNoise.ar()); + chain = FFT(LocalBuf(~fft_size), WhiteNoise.ar()); - chain = chain.pvcollect(1024, {|mag, phase, index| - [mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[0]]; + chain = chain.pvcollect(~fft_size, {|mag, phase, index| + [mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[~which_rank]]; }); IFFT(chain); @@ -40,19 +49,19 @@ x.plot; y.plot; ) //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 +{WhiteNoise.ar(BufRd.kr(5,y.bufnum,Phasor.ar(1,1/~hop_size,0,(b.numFrames / ~hop_size + 1)),0,1)[~which_rank] * 0.01)}.play //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); + chain = FFT(LocalBuf(~fft_size), WhiteNoise.ar(BufRd.kr(5,y.bufnum,Phasor.ar(1,1/~hop_size,0,(b.numFrames / ~hop_size + 1)),0,1)[~which_rank]*0.15),0.25,1); - chain = chain.pvcollect(1024, {|mag, phase, index| - [mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[0]]; + chain = chain.pvcollect(~fft_size, {|mag, phase, index| + [mag * BufRd.kr(5,x.bufnum,DC.kr(index),0,1)[~which_rank]]; }); - IFFT(chain); + [0,IFFT(chain)]; }.play )