Mercurial > mplayer.hg
annotate libfaad2/pns.c @ 31685:31b6397e3b28
Another try at fixing swscale on win64, as per r31153.
Don't change paramater passing, but instead use casts.
Shouldn't affect asm output on anything other than win64.
libswscale should work on win64 now.
The rest of ffmpeg still isn't win64 compatible due to the issue of xmm
clobbers, but swscale doesn't use any SSE.
Patch by Anton Mitrofanov <BugMaster AT narod DOT ru>.
author | darkshikari |
---|---|
date | Sun, 18 Jul 2010 21:39:57 +0000 |
parents | e83eef58b30a |
children |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
18141
diff
changeset
|
4 ** |
10725 | 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. | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
18141
diff
changeset
|
9 ** |
10725 | 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. | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
18141
diff
changeset
|
14 ** |
10725 | 15 ** You should have received a copy of the GNU General Public License |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
18141
diff
changeset
|
16 ** along with this program; if not, write to the Free Software |
10725 | 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 ** | |
18141 | 25 ** $Id: pns.c,v 1.34 2004/09/04 14:56:28 menno Exp $ |
10725 | 26 **/ |
27 | |
28 #include "common.h" | |
29 #include "structs.h" | |
30 | |
31 #include "pns.h" | |
32 | |
33 | |
12527 | 34 /* static function declarations */ |
35 static void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size, | |
36 uint8_t sub); | |
37 | |
38 | |
10725 | 39 #ifdef FIXED_POINT |
40 | |
10989 | 41 #define DIV(A, B) (((int64_t)A << REAL_BITS)/B) |
10725 | 42 |
43 #define step(shift) \ | |
44 if ((0x40000000l >> shift) + root <= value) \ | |
45 { \ | |
46 value -= (0x40000000l >> shift) + root; \ | |
47 root = (root >> 1) | (0x40000000l >> shift); \ | |
48 } else { \ | |
49 root = root >> 1; \ | |
50 } | |
51 | |
52 /* fixed point square root approximation */ | |
10989 | 53 /* !!!! ONLY WORKS FOR EVEN %REAL_BITS% !!!! */ |
10725 | 54 real_t fp_sqrt(real_t value) |
55 { | |
56 real_t root = 0; | |
57 | |
58 step( 0); step( 2); step( 4); step( 6); | |
59 step( 8); step(10); step(12); step(14); | |
60 step(16); step(18); step(20); step(22); | |
61 step(24); step(26); step(28); step(30); | |
62 | |
63 if (root < value) | |
64 ++root; | |
65 | |
10989 | 66 root <<= (REAL_BITS/2); |
10725 | 67 |
68 return root; | |
69 } | |
70 | |
71 static real_t pow2_table[] = | |
72 { | |
73 COEF_CONST(1.0), | |
74 COEF_CONST(1.18920711500272), | |
75 COEF_CONST(1.41421356237310), | |
76 COEF_CONST(1.68179283050743) | |
77 }; | |
78 #endif | |
79 | |
80 /* The function gen_rand_vector(addr, size) generates a vector of length | |
81 <size> with signed random values of average energy MEAN_NRG per random | |
82 value. A suitable random number generator can be realized using one | |
83 multiplication/accumulation per random value. | |
84 */ | |
10989 | 85 static INLINE void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size, |
86 uint8_t sub) | |
10725 | 87 { |
88 #ifndef FIXED_POINT | |
89 uint16_t i; | |
90 real_t energy = 0.0; | |
91 | |
10989 | 92 real_t scale = (real_t)1.0/(real_t)size; |
10725 | 93 |
94 for (i = 0; i < size; i++) | |
95 { | |
96 real_t tmp = scale*(real_t)(int32_t)random_int(); | |
97 spec[i] = tmp; | |
98 energy += tmp*tmp; | |
99 } | |
100 | |
10989 | 101 scale = (real_t)1.0/(real_t)sqrt(energy); |
10725 | 102 scale *= (real_t)pow(2.0, 0.25 * scale_factor); |
103 for (i = 0; i < size; i++) | |
104 { | |
105 spec[i] *= scale; | |
106 } | |
107 #else | |
108 uint16_t i; | |
109 real_t energy = 0, scale; | |
110 int32_t exp, frac; | |
111 | |
112 for (i = 0; i < size; i++) | |
113 { | |
10989 | 114 /* this can be replaced by a 16 bit random generator!!!! */ |
115 real_t tmp = (int32_t)random_int(); | |
116 if (tmp < 0) | |
117 tmp = -(tmp & ((1<<(REAL_BITS-1))-1)); | |
118 else | |
119 tmp = (tmp & ((1<<(REAL_BITS-1))-1)); | |
10725 | 120 |
12527 | 121 energy += MUL_R(tmp,tmp); |
10725 | 122 |
10989 | 123 spec[i] = tmp; |
10725 | 124 } |
125 | |
126 energy = fp_sqrt(energy); | |
127 if (energy > 0) | |
128 { | |
10989 | 129 scale = DIV(REAL_CONST(1),energy); |
10725 | 130 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
131 exp = scale_factor >> 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
132 frac = scale_factor & 3; |
10725 | 133 |
10989 | 134 /* IMDCT pre-scaling */ |
135 exp -= sub; | |
136 | |
10725 | 137 if (exp < 0) |
138 scale >>= -exp; | |
139 else | |
140 scale <<= exp; | |
141 | |
142 if (frac) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
143 scale = MUL_C(scale, pow2_table[frac]); |
10725 | 144 |
145 for (i = 0; i < size; i++) | |
146 { | |
12527 | 147 spec[i] = MUL_R(spec[i], scale); |
10725 | 148 } |
149 } | |
150 #endif | |
151 } | |
152 | |
153 void pns_decode(ic_stream *ics_left, ic_stream *ics_right, | |
154 real_t *spec_left, real_t *spec_right, uint16_t frame_len, | |
10989 | 155 uint8_t channel_pair, uint8_t object_type) |
10725 | 156 { |
157 uint8_t g, sfb, b; | |
158 uint16_t size, offs; | |
159 | |
160 uint8_t group = 0; | |
161 uint16_t nshort = frame_len >> 3; | |
162 | |
10989 | 163 uint8_t sub = 0; |
164 | |
165 #ifdef FIXED_POINT | |
166 /* IMDCT scaling */ | |
167 if (object_type == LD) | |
168 { | |
169 sub = 9 /*9*/; | |
170 } else { | |
171 if (ics_left->window_sequence == EIGHT_SHORT_SEQUENCE) | |
172 sub = 7 /*7*/; | |
173 else | |
174 sub = 10 /*10*/; | |
175 } | |
176 #endif | |
177 | |
10725 | 178 for (g = 0; g < ics_left->num_window_groups; g++) |
179 { | |
180 /* Do perceptual noise substitution decoding */ | |
181 for (b = 0; b < ics_left->window_group_length[g]; b++) | |
182 { | |
183 for (sfb = 0; sfb < ics_left->max_sfb; sfb++) | |
184 { | |
185 if (is_noise(ics_left, g, sfb)) | |
186 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
187 #ifdef LTP_DEC |
10725 | 188 /* Simultaneous use of LTP and PNS is not prevented in the |
189 syntax. If both LTP, and PNS are enabled on the same | |
190 scalefactor band, PNS takes precedence, and no prediction | |
191 is applied to this band. | |
192 */ | |
193 ics_left->ltp.long_used[sfb] = 0; | |
194 ics_left->ltp2.long_used[sfb] = 0; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
195 #endif |
10725 | 196 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
197 #ifdef MAIN_DEC |
10725 | 198 /* For scalefactor bands coded using PNS the corresponding |
199 predictors are switched to "off". | |
200 */ | |
201 ics_left->pred.prediction_used[sfb] = 0; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
202 #endif |
10725 | 203 |
204 offs = ics_left->swb_offset[sfb]; | |
205 size = ics_left->swb_offset[sfb+1] - offs; | |
206 | |
207 /* Generate random vector */ | |
208 gen_rand_vector(&spec_left[(group*nshort)+offs], | |
10989 | 209 ics_left->scale_factors[g][sfb], size, sub); |
10725 | 210 } |
211 | |
212 /* From the spec: | |
213 If the same scalefactor band and group is coded by perceptual noise | |
214 substitution in both channels of a channel pair, the correlation of | |
215 the noise signal can be controlled by means of the ms_used field: While | |
216 the default noise generation process works independently for each channel | |
217 (separate generation of random vectors), the same random vector is used | |
218 for both channels if ms_used[] is set for a particular scalefactor band | |
219 and group. In this case, no M/S stereo coding is carried out (because M/S | |
220 stereo coding and noise substitution coding are mutually exclusive). | |
221 If the same scalefactor band and group is coded by perceptual noise | |
222 substitution in only one channel of a channel pair the setting of ms_used[] | |
223 is not evaluated. | |
224 */ | |
225 if (channel_pair) | |
226 { | |
227 if (is_noise(ics_right, g, sfb)) | |
228 { | |
229 if (((ics_left->ms_mask_present == 1) && | |
230 (ics_left->ms_used[g][sfb])) || | |
231 (ics_left->ms_mask_present == 2)) | |
232 { | |
233 uint16_t c; | |
234 | |
235 offs = ics_right->swb_offset[sfb]; | |
236 size = ics_right->swb_offset[sfb+1] - offs; | |
237 | |
238 for (c = 0; c < size; c++) | |
239 { | |
240 spec_right[(group*nshort) + offs + c] = | |
241 spec_left[(group*nshort) + offs + c]; | |
242 } | |
243 } else /*if (ics_left->ms_mask_present == 0)*/ { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
244 #ifdef LTP_DEC |
10725 | 245 ics_right->ltp.long_used[sfb] = 0; |
246 ics_right->ltp2.long_used[sfb] = 0; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
247 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
248 #ifdef MAIN_DEC |
10725 | 249 ics_right->pred.prediction_used[sfb] = 0; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
250 #endif |
10725 | 251 |
252 offs = ics_right->swb_offset[sfb]; | |
253 size = ics_right->swb_offset[sfb+1] - offs; | |
254 | |
255 /* Generate random vector */ | |
256 gen_rand_vector(&spec_right[(group*nshort)+offs], | |
10989 | 257 ics_right->scale_factors[g][sfb], size, sub); |
10725 | 258 } |
259 } | |
260 } | |
261 } /* sfb */ | |
262 group++; | |
263 } /* b */ | |
264 } /* g */ | |
265 } |