annotate liba52/bit_allocate.c @ 17111:1bfbe748d908

100l, codec-cfg needs fixing after -msgl patch
author ods15
date Tue, 06 Dec 2005 11:59:14 +0000
parents 35b18ed357c2
children 4bad7f00556e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
1 /*
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
2 * bit_allocate.c
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
5 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
7 * See http://liba52.sourceforge.net/ for updates.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
8 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
9 * a52dec is free software; you can redistribute it and/or modify
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
12 * (at your option) any later version.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
13 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
14 * a52dec is distributed in the hope that it will be useful,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
18 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
22 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
23
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
24 #include "config.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
25
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
26 #include <inttypes.h>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
27
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
28 #include "a52.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
29 #include "a52_internal.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
30
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
31 static int hthtab[3][50] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
32 {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
33 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
34 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
35 0x910, 0x910, 0x910, 0x910, 0x900, 0x8f0, 0x8c0, 0x870, 0x820, 0x7e0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
36 0x7a0, 0x770, 0x760, 0x7a0, 0x7c0, 0x7c0, 0x6e0, 0x400, 0x3c0, 0x3c0},
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
37 {0x710, 0x710, 0x7a0, 0x7f0, 0x820, 0x830, 0x840, 0x850, 0x850, 0x860,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
38 0x860, 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
39 0x890, 0x890, 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8e0, 0x8f0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
40 0x900, 0x910, 0x910, 0x910, 0x910, 0x900, 0x8e0, 0x8b0, 0x870, 0x820,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
41 0x7e0, 0x7b0, 0x760, 0x770, 0x7a0, 0x7c0, 0x780, 0x5d0, 0x3c0, 0x3c0},
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
42 {0x680, 0x680, 0x750, 0x7b0, 0x7e0, 0x810, 0x820, 0x830, 0x840, 0x850,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
43 0x850, 0x850, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
44 0x870, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880, 0x890, 0x8a0, 0x8b0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
45 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900, 0x910, 0x910, 0x910, 0x900, 0x8f0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
46 0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720}
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
47 };
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
48
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
49 static int8_t baptab[305] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
50 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
51 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
52 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
53 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
54 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
55 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /* 93 padding elems */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
56
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
57 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
58 14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
59 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
60 5, 4, 4, -3, -3, 3, 3, 3, -2, -2, -1, -1, -1, -1, -1, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
61
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
71 0, 0, 0, 0 /* 148 padding elems */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
72 };
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
73
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
74 static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
75 37, 40, 43, 46, 49, 55, 61, 67, 73, 79,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
76 85, 97, 109, 121, 133, 157, 181, 205, 229, 253};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
77
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
78 static int8_t latab[256] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
79 -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
80 -52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
81 -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
82 -35, -34, -33, -33, -32, -32, -31, -30, -30, -29, -29, -28,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
83 -28, -27, -27, -26, -26, -25, -25, -24, -24, -23, -23, -22,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
84 -22, -21, -21, -21, -20, -20, -19, -19, -19, -18, -18, -18,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
85 -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
86 -13, -13, -13, -13, -12, -12, -12, -12, -11, -11, -11, -11,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
87 -10, -10, -10, -10, -10, -9, -9, -9, -9, -9, -8, -8,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
88 -8, -8, -8, -8, -7, -7, -7, -7, -7, -7, -6, -6,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
89 -6, -6, -6, -6, -6, -6, -5, -5, -5, -5, -5, -5,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
90 -5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
91 -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
92 -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
93 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
94 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
95 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
96 -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
100 0, 0, 0, 0
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
101 };
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
102
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
103 #define UPDATE_LEAK() \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
104 do { \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
105 fastleak += fdecay; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
106 if (fastleak > psd + fgain) \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
107 fastleak = psd + fgain; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
108 slowleak += sdecay; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
109 if (slowleak > psd + sgain) \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
110 slowleak = psd + sgain; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
111 } while (0)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
112
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
113 #define COMPUTE_MASK() \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
114 do { \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
115 if (psd > dbknee) \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
116 mask -= (psd - dbknee) >> 2; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
117 if (mask > hth [i >> halfrate]) \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
118 mask = hth [i >> halfrate]; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
119 mask -= snroffset + 128 * deltba[i]; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
120 mask = (mask > 0) ? 0 : ((-mask) >> 5); \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
121 mask -= floor; \
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
122 } while (0)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
123
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
124 void bit_allocate (a52_state_t * state, a52_ba_t * ba, int bndstart,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
125 int start, int end, int fastleak, int slowleak,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
126 uint8_t * exp, int8_t * bap)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
127 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
128 static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
129 static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
130 static int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
131 0xa10, 0xa90, 0xb10, 0x1400};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
132
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
133 int i, j;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
134 int fdecay, fgain, sdecay, sgain, dbknee, floor, snroffset;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
135 int psd, mask;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
136 int8_t * deltba;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
137 int * hth;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
138 int halfrate;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
139
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
140 halfrate = state->halfrate;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
141 fdecay = (63 + 20 * state->fdcycod) >> halfrate;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
142 fgain = 128 + 128 * ba->fgaincod;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
143 sdecay = (15 + 2 * state->sdcycod) >> halfrate;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
144 sgain = slowgain[state->sgaincod];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
145 dbknee = dbpbtab[state->dbpbcod];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
146 hth = hthtab[state->fscod];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
147 /*
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
148 * if there is no delta bit allocation, make deltba point to an area
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
149 * known to contain zeroes. baptab+156 here.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
150 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
151 deltba = (ba->deltbae == DELTA_BIT_NONE) ? baptab + 156 : ba->deltba;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
152 floor = floortab[state->floorcod];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
153 snroffset = 960 - 64 * state->csnroffst - 4 * ba->fsnroffst + floor;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
154 floor >>= 5;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
155
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
156 i = bndstart;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
157 j = start;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
158 if (start == 0) { /* not the coupling channel */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
159 int lowcomp;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
160
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
161 lowcomp = 0;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
162 j = end - 1;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
163 do {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
164 if (i < j) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
165 if (exp[i+1] == exp[i] - 2)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
166 lowcomp = 384;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
167 else if (lowcomp && (exp[i+1] > exp[i]))
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
168 lowcomp -= 64;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
169 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
170 psd = 128 * exp[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
171 mask = psd + fgain + lowcomp;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
172 COMPUTE_MASK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
173 bap[i] = (baptab+156)[mask + 4 * exp[i]];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
174 i++;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
175 } while ((i < 3) || ((i < 7) && (exp[i] > exp[i-1])));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
176 fastleak = psd + fgain;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
177 slowleak = psd + sgain;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
178
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
179 while (i < 7) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
180 if (i < j) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
181 if (exp[i+1] == exp[i] - 2)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
182 lowcomp = 384;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
183 else if (lowcomp && (exp[i+1] > exp[i]))
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
184 lowcomp -= 64;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
185 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
186 psd = 128 * exp[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
187 UPDATE_LEAK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
188 mask = ((fastleak + lowcomp < slowleak) ?
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
189 fastleak + lowcomp : slowleak);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
190 COMPUTE_MASK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
191 bap[i] = (baptab+156)[mask + 4 * exp[i]];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
192 i++;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
193 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
194
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
195 if (end == 7) /* lfe channel */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
196 return;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
197
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
198 do {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
199 if (exp[i+1] == exp[i] - 2)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
200 lowcomp = 320;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
201 else if (lowcomp && (exp[i+1] > exp[i]))
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
202 lowcomp -= 64;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
203 psd = 128 * exp[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
204 UPDATE_LEAK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
205 mask = ((fastleak + lowcomp < slowleak) ?
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
206 fastleak + lowcomp : slowleak);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
207 COMPUTE_MASK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
208 bap[i] = (baptab+156)[mask + 4 * exp[i]];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
209 i++;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
210 } while (i < 20);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
211
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
212 while (lowcomp > 128) { /* two iterations maximum */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
213 lowcomp -= 128;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
214 psd = 128 * exp[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
215 UPDATE_LEAK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
216 mask = ((fastleak + lowcomp < slowleak) ?
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
217 fastleak + lowcomp : slowleak);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
218 COMPUTE_MASK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
219 bap[i] = (baptab+156)[mask + 4 * exp[i]];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
220 i++;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
221 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
222 j = i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
223 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
224
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
225 do {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
226 int startband, endband;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
227
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
228 startband = j;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
229 endband = ((bndtab-20)[i] < end) ? (bndtab-20)[i] : end;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
230 psd = 128 * exp[j++];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
231 while (j < endband) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
232 int next, delta;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
233
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
234 next = 128 * exp[j++];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
235 delta = next - psd;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
236 switch (delta >> 9) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
237 case -6: case -5: case -4: case -3: case -2:
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
238 psd = next;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
239 break;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
240 case -1:
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
241 psd = next + latab[(-delta) >> 1];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
242 break;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
243 case 0:
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
244 psd += latab[delta >> 1];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
245 break;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
246 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
247 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
248 /* minpsd = -289 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
249 UPDATE_LEAK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
250 mask = (fastleak < slowleak) ? fastleak : slowleak;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
251 COMPUTE_MASK ();
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
252 i++;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
253 j = startband;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
254 do {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
255 /* max(mask+4*exp)=147=-(minpsd+fgain-deltba-snroffset)>>5+4*exp */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
256 /* min(mask+4*exp)=-156=-(sgain-deltba-snroffset)>>5 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
257 bap[j] = (baptab+156)[mask + 4 * exp[j]];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
258 } while (++j < endband);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
259 } while (j < end);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
260 }