Mercurial > mplayer.hg
annotate liba52/parse.c @ 26557:bced0f27c9a5
Remove unnecessary dependency declaration.
author | diego |
---|---|
date | Tue, 29 Apr 2008 07:00:27 +0000 |
parents | b6bd2e6fa76d |
children | 94d9e6403ee4 |
rev | line source |
---|---|
3394 | 1 /* |
2 * parse.c | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> |
3394 | 4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> |
5 * | |
6 * This file is part of a52dec, a free ATSC A-52 stream decoder. | |
7 * See http://liba52.sourceforge.net/ for updates. | |
8 * | |
14991
07f1e7669772
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12089
diff
changeset
|
9 * Modified for use with MPlayer, changes contained in liba52_changes.diff. |
18783 | 10 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ |
14991
07f1e7669772
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12089
diff
changeset
|
11 * $Id$ |
07f1e7669772
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12089
diff
changeset
|
12 * |
3394 | 13 * a52dec is free software; you can redistribute it and/or modify |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * a52dec is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 */ | |
27 | |
28 #include "config.h" | |
29 | |
30 #include <stdlib.h> | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
31 #include <stdio.h> |
3394 | 32 #include <string.h> |
33 #include <inttypes.h> | |
34 | |
35 #include "a52.h" | |
36 #include "a52_internal.h" | |
37 #include "bitstream.h" | |
38 #include "tables.h" | |
12089
1fe597788e3f
prevent crash in case we are unable to get aligned buffer
faust3
parents:
12088
diff
changeset
|
39 #include "mm_accel.h" |
20763
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
40 #include "libavutil/avutil.h" |
3394 | 41 |
42 #ifdef HAVE_MEMALIGN | |
43 /* some systems have memalign() but no declaration for it */ | |
44 void * memalign (size_t align, size_t size); | |
45 #endif | |
46 | |
47 typedef struct { | |
48 sample_t q1[2]; | |
49 sample_t q2[2]; | |
50 sample_t q4; | |
51 int q1_ptr; | |
52 int q2_ptr; | |
53 int q4_ptr; | |
54 } quantizer_t; | |
55 | |
56 static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}; | |
57 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
58 a52_state_t * a52_init (uint32_t mm_accel) |
3394 | 59 { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
60 a52_state_t * state; |
3394 | 61 int i; |
62 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
63 state = malloc (sizeof (a52_state_t)); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
64 if (state == NULL) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
65 return NULL; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
66 |
20763
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
67 #if defined(__MINGW32__) && defined(HAVE_SSE) |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
68 state->samples = av_malloc(256 * 12 * sizeof (sample_t)); |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
69 #else |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
70 state->samples = memalign (16, 256 * 12 * sizeof (sample_t)); |
12088
f52e662bf365
although this SSE fix is an ugly hack it seems to work fine for me
faust3
parents:
6057
diff
changeset
|
71 #endif |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
72 if(((int)state->samples%16) && (mm_accel&MM_ACCEL_X86_SSE)){ |
12089
1fe597788e3f
prevent crash in case we are unable to get aligned buffer
faust3
parents:
12088
diff
changeset
|
73 mm_accel &=~MM_ACCEL_X86_SSE; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
74 fprintf(stderr, "liba52: unable to get 16 byte aligned memory disabling usage of SSE instructions\n"); |
12089
1fe597788e3f
prevent crash in case we are unable to get aligned buffer
faust3
parents:
12088
diff
changeset
|
75 } |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
76 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
77 if (state->samples == NULL) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
78 free (state); |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
79 return NULL; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
80 } |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
81 |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
82 for (i = 0; i < 256 * 12; i++) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
83 state->samples[i] = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
84 |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
85 state->downmixed = 1; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
86 |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
87 state->lfsr_state = 1; |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
88 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
89 a52_imdct_init (mm_accel); |
12089
1fe597788e3f
prevent crash in case we are unable to get aligned buffer
faust3
parents:
12088
diff
changeset
|
90 downmix_accel_init(mm_accel); |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
91 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
92 return state; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
93 } |
3394 | 94 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
95 sample_t * a52_samples (a52_state_t * state) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
96 { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
97 return state->samples; |
3394 | 98 } |
99 | |
100 int a52_syncinfo (uint8_t * buf, int * flags, | |
101 int * sample_rate, int * bit_rate) | |
102 { | |
103 static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112, | |
104 128, 160, 192, 224, 256, 320, 384, 448, | |
105 512, 576, 640}; | |
106 static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01}; | |
107 int frmsizecod; | |
108 int bitrate; | |
109 int half; | |
110 int acmod; | |
111 | |
112 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */ | |
113 return 0; | |
114 | |
115 if (buf[5] >= 0x60) /* bsid >= 12 */ | |
116 return 0; | |
117 half = halfrate[buf[5] >> 3]; | |
118 | |
119 /* acmod, dsurmod and lfeon */ | |
120 acmod = buf[6] >> 5; | |
121 *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) | | |
122 ((buf[6] & lfeon[acmod]) ? A52_LFE : 0)); | |
123 | |
124 frmsizecod = buf[4] & 63; | |
125 if (frmsizecod >= 38) | |
126 return 0; | |
127 bitrate = rate [frmsizecod >> 1]; | |
128 *bit_rate = (bitrate * 1000) >> half; | |
129 | |
130 switch (buf[4] & 0xc0) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
131 case 0: |
3394 | 132 *sample_rate = 48000 >> half; |
133 return 4 * bitrate; | |
134 case 0x40: | |
135 *sample_rate = 44100 >> half; | |
136 return 2 * (320 * bitrate / 147 + (frmsizecod & 1)); | |
137 case 0x80: | |
138 *sample_rate = 32000 >> half; | |
139 return 6 * bitrate; | |
140 default: | |
141 return 0; | |
142 } | |
143 } | |
144 | |
145 int a52_frame (a52_state_t * state, uint8_t * buf, int * flags, | |
146 sample_t * level, sample_t bias) | |
147 { | |
148 static sample_t clev[4] = {LEVEL_3DB, LEVEL_45DB, LEVEL_6DB, LEVEL_45DB}; | |
149 static sample_t slev[4] = {LEVEL_3DB, LEVEL_6DB, 0, LEVEL_6DB}; | |
150 int chaninfo; | |
151 int acmod; | |
152 | |
153 state->fscod = buf[4] >> 6; | |
154 state->halfrate = halfrate[buf[5] >> 3]; | |
155 state->acmod = acmod = buf[6] >> 5; | |
156 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
157 a52_bitstream_set_ptr (state, buf + 6); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
158 bitstream_skip (state, 3); /* skip acmod we already parsed */ |
3394 | 159 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
160 if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */ |
3394 | 161 acmod = A52_DOLBY; |
162 | |
163 if ((acmod & 1) && (acmod != 1)) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
164 state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */ |
3394 | 165 |
166 if (acmod & 4) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
167 state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */ |
3394 | 168 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
169 state->lfeon = bitstream_get (state, 1); |
3394 | 170 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
171 state->output = a52_downmix_init (acmod, *flags, level, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
172 state->clev, state->slev); |
3394 | 173 if (state->output < 0) |
174 return 1; | |
175 if (state->lfeon && (*flags & A52_LFE)) | |
176 state->output |= A52_LFE; | |
177 *flags = state->output; | |
178 /* the 2* compensates for differences in imdct */ | |
179 state->dynrng = state->level = 2 * *level; | |
180 state->bias = bias; | |
181 state->dynrnge = 1; | |
182 state->dynrngcall = NULL; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
183 state->cplba.deltbae = DELTA_BIT_NONE; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
184 state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae = |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
185 state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE; |
3394 | 186 |
187 chaninfo = !acmod; | |
188 do { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
189 bitstream_skip (state, 5); /* dialnorm */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
190 if (bitstream_get (state, 1)) /* compre */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
191 bitstream_skip (state, 8); /* compr */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
192 if (bitstream_get (state, 1)) /* langcode */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
193 bitstream_skip (state, 8); /* langcod */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
194 if (bitstream_get (state, 1)) /* audprodie */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
195 bitstream_skip (state, 7); /* mixlevel + roomtyp */ |
3394 | 196 } while (chaninfo--); |
197 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
198 bitstream_skip (state, 2); /* copyrightb + origbs */ |
3394 | 199 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
200 if (bitstream_get (state, 1)) /* timecod1e */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
201 bitstream_skip (state, 14); /* timecod1 */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
202 if (bitstream_get (state, 1)) /* timecod2e */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
203 bitstream_skip (state, 14); /* timecod2 */ |
3394 | 204 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
205 if (bitstream_get (state, 1)) { /* addbsie */ |
3394 | 206 int addbsil; |
207 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
208 addbsil = bitstream_get (state, 6); |
3394 | 209 do { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
210 bitstream_skip (state, 8); /* addbsi */ |
3394 | 211 } while (addbsil--); |
212 } | |
213 | |
214 return 0; | |
215 } | |
216 | |
217 void a52_dynrng (a52_state_t * state, | |
218 sample_t (* call) (sample_t, void *), void * data) | |
219 { | |
220 state->dynrnge = 0; | |
221 if (call) { | |
222 state->dynrnge = 1; | |
223 state->dynrngcall = call; | |
224 state->dynrngdata = data; | |
225 } | |
226 } | |
227 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
228 static int parse_exponents (a52_state_t * state, int expstr, int ngrps, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
229 uint8_t exponent, uint8_t * dest) |
3394 | 230 { |
231 int exps; | |
232 | |
233 while (ngrps--) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
234 exps = bitstream_get (state, 7); |
3394 | 235 |
236 exponent += exp_1[exps]; | |
237 if (exponent > 24) | |
238 return 1; | |
239 | |
240 switch (expstr) { | |
241 case EXP_D45: | |
242 *(dest++) = exponent; | |
243 *(dest++) = exponent; | |
244 case EXP_D25: | |
245 *(dest++) = exponent; | |
246 case EXP_D15: | |
247 *(dest++) = exponent; | |
248 } | |
249 | |
250 exponent += exp_2[exps]; | |
251 if (exponent > 24) | |
252 return 1; | |
253 | |
254 switch (expstr) { | |
255 case EXP_D45: | |
256 *(dest++) = exponent; | |
257 *(dest++) = exponent; | |
258 case EXP_D25: | |
259 *(dest++) = exponent; | |
260 case EXP_D15: | |
261 *(dest++) = exponent; | |
262 } | |
263 | |
264 exponent += exp_3[exps]; | |
265 if (exponent > 24) | |
266 return 1; | |
267 | |
268 switch (expstr) { | |
269 case EXP_D45: | |
270 *(dest++) = exponent; | |
271 *(dest++) = exponent; | |
272 case EXP_D25: | |
273 *(dest++) = exponent; | |
274 case EXP_D15: | |
275 *(dest++) = exponent; | |
276 } | |
277 } | |
278 | |
279 return 0; | |
280 } | |
281 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
282 static int parse_deltba (a52_state_t * state, int8_t * deltba) |
3394 | 283 { |
284 int deltnseg, deltlen, delta, j; | |
285 | |
286 memset (deltba, 0, 50); | |
287 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
288 deltnseg = bitstream_get (state, 3); |
3394 | 289 j = 0; |
290 do { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
291 j += bitstream_get (state, 5); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
292 deltlen = bitstream_get (state, 4); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
293 delta = bitstream_get (state, 3); |
3394 | 294 delta -= (delta >= 4) ? 3 : 4; |
295 if (!deltlen) | |
296 continue; | |
297 if (j + deltlen >= 50) | |
298 return 1; | |
299 while (deltlen--) | |
300 deltba[j++] = delta; | |
301 } while (deltnseg--); | |
302 | |
303 return 0; | |
304 } | |
305 | |
306 static inline int zero_snr_offsets (int nfchans, a52_state_t * state) | |
307 { | |
308 int i; | |
309 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
310 if ((state->csnroffst) || |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
311 (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
312 (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */ |
3394 | 313 return 0; |
314 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
315 if (state->ba[i].bai >> 3) /* fsnroffst */ |
3394 | 316 return 0; |
317 return 1; | |
318 } | |
319 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
320 static inline int16_t dither_gen (a52_state_t * state) |
3394 | 321 { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
322 int16_t nstate; |
3394 | 323 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
324 nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8); |
3394 | 325 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
326 state->lfsr_state = (uint16_t) nstate; |
3394 | 327 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
328 return nstate; |
3394 | 329 } |
330 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
331 static void coeff_get (a52_state_t * state, sample_t * coeff, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
332 expbap_t * expbap, quantizer_t * quantizer, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
333 sample_t level, int dither, int end) |
3394 | 334 { |
335 int i; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
336 uint8_t * exp; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
337 int8_t * bap; |
3394 | 338 sample_t factor[25]; |
339 | |
340 for (i = 0; i <= 24; i++) | |
341 factor[i] = scale_factor[i] * level; | |
342 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
343 exp = expbap->exp; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
344 bap = expbap->bap; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
345 |
3394 | 346 for (i = 0; i < end; i++) { |
347 int bapi; | |
348 | |
349 bapi = bap[i]; | |
350 switch (bapi) { | |
351 case 0: | |
352 if (dither) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
353 coeff[i] = dither_gen (state) * LEVEL_3DB * factor[exp[i]]; |
3394 | 354 continue; |
355 } else { | |
356 coeff[i] = 0; | |
357 continue; | |
358 } | |
359 | |
360 case -1: | |
361 if (quantizer->q1_ptr >= 0) { | |
362 coeff[i] = quantizer->q1[quantizer->q1_ptr--] * factor[exp[i]]; | |
363 continue; | |
364 } else { | |
365 int code; | |
366 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
367 code = bitstream_get (state, 5); |
3394 | 368 |
369 quantizer->q1_ptr = 1; | |
370 quantizer->q1[0] = q_1_2[code]; | |
371 quantizer->q1[1] = q_1_1[code]; | |
372 coeff[i] = q_1_0[code] * factor[exp[i]]; | |
373 continue; | |
374 } | |
375 | |
376 case -2: | |
377 if (quantizer->q2_ptr >= 0) { | |
378 coeff[i] = quantizer->q2[quantizer->q2_ptr--] * factor[exp[i]]; | |
379 continue; | |
380 } else { | |
381 int code; | |
382 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
383 code = bitstream_get (state, 7); |
3394 | 384 |
385 quantizer->q2_ptr = 1; | |
386 quantizer->q2[0] = q_2_2[code]; | |
387 quantizer->q2[1] = q_2_1[code]; | |
388 coeff[i] = q_2_0[code] * factor[exp[i]]; | |
389 continue; | |
390 } | |
391 | |
392 case 3: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
393 coeff[i] = q_3[bitstream_get (state, 3)] * factor[exp[i]]; |
3394 | 394 continue; |
395 | |
396 case -3: | |
397 if (quantizer->q4_ptr == 0) { | |
398 quantizer->q4_ptr = -1; | |
399 coeff[i] = quantizer->q4 * factor[exp[i]]; | |
400 continue; | |
401 } else { | |
402 int code; | |
403 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
404 code = bitstream_get (state, 7); |
3394 | 405 |
406 quantizer->q4_ptr = 0; | |
407 quantizer->q4 = q_4_1[code]; | |
408 coeff[i] = q_4_0[code] * factor[exp[i]]; | |
409 continue; | |
410 } | |
411 | |
412 case 4: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
413 coeff[i] = q_5[bitstream_get (state, 4)] * factor[exp[i]]; |
3394 | 414 continue; |
415 | |
416 default: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
417 coeff[i] = ((bitstream_get_2 (state, bapi) << (16 - bapi)) * |
3394 | 418 factor[exp[i]]); |
419 } | |
420 } | |
421 } | |
422 | |
423 static void coeff_get_coupling (a52_state_t * state, int nfchans, | |
424 sample_t * coeff, sample_t (* samples)[256], | |
425 quantizer_t * quantizer, uint8_t dithflag[5]) | |
426 { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
427 int cplbndstrc, bnd, i, i_end, ch; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
428 uint8_t * exp; |
3394 | 429 int8_t * bap; |
430 sample_t cplco[5]; | |
431 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
432 exp = state->cpl_expbap.exp; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
433 bap = state->cpl_expbap.bap; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
434 bnd = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
435 cplbndstrc = state->cplbndstrc; |
3394 | 436 i = state->cplstrtmant; |
437 while (i < state->cplendmant) { | |
438 i_end = i + 12; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
439 while (cplbndstrc & 1) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
440 cplbndstrc >>= 1; |
3394 | 441 i_end += 12; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
442 } |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
443 cplbndstrc >>= 1; |
3394 | 444 for (ch = 0; ch < nfchans; ch++) |
445 cplco[ch] = state->cplco[ch][bnd] * coeff[ch]; | |
446 bnd++; | |
447 | |
448 while (i < i_end) { | |
449 sample_t cplcoeff; | |
450 int bapi; | |
451 | |
452 bapi = bap[i]; | |
453 switch (bapi) { | |
454 case 0: | |
455 cplcoeff = LEVEL_3DB * scale_factor[exp[i]]; | |
456 for (ch = 0; ch < nfchans; ch++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
457 if ((state->chincpl >> ch) & 1) { |
3394 | 458 if (dithflag[ch]) |
459 samples[ch][i] = (cplcoeff * cplco[ch] * | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
460 dither_gen (state)); |
3394 | 461 else |
462 samples[ch][i] = 0; | |
463 } | |
464 i++; | |
465 continue; | |
466 | |
467 case -1: | |
468 if (quantizer->q1_ptr >= 0) { | |
469 cplcoeff = quantizer->q1[quantizer->q1_ptr--]; | |
470 break; | |
471 } else { | |
472 int code; | |
473 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
474 code = bitstream_get (state, 5); |
3394 | 475 |
476 quantizer->q1_ptr = 1; | |
477 quantizer->q1[0] = q_1_2[code]; | |
478 quantizer->q1[1] = q_1_1[code]; | |
479 cplcoeff = q_1_0[code]; | |
480 break; | |
481 } | |
482 | |
483 case -2: | |
484 if (quantizer->q2_ptr >= 0) { | |
485 cplcoeff = quantizer->q2[quantizer->q2_ptr--]; | |
486 break; | |
487 } else { | |
488 int code; | |
489 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
490 code = bitstream_get (state, 7); |
3394 | 491 |
492 quantizer->q2_ptr = 1; | |
493 quantizer->q2[0] = q_2_2[code]; | |
494 quantizer->q2[1] = q_2_1[code]; | |
495 cplcoeff = q_2_0[code]; | |
496 break; | |
497 } | |
498 | |
499 case 3: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
500 cplcoeff = q_3[bitstream_get (state, 3)]; |
3394 | 501 break; |
502 | |
503 case -3: | |
504 if (quantizer->q4_ptr == 0) { | |
505 quantizer->q4_ptr = -1; | |
506 cplcoeff = quantizer->q4; | |
507 break; | |
508 } else { | |
509 int code; | |
510 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
511 code = bitstream_get (state, 7); |
3394 | 512 |
513 quantizer->q4_ptr = 0; | |
514 quantizer->q4 = q_4_1[code]; | |
515 cplcoeff = q_4_0[code]; | |
516 break; | |
517 } | |
518 | |
519 case 4: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
520 cplcoeff = q_5[bitstream_get (state, 4)]; |
3394 | 521 break; |
522 | |
523 default: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
524 cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi); |
3394 | 525 } |
526 | |
527 cplcoeff *= scale_factor[exp[i]]; | |
528 for (ch = 0; ch < nfchans; ch++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
529 if ((state->chincpl >> ch) & 1) |
3394 | 530 samples[ch][i] = cplcoeff * cplco[ch]; |
531 i++; | |
532 } | |
533 } | |
534 } | |
535 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
536 int a52_block (a52_state_t * state) |
3394 | 537 { |
538 static const uint8_t nfchans_tbl[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2}; | |
539 static int rematrix_band[4] = {25, 37, 61, 253}; | |
540 int i, nfchans, chaninfo; | |
541 uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl; | |
542 uint8_t blksw[5], dithflag[5]; | |
543 sample_t coeff[5]; | |
544 int chanbias; | |
545 quantizer_t quantizer; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
546 sample_t * samples; |
3394 | 547 |
548 nfchans = nfchans_tbl[state->acmod]; | |
549 | |
550 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
551 blksw[i] = bitstream_get (state, 1); |
3394 | 552 |
553 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
554 dithflag[i] = bitstream_get (state, 1); |
3394 | 555 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
556 chaninfo = !state->acmod; |
3394 | 557 do { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
558 if (bitstream_get (state, 1)) { /* dynrnge */ |
3394 | 559 int dynrng; |
560 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
561 dynrng = bitstream_get_2 (state, 8); |
3394 | 562 if (state->dynrnge) { |
563 sample_t range; | |
564 | |
565 range = ((((dynrng & 0x1f) | 0x20) << 13) * | |
566 scale_factor[3 - (dynrng >> 5)]); | |
567 if (state->dynrngcall) | |
568 range = state->dynrngcall (range, state->dynrngdata); | |
569 state->dynrng = state->level * range; | |
570 } | |
571 } | |
572 } while (chaninfo--); | |
573 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
574 if (bitstream_get (state, 1)) { /* cplstre */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
575 state->chincpl = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
576 if (bitstream_get (state, 1)) { /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
577 static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
578 45, 45, 46, 46, 47, 47, 48, 48}; |
3394 | 579 int cplbegf; |
580 int cplendf; | |
581 int ncplsubnd; | |
582 | |
583 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
584 state->chincpl |= bitstream_get (state, 1) << i; |
3394 | 585 switch (state->acmod) { |
586 case 0: case 1: | |
587 return 1; | |
588 case 2: | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
589 state->phsflginu = bitstream_get (state, 1); |
3394 | 590 } |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
591 cplbegf = bitstream_get (state, 4); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
592 cplendf = bitstream_get (state, 4); |
3394 | 593 |
594 if (cplendf + 3 - cplbegf < 0) | |
595 return 1; | |
596 state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf; | |
597 state->cplstrtbnd = bndtab[cplbegf]; | |
598 state->cplstrtmant = cplbegf * 12 + 37; | |
599 state->cplendmant = cplendf * 12 + 73; | |
600 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
601 state->cplbndstrc = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
602 for (i = 0; i < ncplsubnd - 1; i++) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
603 if (bitstream_get (state, 1)) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
604 state->cplbndstrc |= 1 << i; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
605 state->ncplbnd--; |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
606 } |
3394 | 607 } |
608 } | |
609 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
610 if (state->chincpl) { /* cplinu */ |
3394 | 611 int j, cplcoe; |
612 | |
613 cplcoe = 0; | |
614 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
615 if ((state->chincpl) >> i & 1) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
616 if (bitstream_get (state, 1)) { /* cplcoe */ |
3394 | 617 int mstrcplco, cplcoexp, cplcomant; |
618 | |
619 cplcoe = 1; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
620 mstrcplco = 3 * bitstream_get (state, 2); |
3394 | 621 for (j = 0; j < state->ncplbnd; j++) { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
622 cplcoexp = bitstream_get (state, 4); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
623 cplcomant = bitstream_get (state, 4); |
3394 | 624 if (cplcoexp == 15) |
625 cplcomant <<= 14; | |
626 else | |
627 cplcomant = (cplcomant | 0x10) << 13; | |
628 state->cplco[i][j] = | |
629 cplcomant * scale_factor[cplcoexp + mstrcplco]; | |
630 } | |
631 } | |
632 if ((state->acmod == 2) && state->phsflginu && cplcoe) | |
633 for (j = 0; j < state->ncplbnd; j++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
634 if (bitstream_get (state, 1)) /* phsflg */ |
3394 | 635 state->cplco[1][j] = -state->cplco[1][j]; |
636 } | |
637 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
638 if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */ |
3394 | 639 int end; |
640 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
641 state->rematflg = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
642 end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */ |
3394 | 643 i = 0; |
644 do | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
645 state->rematflg |= bitstream_get (state, 1) << i; |
3394 | 646 while (rematrix_band[i++] < end); |
647 } | |
648 | |
649 cplexpstr = EXP_REUSE; | |
650 lfeexpstr = EXP_REUSE; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
651 if (state->chincpl) /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
652 cplexpstr = bitstream_get (state, 2); |
3394 | 653 for (i = 0; i < nfchans; i++) |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
654 chexpstr[i] = bitstream_get (state, 2); |
3394 | 655 if (state->lfeon) |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
656 lfeexpstr = bitstream_get (state, 1); |
3394 | 657 |
658 for (i = 0; i < nfchans; i++) | |
659 if (chexpstr[i] != EXP_REUSE) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
660 if ((state->chincpl >> i) & 1) |
3394 | 661 state->endmant[i] = state->cplstrtmant; |
662 else { | |
663 int chbwcod; | |
664 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
665 chbwcod = bitstream_get (state, 6); |
3394 | 666 if (chbwcod > 60) |
667 return 1; | |
668 state->endmant[i] = chbwcod * 3 + 73; | |
669 } | |
670 } | |
671 | |
672 do_bit_alloc = 0; | |
673 | |
674 if (cplexpstr != EXP_REUSE) { | |
675 int cplabsexp, ncplgrps; | |
676 | |
677 do_bit_alloc = 64; | |
678 ncplgrps = ((state->cplendmant - state->cplstrtmant) / | |
679 (3 << (cplexpstr - 1))); | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
680 cplabsexp = bitstream_get (state, 4) << 1; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
681 if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
682 state->cpl_expbap.exp + state->cplstrtmant)) |
3394 | 683 return 1; |
684 } | |
685 for (i = 0; i < nfchans; i++) | |
686 if (chexpstr[i] != EXP_REUSE) { | |
687 int grp_size, nchgrps; | |
688 | |
689 do_bit_alloc |= 1 << i; | |
690 grp_size = 3 << (chexpstr[i] - 1); | |
691 nchgrps = (state->endmant[i] + grp_size - 4) / grp_size; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
692 state->fbw_expbap[i].exp[0] = bitstream_get (state, 4); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
693 if (parse_exponents (state, chexpstr[i], nchgrps, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
694 state->fbw_expbap[i].exp[0], |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
695 state->fbw_expbap[i].exp + 1)) |
3394 | 696 return 1; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
697 bitstream_skip (state, 2); /* gainrng */ |
3394 | 698 } |
699 if (lfeexpstr != EXP_REUSE) { | |
700 do_bit_alloc |= 32; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
701 state->lfe_expbap.exp[0] = bitstream_get (state, 4); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
702 if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0], |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
703 state->lfe_expbap.exp + 1)) |
3394 | 704 return 1; |
705 } | |
706 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
707 if (bitstream_get (state, 1)) { /* baie */ |
3394 | 708 do_bit_alloc = -1; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
709 state->bai = bitstream_get (state, 11); |
3394 | 710 } |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
711 if (bitstream_get (state, 1)) { /* snroffste */ |
3394 | 712 do_bit_alloc = -1; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
713 state->csnroffst = bitstream_get (state, 6); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
714 if (state->chincpl) /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
715 state->cplba.bai = bitstream_get (state, 7); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
716 for (i = 0; i < nfchans; i++) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
717 state->ba[i].bai = bitstream_get (state, 7); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
718 if (state->lfeon) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
719 state->lfeba.bai = bitstream_get (state, 7); |
3394 | 720 } |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
721 if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */ |
3394 | 722 do_bit_alloc |= 64; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
723 state->cplfleak = 9 - bitstream_get (state, 3); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
724 state->cplsleak = 9 - bitstream_get (state, 3); |
3394 | 725 } |
726 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
727 if (bitstream_get (state, 1)) { /* deltbaie */ |
3394 | 728 do_bit_alloc = -1; |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
729 if (state->chincpl) /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
730 state->cplba.deltbae = bitstream_get (state, 2); |
3394 | 731 for (i = 0; i < nfchans; i++) |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
732 state->ba[i].deltbae = bitstream_get (state, 2); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
733 if (state->chincpl && /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
734 (state->cplba.deltbae == DELTA_BIT_NEW) && |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
735 parse_deltba (state, state->cplba.deltba)) |
3394 | 736 return 1; |
737 for (i = 0; i < nfchans; i++) | |
738 if ((state->ba[i].deltbae == DELTA_BIT_NEW) && | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
739 parse_deltba (state, state->ba[i].deltba)) |
3394 | 740 return 1; |
741 } | |
742 | |
743 if (do_bit_alloc) { | |
744 if (zero_snr_offsets (nfchans, state)) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
745 memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap)); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
746 for (i = 0; i < nfchans; i++) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
747 memset (state->fbw_expbap[i].bap, 0, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
748 sizeof (state->fbw_expbap[i].bap)); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
749 memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap)); |
3394 | 750 } else { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
751 if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
752 a52_bit_allocate (state, &state->cplba, state->cplstrtbnd, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
753 state->cplstrtmant, state->cplendmant, |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
754 state->cplfleak << 8, state->cplsleak << 8, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
755 &state->cpl_expbap); |
3394 | 756 for (i = 0; i < nfchans; i++) |
757 if (do_bit_alloc & (1 << i)) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
758 a52_bit_allocate (state, state->ba + i, 0, 0, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
759 state->endmant[i], 0, 0, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
760 state->fbw_expbap +i); |
3394 | 761 if (state->lfeon && (do_bit_alloc & 32)) { |
762 state->lfeba.deltbae = DELTA_BIT_NONE; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
763 a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
764 &state->lfe_expbap); |
3394 | 765 } |
766 } | |
767 } | |
768 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
769 if (bitstream_get (state, 1)) { /* skiple */ |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
770 i = bitstream_get (state, 9); /* skipl */ |
3394 | 771 while (i--) |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
772 bitstream_skip (state, 8); |
3394 | 773 } |
774 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
775 samples = state->samples; |
3394 | 776 if (state->output & A52_LFE) |
777 samples += 256; /* shift for LFE channel */ | |
778 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
779 chanbias = a52_downmix_coeff (coeff, state->acmod, state->output, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
780 state->dynrng, state->clev, state->slev); |
3394 | 781 |
782 quantizer.q1_ptr = quantizer.q2_ptr = quantizer.q4_ptr = -1; | |
783 done_cpl = 0; | |
784 | |
785 for (i = 0; i < nfchans; i++) { | |
786 int j; | |
787 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
788 coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quantizer, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
789 coeff[i], dithflag[i], state->endmant[i]); |
3394 | 790 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
791 if ((state->chincpl >> i) & 1) { |
3394 | 792 if (!done_cpl) { |
793 done_cpl = 1; | |
794 coeff_get_coupling (state, nfchans, coeff, | |
795 (sample_t (*)[256])samples, &quantizer, | |
796 dithflag); | |
797 } | |
798 j = state->cplendmant; | |
799 } else | |
800 j = state->endmant[i]; | |
801 do | |
802 (samples + 256 * i)[j] = 0; | |
803 while (++j < 256); | |
804 } | |
805 | |
806 if (state->acmod == 2) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
807 int j, end, band, rematflg; |
3394 | 808 |
809 end = ((state->endmant[0] < state->endmant[1]) ? | |
810 state->endmant[0] : state->endmant[1]); | |
811 | |
812 i = 0; | |
813 j = 13; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
814 rematflg = state->rematflg; |
3394 | 815 do { |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
816 if (! (rematflg & 1)) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
817 rematflg >>= 1; |
3394 | 818 j = rematrix_band[i++]; |
819 continue; | |
820 } | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
821 rematflg >>= 1; |
3394 | 822 band = rematrix_band[i++]; |
823 if (band > end) | |
824 band = end; | |
825 do { | |
826 sample_t tmp0, tmp1; | |
827 | |
828 tmp0 = samples[j]; | |
829 tmp1 = (samples+256)[j]; | |
830 samples[j] = tmp0 + tmp1; | |
831 (samples+256)[j] = tmp0 - tmp1; | |
832 } while (++j < band); | |
833 } while (j < end); | |
834 } | |
835 | |
836 if (state->lfeon) { | |
837 if (state->output & A52_LFE) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
838 coeff_get (state, samples - 256, &state->lfe_expbap, &quantizer, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
839 state->dynrng, 0, 7); |
3394 | 840 for (i = 7; i < 256; i++) |
841 (samples-256)[i] = 0; | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
842 a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias); |
3394 | 843 } else { |
844 /* just skip the LFE coefficients */ | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
845 coeff_get (state, samples + 1280, &state->lfe_expbap, &quantizer, |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
846 0, 0, 7); |
3394 | 847 } |
848 } | |
849 | |
850 i = 0; | |
851 if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans) | |
852 for (i = 1; i < nfchans; i++) | |
853 if (blksw[i] != blksw[0]) | |
854 break; | |
855 | |
856 if (i < nfchans) { | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
857 if (state->downmixed) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
858 state->downmixed = 0; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
859 a52_upmix (samples + 1536, state->acmod, state->output); |
3394 | 860 } |
861 | |
862 for (i = 0; i < nfchans; i++) { | |
863 sample_t bias; | |
864 | |
865 bias = 0; | |
866 if (!(chanbias & (1 << i))) | |
867 bias = state->bias; | |
868 | |
869 if (coeff[i]) { | |
870 if (blksw[i]) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
871 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
872 bias); |
3394 | 873 else |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
874 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
875 bias); |
3394 | 876 } else { |
877 int j; | |
878 | |
879 for (j = 0; j < 256; j++) | |
880 (samples + 256 * i)[j] = bias; | |
881 } | |
882 } | |
883 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
884 a52_downmix (samples, state->acmod, state->output, state->bias, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
885 state->clev, state->slev); |
3394 | 886 } else { |
887 nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK]; | |
888 | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
889 a52_downmix (samples, state->acmod, state->output, 0, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
890 state->clev, state->slev); |
3394 | 891 |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
892 if (!state->downmixed) { |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
893 state->downmixed = 1; |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
894 a52_downmix (samples + 1536, state->acmod, state->output, 0, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
895 state->clev, state->slev); |
3394 | 896 } |
897 | |
898 if (blksw[0]) | |
899 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
900 a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
901 state->bias); |
3394 | 902 else |
903 for (i = 0; i < nfchans; i++) | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
904 a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i, |
18721
722ac20fac5f
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
18720
diff
changeset
|
905 state->bias); |
3394 | 906 } |
907 | |
908 return 0; | |
909 } | |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
910 |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
911 void a52_free (a52_state_t * state) |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
912 { |
20763
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
913 #if defined(__MINGW32__) && defined(HAVE_SSE) |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
914 av_free (state->samples); |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
915 #else |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
916 free (state->samples); |
b6bd2e6fa76d
symplify aligned memory allocation on mingw32 by using ffmpeg's av_malloc/av_free
gpoirier
parents:
18783
diff
changeset
|
917 #endif |
18720
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
918 free (state); |
4bad7f00556e
sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents:
14991
diff
changeset
|
919 } |