now working with multichannel input buffers

nix
Pierre Alexandre Tremblay 7 years ago
parent 1d9c962b20
commit d0ff669f2e

@ -53,7 +53,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
dstFrameCount = dstBuf->frames; dstFrameCount = dstBuf->frames;
dstChanCount = dstBuf->channels; 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"); Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return; return;
} }
@ -81,7 +81,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
dictFrameCount = dictBuf->frames; dictFrameCount = dictBuf->frames;
dictChanCount = dictBuf->channels; 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"); Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return; return;
} }
@ -109,7 +109,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
actFrameCount = actBuf->frames; actFrameCount = actBuf->frames;
actChanCount = actBuf->channels; 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"); Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return; return;
} }
@ -127,9 +127,7 @@ void BufNMF(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
NMFClient nmf(rank ,iterations, fftSize, windowSize, hopSize); NMFClient nmf(rank ,iterations, fftSize, windowSize, hopSize);
//for each channels //for each channels
// for (int j=0;j<srcChanCount;j++){ for (int j=0;j<srcChanCount;j++){
// just processing the first input channel instead of iterating through each channel, yet keeping the mechanism in there.
for (int j=0;j<1;j++){
//copies and casts to double the source samples //copies and casts to double the source samples
FluidTensor<double,1> audio_in(in_view.col(j)); FluidTensor<double,1> 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) 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 //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) 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 //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) for (int i = 0; i < rank; ++i)
{ {
out_view.col(i) = nmf.activation(i); out_view.col(i + (j*rank)) = nmf.activation(i);
} }
} }
} }

@ -65,3 +65,26 @@ x.plot; y.plot;
[0,IFFT(chain)]; [0,IFFT(chain)];
}.play }.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})

Loading…
Cancel
Save