annotate liba52/parse.c @ 19861:b251bca5820c

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