Mercurial > mplayer.hg
annotate tremor/misc.h @ 31629:82958b5ad419
Fix indentation.
author | reimar |
---|---|
date | Sun, 11 Jul 2010 09:05:22 +0000 |
parents | 997ae534ebfe |
children |
rev | line source |
---|---|
14280 | 1 /******************************************************************** |
2 * * | |
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * | |
4 * * | |
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * | |
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * | |
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * | |
8 * * | |
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * | |
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * | |
11 * * | |
12 ******************************************************************** | |
13 | |
14 function: miscellaneous math and prototypes | |
15 | |
16 ********************************************************************/ | |
17 | |
18 #ifndef _V_RANDOM_H_ | |
19 #define _V_RANDOM_H_ | |
20 #include "ivorbiscodec.h" | |
29997
997ae534ebfe
Add missing #includes to fix a bunch of 'implicit declaration of..' warnings.
diego
parents:
29401
diff
changeset
|
21 #include "codec_internal.h" |
14280 | 22 #include "os_types.h" |
23 | |
24 #include "asm_arm.h" | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
14280
diff
changeset
|
25 |
14280 | 26 #ifndef _V_WIDE_MATH |
27 #define _V_WIDE_MATH | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
14280
diff
changeset
|
28 |
14280 | 29 #ifndef _LOW_ACCURACY_ |
30 /* 64 bit multiply */ | |
31 | |
32 #include <sys/types.h> | |
29997
997ae534ebfe
Add missing #includes to fix a bunch of 'implicit declaration of..' warnings.
diego
parents:
29401
diff
changeset
|
33 #include <stdlib.h> |
14280 | 34 #include "config.h" |
35 | |
29401
f01023c524c3
Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents:
29264
diff
changeset
|
36 #if !HAVE_BIGENDIAN |
14280 | 37 union magic { |
38 struct { | |
39 ogg_int32_t lo; | |
40 ogg_int32_t hi; | |
41 } halves; | |
42 ogg_int64_t whole; | |
43 }; | |
44 #else | |
45 union magic { | |
46 struct { | |
47 ogg_int32_t hi; | |
48 ogg_int32_t lo; | |
49 } halves; | |
50 ogg_int64_t whole; | |
51 }; | |
52 #endif | |
53 | |
54 static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { | |
55 union magic magic; | |
56 magic.whole = (ogg_int64_t)x * y; | |
57 return magic.halves.hi; | |
58 } | |
59 | |
60 static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { | |
61 return MULT32(x,y)<<1; | |
62 } | |
63 | |
64 static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { | |
65 union magic magic; | |
66 magic.whole = (ogg_int64_t)x * y; | |
67 return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); | |
68 } | |
69 | |
70 #else | |
71 /* 32 bit multiply, more portable but less accurate */ | |
72 | |
73 /* | |
74 * Note: Precision is biased towards the first argument therefore ordering | |
75 * is important. Shift values were chosen for the best sound quality after | |
76 * many listening tests. | |
77 */ | |
78 | |
79 /* | |
80 * For MULT32 and MULT31: The second argument is always a lookup table | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
14280
diff
changeset
|
81 * value already preshifted from 31 to 8 bits. We therefore take the |
14280 | 82 * opportunity to save on text space and use unsigned char for those |
83 * tables in this case. | |
84 */ | |
85 | |
86 static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { | |
87 return (x >> 9) * y; /* y preshifted >>23 */ | |
88 } | |
89 | |
90 static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { | |
91 return (x >> 8) * y; /* y preshifted >>23 */ | |
92 } | |
93 | |
94 static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { | |
95 return (x >> 6) * y; /* y preshifted >>9 */ | |
96 } | |
97 | |
98 #endif | |
99 | |
100 /* | |
101 * This should be used as a memory barrier, forcing all cached values in | |
102 * registers to wr writen back to memory. Might or might not be beneficial | |
103 * depending on the architecture and compiler. | |
104 */ | |
105 #define MB() | |
106 | |
107 /* | |
108 * The XPROD functions are meant to optimize the cross products found all | |
109 * over the place in mdct.c by forcing memory operation ordering to avoid | |
110 * unnecessary register reloads as soon as memory is being written to. | |
111 * However this is only beneficial on CPUs with a sane number of general | |
112 * purpose registers which exclude the Intel x86. On Intel, better let the | |
113 * compiler actually reload registers directly from original memory by using | |
114 * macros. | |
115 */ | |
116 | |
117 #ifdef __i386__ | |
118 | |
119 #define XPROD32(_a, _b, _t, _v, _x, _y) \ | |
120 { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \ | |
121 *(_y)=MULT32(_b,_t)-MULT32(_a,_v); } | |
122 #define XPROD31(_a, _b, _t, _v, _x, _y) \ | |
123 { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \ | |
124 *(_y)=MULT31(_b,_t)-MULT31(_a,_v); } | |
125 #define XNPROD31(_a, _b, _t, _v, _x, _y) \ | |
126 { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \ | |
127 *(_y)=MULT31(_b,_t)+MULT31(_a,_v); } | |
128 | |
129 #else | |
130 | |
131 static inline void XPROD32(ogg_int32_t a, ogg_int32_t b, | |
132 ogg_int32_t t, ogg_int32_t v, | |
133 ogg_int32_t *x, ogg_int32_t *y) | |
134 { | |
135 *x = MULT32(a, t) + MULT32(b, v); | |
136 *y = MULT32(b, t) - MULT32(a, v); | |
137 } | |
138 | |
139 static inline void XPROD31(ogg_int32_t a, ogg_int32_t b, | |
140 ogg_int32_t t, ogg_int32_t v, | |
141 ogg_int32_t *x, ogg_int32_t *y) | |
142 { | |
143 *x = MULT31(a, t) + MULT31(b, v); | |
144 *y = MULT31(b, t) - MULT31(a, v); | |
145 } | |
146 | |
147 static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b, | |
148 ogg_int32_t t, ogg_int32_t v, | |
149 ogg_int32_t *x, ogg_int32_t *y) | |
150 { | |
151 *x = MULT31(a, t) - MULT31(b, v); | |
152 *y = MULT31(b, t) + MULT31(a, v); | |
153 } | |
154 | |
155 #endif | |
156 | |
157 #endif | |
158 | |
159 #ifndef _V_CLIP_MATH | |
160 #define _V_CLIP_MATH | |
161 | |
162 static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) { | |
163 int ret=x; | |
164 ret-= ((x<=32767)-1)&(x-32767); | |
165 ret-= ((x>=-32768)-1)&(x+32768); | |
166 return(ret); | |
167 } | |
168 | |
169 #endif | |
170 | |
171 static inline ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, | |
172 ogg_int32_t b,ogg_int32_t bp, | |
173 ogg_int32_t *p){ | |
174 if(a && b){ | |
175 #ifndef _LOW_ACCURACY_ | |
176 *p=ap+bp+32; | |
177 return MULT32(a,b); | |
178 #else | |
179 *p=ap+bp+31; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
14280
diff
changeset
|
180 return (a>>15)*(b>>16); |
14280 | 181 #endif |
182 }else | |
183 return 0; | |
184 } | |
185 | |
186 static inline ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap, | |
187 ogg_int32_t i, | |
188 ogg_int32_t *p){ | |
189 | |
190 int ip=_ilog(abs(i))-31; | |
191 return VFLOAT_MULT(a,ap,i<<-ip,ip,p); | |
192 } | |
193 | |
194 static inline ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, | |
195 ogg_int32_t b,ogg_int32_t bp, | |
196 ogg_int32_t *p){ | |
197 | |
198 if(!a){ | |
199 *p=bp; | |
200 return b; | |
201 }else if(!b){ | |
202 *p=ap; | |
203 return a; | |
204 } | |
205 | |
206 /* yes, this can leak a bit. */ | |
207 if(ap>bp){ | |
208 int shift=ap-bp+1; | |
209 *p=ap+1; | |
210 a>>=1; | |
211 if(shift<32){ | |
212 b=(b+(1<<(shift-1)))>>shift; | |
213 }else{ | |
214 b=0; | |
215 } | |
216 }else{ | |
217 int shift=bp-ap+1; | |
218 *p=bp+1; | |
219 b>>=1; | |
220 if(shift<32){ | |
221 a=(a+(1<<(shift-1)))>>shift; | |
222 }else{ | |
223 a=0; | |
224 } | |
225 } | |
226 | |
227 a+=b; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
14280
diff
changeset
|
228 if((a&0xc0000000)==0xc0000000 || |
14280 | 229 (a&0xc0000000)==0){ |
230 a<<=1; | |
231 (*p)--; | |
232 } | |
233 return(a); | |
234 } | |
235 | |
236 #endif | |
237 | |
238 | |
239 | |
240 |