00 /**********************************************************************
01 Copyright (c) 2014-2016 Mark C. Erickson
02
03 Permission is hereby granted, free of charge, to any person obtaining
04 a copy of this software and associated documentation files (the
05 "Software"), to deal in the Software without restriction, including
06 without limitation the rights to use, copy, modify, merge, publish,
07 distribute, sublicense, and/or sell copies of the Software, and to
08 permit persons to whom the Software is furnished to do so, subject to
09 the following conditions:
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 CHANGE LOG:
23 v1.1.0 - pan angle changed from 45->120
24 buflength changed from 20->72
25 v1.0.0 - initial release
26
27 **********************************************************************/
28
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