thank you so much also for the additional explanations. Im so happy
i think instead of ~recBufs.add(subfolder.folderName.asSymbol
it should be ~buffers.add(subfolder.folderName.asSymbol
ive adjusted the code with ~rate
from this example PV Ugens and DXEnvFan (miSCellaneous) - #6 by dkmayer so you have each analysed Buffer with 12 different rates for playing back with PV_BufRd.
The syntax for a Pbind would be \buf, ~buffers[*\subfoldername*][*index of buffer*][\pvRecBuf][*index of playbackrate*],
see the code below, i hope my implementation is correct. I have tested it with
~buffers[*\subfoldername*][*index of buffer*][\pvRecBuf][*index of playbackrate*].numFrames;
for the different playbackrates and it was working nicely.
(
// path to a sound file here
~path = PathName(thisProcess.nowExecutingPath).parentPath ++ "buffers/";
// the frame size for the analysis - experiment with other sizes (powers of 2)
~windowSize = 1024;
// the hop size
~hopSize = 0.25;
// Hann window
~winType = 1;
//different playback rates
~rates = (1..12) * 0.1 + 0.4;
~buffers = Dictionary.new;
PathName(~path).entries.do {
arg subfolder;
var soundfile, data, rates;
~buffers.add(
subfolder.folderName.asSymbol ->
Array.fill(
subfolder.entries.size,
{
arg i;
// read size of Soundfiles
soundfile = SoundFile.openRead(subfolder.entries[i].fullPath);
protect {
(
pvRecBuf: ~rates.collect { |rate, i|
Buffer.alloc(s, (soundfile.duration / rate).calcPVRecSize(~windowSize, ~hopSize))
},
sndBuf: Buffer.read(s, subfolder.entries[i].fullPath)
)
} { |err|
if(err.notNil) {
"Error opening '%'".format(subfolder.entries[i].fullPath.basename).warn;
};
soundfile.close
};
}
);
);
};
// this does the analysis and saves it to ~recBufs... frees itself when done (in addition uses rate)
SynthDef(\pvrec_2, {
arg recBuf, soundBufnum, rate = 1;
var in, chain;
Line.kr(1, 1, BufDur.kr(soundBufnum) / rate, doneAction: 2);
in = PlayBuf.ar(1, soundBufnum, rate * BufRateScale.kr(soundBufnum), loop: 0);
chain = FFT(LocalBuf(~windowSize), in, ~hopSize, ~winType);
chain = PV_RecordBuf(chain, recBuf, 0, 1, 0, ~hopSize, ~winType);
}).add;
)
(
~buffers.do { |subdirArray|
subdirArray.do { |buf|
~rates.do { |rate, i|
Synth(\pvrec_2, [
\recBuf, buf.pvRecBuf[i],
\soundBufnum, buf.sndBuf,
\rate, rate
]);
};
};
};
)