annotate libac3/bit_allocate.c @ 44:92d51f683931 libavcodec

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