I was checking this nice short video by @elifieldsteel about PV_PlayBuf and PV_RecordBuf. In the example the source signal is first analyzed and when the analysis is done, the fun begins.
I am trying to do a real time version and it is almost working but I got some issues with initialization. Any ideas about what is going on? These classes are new to me, so there might be something obvious I overlooked. I also realize that they were not necessarily intended for real time use, but but but…
(
s.waitForBoot{
SynthDef(\pv, {
var in = In.ar(\in.kr(0), 1);
var recBuf = \recBuf.kr(0);
var pvBuf = \pvBuf.kr(0);
var rec = RecordBuf.ar(in, recBuf, loop: 1);
var sig = PlayBuf.ar(1, recBuf, BufRateScale.kr(b), loop: 1);
var localbuf = LocalBuf.new(8192);
var chain = FFT(localbuf, sig, hop: 0.25);
chain = PV_RecordBuf(chain, pvBuf, run: 1, hop: 0.25, loop: 1);
chain = PV_PlayBuf(localbuf, pvBuf, \rate.kr(1), loop: 1);
sig = IFFT(chain);
Out.ar(\out.kr(0), sig!2)
}).add;
~buf = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
s.sync;
~recBuf = Buffer.alloc(s, ~buf.duration * s.sampleRate);
s.sync;
~pvBuf = Buffer.alloc(s, ~buf.duration.calcPVRecSize(8192, 0.25));
s.sync;
~bus = Bus.audio(s, 1);
~sig = { Out.ar(~bus, PlayBuf.ar(1, ~buf, loop: 1)) }.play; // silent output at first
}
)
// now, first time I try to instantiate the synth, I get this error
//....//
// WARNING: There is a mismatch between the PV databuffer you are using and this instance of PV_PlayBuf
// FFT size of databuf: 0.000000
// FFT size of current process: 8192.000000
// sometimes I also get 'Bad values' messages
// ..... ////
// WATCHED THE VOLUME, the playback is wrong and choppy
~syn = Synth(\pv, [recBuf: ~recBuf, pvBuf: ~pvBuf, in: ~bus], addAction: 'addToTail')
( // BUT, after freeing the synth and trying again, it works as suspected without error messages
~syn.free;
~syn = Synth(\pv, [recBuf: ~recBuf, pvBuf: ~pvBuf, in: ~bus], addAction: 'addToTail')
)
//...and we can set the rate
~syn.set(\rate, 0.1) // very slow
~syn.set(\rate, 0) // spectral freeze
~syn.set(\rate, -0.3) // reversed