Mercurial > mplayer.hg
annotate libfaad2/output.c @ 14765:106106dac710
Finish incomplete -af-adv documentation.
author | diego |
---|---|
date | Tue, 22 Feb 2005 20:24:15 +0000 |
parents | b4378a6f87a6 |
children | 3f80d5095f3e |
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 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
25 ** $Id$ | |
26 **/ | |
27 | |
28 #include "common.h" | |
29 #include "structs.h" | |
30 | |
31 #include "output.h" | |
32 #include "decoder.h" | |
33 | |
34 #ifndef FIXED_POINT | |
35 | |
36 | |
37 #define FLOAT_SCALE (1.0f/(1<<15)) | |
38 | |
12527 | 39 #define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2)) |
40 #define RSQRT2 REAL_CONST(0.7071067811865475244) // 1/sqrt(2) | |
10725 | 41 |
42 | |
43 static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample, | |
12527 | 44 uint8_t down_matrix, uint8_t *internal_channel) |
45 { | |
46 if (!down_matrix) | |
47 return input[internal_channel[channel]][sample]; | |
48 | |
49 if (channel == 0) | |
50 { | |
51 return DM_MUL * (input[internal_channel[1]][sample] + | |
52 input[internal_channel[0]][sample] * RSQRT2 + | |
53 input[internal_channel[3]][sample] * RSQRT2); | |
54 } else { | |
55 return DM_MUL * (input[internal_channel[2]][sample] + | |
56 input[internal_channel[0]][sample] * RSQRT2 + | |
57 input[internal_channel[4]][sample] * RSQRT2); | |
58 } | |
59 } | |
60 | |
61 #ifndef HAS_LRINTF | |
62 #define CLIP(sample, max, min) \ | |
63 if (sample >= 0.0f) \ | |
64 { \ | |
65 sample += 0.5f; \ | |
66 if (sample >= max) \ | |
67 sample = max; \ | |
68 } else { \ | |
69 sample += -0.5f; \ | |
70 if (sample <= min) \ | |
71 sample = min; \ | |
72 } | |
73 #else | |
74 #define CLIP(sample, max, min) \ | |
75 if (sample >= 0.0f) \ | |
76 { \ | |
77 if (sample >= max) \ | |
78 sample = max; \ | |
79 } else { \ | |
80 if (sample <= min) \ | |
81 sample = min; \ | |
82 } | |
83 #endif | |
84 | |
85 #define CONV(a,b) ((a<<1)|(b&0x1)) | |
86 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
87 static void to_PCM_16bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 88 uint8_t channels, uint16_t frame_len, |
89 int16_t **sample_buffer) | |
10725 | 90 { |
12527 | 91 uint8_t ch, ch1; |
92 uint16_t i; | |
93 | |
94 switch (CONV(channels,hDecoder->downMatrix)) | |
95 { | |
96 case CONV(1,0): | |
97 case CONV(1,1): | |
98 for(i = 0; i < frame_len; i++) | |
99 { | |
100 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
101 | |
102 CLIP(inp, 32767.0f, -32768.0f); | |
103 | |
104 (*sample_buffer)[i] = (int16_t)lrintf(inp); | |
105 } | |
106 break; | |
107 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
108 if (hDecoder->upMatrix) |
12527 | 109 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
110 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
111 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
|
112 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
113 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
|
114 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
115 CLIP(inp0, 32767.0f, -32768.0f); |
12527 | 116 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
117 (*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
|
118 (*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
|
119 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
120 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
121 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
122 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
123 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
|
124 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
125 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
|
126 real_t inp1 = input[ch1][i]; |
12527 | 127 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
128 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
|
129 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
|
130 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
131 (*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
|
132 (*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
|
133 } |
12527 | 134 } |
135 break; | |
136 default: | |
137 for (ch = 0; ch < channels; ch++) | |
138 { | |
139 for(i = 0; i < frame_len; i++) | |
140 { | |
141 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
142 | |
143 CLIP(inp, 32767.0f, -32768.0f); | |
144 | |
145 (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp); | |
146 } | |
147 } | |
148 break; | |
149 } | |
150 } | |
151 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
152 static void to_PCM_24bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 153 uint8_t channels, uint16_t frame_len, |
154 int32_t **sample_buffer) | |
155 { | |
156 uint8_t ch, ch1; | |
157 uint16_t i; | |
158 | |
159 switch (CONV(channels,hDecoder->downMatrix)) | |
10725 | 160 { |
12527 | 161 case CONV(1,0): |
162 case CONV(1,1): | |
163 for(i = 0; i < frame_len; i++) | |
164 { | |
165 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
166 | |
167 inp *= 256.0f; | |
168 CLIP(inp, 8388607.0f, -8388608.0f); | |
169 | |
170 (*sample_buffer)[i] = (int32_t)lrintf(inp); | |
171 } | |
172 break; | |
173 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
174 if (hDecoder->upMatrix) |
12527 | 175 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
176 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
177 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
|
178 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
179 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
|
180 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
181 inp0 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
182 CLIP(inp0, 8388607.0f, -8388608.0f); |
12527 | 183 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
184 (*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
|
185 (*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
|
186 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
187 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
188 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
189 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
190 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
|
191 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
192 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
|
193 real_t inp1 = input[ch1][i]; |
12527 | 194 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
195 inp0 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
196 inp1 *= 256.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
197 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
|
198 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
|
199 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
200 (*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
|
201 (*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
|
202 } |
12527 | 203 } |
204 break; | |
205 default: | |
206 for (ch = 0; ch < channels; ch++) | |
207 { | |
208 for(i = 0; i < frame_len; i++) | |
209 { | |
210 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
211 | |
212 inp *= 256.0f; | |
213 CLIP(inp, 8388607.0f, -8388608.0f); | |
214 | |
215 (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp); | |
216 } | |
217 } | |
218 break; | |
219 } | |
220 } | |
221 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
222 static void to_PCM_32bit(NeAACDecHandle hDecoder, real_t **input, |
12527 | 223 uint8_t channels, uint16_t frame_len, |
224 int32_t **sample_buffer) | |
225 { | |
226 uint8_t ch, ch1; | |
227 uint16_t i; | |
228 | |
229 switch (CONV(channels,hDecoder->downMatrix)) | |
230 { | |
231 case CONV(1,0): | |
232 case CONV(1,1): | |
233 for(i = 0; i < frame_len; i++) | |
234 { | |
235 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
236 | |
237 inp *= 65536.0f; | |
238 CLIP(inp, 2147483647.0f, -2147483648.0f); | |
239 | |
240 (*sample_buffer)[i] = (int32_t)lrintf(inp); | |
241 } | |
242 break; | |
243 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
244 if (hDecoder->upMatrix) |
10725 | 245 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
246 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
247 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
|
248 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
249 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
|
250 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
251 inp0 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
252 CLIP(inp0, 2147483647.0f, -2147483648.0f); |
12527 | 253 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
254 (*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
|
255 (*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
|
256 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
257 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
258 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
259 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
260 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
|
261 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
262 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
|
263 real_t inp1 = input[ch1][i]; |
12527 | 264 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
265 inp0 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
266 inp1 *= 65536.0f; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
267 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
|
268 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
|
269 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
270 (*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
|
271 (*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
|
272 } |
12527 | 273 } |
274 break; | |
275 default: | |
276 for (ch = 0; ch < channels; ch++) | |
277 { | |
278 for(i = 0; i < frame_len; i++) | |
279 { | |
280 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
281 | |
282 inp *= 65536.0f; | |
283 CLIP(inp, 2147483647.0f, -2147483648.0f); | |
284 | |
285 (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp); | |
286 } | |
287 } | |
288 break; | |
289 } | |
290 } | |
291 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
292 static void to_PCM_float(NeAACDecHandle hDecoder, real_t **input, |
12527 | 293 uint8_t channels, uint16_t frame_len, |
294 float32_t **sample_buffer) | |
295 { | |
296 uint8_t ch, ch1; | |
297 uint16_t i; | |
298 | |
299 switch (CONV(channels,hDecoder->downMatrix)) | |
300 { | |
301 case CONV(1,0): | |
302 case CONV(1,1): | |
303 for(i = 0; i < frame_len; i++) | |
304 { | |
305 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
306 (*sample_buffer)[i] = inp*FLOAT_SCALE; | |
307 } | |
308 break; | |
309 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
310 if (hDecoder->upMatrix) |
12527 | 311 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
312 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
313 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
|
314 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
315 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
|
316 (*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
|
317 (*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
|
318 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
319 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
320 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
321 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
322 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
|
323 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
324 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
|
325 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
|
326 (*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
|
327 (*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
|
328 } |
12527 | 329 } |
330 break; | |
331 default: | |
332 for (ch = 0; ch < channels; ch++) | |
333 { | |
334 for(i = 0; i < frame_len; i++) | |
335 { | |
336 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
337 (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE; | |
338 } | |
339 } | |
340 break; | |
341 } | |
342 } | |
343 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
344 static void to_PCM_double(NeAACDecHandle hDecoder, real_t **input, |
12527 | 345 uint8_t channels, uint16_t frame_len, |
346 double **sample_buffer) | |
347 { | |
348 uint8_t ch, ch1; | |
349 uint16_t i; | |
350 | |
351 switch (CONV(channels,hDecoder->downMatrix)) | |
352 { | |
353 case CONV(1,0): | |
354 case CONV(1,1): | |
355 for(i = 0; i < frame_len; i++) | |
356 { | |
357 real_t inp = input[hDecoder->internal_channel[0]][i]; | |
358 (*sample_buffer)[i] = (double)inp*FLOAT_SCALE; | |
10725 | 359 } |
12527 | 360 break; |
361 case CONV(2,0): | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
362 if (hDecoder->upMatrix) |
12527 | 363 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
364 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
365 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
|
366 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
367 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
|
368 (*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
|
369 (*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
|
370 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
371 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
372 ch = hDecoder->internal_channel[0]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
373 ch1 = hDecoder->internal_channel[1]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
374 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
|
375 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
376 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
|
377 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
|
378 (*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
|
379 (*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
|
380 } |
12527 | 381 } |
382 break; | |
383 default: | |
384 for (ch = 0; ch < channels; ch++) | |
385 { | |
386 for(i = 0; i < frame_len; i++) | |
387 { | |
388 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel); | |
389 (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE; | |
390 } | |
391 } | |
392 break; | |
393 } | |
394 } | |
395 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
396 void *output_to_PCM(NeAACDecHandle hDecoder, |
12527 | 397 real_t **input, void *sample_buffer, uint8_t channels, |
398 uint16_t frame_len, uint8_t format) | |
399 { | |
400 int16_t *short_sample_buffer = (int16_t*)sample_buffer; | |
401 int32_t *int_sample_buffer = (int32_t*)sample_buffer; | |
402 float32_t *float_sample_buffer = (float32_t*)sample_buffer; | |
403 double *double_sample_buffer = (double*)sample_buffer; | |
404 | |
405 #ifdef PROFILE | |
406 int64_t count = faad_get_ts(); | |
407 #endif | |
408 | |
409 /* Copy output to a standard PCM buffer */ | |
410 switch (format) | |
411 { | |
412 case FAAD_FMT_16BIT: | |
413 to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer); | |
414 break; | |
415 case FAAD_FMT_24BIT: | |
416 to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer); | |
417 break; | |
418 case FAAD_FMT_32BIT: | |
419 to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer); | |
420 break; | |
421 case FAAD_FMT_FLOAT: | |
422 to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer); | |
423 break; | |
424 case FAAD_FMT_DOUBLE: | |
425 to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer); | |
426 break; | |
427 } | |
428 | |
429 #ifdef PROFILE | |
430 count = faad_get_ts() - count; | |
431 hDecoder->output_cycles += count; | |
432 #endif | |
433 | |
434 return sample_buffer; | |
435 } | |
436 | |
437 #else | |
438 | |
439 #define DM_MUL FRAC_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2)) | |
440 #define RSQRT2 FRAC_CONST(0.7071067811865475244) // 1/sqrt(2) | |
441 | |
442 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
|
443 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
|
444 uint8_t *internal_channel) |
12527 | 445 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
446 if (up_matrix == 1) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
447 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
|
448 |
12527 | 449 if (!down_matrix) |
450 return input[internal_channel[channel]][sample]; | |
451 | |
452 if (channel == 0) | |
453 { | |
454 real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); | |
455 real_t L_S = MUL_F(input[internal_channel[3]][sample], RSQRT2); | |
456 real_t cum = input[internal_channel[1]][sample] + C + L_S; | |
457 return MUL_F(cum, DM_MUL); | |
10725 | 458 } else { |
12527 | 459 real_t C = MUL_F(input[internal_channel[0]][sample], RSQRT2); |
460 real_t R_S = MUL_F(input[internal_channel[4]][sample], RSQRT2); | |
461 real_t cum = input[internal_channel[2]][sample] + C + R_S; | |
462 return MUL_F(cum, DM_MUL); | |
10725 | 463 } |
464 } | |
465 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
466 void* output_to_PCM(NeAACDecHandle hDecoder, |
10725 | 467 real_t **input, void *sample_buffer, uint8_t channels, |
468 uint16_t frame_len, uint8_t format) | |
469 { | |
470 uint8_t ch; | |
12527 | 471 uint16_t i; |
472 int16_t *short_sample_buffer = (int16_t*)sample_buffer; | |
473 int32_t *int_sample_buffer = (int32_t*)sample_buffer; | |
10725 | 474 |
475 /* Copy output to a standard PCM buffer */ | |
476 for (ch = 0; ch < channels; ch++) | |
477 { | |
478 switch (format) | |
479 { | |
480 case FAAD_FMT_16BIT: | |
481 for(i = 0; i < frame_len; i++) | |
482 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
483 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
|
484 hDecoder->internal_channel); |
12527 | 485 if (tmp >= 0) |
486 { | |
487 tmp += (1 << (REAL_BITS-1)); | |
488 if (tmp >= REAL_CONST(32767)) | |
489 { | |
490 tmp = REAL_CONST(32767); | |
491 } | |
492 } else { | |
493 tmp += -(1 << (REAL_BITS-1)); | |
494 if (tmp <= REAL_CONST(-32768)) | |
495 { | |
496 tmp = REAL_CONST(-32768); | |
497 } | |
498 } | |
499 tmp >>= REAL_BITS; | |
500 short_sample_buffer[(i*channels)+ch] = (int16_t)tmp; | |
10725 | 501 } |
502 break; | |
503 case FAAD_FMT_24BIT: | |
504 for(i = 0; i < frame_len; i++) | |
505 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
506 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
|
507 hDecoder->internal_channel); |
12527 | 508 if (tmp >= 0) |
509 { | |
510 tmp += (1 << (REAL_BITS-9)); | |
511 tmp >>= (REAL_BITS-8); | |
512 if (tmp >= 8388607) | |
513 { | |
514 tmp = 8388607; | |
515 } | |
516 } else { | |
517 tmp += -(1 << (REAL_BITS-9)); | |
518 tmp >>= (REAL_BITS-8); | |
519 if (tmp <= -8388608) | |
520 { | |
521 tmp = -8388608; | |
522 } | |
523 } | |
524 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp; | |
10725 | 525 } |
526 break; | |
527 case FAAD_FMT_32BIT: | |
528 for(i = 0; i < frame_len; i++) | |
529 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
530 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
|
531 hDecoder->internal_channel); |
12527 | 532 if (tmp >= 0) |
533 { | |
534 tmp += (1 << (16-REAL_BITS-1)); | |
535 tmp <<= (16-REAL_BITS); | |
536 } else { | |
537 tmp += -(1 << (16-REAL_BITS-1)); | |
538 tmp <<= (16-REAL_BITS); | |
539 } | |
540 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp; | |
10725 | 541 } |
542 break; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
543 case FAAD_FMT_FIXED: |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
544 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
|
545 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
546 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
|
547 hDecoder->internal_channel); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
548 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
|
549 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
550 break; |
10725 | 551 } |
552 } | |
553 | |
554 return sample_buffer; | |
555 } | |
556 | |
557 #endif |