«Example of morphing (interpolating) between two Signals/Wavetables» by totalgee
on 12 Oct'13 18:24 inThis is in response to a question on sc-users, with subject: Envelope as signal, about how to morph between two different Envelopes-as-wavetables...
I tried to do one with double-buffering and cross-fading between the two buffers using XFade2.ar, but it gave me a sort of "pulsing" effect. You even get this when doing XFade2 between two versions of the same signal! But, fortunately, single-buffering seems to work fine. The changes to any given sample in the Signal/Wavetable are small at any iteration, so you don't hear any noise or clicking. (you would if you had too few steps in the interpolation, but even with 20-50 steps, it seems noise-free)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
( // Set things up, and start the Synth s.waitForBoot { SynthDef(\oscplayer,{ arg out = 0, bufnum; var signal; signal = Osc.ar(bufnum, MouseX.kr(60, 300)); Out.ar(out, signal ! 2) }).add; z = { Env([0] ++ rrand(-0.5, 0.5!5) ++ 0, [0.1, 0.2, 0.05, 0.3, 0.4, 0.1].scramble, \sin).asSignal(512) }; a = z ! 2; // a[0] is the start waveform, a[1] is the target to morph to... a.plot; c = a[0].asWavetable; b.free; b = Buffer.alloc(s, c.size); // 1024: twice the size of the 512-element signal! s.sync; b.setn(0, c); x = Synth(\oscplayer, [\bufnum, b]); }; ) ( // Do interpolation from one wave to another fork { var fadeTime = 5; // seconds var stepSize = 0.025; // seconds var numSteps = fadeTime / stepSize; "Fading...".postln; numSteps.do { arg i; var interp = i / (numSteps - 1); var interpSignal = a[0] * (1 - interp) + (a[1] * interp); b.setn(0, interpSignal.asWavetable); (fadeTime/numSteps).wait; }; "...done!".postln; }; ) ( // Generate a new target buffer, then run the fork above again to morph to new wave! a[0] = a[1]; a[1] = z.value; a.plot; ) x.free; b.free;
reception
comments