Pan, Binaural

Download

     Disclaimer...

29   desc:Pan, Binaural, v1.1.0
30  
31   slider1:0<-120,120,0.1>Pan Angle [degrees]
32  
33   @init
34   x=0;
35   x1=0;
36   x2=0;
37   y=0;
38   y1=0;
39   y2=0;
40   d=1.414;
41   who = 0;
42  
43   buf = 0; // buffer exists at offset 0
44   bufposR = 0;
45   delay = 0;
46   bufposW = delay;
47   buflength = 72;
48  
49   m = 1;
50   gainL = 0.707106781186547;
51   gainR = 0.707106781186547;
52  
53  
54   @slider
55   who = slider1;
56  
57   // lo pass pan
58   f = slider1 * 60/120; // 0 < f < 60
59   f > 0 ? f = f * -1; // -60 < f < 0
60   dd = pow(2, f/12.0)*16000; // 16,000 -> 500 Hz
61   w = 2.0 * $pi * dd / srate;
62   mBeta = 0.5 * (( 1.0 - d / 2.0 * sin(w) ) / ( 1.0 + d / 2.0 * sin(w) ));
63   mGamma = ( 0.5 + mBeta ) * cos(w);
64   mAlpha = ( 0.5 + mBeta - mGamma ) / 4.0;
65  
66   // delay pan
67   delay = slider1 * 72/120;
68   d1 = delay;
69   d1 < 0 ? d1 = d1 * -1; // absolute value
70   bufposR = bufposW - d1;
71   bufposR < 0 ? bufposR = bufPosR + buflength;
72  
73   // cos pan
74   m = slider1;
75   m = slider1 + 120;
76   m *= 90/240;
77   gainL = cos( m * $pi / 180.0 );
78   gainR = sin( m * $pi / 180.0 );
79  
80  
81   @sample
82   who == 0 ? (
83   spl0 *= gainL;
84   spl1 *= gainR;
85   ) : (
86   who < 0 ? (
87   x = spl1;
88   spl1 = buf[bufposR];
89   buf[bufposW] = x;
90   bufposR = bufposR + 1 ;
91   bufposR > buflength ? bufposR = 0;
92   bufposW = bufposW + 1 ;
93   bufposW > buflength ? bufposW = 0;
94  
95   x = spl1;
96   y = 2.0 * ( mAlpha * ( x + 2.0 * x1 + x2 ) + mGamma * y1 - mBeta * y2 );
97   x2 = x1;
98   x1 = x;
99   y2 = y1;
100   y1 = y;
101   spl1 = y * gainR;
102   spl0 *= gainL;
103  
104   ) : (
105   x = spl0;
106   spl0 = buf[bufposR];
107   buf[bufposW] = x;
108   bufposR = bufposR + 1 ;
109   bufposR > buflength ? bufposR = 0;
110   bufposW = bufposW + 1 ;
111   bufposW > buflength ? bufposW = 0;
112  
113   x = spl0;
114   y = 2.0 * ( mAlpha * ( x + 2.0 * x1 + x2 ) + mGamma * y1 - mBeta * y2 );
115   x2 = x1;
116   x1 = x;
117   y2 = y1;
118   y1 = y;
119   spl0 = y * gainL;
120   spl1 *= gainR;
121   );
122   );
123  

Download