annotate libfaad2/common.c @ 13032:2ba5eb44eabd

maybe more understandable?
author michael
date Tue, 17 Aug 2004 01:06:24 +0000
parents d81145997036
children 6d50ef45a058
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
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
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: common.c,v 1.3 2004/06/02 22:59:02 diego Exp $
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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 /* just some common functions that could be used anywhere */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
35 #include <stdlib.h>
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
38 #ifdef USE_SSE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
39 __declspec(naked) static int32_t __fastcall test_cpuid(void)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
40 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
41 __asm
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
42 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
43 pushf
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
44 pop eax
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
45 mov ecx,eax
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
46 xor eax,(1<<21)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
47 push eax
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
48 popf
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
49 pushf
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
50 pop eax
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
51 push ecx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
52 popf
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
53 cmp eax,ecx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
54 mov eax,0
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
55 setne al
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
56 ret
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
57 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
58 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
59
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
60 __declspec(naked) static void __fastcall run_cpuid(int32_t param, int32_t out[4])
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
61 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
62 __asm
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
63 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
64 pushad
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
65 push edx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
66 mov eax,ecx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
67 cpuid
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
68 pop edi
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
69 mov [edi+0],eax
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
70 mov [edi+4],ebx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
71 mov [edi+8],ecx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
72 mov [edi+12],edx
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
73 popad
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
74 ret
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
75 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
76 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
77
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
78 uint8_t cpu_has_sse()
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
79 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
80 int32_t features[4];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
81
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
82 if (test_cpuid())
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
83 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
84 run_cpuid(1, features);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
85 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
86
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
87 /* check for SSE */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
88 if (features[3] & 0x02000000)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
89 return 1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
90
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
91 return 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
92 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
93 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
94 uint8_t cpu_has_sse()
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
95 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
96 return 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
97 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
98 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
99
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 /* Returns the sample rate index based on the samplerate */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
101 uint8_t get_sr_index(const uint32_t samplerate)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 if (92017 <= samplerate) return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 if (75132 <= samplerate) return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 if (55426 <= samplerate) return 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 if (46009 <= samplerate) return 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 if (37566 <= samplerate) return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 if (27713 <= samplerate) return 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 if (23004 <= samplerate) return 6;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 if (18783 <= samplerate) return 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 if (13856 <= samplerate) return 8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 if (11502 <= samplerate) return 9;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 if (9391 <= samplerate) return 10;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
114 if (16428320 <= samplerate) return 11;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 return 11;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
119 /* Returns the sample rate based on the sample rate index */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
120 uint32_t get_sample_rate(const uint8_t sr_index)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
121 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
122 static const uint32_t sample_rates[] =
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
123 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
124 96000, 88200, 64000, 48000, 44100, 32000,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
125 24000, 22050, 16000, 12000, 11025, 8000
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
126 };
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
127
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
128 if (sr_index < 12)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
129 return sample_rates[sr_index];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
130
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
131 return 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
132 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
133
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
134 uint8_t max_pred_sfb(const uint8_t sr_index)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
135 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
136 static const uint8_t pred_sfb_max[] =
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
137 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
138 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
139 };
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
140
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
141
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
142 if (sr_index < 12)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
143 return pred_sfb_max[sr_index];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
144
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
145 return 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
146 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
147
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
148 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
149 const uint8_t is_short)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
150 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
151 /* entry for each sampling rate
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
152 * 1 Main/LC long window
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
153 * 2 Main/LC short window
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
154 * 3 SSR long window
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
155 * 4 SSR short window
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
156 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
157 static const uint8_t tns_sbf_max[][4] =
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
158 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
159 {31, 9, 28, 7}, /* 96000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
160 {31, 9, 28, 7}, /* 88200 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
161 {34, 10, 27, 7}, /* 64000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
162 {40, 14, 26, 6}, /* 48000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
163 {42, 14, 26, 6}, /* 44100 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
164 {51, 14, 26, 6}, /* 32000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
165 {46, 14, 29, 7}, /* 24000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
166 {46, 14, 29, 7}, /* 22050 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
167 {42, 14, 23, 8}, /* 16000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
168 {42, 14, 23, 8}, /* 12000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
169 {42, 14, 23, 8}, /* 11025 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
170 {39, 14, 19, 7}, /* 8000 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
171 {39, 14, 19, 7}, /* 7350 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
172 {0,0,0,0},
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
173 {0,0,0,0},
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
174 {0,0,0,0}
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
175 };
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
176 uint8_t i = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
177
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
178 if (is_short) i++;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
179 if (object_type == SSR) i += 2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
180
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
181 return tns_sbf_max[sr_index][i];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
182 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
183
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 /* Returns 0 if an object type is decodable, otherwise returns -1 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
185 int8_t can_decode_ot(const uint8_t object_type)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 switch (object_type)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 case LC:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 case MAIN:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 case SSR:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 case LTP:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 /* ER object types */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 case ER_LC:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 #ifdef DRM
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 case DRM_ER_LC:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 case ER_LTP:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 case LD:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
235 /* common malloc function */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
236 void *faad_malloc(int32_t size)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
237 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
238 #if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
239 return _aligned_malloc(size, 16);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
240 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
241 return malloc(size);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
242 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
243 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
244
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
245 /* common free function */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
246 void faad_free(void *b)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
247 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
248 #if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
249 _aligned_free(b);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
250 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
251 free(b);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
252 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
253 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
254
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 static const uint8_t Parity [256] = { // parity
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 static uint32_t __r1 = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 static uint32_t __r2 = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 * This is a simple random number generator with good quality for audio purposes.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 * It consists of two polycounters with opposite rotation direction and different
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 * periods. The periods are coprime, so the total period is the product of both.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 * -------------------------------------------------------------------------------------------------
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 * +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0|
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 * | -------------------------------------------------------------------------------------------------
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 * | | | | | | |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 * | +--+--+--+-XOR-+--------+
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 * | |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 * +--------------------------------------------------------------------------------------+
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 * -------------------------------------------------------------------------------------------------
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 * |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 * ------------------------------------------------------------------------------------------------- |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 * | | | | |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 * +--+----XOR----+--+ |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 * | |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 * +----------------------------------------------------------------------------------------+
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 * The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 * which gives a period of 18.410.713.077.675.721.215. The result is the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 * XORed values of both generators.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 uint32_t random_int(void)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 uint32_t t1, t2, t3, t4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 t3 = t1 = __r1; t4 = t2 = __r2; // Parity calculation is done via table lookup, this is also available
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 t1 <<= 31; t2 = Parity [t2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 return (__r1 = (t3 >> 1) | t1 ) ^ (__r2 = (t4 + t4) | t2 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 }