annotate liba52/parse.c @ 17088:f067a9de373c

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