Mercurial > mplayer.hg
annotate libfaad2/output.c @ 22188:b9fa8b0ddab9
strncat() misuses, may have been exploitable.
Reported by Sascha Sommer.
author | rtogni |
---|---|
date | Sun, 11 Feb 2007 18:00:06 +0000 |
parents | 0783dd397f74 |
children | 3a4e51bbca62 |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com | |
14729
b4378a6f87a6
Sync missing cosmetics from the 2004-07-12 CVS snapshot.
diego
parents:
14727
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. | |
14729
b4378a6f87a6
Sync missing cosmetics from the 2004-07-12 CVS snapshot.
diego
parents:
14727
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. | |
14729
b4378a6f87a6
Sync missing cosmetics from the 2004-07-12 CVS snapshot.
diego
parents:
14727
diff
changeset
|
14 ** |
10725 | 15 ** You should have received a copy of the GNU General Public License |
14729
b4378a6f87a6
Sync missing cosmetics from the 2004-07-12 CVS snapshot.
diego
parents:
14727
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 ** | |
15023 | 22 ** Initially modified for use with MPlayer by Rich Felker on 2005/03/29 |
10725 | 23 ** $Id$ |
18783 | 24 ** detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ |
10725 | 25 **/ |
26 | |
27 #include "common.h" | |
28 #include "structs.h" | |
29 | |
30 #include "output.h" | |
31 #include "decoder.h" | |
32 | |
33 #ifndef FIXED_POINT | |
34 | |
35 | |
36 #define FLOAT_SCALE (1.0f/(1<<15)) | |
37 | |
12527 | 38 #define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2)) |
39 #define RSQRT2 REAL_CONST(0.7071067811865475244) // 1/sqrt(2) | |
10725 | 40 |
41 | |
42 static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample, | |
12527 | 43 uint8_t down_matrix, uint8_t *internal_channel) |
44 { | |
45 if (!down_matrix) | |
46 return input[internal_channel[channel]][sample]; | |
47 | |
48 if (channel == 0) | |
49 { | |
50 return DM_MUL * (input[internal_channel[1]][sample] + | |
51 input[internal_channel[0]][sample] * RSQRT2 + | |
52 input[internal_channel[3]][sample] * RSQRT2); | |
53 } else { | |
54 return DM_MUL * (input[internal_channel[2]][sample] + | |
55 input[internal_channel[0]][sample] * RSQRT2 + | |
56 input[internal_channel[4]][sample] * RSQRT2); | |
57 } | |
58 } | |
59 | |
60 #ifndef HAS_LRINTF | |
61 #define CLIP(sample, max, min) \ | |
62 if (sample >= 0.0f) \ | |
63 { \ | |
64 sample += 0.5f; \ | |
65 if (sample >= max) \ | |
66 sample = max; \ | |
67 } else { \ | |
68 sample += -0.5f; \ | |
69 if (sample <= min) \ | |
70 sample = min; \ | |
71 } | |
72 #else | |
73 #define CLIP(sample, max, min) \ | |
74 if (sample >= 0.0f) \ | |
75 { \ | |
76 if (sample >= max) \ | |
77 sample = max; \ | |
78 } else { \ | |
79 if (sample <= min) \ | |
80 sample = min; \ | |
81 } | |
82 #endif | |
83 | |
84 #define CONV(a,b) ((a<<1)|(b&0x1)) | |
85 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
86 static void to_PCM_16bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 87 uint8_t channels, uint16_t frame_len, |
88 int16_t **sample_buffer) | |
10725 | 89 { |
12527 | 90 uint8_t ch, ch1; |
91 uint16_t i; | |
92 | |
93 switch (CONV(channels,hDecoder->downMatrix)) | |
94 { | |
95 case CONV(1,0): | |
96 case CONV(1,1): | |
97 for(i = 0; i < frame_len; i++) | |
98 { | |
99 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
100 | |
101 CLIP(inp, 32767.0f, -32768.0f); | |
102 | |
103 (*sample_buffer)[i] = (int16_t)lrintf(inp); | |
104 } | |
105 break; | |
106 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
107 if (hDecoder->upMatrix) |
12527 | 108 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
109 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
110 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
111 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
112 real_t inp0 = input[ch][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
113 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
114 CLIP(inp0, 32767.0f, -32768.0f); |
12527 | 115 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
116 (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
117 (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
118 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
119 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
120 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
121 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
122 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
123 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
124 real_t inp0 = input[ch ][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
125 real_t inp1 = input[ch1][i]; |
12527 | 126 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
127 CLIP(inp0, 32767.0f, -32768.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
128 CLIP(inp1, 32767.0f, -32768.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
129 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
130 (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
131 (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
132 } |
12527 | 133 } |
134 break; | |
135 default: | |
136 for (ch = 0; ch < channels; ch++) | |
137 { | |
138 for(i = 0; i < frame_len; i++) | |
139 { | |
140 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
141 | |
142 CLIP(inp, 32767.0f, -32768.0f); | |
143 | |
144 (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp); | |
145 } | |
146 } | |
147 break; | |
148 } | |
149 } | |
150 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
151 static void to_PCM_24bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 152 uint8_t channels, uint16_t frame_len, |
153 int32_t **sample_buffer) | |
154 { | |
155 uint8_t ch, ch1; | |
156 uint16_t i; | |
157 | |
158 switch (CONV(channels,hDecoder->downMatrix)) | |
10725 | 159 { |
12527 | 160 case CONV(1,0): |
161 case CONV(1,1): | |
162 for(i = 0; i < frame_len; i++) | |
163 { | |
164 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
165 | |
166 inp *= 256.0f; | |
167 CLIP(inp, 8388607.0f, -8388608.0f); | |
168 | |
169 (*sample_buffer)[i] = (int32_t)lrintf(inp); | |
170 } | |
171 break; | |
172 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
173 if (hDecoder->upMatrix) |
12527 | 174 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
175 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
176 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
177 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
178 real_t inp0 = input[ch][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
179 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
180 inp0 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
181 CLIP(inp0, 8388607.0f, -8388608.0f); |
12527 | 182 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
183 (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
184 (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
185 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
186 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
187 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
188 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
189 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
190 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
191 real_t inp0 = input[ch ][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
192 real_t inp1 = input[ch1][i]; |
12527 | 193 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
194 inp0 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
195 inp1 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
196 CLIP(inp0, 8388607.0f, -8388608.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
197 CLIP(inp1, 8388607.0f, -8388608.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
198 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
199 (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
200 (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
201 } |
12527 | 202 } |
203 break; | |
204 default: | |
205 for (ch = 0; ch < channels; ch++) | |
206 { | |
207 for(i = 0; i < frame_len; i++) | |
208 { | |
209 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
210 | |
211 inp *= 256.0f; | |
212 CLIP(inp, 8388607.0f, -8388608.0f); | |
213 | |
214 (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp); | |
215 } | |
216 } | |
217 break; | |
218 } | |
219 } | |
220 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
221 static void to_PCM_32bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 222 uint8_t channels, uint16_t frame_len, |
223 int32_t **sample_buffer) | |
224 { | |
225 uint8_t ch, ch1; | |
226 uint16_t i; | |
227 | |
228 switch (CONV(channels,hDecoder->downMatrix)) | |
229 { | |
230 case CONV(1,0): | |
231 case CONV(1,1): | |
232 for(i = 0; i < frame_len; i++) | |
233 { | |
234 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
235 | |
236 inp *= 65536.0f; | |
237 CLIP(inp, 2147483647.0f, -2147483648.0f); | |
238 | |
239 (*sample_buffer)[i] = (int32_t)lrintf(inp); | |
240 } | |
241 break; | |
242 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
243 if (hDecoder->upMatrix) |
10725 | 244 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
245 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
246 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
247 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
248 real_t inp0 = input[ch][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
249 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
250 inp0 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
251 CLIP(inp0, 2147483647.0f, -2147483648.0f); |
12527 | 252 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
253 (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
254 (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
255 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
256 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
257 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
258 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
259 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
260 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
261 real_t inp0 = input[ch ][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
262 real_t inp1 = input[ch1][i]; |
12527 | 263 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
264 inp0 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
265 inp1 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
266 CLIP(inp0, 2147483647.0f, -2147483648.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
267 CLIP(inp1, 2147483647.0f, -2147483648.0f); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
268 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
269 (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
270 (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
271 } |
12527 | 272 } |
273 break; | |
274 default: | |
275 for (ch = 0; ch < channels; ch++) | |
276 { | |
277 for(i = 0; i < frame_len; i++) | |
278 { | |
279 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
280 | |
281 inp *= 65536.0f; | |
282 CLIP(inp, 2147483647.0f, -2147483648.0f); | |
283 | |
284 (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp); | |
285 } | |
286 } | |
287 break; | |
288 } | |
289 } | |
290 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
291 static void to_PCM_float(NeAACDecHandle hDecoder, real_t **input, |
12527 | 292 uint8_t channels, uint16_t frame_len, |
293 float32_t **sample_buffer) | |
294 { | |
295 uint8_t ch, ch1; | |
296 uint16_t i; | |
297 | |
298 switch (CONV(channels,hDecoder->downMatrix)) | |
299 { | |
300 case CONV(1,0): | |
301 case CONV(1,1): | |
302 for(i = 0; i < frame_len; i++) | |
303 { | |
304 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
305 (*sample_buffer)[i] = inp*FLOAT_SCALE; | |
306 } | |
307 break; | |
308 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
309 if (hDecoder->upMatrix) |
12527 | 310 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
311 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
312 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
313 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
314 real_t inp0 = input[ch][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
315 (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
316 (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
317 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
318 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
319 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
320 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
321 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
322 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
323 real_t inp0 = input[ch ][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
324 real_t inp1 = input[ch1][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
325 (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
326 (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
327 } |
12527 | 328 } |
329 break; | |
330 default: | |
331 for (ch = 0; ch < channels; ch++) | |
332 { | |
333 for(i = 0; i < frame_len; i++) | |
334 { | |
335 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
336 (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE; | |
337 } | |
338 } | |
339 break; | |
340 } | |
341 } | |
342 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
343 static void to_PCM_double(NeAACDecHandle hDecoder, real_t **input, |
12527 | 344 uint8_t channels, uint16_t frame_len, |
345 double **sample_buffer) | |
346 { | |
347 uint8_t ch, ch1; | |
348 uint16_t i; | |
349 | |
350 switch (CONV(channels,hDecoder->downMatrix)) | |
351 { | |
352 case CONV(1,0): | |
353 case CONV(1,1): | |
354 for(i = 0; i < frame_len; i++) | |
355 { | |
356 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
357 (*sample_buffer)[i] = (double)inp*FLOAT_SCALE; | |
10725 | 358 } |
12527 | 359 break; |
360 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
361 if (hDecoder->upMatrix) |
12527 | 362 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
363 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
364 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
365 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
366 real_t inp0 = input[ch][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
367 (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
368 (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
369 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
370 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
371 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
372 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
373 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
374 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
375 real_t inp0 = input[ch ][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
376 real_t inp1 = input[ch1][i]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
377 (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
378 (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
379 } |
12527 | 380 } |
381 break; | |
382 default: | |
383 for (ch = 0; ch < channels; ch++) | |
384 { | |
385 for(i = 0; i < frame_len; i++) | |
386 { | |
387 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
388 (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE; | |
389 } | |
390 } | |
391 break; | |
392 } | |
393 } | |
394 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
395 void *output_to_PCM(NeAACDecHandle hDecoder, |
12527 | 396 real_t **input, void *sample_buffer, uint8_t channels, |
397 uint16_t frame_len, uint8_t format) | |
398 { | |
399 int16_t *short_sample_buffer = (int16_t*)sample_buffer; | |
400 int32_t *int_sample_buffer = (int32_t*)sample_buffer; | |
401 float32_t *float_sample_buffer = (float32_t*)sample_buffer; | |
402 double *double_sample_buffer = (double*)sample_buffer; | |
403 | |
404 #ifdef PROFILE | |
405 int64_t count = faad_get_ts(); | |
406 #endif | |
407 | |
408 /* Copy output to a standard PCM buffer */ | |
409 switch (format) | |
410 { | |
411 case FAAD_FMT_16BIT: | |
412 to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer); | |
413 break; | |
414 case FAAD_FMT_24BIT: | |
415 to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer); | |
416 break; | |
417 case FAAD_FMT_32BIT: | |
418 to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer); | |
419 break; | |
420 case FAAD_FMT_FLOAT: | |
421 to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer); | |
422 break; | |
423 case FAAD_FMT_DOUBLE: | |
424 to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer); | |
425 break; | |
426 } | |
427 | |
428 #ifdef PROFILE | |
429 count = faad_get_ts() - count; | |
430 hDecoder->output_cycles += count; | |
431 #endif | |
432 | |
433 return sample_buffer; | |
434 } | |
435 | |
436 #else | |
437 | |
438 #define DM_MUL FRAC_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2)) | |
439 #define RSQRT2 FRAC_CONST(0.7071067811865475244) // 1/sqrt(2) | |
440 | |
441 static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample, | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
442 uint8_t down_matrix, uint8_t up_matrix, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
443 uint8_t *internal_channel) |
12527 | 444 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
445 if (up_matrix == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
446 return input[internal_channel[0]][sample]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
447 |
12527 | 448 if (!down_matrix) |
449 return input[internal_channel[channel]][sample]; | |
450 | |
451 if (channel == 0) | |
452 { | |
453 real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); | |
454 real_t L_S = MUL_F(input[internal_channel[3]][sample], RSQRT2); | |
455 real_t cum = input[internal_channel[1]][sample] + C + L_S; | |
456 return MUL_F(cum, DM_MUL); | |
10725 | 457 } else { |
12527 | 458 real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); |
459 real_t R_S = MUL_F(input[internal_channel[4]][sample], RSQRT2); | |
460 real_t cum = input[internal_channel[2]][sample] + C + R_S; | |
461 return MUL_F(cum, DM_MUL); | |
10725 | 462 } |
463 } | |
464 | |
15020
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
465 void* output_to_PCM_sux(NeAACDecHandle hDecoder, |
10725 | 466 real_t **input, void *sample_buffer, uint8_t channels, |
467 uint16_t frame_len, uint8_t format) | |
468 { | |
469 uint8_t ch; | |
12527 | 470 uint16_t i; |
471 int16_t *short_sample_buffer = (int16_t*)sample_buffer; | |
472 int32_t *int_sample_buffer = (int32_t*)sample_buffer; | |
10725 | 473 |
474 /* Copy output to a standard PCM buffer */ | |
475 for (ch = 0; ch < channels; ch++) | |
476 { | |
477 switch (format) | |
478 { | |
479 case FAAD_FMT_16BIT: | |
480 for(i = 0; i < frame_len; i++) | |
481 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
482 int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
483 hDecoder->internal_channel); |
12527 | 484 if (tmp >= 0) |
485 { | |
486 tmp += (1 << (REAL_BITS-1)); | |
487 if (tmp >= REAL_CONST(32767)) | |
488 { | |
489 tmp = REAL_CONST(32767); | |
490 } | |
491 } else { | |
492 tmp += -(1 << (REAL_BITS-1)); | |
493 if (tmp <= REAL_CONST(-32768)) | |
494 { | |
495 tmp = REAL_CONST(-32768); | |
496 } | |
497 } | |
498 tmp >>= REAL_BITS; | |
499 short_sample_buffer[(i*channels)+ch] = (int16_t)tmp; | |
10725 | 500 } |
501 break; | |
502 case FAAD_FMT_24BIT: | |
503 for(i = 0; i < frame_len; i++) | |
504 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
505 int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
506 hDecoder->internal_channel); |
12527 | 507 if (tmp >= 0) |
508 { | |
509 tmp += (1 << (REAL_BITS-9)); | |
510 tmp >>= (REAL_BITS-8); | |
511 if (tmp >= 8388607) | |
512 { | |
513 tmp = 8388607; | |
514 } | |
515 } else { | |
516 tmp += -(1 << (REAL_BITS-9)); | |
517 tmp >>= (REAL_BITS-8); | |
518 if (tmp <= -8388608) | |
519 { | |
520 tmp = -8388608; | |
521 } | |
522 } | |
523 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp; | |
10725 | 524 } |
525 break; | |
526 case FAAD_FMT_32BIT: | |
527 for(i = 0; i < frame_len; i++) | |
528 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
529 int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
530 hDecoder->internal_channel); |
12527 | 531 if (tmp >= 0) |
532 { | |
533 tmp += (1 << (16-REAL_BITS-1)); | |
534 tmp <<= (16-REAL_BITS); | |
535 } else { | |
536 tmp += -(1 << (16-REAL_BITS-1)); | |
537 tmp <<= (16-REAL_BITS); | |
538 } | |
539 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp; | |
10725 | 540 } |
541 break; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
542 case FAAD_FMT_FIXED: |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
543 for(i = 0; i < frame_len; i++) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
544 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
545 real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
546 hDecoder->internal_channel); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
547 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
548 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
549 break; |
10725 | 550 } |
551 } | |
552 | |
553 return sample_buffer; | |
554 } | |
555 | |
15020
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
556 void* output_to_PCM(NeAACDecHandle hDecoder, |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
557 real_t **input, void *sample_buffer, uint8_t channels, |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
558 uint16_t frame_len, uint8_t format) |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
559 { |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
560 int ch; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
561 int i; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
562 int16_t *short_sample_buffer = (int16_t*)sample_buffer; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
563 real_t *ch0 = input[hDecoder->internal_channel[0]]; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
564 real_t *ch1 = input[hDecoder->internal_channel[1]]; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
565 real_t *ch2 = input[hDecoder->internal_channel[2]]; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
566 real_t *ch3 = input[hDecoder->internal_channel[3]]; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
567 real_t *ch4 = input[hDecoder->internal_channel[4]]; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
568 |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
569 if (format != FAAD_FMT_16BIT) |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
570 return output_to_PCM_sux(hDecoder, input, sample_buffer, channels, frame_len, format); |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
571 |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
572 if (hDecoder->downMatrix) { |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
573 for(i = 0; i < frame_len; i++) |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
574 { |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
575 int32_t tmp; |
15054
d8f97f45cfbe
10l, integer overflow. who uses 14 fractional bits?! only faad developers.... *sigh*
rfelker
parents:
15053
diff
changeset
|
576 tmp = (ch1[i] + ((ch0[i]+ch3[i])>>1) + ((ch0[i]+ch3[i])>>2) + (1<<(REAL_BITS))) >> (REAL_BITS+1); |
15020
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
577 if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
578 short_sample_buffer[0] = tmp; |
15054
d8f97f45cfbe
10l, integer overflow. who uses 14 fractional bits?! only faad developers.... *sigh*
rfelker
parents:
15053
diff
changeset
|
579 tmp = (ch2[i] + ((ch0[i]+ch4[i])>>1) + ((ch0[i]+ch4[i])>>2) + (1<<(REAL_BITS))) >> (REAL_BITS+1); |
15020
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
580 if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
581 short_sample_buffer[1] = tmp; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
582 short_sample_buffer += channels; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
583 } |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
584 return sample_buffer; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
585 } |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
586 |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
587 /* Copy output to a standard PCM buffer */ |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
588 for(i = 0; i < frame_len; i++) |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
589 { |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
590 for (ch = 0; ch < channels; ch++) |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
591 { |
18141 | 592 int32_t tmp = input[hDecoder->internal_channel[ch]][i]; |
15020
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
593 tmp += (1 << (REAL_BITS-1)); |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
594 tmp >>= REAL_BITS; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
595 if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
596 *(short_sample_buffer++) = tmp; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
597 } |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
598 } |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
599 |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
600 return sample_buffer; |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
601 } |
3f80d5095f3e
usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
rfelker
parents:
14729
diff
changeset
|
602 |
10725 | 603 #endif |