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