hey,
i was trying to apply the VOsc Style Buffer Crossfading idea from this thread: Crossfade between Buffers with BufRd Vosc style - #2 by jamshark70
to the example Ex.1h: Buffer granulation with (half) wavesets: TZeroXBufRd from the https://github.com/dkmayer/miSCellaneous_lib for the granulation of half-wavesets and additional buffer crossfading. In the Example Ex.1h the Phasor for the position in the buffer gets multiplied by the number of zero crossings zeroXNum
, which is analysed by the function ~get_zeroX_nums
for in this case three different arbitary waveforms analysed and written to buffers. When zeroXNum
differs for each buffer, im wondering how i can crossfade between the buffers (which is already working fine without granulation) and the right zeroXnum
is picked from the array each time?
any ideas ? anyone else using TZeroXBufRd? thanks a lot
// prepare 3 buffers
(
b = { Buffer.alloc(s, 1000, 1) } ! 3;
z = { Buffer.alloc(s, 100, 1) } ! 3;
)
// fill with basic waveforms
(
{
var src = [
LFSaw.ar(100),
SinOsc.ar(200),
LFTri.ar(400),
];
ZeroXBufWr.ar(src, b, z, startWithZeroX: 1, doneAction: 2);
Silent.ar
}.play
)
b[0].plot;
b[1].plot;
b[2].plot;
// function for getting zero crossings for each buffer
(
~get_zeroX_nums = {|sndBufArray, zeroXBufArray|
var size = sndBufArray.size;
var zeroXNum = Array.fill(size);
var zeroXs = Array.fill(size);
fork {
// adjust from lang and get zeroXs
sndBufArray.do({|bufnum, i|
bufnum.adjustZeroXs(zeroXBufArray[i], { |z| zeroXs[i] = z.reject(_==0) });
});
s.sync;
// get number of zeroXs
zeroXs.do({|bufnum, i|
zeroXNum[i] = bufnum.size;
});
s.sync;
zeroXNum.postln;
};
zeroXNum;
};
)
// get number of zero crossings for each buffer
~zeroXNum = ~get_zeroX_nums.(b, z);
// crossfade between different buffers Vosc style + Ex.1h granulation of half-wavesets
(
SynthDef(\zeroX, {
arg sndBuf=0, zeroXBuf=0, trigRate=100,
posLo=0.01, posHi=0.99, posRateE=1, posRateM=0.1, rate=1, xNum=1, xRep=1;
var mod, evenIndex, oddIndex;
var sig, posRate, bufDur, pos;
var trig = Impulse.ar(trigRate);
//var zeroXNum = Array.fill(3, \zeroXNum.kr(0));
var zeroXNum = \zeroXNum.kr(0);
mod = SinOsc.kr(0.1).range(0, 2);
evenIndex = min(2.999, mod.round(2));
oddIndex = mod.trunc(2) + 1;
posRate = 10 ** posRateE * posRateM;
bufDur = BufDur.kr(sndBuf);
pos = Phasor.ar(
0,
BufRateScale.kr(sndBuf) * posRate * SampleDur.ir / bufDur,
posLo,
posHi
) * ( zeroXNum + [evenIndex, oddIndex] ); // how do you apply the right zeroXNum for the current buffer / crossfade between the zeroXNums?
sig = TZeroXBufRd.ar(
sndBuf: sndBuf + [evenIndex, oddIndex],
zeroXBuf: zeroXBuf + [evenIndex, oddIndex],
trig: trig,
zeroX: 0, //use "pos" instead of "0" for granulation of half-wavesets
xNum: xNum,
xRep: xRep,
rate: rate,
overlapSize: 20,
);
sig = XFade2.ar(sig[0], sig[1], mod.fold(0, 1) * 2 - 1);
sig = LeakDC.ar(sig);
sig = Pan2.ar(sig, \pan.kr(0), \amp.kr(0.25));
Out.ar(\out.kr(0), sig);
}).add;
)
(
x = Synth(\zeroX, [
\amp, 0.5,
\trigRate, 100,
\posHi, 0.01,
\posLo, 0.99,
\posRateE, 1,
\posRateM, 0.1,
\xNum, 2,
\xRep, 2,
\rate, 1,
\sndBuf, b.first,
\zeroXBuf, z.first,
\zeroXNum, ~zeroXNum.first
]);
)
s.scope(2);
x.free;