From d0ff669f2edbbe2500a6f89a33d52d2979a8b6d1 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Thu, 23 Aug 2018 16:16:19 +0100 Subject: [PATCH] now working with multichannel input buffers --- fdNMF/fdNMF.cpp | 16 +++++++--------- fdNMF/tests.scd | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/fdNMF/fdNMF.cpp b/fdNMF/fdNMF.cpp index e5ed337..777e0cc 100644 --- a/fdNMF/fdNMF.cpp +++ b/fdNMF/fdNMF.cpp @@ -53,7 +53,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) dstFrameCount = dstBuf->frames; dstChanCount = dstBuf->channels; - if (dstChanCount < rank) { + if (dstChanCount < (rank * srcChanCount)) { Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n"); return; } @@ -81,7 +81,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) dictFrameCount = dictBuf->frames; dictChanCount = dictBuf->channels; - if (dictChanCount < rank) { + if (dictChanCount < (rank * srcChanCount)) { Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n"); return; } @@ -109,7 +109,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) actFrameCount = actBuf->frames; actChanCount = actBuf->channels; - if (actChanCount < rank) { + if (actChanCount < (rank * srcChanCount)) { Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n"); return; } @@ -127,9 +127,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) NMFClient nmf(rank ,iterations, fftSize, windowSize, hopSize); //for each channels - // for (int j=0;j audio_in(in_view.col(j)); @@ -146,7 +144,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) for (int i = 0; i < rank; ++i) { - out_view.col(i) = nmf.source(i); + out_view.col(i + (j*rank)) = nmf.source(i); } } //Copy dictionaries if they are requested @@ -155,7 +153,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) for (int i = 0; i < rank; ++i) { - out_view.col(i) = nmf.dictionary(i); + out_view.col(i + (j*rank)) = nmf.dictionary(i); } } //Copy activations if they are requested @@ -164,7 +162,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg) for (int i = 0; i < rank; ++i) { - out_view.col(i) = nmf.activation(i); + out_view.col(i + (j*rank)) = nmf.activation(i); } } } diff --git a/fdNMF/tests.scd b/fdNMF/tests.scd index 50c998e..c29ce1d 100644 --- a/fdNMF/tests.scd +++ b/fdNMF/tests.scd @@ -65,3 +65,26 @@ x.plot; y.plot; [0,IFFT(chain)]; }.play ) + + +// test with stereo input +Buffer.freeAll(s) + +( +b = Buffer.read(s,"/Users/pa/Desktop/verystereo.wav"); +~fft_size = 1024; +~frame_size = 512; +~hop_size = 256; +) + +( +c = Buffer.alloc(s,b.numFrames,10); +x = Buffer.alloc(s,(~fft_size / 2 +1),10); +y = Buffer.alloc(s,(b.numFrames / ~hop_size + 1) ,10); +) + +d = Main.elapsedTime; b.fdNMF(c, x, y, 5, 100, ~fft_size,~frame_size,~hop_size,{e = Main.elapsedTime; (e-d).postln}) + +{PlayBuf.ar(10,c.bufnum,doneAction:2)[5].dup}.play + +c.getn(0, 10, {|x|x.postln})