annotate liba52/parse.c @ 1194:432d9a42a244 libavcodec

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