// title: Wave Field Synthesis // author: miguel.negrao // description: // A simple synthdef for Wave Field Synthesis rendering. // code: /* The basic principles of WFS are very simple: 1 - calculate distance from virtual source to each speaker. 2 - calculate time that sound takes to travel that distance t = d/340. 3 - calculate amplitude decay due to that distance a = 1/d 4 - delay sound by the delay time and multiply by amplitude. */ // your speaker positions p = 112.collect{ |i| Point(i.linlin(0,111,-10.0,10.0), 5) }; // now go, buy 112 speakers and play this synthdef :-) ( SynthDef(\minimalWFS,{ var excitation = Dust.ar(20) * 0.2; var in = Klank.ar(`[20.collect{ exprand(100,3000) }], excitation); var x = MouseX.kr(-20,20); var y = MouseY.kr(-30,5); //this is in meters. var max = 2 ** ( (3 * 44100).log2.roundUp(1).max(0) ); var buf = LocalBuf(max,1).clear; var dists = p.collect{ |point| Point(x,y).dist(point) }; var delayTimes = dists / 340; var amps = dists.collect{ |d| d.reciprocal.min(1.0) }; var delays = BufDelayL.ar(buf, in, delayTimes); Out.ar(0, delays * amps ) }).play )