{
   "is_private" : null,
   "id" : "1-4V1",
   "code" : "(\r\n// Set things up, and start the Synth\r\ns.waitForBoot {\r\n\tSynthDef(\\oscplayer,{ arg out = 0, bufnum;\r\n\t\tvar signal;\r\n\t\tsignal = Osc.ar(bufnum, MouseX.kr(60, 300));\r\n\t\tOut.ar(out, signal ! 2)\r\n\t}).add;\r\n\r\n\tz = { 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) };\r\n\ta = z ! 2;\r\n\t// a[0] is the start waveform, a[1] is the target to morph to...\r\n\ta.plot;\r\n\r\n\tc = a[0].asWavetable;\r\n\tb.free; b = Buffer.alloc(s, c.size);  // 1024: twice the size of the 512-element signal!\r\n\ts.sync;\r\n\tb.setn(0, c);\r\n\r\n\tx = Synth(\\oscplayer, [\\bufnum, b]);\r\n};\r\n)\r\n\r\n(\r\n// Do interpolation from one wave to another\r\nfork {\r\n\tvar fadeTime = 5; // seconds\r\n\tvar stepSize = 0.025; // seconds\r\n\tvar numSteps = fadeTime / stepSize;\r\n\t\"Fading...\".postln;\r\n\tnumSteps.do { arg i;\r\n\t\tvar interp = i / (numSteps - 1);\r\n\t\tvar interpSignal = a[0] * (1 - interp) + (a[1] * interp);\r\n\t\tb.setn(0, interpSignal.asWavetable);\r\n\t\t(fadeTime/numSteps).wait;\r\n\t};\r\n\t\"...done!\".postln;\r\n};\r\n)\r\n\r\n(\r\n// Generate a new target buffer, then run the fork above again to morph to new wave!\r\na[0] = a[1];\r\na[1] = z.value;\r\na.plot;\r\n)\r\n\r\nx.free; b.free;",
   "labels" : [
      "interpolate",
      "morph"
   ],
   "description" : "This is in response to a question on sc-users, with subject: [Envelope as signal](http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Envelope-as-signal-td7603680.html), about how to morph between two different Envelopes-as-wavetables...\r\n\r\nI 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)",
   "ancestor_list" : [],
   "author" : "totalgee",
   "name" : "Example of morphing (interpolating) between two Signals/Wavetables"
}
