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);
if (dstChanCount < rank) {
Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
return;
}
// if (dstChanCount < rank) {
// Print("fdNMF is not happy because the destination buffer has a lower channel count than the number of ranks.\n");
// return;
// }
// make a vector of doubles for the samples
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 (int j=0;j<srcChanCount;j++){
//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];
}
//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
// Spectrogram spec = stft.process(tmp_vec);
// std::vector<double> out_vec = istft.process(spec);
stft::Spectrogram spec = stft.process(tmp_vec);
std::vector<double> out_vec = istft.process(spec);
//writes the output
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.boot
// allocates a 16-sample buffer and fills it with ascending values
b = Buffer.alloc(s,16);
c = Buffer.alloc(s,16,5);
b.setn(0, Array.series(16,-8,1));
// read to check
b.getn(0,16, {|msg| msg.postln});
c.getn(0,16, {|msg| msg.postln});
b = Buffer.alloc(s,50000);
b.sine1([0,0,0,0,0,0,0,0,0,1],true,false);
b.plot;
c = Buffer.alloc(s,50000);
// run the code
b.fdNMF(c);
// read to check
b.getn(0,16, {|msg| msg.postln});
c.getn(0,16, {|msg| msg.postln});
c.plot
Loading…
Cancel
Save