[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] Crossfade between buffers in Audio-visuals
hi,
try the example below. it's using Synth (together with SynthDef) and show how to do precise crossfading between buffer players.
whenever a message arrive we start the fade out the current synth by setting its envelope's gate to 0. we also set release time and release curvature of the fade out. at the same time we create a new synth and fade that in with whatever attack time and curvature that will fit that buffer.
Ndef will also work but it's a different working method (kind of combination of Synth and SynthDef). usually you'll want to pick one and not mix the two ways of working.
s.boot;
(
SynthDef(\playbuf_test, {|out= 0, gate= 1, buf, amp= 1, rate= 1, attackTime= 1, releaseTime= 2, attackCurve= -3, releaseCurve= 3|
var env= EnvGen.ar(Env.asr(attackTime, 1, releaseTime, [attackCurve, releaseCurve]), gate, doneAction: 2);
var snd= PlayBuf.ar(2, buf, rate, loop: 1);
Out.ar(out, snd*amp*env);
}).add;
d= (
\buf0: Buffer.read(s, "path/to/a/stereofile"),
\buf1: Buffer.read(s, "path/to/a/stereofile"),
\buf2: Buffer.read(s, "path/to/a/stereofile"),
//etc.
);
)
(
var synth; //keep track of current synth
OSCdef(\keyPressedListener, {|msg|
msg.postln;
if(msg[1] == 'kitchen'){
//here you can set attack and release times as well as different curvatures
//curve= 0 will result in a linear fade
synth.set(\releaseTime, 3, \releaseCurve, 3, \gate, 0); //release current synth node
synth= Synth.new(\playbuf_test, [\buf, d.buf0, \rate, -1.midiratio, \amp, 0.8, \attackTime, 3, \attackCurve, -3]);
};
if(msg[1] == 'island'){ //make symbol ' ' not string ""
synth.set(\releaseTime, 2, \releaseCurve, 4, \gate, 0);
synth= Synth.new(\playbuf_test, [\buf, d.buf1, \rate, -1.midiratio, \amp, 0.4, \attackTime, 2, \attackCurve, -4]);
};
if(msg[1] == 'aurora'){
synth.set(\releaseTime, 3, \releaseCurve, 3, \gate, 0);
synth= Synth.new(\playbuf_test, [\buf, d.buf2, \rate, -1.midiratio, \amp, 1, \attackTime, 3, \attackCurve, -3]);
};
if(msg[1] == 'night_sky'){
synth.set(\releaseTime, 3, \releaseCurve, 4, \gate, 0);
synth= Synth.new(\playbuf_test, [\buf, d.buf7, \rate, -2.midiratio, \amp, 1, \attackTime, 3, \attackCurve, -4]);
};
if(msg[1] == 'stars'){
synth.set(\releaseTime, 5, \releaseCurve, 4, \gate, 0);
synth= Synth.new(\playbuf_test, [\buf, d.buf8, \amp, 0.4, \attackTime, 5, \releaseCurve, -4]);
};
if(msg[1] == 'volcano+kitchen'){
synth.set(\releaseTime, 3, \releaseCurve, 4, \gate, 0);
synth= Synth.new(\playbuf_test, [\buf, d.buf9, \rate, -2.midiratio, \amp, 1, \attackTime, 3, \attackCurve, -4]);
}
}, 'keyPressed'))
experiment with attack and release times as well as different curvatures.
//test plot curves
Env.asr(0.5, 1, 1.5, [-4, 4]).plot //-4 is attack, 4 release
good luck,
_f
> 26 dec. 2018 kl. 21:23 skrev aslikobaner82@xxxxxxxxx:
>
> Hi All,
>
> I'm a novice supercollider user currently working on an audio-visual prototype. I established an OSC connection between processing and supercollider in which I assigned a number of images to an array of specified audio buffers. The images are triggered by keyboard. The only problem is, I'm having a hard time to manage the duration of the buffers triggered by the subtle image changes (when the assigned image changes, so should the related buffer fade out) and sounds jumble into each other. I tried using Ndef outside the OSC but that did not work either. I'd appreciate very much if any of you could give me an idea, a relatively easy idea for a beginner supercollider user.
> Thanks in advance,
> Best.
>
> Asli
>
>
> Here's a part from my OSCdef:
>
> (
> OSCdef(\keyPressedListener, {|msg|
> msg.postln;
> if(msg[1] == 'kitchen'){
> Synth.new(\playbuf_test, [\buf, d.buf0, \rate, -1.midiratio, \amp, 0.8]);
>
> };
> if(msg[1] == 'island'){ //make symbol ' ' not string ""
> Synth.new(\playbuf_test, [\buf, d.buf1, \rate, -1.midiratio, \amp, 0.4]);
> };
> if(msg[1] == 'aurora'){
>
> Synth.new(\playbuf_test, [\buf, d.buf2, \rate, -1.midiratio, \amp, 1]);
> };
> if(msg[1] == 'night_sky'){
> Ndef(\playbuf_test).fadeTime = 2;
> Synth.new(\playbuf_test, [\buf, d.buf7, \rate, -2.midiratio, \amp, 1]);
>
> };
>
> if(msg[1] == 'stars'){
> Synth.new(\playbuf_test, [\buf, d.buf8, \amp, 0.4]);
> };
> if(msg[1] == 'volcano+kitchen'){
>
> Synth.new(\playbuf_test, [\buf, d.buf9, \rate, -2.midiratio, \amp, 1]);
> }
> }, 'keyPressed'))
>
> Ndef(\playbuf_test).fadeTime = 2;
#|
fredrikolofsson.com musicalfieldsforever.com
|#
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/