«Wave Field Synthesis» by miguel.negrao

on 14 Dec'12 23:41 in wfsspatializationwave field synthesis

A simple synthdef for Wave Field Synthesis rendering.

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
/*
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
)
raw 1122 chars (focus & ctrl+a+c to copy)
reception
comments