Mercurial > audlegacy
annotate Plugins/Input/aac/libfaad2/fixed.h @ 1010:29feaace84d0 trunk
[svn] - synchronize audacious-faad with FAAD2 CVS.
author | nenolod |
---|---|
date | Mon, 08 May 2006 06:56:47 -0700 |
parents | 0a2ad94e8607 |
children | 1e6c0a3f2d15 |
rev | line source |
---|---|
61 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
61 | 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
1010 | 25 ** $Id: fixed.h,v 1.18 2004/01/28 19:17:25 menno Exp $ |
61 | 26 **/ |
27 | |
28 #ifndef __FIXED_H__ | |
29 #define __FIXED_H__ | |
30 | |
31 #ifdef __cplusplus | |
32 extern "C" { | |
33 #endif | |
34 | |
1010 | 35 #ifdef _WIN32_WCE |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
36 #include <cmnintrin.h> |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
37 #endif |
61 | 38 |
39 #define COEF_BITS 28 | |
40 #define COEF_PRECISION (1 << COEF_BITS) | |
41 #define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR | |
42 #define REAL_PRECISION (1 << REAL_BITS) | |
43 | |
44 /* FRAC is the fractional only part of the fixed point number [0.0..1.0) */ | |
45 #define FRAC_SIZE 32 /* frac is a 32 bit integer */ | |
46 #define FRAC_BITS 31 | |
47 #define FRAC_PRECISION ((uint32_t)(1 << FRAC_BITS)) | |
48 #define FRAC_MAX 0x7FFFFFFF | |
49 | |
50 typedef int32_t real_t; | |
51 | |
52 | |
53 #define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5))) | |
54 #define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5))) | |
55 #define FRAC_CONST(A) (((A) == 1.00) ? ((real_t)FRAC_MAX) : (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5)))) | |
56 | |
57 #if defined(_WIN32) && !defined(_WIN32_WCE) | |
58 | |
59 /* multiply with real shift */ | |
60 static INLINE real_t MUL_R(real_t A, real_t B) | |
61 { | |
62 _asm { | |
63 mov eax,A | |
64 imul B | |
65 shrd eax,edx,REAL_BITS | |
66 } | |
67 } | |
68 | |
69 /* multiply with coef shift */ | |
70 static INLINE real_t MUL_C(real_t A, real_t B) | |
71 { | |
72 _asm { | |
73 mov eax,A | |
74 imul B | |
75 shrd eax,edx,COEF_BITS | |
76 } | |
77 } | |
78 | |
79 static INLINE real_t _MulHigh(real_t A, real_t B) | |
80 { | |
81 _asm { | |
82 mov eax,A | |
83 imul B | |
84 mov eax,edx | |
85 } | |
86 } | |
87 | |
88 /* multiply with fractional shift */ | |
89 static INLINE real_t MUL_F(real_t A, real_t B) | |
90 { | |
91 return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS); | |
92 } | |
93 | |
94 /* Complex multiplication */ | |
95 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
96 real_t x1, real_t x2, real_t c1, real_t c2) | |
97 { | |
98 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
99 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
100 } | |
101 | |
102 #elif defined(__GNUC__) && defined (__arm__) | |
103 | |
104 /* taken from MAD */ | |
105 #define arm_mul(x, y, SCALEBITS) \ | |
106 ({ \ | |
107 uint32_t __hi; \ | |
108 uint32_t __lo; \ | |
109 uint32_t __result; \ | |
110 asm("smull %0, %1, %3, %4\n\t" \ | |
111 "movs %0, %0, lsr %5\n\t" \ | |
112 "adc %2, %0, %1, lsl %6" \ | |
113 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ | |
114 : "%r" (x), "r" (y), \ | |
115 "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \ | |
116 : "cc"); \ | |
117 __result; \ | |
118 }) | |
119 | |
120 static INLINE real_t MUL_R(real_t A, real_t B) | |
121 { | |
122 return arm_mul(A, B, REAL_BITS); | |
123 } | |
124 | |
125 static INLINE real_t MUL_C(real_t A, real_t B) | |
126 { | |
127 return arm_mul(A, B, COEF_BITS); | |
128 } | |
129 | |
130 static INLINE real_t _MulHigh(real_t x, real_t y) | |
131 { | |
132 uint32_t __lo; | |
133 uint32_t __hi; | |
134 asm("smull\t%0, %1, %2, %3" | |
135 : "=&r"(__lo),"=&r"(__hi) | |
136 : "%r"(x),"r"(y) | |
137 : "cc"); | |
138 return __hi; | |
139 } | |
140 | |
141 static INLINE real_t MUL_F(real_t A, real_t B) | |
142 { | |
143 return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS); | |
144 } | |
145 | |
146 /* Complex multiplication */ | |
147 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
148 real_t x1, real_t x2, real_t c1, real_t c2) | |
149 { | |
150 int32_t tmp, yt1, yt2; | |
151 asm("smull %0, %1, %4, %6\n\t" | |
152 "smlal %0, %1, %5, %7\n\t" | |
153 "rsb %3, %4, #0\n\t" | |
154 "smull %0, %2, %5, %6\n\t" | |
155 "smlal %0, %2, %3, %7" | |
156 : "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1) | |
157 : "3" (x1), "r" (x2), "r" (c1), "r" (c2) | |
158 : "cc" ); | |
159 *y1 = yt1 << (FRAC_SIZE-FRAC_BITS); | |
160 *y2 = yt2 << (FRAC_SIZE-FRAC_BITS); | |
161 } | |
162 | |
163 #else | |
164 | |
165 /* multiply with real shift */ | |
166 #define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS) | |
167 /* multiply with coef shift */ | |
168 #define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS) | |
169 /* multiply with fractional shift */ | |
1010 | 170 #ifndef _WIN32_WCE |
171 #define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_SIZE-1))) >> FRAC_SIZE) | |
172 #define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS) | |
173 #else | |
61 | 174 /* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */ |
175 static INLINE real_t MUL_F(real_t A, real_t B) | |
176 { | |
177 return _MulHigh(A,B) << (32-FRAC_BITS); | |
178 } | |
179 #endif | |
180 | |
181 /* Complex multiplication */ | |
182 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
183 real_t x1, real_t x2, real_t c1, real_t c2) | |
184 { | |
185 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
186 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
187 } | |
188 | |
189 #endif | |
190 | |
191 | |
192 | |
193 #ifdef __cplusplus | |
194 } | |
195 #endif | |
196 #endif |