now with working stft return trip

nix
Pierre Alexandre Tremblay 8 years ago
parent fd45d2c38b
commit 22c21782aa

@ -33,14 +33,18 @@ void BufNMF(World *world, struct SndBuf *dstBuf, struct sc_msg_iter *msg)
Print("dstChanCount = %d\n",dstChanCount); Print("dstChanCount = %d\n",dstChanCount);
if (dstChanCount < rank) { // if (dstChanCount < rank) {
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;
} // }
// make a vector of doubles for the samples // make a vector of doubles for the samples
std::vector<double> tmp_vec(srcFrameCount); std::vector<double> tmp_vec(srcFrameCount);
//construct STFT processors
stft::STFT stft(1024, 2048, 256);
stft::ISTFT istft(1024, 2048, 256);
//for each channels //for each channels
for (int j=0;j<srcChanCount;j++){ for (int j=0;j<srcChanCount;j++){
//copies and casts to double the source samples //copies and casts to double the source samples
@ -48,23 +52,13 @@ void BufNMF(World *world, struct SndBuf *dstBuf, struct sc_msg_iter *msg)
tmp_vec[i] = srcBuf->data[(i*srcChanCount)+j]; tmp_vec[i] = srcBuf->data[(i*srcChanCount)+j];
} }
//dumb vector process with c++ syntax
for(double& value : tmp_vec){
value *= -1;
}
// //dumb vector process with c syntax
// for(int i=0;i<tmp_vec.size();i++){
// tmp_vec[i] *= -1;
// }
// fft and ifft for fun // fft and ifft for fun
// Spectrogram spec = stft.process(tmp_vec); stft::Spectrogram spec = stft.process(tmp_vec);
// std::vector<double> out_vec = istft.process(spec); std::vector<double> out_vec = istft.process(spec);
//writes the output //writes the output
for (int i=0;i<srcFrameCount;i++){ for (int i=0;i<srcFrameCount;i++){
dstBuf->data[(i*srcChanCount)+j] = (float)tmp_vec[i]; dstBuf->data[(i*srcChanCount)+j] = (float)out_vec[i];
} }
} }
} }

@ -1,17 +1,13 @@
s.quit s.quit
s.boot s.boot
// allocates a 16-sample buffer and fills it with ascending values // allocates a 16-sample buffer and fills it with ascending values
b = Buffer.alloc(s,16); b = Buffer.alloc(s,50000);
c = Buffer.alloc(s,16,5); b.sine1([0,0,0,0,0,0,0,0,0,1],true,false);
b.setn(0, Array.series(16,-8,1)); b.plot;
c = Buffer.alloc(s,50000);
// read to check
b.getn(0,16, {|msg| msg.postln});
c.getn(0,16, {|msg| msg.postln});
// run the code // run the code
b.fdNMF(c); b.fdNMF(c);
// read to check // read to check
b.getn(0,16, {|msg| msg.postln}); c.plot
c.getn(0,16, {|msg| msg.postln});
Loading…
Cancel
Save