1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2004-2009 Fons Adriaensen <fons@kokkinizita.net>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // -----------------------------------------------------------------------------
20
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <math.h>
25 #include "virtmic.h"
26
27
28 #define TWOPI 6.283185f
29
30
Virtmic(void)31 Virtmic::Virtmic (void) :
32 _azim (0),
33 _azim1 (0),
34 _elev (0),
35 _elev1 (0),
36 _angle (0),
37 _angle1 (0),
38 _direc (0),
39 _direc1 (0),
40 _csw (0),
41 _csx (0),
42 _csy (0),
43 _csz (0),
44 _cdx (0),
45 _cdy (0)
46 {
47 }
48
49
~Virtmic(void)50 Virtmic::~Virtmic (void)
51 {
52 }
53
54
process(int n,float * W,float * X,float * Y,float * Z,float * L,float * R)55 void Virtmic::process (int n, float *W, float *X, float *Y, float *Z, float *L, float *R)
56 {
57 int i, k;
58 float w, dw, x, dx, y, dy, z, dz;
59 float ca, sa, ce, se, cv, sv;
60 float S [80];
61 float D [80];
62
63 while (n)
64 {
65 k = (n > 80) ? 64 : n;
66 if ( circheck (_azim, _azim1)
67 + lincheck (_elev, _elev1)
68 + lincheck (_angle, _angle1)
69 + lincheck (_direc, _direc1))
70 {
71 ca = cosf (TWOPI * _azim);
72 sa = sinf (TWOPI * _azim);
73 ce = cosf (TWOPI * _elev);
74 se = sinf (TWOPI * _elev);
75 cv = cosf (TWOPI * _angle);
76 sv = sinf (TWOPI * _angle);
77
78 w = _csw;
79 x = _csx;
80 y = _csy;
81 z = _csz;
82 dw = diff (k, w, _csw = 0.707107f * (1 - _direc));
83 dx = diff (k, x, _csx = _direc * ca * ce * cv);
84 dy = diff (k, y, _csy = _direc * sa * ce * cv);
85 dz = diff (k, z, _csz = _direc * cv * se);
86 for (i = 0; i < k; i++)
87 {
88 w += dw;
89 x += dx;
90 y += dy;
91 z += dz;
92 S [i] = w * W [i] + x * X [i] + y * Y [i] + z * Z [i];
93 }
94
95 x = _cdx;
96 y = _cdy;
97 dx = diff (k, x, _cdx = -_direc * sa * sv);
98 dy = diff (k, y, _cdy = _direc * ca * sv);
99 for (i = 0; i < k; i++)
100 {
101 x += dx;
102 y += dy;
103 D [i] = x * X [i] + y * Y [i];
104 }
105 }
106 else
107 {
108 for (i = 0; i < k; i++)
109 {
110 S [i] = _csw * W [i] + _csx * X [i] + _csy * Y [i] + _csz * Z [i];
111 D [i] = _cdx * X [i] + _cdy * Y [i];
112 }
113 }
114
115 for (i = 0; i < k; i++)
116 {
117 *L++ = S [i] + D [i];
118 *R++ = S [i] - D [i];
119 }
120
121 W += k;
122 X += k;
123 Y += k;
124 Z += k;
125 n -= k;
126 }
127 }
128
129