Rewrite dircache generation to take advantage for the FAT code. Reduce RAM usage...
[kugel-rb.git] / apps / codecs / liba52 / a52_internal.h
blob0db16a8bcfdb2ff5fdfc54f299f153d8eba7d989
1 /*
2 * a52_internal.h
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 typedef struct {
25 uint8_t bai; /* fine SNR offset, fast gain */
26 uint8_t deltbae; /* delta bit allocation exists */
27 int8_t deltba[50]; /* per-band delta bit allocation */
28 } ba_t;
30 typedef struct {
31 uint8_t exp[256]; /* decoded channel exponents */
32 int8_t bap[256]; /* derived channel bit allocation */
33 } expbap_t;
35 struct a52_state_s {
36 uint8_t fscod; /* sample rate */
37 uint8_t halfrate; /* halfrate factor */
38 uint8_t acmod; /* coded channels */
39 uint8_t lfeon; /* coded lfe channel */
40 level_t clev; /* centre channel mix level */
41 level_t slev; /* surround channels mix level */
43 int output; /* type of output */
44 level_t level; /* output level */
45 sample_t bias; /* output bias */
47 int dynrnge; /* apply dynamic range */
48 level_t dynrng; /* dynamic range */
49 void * dynrngdata; /* dynamic range callback funtion and data */
50 level_t (* dynrngcall) (level_t range, void * dynrngdata);
52 uint8_t chincpl; /* channel coupled */
53 uint8_t phsflginu; /* phase flags in use (stereo only) */
54 uint8_t cplstrtmant; /* coupling channel start mantissa */
55 uint8_t cplendmant; /* coupling channel end mantissa */
56 uint32_t cplbndstrc; /* coupling band structure */
57 level_t cplco[5][18]; /* coupling coordinates */
59 /* derived information */
60 uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
61 uint8_t ncplbnd; /* number of coupling bands */
63 uint8_t rematflg; /* stereo rematrixing */
65 uint8_t endmant[5]; /* channel end mantissa */
67 uint16_t bai; /* bit allocation information */
69 uint32_t * buffer_start;
70 uint16_t lfsr_state; /* dither state */
71 uint32_t bits_left;
72 uint32_t current_word;
74 uint8_t csnroffst; /* coarse SNR offset */
75 ba_t cplba; /* coupling bit allocation parameters */
76 ba_t ba[5]; /* channel bit allocation parameters */
77 ba_t lfeba; /* lfe bit allocation parameters */
79 uint8_t cplfleak; /* coupling fast leak init */
80 uint8_t cplsleak; /* coupling slow leak init */
82 expbap_t cpl_expbap;
83 expbap_t fbw_expbap[5];
84 expbap_t lfe_expbap;
86 sample_t * samples;
87 int downmixed;
90 #define LEVEL_PLUS6DB 2.0
91 #define LEVEL_PLUS3DB 1.4142135623730951
92 #define LEVEL_3DB 0.7071067811865476
93 #define LEVEL_45DB 0.5946035575013605
94 #define LEVEL_6DB 0.5
96 #define EXP_REUSE (0)
97 #define EXP_D15 (1)
98 #define EXP_D25 (2)
99 #define EXP_D45 (3)
101 #define DELTA_BIT_REUSE (0)
102 #define DELTA_BIT_NEW (1)
103 #define DELTA_BIT_NONE (2)
104 #define DELTA_BIT_RESERVED (3)
106 void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
107 int start, int end, int fastleak, int slowleak,
108 expbap_t * expbap);
110 int a52_downmix_init (int input, int flags, level_t * level,
111 level_t clev, level_t slev);
112 int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
113 level_t clev, level_t slev);
114 void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
115 level_t clev, level_t slev);
116 void a52_upmix (sample_t * samples, int acmod, int output);
118 void a52_imdct_init (uint32_t mm_accel);
119 void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias);
120 void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias);
122 #define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
124 #ifndef LIBA52_FIXED
126 typedef sample_t quantizer_t;
127 #define SAMPLE(x) (x)
128 #define LEVEL(x) (x)
129 #define MUL(a,b) ((a) * (b))
130 #define MUL_L(a,b) ((a) * (b))
131 #define MUL_C(a,b) ((a) * (b))
132 #define DIV(a,b) ((a) / (b))
133 #define BIAS(x) ((x) + bias)
135 #else /* LIBA52_FIXED */
137 typedef int16_t quantizer_t;
138 #define SAMPLE(x) (sample_t)((x) * (1 << 30))
139 #define LEVEL(x) (level_t)((x) * (1 << 26))
141 #if 0
142 #define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
143 #define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
144 #elif defined(CPU_COLDFIRE)
145 /* loses 1 bit of accuracy */
146 #define MUL(a, b) \
147 ({ \
148 int32_t t; \
149 asm volatile ( \
150 "mac.l %[A], %[B], %%acc0\n\t" \
151 "movclr.l %%acc0, %[t]\n\t" \
152 "asl.l #1, %[t]" \
153 : [t] "=d" (t) \
154 : [A] "r" ((a)), [B] "r" ((b))); \
155 t; \
157 /* loses 5 bits of accuracy */
158 #define MUL_L(a, b) \
159 ({ \
160 int32_t t; \
161 asm volatile ( \
162 "mac.l %[A], %[B], %%acc0\n\t" \
163 "movclr.l %%acc0, %[t]\n\t" \
164 "asl.l #5, %[t]" \
165 : [t] "=d" (t) \
166 : [A] "r" ((a)), [B] "r" ((b))); \
167 t; \
170 #elif defined(CPU_ARM)
171 #define MUL(x, y) \
172 ({ int32_t __hi; \
173 uint32_t __lo; \
174 int32_t __result; \
175 asm ("smull %0, %1, %3, %4\n\t" \
176 "movs %2, %1, lsl #2" \
177 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
178 : "%r" (x), "r" (y) \
179 : "cc"); \
180 __result; \
184 #define MUL_L(x, y) \
185 ({ int32_t __hi; \
186 uint32_t __lo; \
187 int32_t __result; \
188 asm ("smull %0, %1, %3, %4\n\t" \
189 "movs %0, %0, lsr %5\n\t" \
190 "adc %2, %0, %1, lsl %6" \
191 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
192 : "%r" (x), "r" (y), \
193 "M" (26), "M" (32 - 26) \
194 : "cc"); \
195 __result; \
199 #elif 1
200 #define MUL(a,b) \
201 ({ int32_t _ta=(a), _tb=(b), _tc; \
202 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
203 #define MUL_L(a,b) \
204 ({ int32_t _ta=(a), _tb=(b), _tc; \
205 _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
206 #else
207 #define MUL(a,b) (((a) >> 15) * ((b) >> 15))
208 #define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
209 #endif
211 #define MUL_C(a,b) MUL_L (a, LEVEL (b))
212 #define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
213 #define BIAS(x) ((x) + (bias*0))
215 #endif