PlayBufCF crossfading version of playbuf

part of wslib


PlayBufCF.ar(numChannels, bufnum, rate, trigger, startPos, loop, lag, n )


Arguments are the same as PlayBuf. But PlayBufCF makes a crossfade every time it is triggered. In order to do so it uses two PlayBufs internally uses equal power crossfades between them. Triggers can be audio or control rate.


lag: the crossfade duration in seconds (default: 0.1)

n: number of overlaps. The default (2) is enough if the lag time never exceeds the time between two triggers. If the n is set too low there is a chance of audible clicks. When using for example a lagtime of 1 and triggers happen every 0.5s, n should be set to 3. If n == 1 no crossfading will happen, and triggers will always result in clicks. n is not modulatable. Higher values for n use more cpu.


See also: PlayBuf



b = Buffer.read(s, "sounds/a11wlk01.wav"); // remember to free the buffer later.


(

z = SynthDef(\help_PlayBufCF, { | out = 0, bufnum = 0 |

Out.ar( out, 

PlayBufCF.ar(1, bufnum, BufRateScale.kr(bufnum), 

Impulse.kr(2), 

WhiteNoise.kr(1).range(0, BufFrames.kr(bufnum) - (0.5 * 44100) ) )

).dup

}).play(s, [\bufnum, b]);

)


z.free;


/// compare with PlayBuf:

(

y = SynthDef(\help_PlayBufCF2, { | out = 0, bufnum = 0 |

Out.ar( out, 

PlayBuf.ar(1,  bufnum, BufRateScale.kr(bufnum), 

Impulse.kr(2), 

WhiteNoise.kr(1).range(0, BufFrames.kr(bufnum) - (0.5 * 44100) ) )

).dup

}).play(s, [\bufnum, b]);

)


y.free;


/// also accepts Demand UGens:


(

x = SynthDef(\help_PlayBufCF3, { | out = 0, bufnum = 0, division = 80 |

Out.ar( out, 

PlayBufCF.ar(1, bufnum, BufRateScale.kr(bufnum), 

Dwhite(0.1, 0.3), 

Dbrown(0, 0.95, 0.1 ) * BufFrames.kr(bufnum)

).dup

)

}).play(s, [\bufnum, b]);

)


x.free;


(

x = SynthDef(\help_PlayBufCF3, { | out = 0, bufnum = 0, division = 80 |

Out.ar( out, 

PlayBufCF.ar(1, bufnum, 

Drand( (1..5) / 2, inf ), 

Dwhite(0.05, 0.2), 

Dbrown(0, 0.95, 0.1 ) * BufFrames.kr(bufnum),

lag: 0.05

).dup

)

}).play(s, [\bufnum, b]);

)


x.free;


(

x = SynthDef(\help_PlayBufCF3, { | out = 0, bufnum = 0, division = 80 |

Out.ar( out, 

PlayBufCF.ar(1, bufnum, 

2 ** Dbrown( -1, 1, 0.05 ), 

Dbrown( 0.01, 0.05, 0.01 ), 

Dseq( [ Dseries( 0, 0.002, 500 ) ], inf ) * BufFrames.kr(bufnum),

n: 10  // because the shortest possible trigger time is 0.01

).dup

)

}).play(s, [\bufnum, b]);

)


x.free;



b.free; // free buffer