diff --git a/mythtv/libs/libmythfreesurround/el_processor.cpp b/mythtv/libs/libmythfreesurround/el_processor.cpp
index 1cf0dc8..7073d6d 100644
a
|
b
|
along with this program; if not, write to the Free Software |
16 | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 | */ |
18 | 18 | |
| 19 | #include "../libmyth/mythconfig.h" |
19 | 20 | #include "el_processor.h" |
20 | 21 | #include <cstdlib> |
21 | 22 | #include <cstring> |
… |
… |
extern "C" { |
31 | 32 | typedef FFTSample FFTComplexArray[2]; |
32 | 33 | #endif |
33 | 34 | |
| 35 | // use inline asm trig on x86_32/64 |
| 36 | #ifdef ARCH_X86 |
| 37 | #include "imath.h" |
| 38 | #define SQRT isqrtf |
| 39 | #define SIN isin |
| 40 | #define COS icos |
| 41 | #define TAN itan |
| 42 | #define ASIN iasin |
| 43 | #define ATAN2 iatan2f |
| 44 | #else |
| 45 | #define SQRT sqrt |
| 46 | #define SIN sin |
| 47 | #define COS cos |
| 48 | #define TAN tan |
| 49 | #define ASIN asin |
| 50 | #define ATAN2 atan2 |
| 51 | #endif |
34 | 52 | |
35 | 53 | #ifdef USE_FFTW3 |
36 | 54 | #pragma comment (lib,"libfftw3f-3.lib") |
… |
… |
typedef std::complex<float> cfloat; |
40 | 58 | |
41 | 59 | const float PI = 3.141592654; |
42 | 60 | const float epsilon = 0.000001; |
43 | | const float center_level = 0.5*sqrt(0.5); |
| 61 | const float center_level = 0.5*SQRT(0.5); |
44 | 62 | |
45 | 63 | // private implementation of the surround decoder |
46 | 64 | class decoder_impl { |
… |
… |
public: |
177 | 195 | unsigned int cutoff = (30*N)/srate; |
178 | 196 | for (unsigned f=0;f<=halfN;f++) { |
179 | 197 | if (f<cutoff) |
180 | | filter[5][f] = 0.5*sqrt(0.5); |
| 198 | filter[5][f] = 0.5*SQRT(0.5); |
181 | 199 | else |
182 | 200 | filter[5][f] = 0.0; |
183 | 201 | } |
… |
… |
public: |
214 | 232 | |
215 | 233 | private: |
216 | 234 | // polar <-> cartesian coodinates conversion |
217 | | static inline float amplitude(const float cf[2]) { return sqrt(cf[0]*cf[0] + cf[1]*cf[1]); } |
218 | | static inline float phase(const float cf[2]) { return atan2(cf[1],cf[0]); } |
| 235 | static inline float amplitude(const float cf[2]) { return SQRT(cf[0]*cf[0] + cf[1]*cf[1]); } |
| 236 | static inline float phase(const float cf[2]) { return ATAN2(cf[1],cf[0]); } |
| 237 | #ifdef ARCH_X86 |
| 238 | static inline cfloat polar(float a, float p) { |
| 239 | float sc[2]; |
| 240 | isincosf(p, sc); |
| 241 | return cfloat(a*sc[0],a*sc[1]); |
| 242 | } |
| 243 | #else |
219 | 244 | static inline cfloat polar(float a, float p) { return cfloat(a*cos(p),a*sin(p)); } |
| 245 | #endif |
220 | 246 | static inline float sqr(float x) { return x*x; } |
221 | 247 | // the dreaded min/max |
222 | 248 | static inline float min(float a, float b) { return a<b?a:b; } |
… |
… |
private: |
377 | 403 | inline double get_yfs(double ampDiff, double phaseDiff) { |
378 | 404 | double x = 1-(((1-sqr(ampDiff))*phaseDiff)/PI*2); |
379 | 405 | #ifdef FASTER_CALC |
380 | | double tanX = tan(x); |
| 406 | double tanX = TAN(x); |
381 | 407 | return 0.16468622925824683 + 0.5009268347818189*x - 0.06462757726992101*x*x |
382 | 408 | + 0.09170680403453149*x*x*x + 0.2617754892323973*tanX - 0.04180413533856156*sqr(tanX); |
383 | 409 | #else |
… |
… |
private: |
390 | 416 | inline double get_xfs(double ampDiff, double yfs) { |
391 | 417 | double x=ampDiff,y=yfs; |
392 | 418 | #ifdef FASTER_CALC |
393 | | double tanX = tan(x); |
394 | | double tanY = tan(y); |
395 | | double asinX = asin(x); |
396 | | double sinX = sin(x); |
397 | | double sinY = sin(y); |
| 419 | double tanX = TAN(x); |
| 420 | double tanY = TAN(y); |
| 421 | double asinX = ASIN(x); |
| 422 | double sinX = SIN(x); |
| 423 | double sinY = SIN(y); |
398 | 424 | double x3 = x*x*x; |
399 | 425 | double y2 = y*y; |
400 | 426 | double y3 = y*y2; |
diff --git a/mythtv/libs/libmythfreesurround/imath.h b/mythtv/libs/libmythfreesurround/imath.h
new file mode 100644
index 0000000..86f04c6
-
|
+
|
|
| 1 | static inline double icos(double x) |
| 2 | { |
| 3 | double y; |
| 4 | asm ( |
| 5 | "fldl %1\n\t" |
| 6 | "fcos \n\t" |
| 7 | :"=&t"(y):"m"(x) |
| 8 | ); |
| 9 | return y; |
| 10 | } |
| 11 | |
| 12 | static inline float icosf(float x) |
| 13 | { |
| 14 | float y; |
| 15 | asm ( |
| 16 | "flds %1\n\t" |
| 17 | "fcos \n\t" |
| 18 | :"=&t"(y):"m"(x) |
| 19 | ); |
| 20 | return y; |
| 21 | } |
| 22 | |
| 23 | static inline double isin(double x) |
| 24 | { |
| 25 | double y; |
| 26 | asm ( |
| 27 | "fldl %1\n\t" |
| 28 | "fsin \n\t" |
| 29 | :"=&t"(y):"m"(x) |
| 30 | ); |
| 31 | return y; |
| 32 | } |
| 33 | |
| 34 | static inline float isinf(float x) |
| 35 | { |
| 36 | float y; |
| 37 | asm ( |
| 38 | "flds %1\n\t" |
| 39 | "fsin \n\t" |
| 40 | :"=&t"(y):"m"(x) |
| 41 | ); |
| 42 | return y; |
| 43 | } |
| 44 | |
| 45 | static inline double itan(double x) |
| 46 | { |
| 47 | double y; |
| 48 | asm ( |
| 49 | "fldl %1\n\t" |
| 50 | "fptan \n\t" |
| 51 | "fstp %%st(0)\n\t" |
| 52 | :"=&t"(y):"m"(x) |
| 53 | ); |
| 54 | return y; |
| 55 | } |
| 56 | |
| 57 | static inline float itanf(float x) |
| 58 | { |
| 59 | float y; |
| 60 | asm ( |
| 61 | "flds %1\n\t" |
| 62 | "fptan \n\t" |
| 63 | :"=&t"(y):"m"(x) |
| 64 | ); |
| 65 | return y; |
| 66 | } |
| 67 | |
| 68 | static inline double *isincos(double x, double *ptr) |
| 69 | { |
| 70 | double *ptr2 = ptr + 1; |
| 71 | asm ( |
| 72 | "fldl %2\n\t" |
| 73 | "fsincos \n\t" |
| 74 | "fstpl %0\n\t" |
| 75 | "fstpl %1\n\t" |
| 76 | :"=m"(*ptr),"=m"(*ptr2):"m"(x) |
| 77 | ); |
| 78 | return ptr; |
| 79 | } |
| 80 | |
| 81 | static inline float *isincosf(float x, float *ptr) |
| 82 | { |
| 83 | float *ptr2 = ptr + 1; |
| 84 | asm ( |
| 85 | "flds %2\n\t" |
| 86 | "fsincos \n\t" |
| 87 | "fstps %0\n\t" |
| 88 | "fstps %1\n\t" |
| 89 | :"=m"(*ptr),"=m"(*ptr2):"m"(x) |
| 90 | ); |
| 91 | return ptr; |
| 92 | } |
| 93 | |
| 94 | static inline double iasin(double x) |
| 95 | { |
| 96 | double y; |
| 97 | asm ( |
| 98 | "fldl %1\n\t" |
| 99 | "fld %%st\n\t" |
| 100 | "fmul %%st(0)\n\t" |
| 101 | "fld1 \n\t" |
| 102 | "fsubp \n\t" |
| 103 | "fsqrt \n\t" |
| 104 | "fpatan \n\t" |
| 105 | :"=&t"(y):"m"(x) |
| 106 | ); |
| 107 | return y; |
| 108 | } |
| 109 | |
| 110 | static inline float iasinf(float x) |
| 111 | { |
| 112 | float y; |
| 113 | asm ( |
| 114 | "flds %1\n\t" |
| 115 | "fld %%st\n\t" |
| 116 | "fmul %%st(0)\n\t" |
| 117 | "fld1 \n\t" |
| 118 | "fsubp \n\t" |
| 119 | "fsqrt \n\t" |
| 120 | "fpatan \n\t" |
| 121 | :"=&t"(y):"m"(x) |
| 122 | ); |
| 123 | return y; |
| 124 | } |
| 125 | |
| 126 | static inline double iatan2(double x, double y) |
| 127 | { |
| 128 | double z; |
| 129 | asm ( |
| 130 | "fldl %1\n\t" |
| 131 | "fldl %2\n\t" |
| 132 | "fpatan \n\t" |
| 133 | :"=&t"(z):"m"(x),"m"(y) |
| 134 | ); |
| 135 | return z; |
| 136 | } |
| 137 | |
| 138 | static inline float iatan2f(float x, float y) |
| 139 | { |
| 140 | float z; |
| 141 | asm ( |
| 142 | "flds %1\n\t" |
| 143 | "flds %2\n\t" |
| 144 | "fpatan \n\t" |
| 145 | :"=&t"(z):"m"(x),"m"(y) |
| 146 | ); |
| 147 | return z; |
| 148 | } |
| 149 | |
| 150 | static inline double isqrt(double x) |
| 151 | { |
| 152 | double y; |
| 153 | asm ( |
| 154 | "fldl %1\n\t" |
| 155 | "fsqrt \n\t" |
| 156 | :"=&t"(y):"m"(x) |
| 157 | ); |
| 158 | return y; |
| 159 | } |
| 160 | |
| 161 | static inline float isqrtf(float x) |
| 162 | { |
| 163 | float y; |
| 164 | asm ( |
| 165 | "flds %1\n\t" |
| 166 | "fsqrt \n\t" |
| 167 | :"=&t"(y):"m"(x) |
| 168 | ); |
| 169 | return y; |
| 170 | } |