Debian Codegraph @

external/lame/bitstream.c

raw symbols SCIP
1 /*
2 * MP3 bitstream Output interface for LAME
3 *
4 * Copyright (c) 1999-2000 Mark Taylor
5 * Copyright (c) 1999-2002 Takehiro Tominaga
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * $Id: bitstream.c,v 1.99 2017/08/31 14:14:46 robert Exp $
23 */
24
25
26 //#ifdef HAVE_CONFIG_H
27 #include "lame__config.h"cxx . . $ `<file>/external/lame/lame__config.h`/
28 //#endif
29
30 #include <stdlib.h>
31 #include <stdio.h>
32
33 #include "lame.h"cxx . . $ `<file>/external/lame/lame.h`/
34 #include "machine.h"cxx . . $ `<file>/external/lame/machine.h`/
35 #include "encoder.h"cxx . . $ `<file>/external/lame/encoder.h`/
36 #include "util.h"cxx . . $ `<file>/external/lame/util.h`/
37 #include "tables.h"cxx . . $ `<file>/external/lame/tables.h`/
38 #include "quantize_pvt.h"cxx . . $ `<file>/external/lame/quantize_pvt.h`/
39 #include "lame_global_flags.h"cxx . . $ `<file>/external/lame/lame_global_flags.h`/
40 #include "gain_analysis.h"cxx . . $ `<file>/external/lame/gain_analysis.h`/
41 #include "VbrTag.h"cxx . . $ `<file>/external/lame/VbrTag.h`/
42 #include "bitstream.h"cxx . . $ `<file>/external/lame/bitstream.h`/
43 #include "tables.h"cxx . . $ `<file>/external/lame/tables.h`/
44
45
46
47 /* unsigned int is at least this large: */
48 /* we work with ints, so when doing bit manipulation, we limit
49 * ourselves to MAX_LENGTH-2 just to be on the safe side */
50 #define MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`! 32
51
52
53
54 #ifdef DEBUG
55 static int hogege;
56 #endif
57
58
59
60 static int
61 calcFrameLengthcxx . . $ calcFrameLength(aafcbc9e3c7e26d).(SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg, int kbps, int pad)
62 {
63 return 8 * ((cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version. + 1) * 72000 * kbps / cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. + pad);
64 }
65
66
67 /***********************************************************************
68 * compute bitsperframe and mean_bits for a layer III frame
69 **********************************************************************/
70 int
71 getframebitscxx . . $ getframebits(b815612886108da).(const lame_internal_flagscxx . . $ lame_internal_flags# * gfc)
72 {
73 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
74 EncResult_tcxx . . $ EncResult_t# const *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.;
75 int bit_rate;
76
77 /* get bitrate in kbps [?] */
78 if (eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.)
79 bit_rate = bitrate_tablecxx . . $ bitrate_table.[cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version.][eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.];
80 else
81 bit_rate = cfg->avg_bitratecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#avg_bitrate.;
82 /*assert(bit_rate <= 550); */
83 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(8 <= bit_rate && bit_rate <= 640);
84
85 /* main encoding routine toggles padding on and off */
86 /* one Layer3 Slot consists of 8 bits */
87 return calcFrameLengthcxx . . $ calcFrameLength(aafcbc9e3c7e26d).(cfg, bit_rate, eov->paddingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#padding.);
88 }
89
90 int
91 get_max_frame_buffer_size_by_constraintcxx . . $ get_max_frame_buffer_size_by_constraint(10808010e3d809b5).(SessionConfig_tcxx . . $ SessionConfig_t# const * cfg, int constraint)
92 {
93 int maxmp3buf = 0;
94 if (cfg->avg_bitratecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#avg_bitrate. > 320) {
95 /* in freeformat the buffer is constant */
96 if (constraint == MDB_STRICT_ISOcxx . . $ MDB_STRICT_ISO.) {
97 maxmp3buf = calcFrameLengthcxx . . $ calcFrameLength(aafcbc9e3c7e26d).(cfg, cfg->avg_bitratecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#avg_bitrate., 0);
98 }
99 else {
100 /* maximum allowed bits per granule are 7680 */
101 maxmp3buf = 7680 * (cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version. + 1);
102 }
103 }
104 else {
105 int max_kbps;
106 if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. < 16000) {
107 max_kbps = bitrate_tablecxx . . $ bitrate_table.[cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version.][8]; /* default: allow 64 kbps (MPEG-2.5) */
108 }
109 else {
110 max_kbps = bitrate_tablecxx . . $ bitrate_table.[cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version.][14];
111 }
112 switch (constraint)
113 {
114 default:
115 case MDB_DEFAULTcxx . . $ MDB_DEFAULT.:
116 /* Bouvigne suggests this more lax interpretation of the ISO doc instead of using 8*960. */
117 /* All mp3 decoders should have enough buffer to handle this value: size of a 320kbps 32kHz frame */
118 maxmp3buf = 8 * 1440;
119 break;
120 case MDB_STRICT_ISOcxx . . $ MDB_STRICT_ISO.:
121 maxmp3buf = calcFrameLengthcxx . . $ calcFrameLength(aafcbc9e3c7e26d).(cfg, max_kbps, 0);
122 break;
123 case MDB_MAXIMUMcxx . . $ MDB_MAXIMUM.:
124 maxmp3buf = 7680 * (cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version. + 1);
125 break;
126 }
127 }
128 return maxmp3buf;
129 }
130
131
132 static void
133 putheader_bitscxx . . $ putheader_bits(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc)
134 {
135 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
136 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
137 Bit_stream_struccxx . . $ Bit_stream_struc# *bs = &gfc->bscxx . . $ lame_internal_flags#bs.;
138 #ifdef DEBUG
139 hogege += cfg->sideinfo_len * 8;
140 #endif
141 memcpycxx . . $ memcpy(cc817cb175f282d).(&bs->bufcxx . . $ bit_stream_struc#buf.[bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.], esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr.].bufcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#buf., cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.);
142 bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx. += cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.;
143 bs->totbitcxx . . $ bit_stream_struc#totbit. += cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len. * 8;
144 esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr. = (esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr. + 1) & (MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`! - 1);
145 }
146
147
148
149
150 /*write j bits into the bit stream */
151 inlinecxx . . $ `external/lame/machine.h:107:10`! static void
152 putbits2cxx . . $ putbits2(b6022c2330fef37d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int val, int j)
153 {
154 EncStateVar_tcxx . . $ EncStateVar_t# const *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
155 Bit_stream_struccxx . . $ Bit_stream_struc# *bs;
156 bs = &gfc->bscxx . . $ lame_internal_flags#bs.;
157
158 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`! - 2);
159
160 while (j > 0) {
161 int k;
162 if (bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. == 0) {
163 bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. = 8;
164 bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.++;
165 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(bs->buf_byte_idx < BUFFER_SIZEcxx . . $ `external/lame/util.h:89:17`!);
166 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(esv->header[esv->w_ptr].write_timing >= bs->totbit);
167 if (esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr.].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. == bs->totbitcxx . . $ bit_stream_struc#totbit.) {
168 putheader_bitscxx . . $ putheader_bits(4f558d83b2842a93).(gfc);
169 }
170 bs->bufcxx . . $ bit_stream_struc#buf.[bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.] = 0;
171 }
172
173 k = Mincxx . . $ `external/lame/util.h:91:17`!(j, bs->buf_bit_idx);
174 j -= k;
175
176 bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. -= k;
177
178 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!); /* 32 too large on 32 bit machines */
179 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(bs->buf_bit_idx < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!);
180
181 bs->bufcxx . . $ bit_stream_struc#buf.[bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.] |= ((val >> j) << bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx.);
182 bs->totbitcxx . . $ bit_stream_struc#totbit. += k;
183 }
184 }
185
186 /*write j bits into the bit stream, ignoring frame headers */
187 inlinecxx . . $ `external/lame/machine.h:107:10`! static void
188 putbits_noheaderscxx . . $ putbits_noheaders(b6022c2330fef37d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int val, int j)
189 {
190 Bit_stream_struccxx . . $ Bit_stream_struc# *bs;
191 bs = &gfc->bscxx . . $ lame_internal_flags#bs.;
192
193 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`! - 2);
194
195 while (j > 0) {
196 int k;
197 if (bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. == 0) {
198 bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. = 8;
199 bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.++;
200 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(bs->buf_byte_idx < BUFFER_SIZEcxx . . $ `external/lame/util.h:89:17`!);
201 bs->bufcxx . . $ bit_stream_struc#buf.[bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.] = 0;
202 }
203
204 k = Mincxx . . $ `external/lame/util.h:91:17`!(j, bs->buf_bit_idx);
205 j -= k;
206
207 bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. -= k;
208
209 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!); /* 32 too large on 32 bit machines */
210 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(bs->buf_bit_idx < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!);
211
212 bs->bufcxx . . $ bit_stream_struc#buf.[bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx.] |= ((val >> j) << bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx.);
213 bs->totbitcxx . . $ bit_stream_struc#totbit. += k;
214 }
215 }
216
217
218 /*
219 Some combinations of bitrate, Fs, and stereo make it impossible to stuff
220 out a frame using just main_data, due to the limited number of bits to
221 indicate main_data_length. In these situations, we put stuffing bits into
222 the ancillary data...
223 */
224
225 inlinecxx . . $ `external/lame/machine.h:107:10`! static void
226 drain_into_ancillarycxx . . $ drain_into_ancillary(8f5851925078004a).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int remainingBits)
227 {
228 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
229 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
230 int i;
231 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(remainingBits >= 0);
232
233 if (remainingBits >= 8) {
234 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, 0x4c, 8);
235 remainingBits -= 8;
236 }
237 if (remainingBits >= 8) {
238 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, 0x41, 8);
239 remainingBits -= 8;
240 }
241 if (remainingBits >= 8) {
242 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, 0x4d, 8);
243 remainingBits -= 8;
244 }
245 if (remainingBits >= 8) {
246 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, 0x45, 8);
247 remainingBits -= 8;
248 }
249
250 if (remainingBits >= 32) {
251 const char *const version = get_lame_short_versioncxx . . $ get_lame_short_version(33a1f659e94feb42).();
252 if (remainingBits >= 32)
253 for (i = 0; i < (int) strlencxx . . $ strlen(751346f8406fd082).(version) && remainingBits >= 8; ++i) {
254 remainingBits -= 8;
255 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, version[i], 8);
256 }
257 }
258
259 for (; remainingBits >= 1; remainingBits -= 1) {
260 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, esv->ancillary_flagcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ancillary_flag., 1);
261 esv->ancillary_flagcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ancillary_flag. ^= !cfg->disable_reservoircxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#disable_reservoir.;
262 }
263
264 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(remainingBits == 0);
265
266 }
267
268 /*write N bits into the header */
269 inlinecxx . . $ `external/lame/machine.h:107:10`! static void
270 writeheadercxx . . $ writeheader(b6022c2330fef37d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int val, int j)
271 {
272 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
273 int ptr = esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#ptr.;
274
275 while (j > 0) {
276 int const k = Mincxx . . $ `external/lame/util.h:91:17`!(j, 8 - (ptr & 7));
277 j -= k;
278 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!); /* >> 32 too large for 32 bit machines */
279 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].bufcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#buf.[ptr >> 3]
280 |= ((val >> j)) << (8 - (ptr & 7) - k);
281 ptr += k;
282 }
283 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#ptr. = ptr;
284 }
285
286
287 static int
288 CRC_updatecxx . . $ CRC_update(9b79fb6aee4c0440).(int value, int crc)
289 {
290 int i;
291 value <<= 8;
292 for (i = 0; i < 8; i++) {
293 value <<= 1;
294 crc <<= 1;
295
296 if (((crc ^ value) & 0x10000))
297 crc ^= CRC16_POLYNOMIALcxx . . $ `external/lame/util.h:83:17`!;
298 }
299 return crc;
300 }
301
302
303 void
304 CRC_writeheadercxx . . $ CRC_writeheader(8f513048b0505555).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, char *header)
305 {
306 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
307 int crc = 0xffff; /* (jo) init crc16 for error_protection */
308 int i;
309
310 crc = CRC_updatecxx . . $ CRC_update(9b79fb6aee4c0440).(((unsigned char *) header)[2], crc);
311 crc = CRC_updatecxx . . $ CRC_update(9b79fb6aee4c0440).(((unsigned char *) header)[3], crc);
312 for (i = 6; i < cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.; i++) {
313 crc = CRC_updatecxx . . $ CRC_update(9b79fb6aee4c0440).(((unsigned char *) header)[i], crc);
314 }
315
316 header[4] = crc >> 8;
317 header[5] = crc & 255;
318 }
319
320 inlinecxx . . $ `external/lame/machine.h:107:10`! static void
321 encodeSideInfo2cxx . . $ encodeSideInfo2(8f5851925078004a).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int bitsPerFrame)
322 {
323 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
324 EncResult_tcxx . . $ EncResult_t# const *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.;
325 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
326 III_side_info_tcxx . . $ III_side_info_t# *l3_side;
327 int gr, ch;
328
329 l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.;
330 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#ptr. = 0;
331 memsetcxx . . $ memset(d1de1e4fb215f1c6).(esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].bufcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#buf., 0, cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.);
332 if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. < 16000)
333 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 0xffe, 12);
334 else
335 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 0xfff, 12);
336 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version.), 1);
337 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 4 - 3, 2);
338 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (!cfg->error_protectioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#error_protection.), 1);
339 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.), 4);
340 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->samplerate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_index.), 2);
341 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (eov->paddingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#padding.), 1);
342 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->extensioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#extension.), 1);
343 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->modecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode.), 2);
344 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (eov->mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext.), 2);
345 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->copyrightcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#copyright.), 1);
346 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->originalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#original.), 1);
347 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (cfg->emphasiscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#emphasis.), 2);
348 if (cfg->error_protectioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#error_protection.) {
349 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 0, 16); /* dummy */
350 }
351
352 if (cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version. == 1) {
353 /* MPEG1 */
354 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(l3_side->main_data_begin >= 0);
355 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin.), 9);
356
357 if (cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out. == 2)
358 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, l3_side->private_bitscxx . . $ $anonymous_type_fdda207d22d8fb07_4#private_bits., 3);
359 else
360 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, l3_side->private_bitscxx . . $ $anonymous_type_fdda207d22d8fb07_4#private_bits., 5);
361
362 for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) {
363 int band;
364 for (band = 0; band < 4; band++) {
365 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, l3_side->scfsicxx . . $ $anonymous_type_fdda207d22d8fb07_4#scfsi.[ch][band], 1);
366 }
367 }
368
369 for (gr = 0; gr < 2; gr++) {
370 for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) {
371 gr_infocxx . . $ gr_info# *const gi = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch];
372 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. + gi->part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length., 12);
373 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values. / 2, 9);
374 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain., 8);
375 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->scalefac_compresscxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_compress., 4);
376
377 if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!) {
378 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 1, 1); /* window_switching_flag */
379 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type., 2);
380 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->mixed_block_flagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#mixed_block_flag., 1);
381
382 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] == 14)
383 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] = 16;
384 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 5);
385 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] == 14)
386 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] = 16;
387 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], 5);
388
389 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[0], 3);
390 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[1], 3);
391 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[2], 3);
392 }
393 else {
394 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 0, 1); /* window_switching_flag */
395 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] == 14)
396 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] = 16;
397 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 5);
398 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] == 14)
399 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] = 16;
400 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], 5);
401 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2] == 14)
402 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2] = 16;
403 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2], 5);
404
405 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= gi->region0_count && gi->region0_count < 16);
406 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= gi->region1_count && gi->region1_count < 8);
407 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->region0_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region0_count., 4);
408 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->region1_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region1_count., 3);
409 }
410 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->preflagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#preflag., 1);
411 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale., 1);
412 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->count1table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1table_select., 1);
413 }
414 }
415 }
416 else {
417 /* MPEG2 */
418 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(l3_side->main_data_begin >= 0);
419 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, (l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin.), 8);
420 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, l3_side->private_bitscxx . . $ $anonymous_type_fdda207d22d8fb07_4#private_bits., cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.);
421
422 gr = 0;
423 for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) {
424 gr_infocxx . . $ gr_info# *const gi = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch];
425 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. + gi->part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length., 12);
426 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values. / 2, 9);
427 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain., 8);
428 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->scalefac_compresscxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_compress., 9);
429
430 if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!) {
431 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 1, 1); /* window_switching_flag */
432 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type., 2);
433 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->mixed_block_flagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#mixed_block_flag., 1);
434
435 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] == 14)
436 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] = 16;
437 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 5);
438 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] == 14)
439 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] = 16;
440 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], 5);
441
442 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[0], 3);
443 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[1], 3);
444 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[2], 3);
445 }
446 else {
447 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, 0, 1); /* window_switching_flag */
448 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] == 14)
449 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] = 16;
450 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 5);
451 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] == 14)
452 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] = 16;
453 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], 5);
454 if (gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2] == 14)
455 gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2] = 16;
456 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2], 5);
457
458 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= gi->region0_count && gi->region0_count < 16);
459 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= gi->region1_count && gi->region1_count < 8);
460 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->region0_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region0_count., 4);
461 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->region1_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region1_count., 3);
462 }
463
464 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale., 1);
465 writeheadercxx . . $ writeheader(b6022c2330fef37d).(gfc, gi->count1table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1table_select., 1);
466 }
467 }
468
469 if (cfg->error_protectioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#error_protection.) {
470 /* (jo) error_protection: add crc16 information to header */
471 CRC_writeheadercxx . . $ CRC_writeheader(8f513048b0505555).(gfc, esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].bufcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#buf.);
472 }
473
474 {
475 int const old = esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.;
476 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(esv->header[old].ptr == cfg->sideinfo_len * 8);
477
478 esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr. = (old + 1) & (MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`! - 1);
479 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. = esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[old].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. + bitsPerFrame;
480
481 if (esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr. == esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr.) {
482 /* yikes! we are out of header buffer space */
483 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "Error: MAX_HEADER_BUF too small in bitstream.c \n");
484 }
485
486 }
487 }
488
489
490 inlinecxx . . $ `external/lame/machine.h:107:10`! static int
491 huffman_coder_count1cxx . . $ huffman_coder_count1(4c3c04bbcbe3c6b7).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# const *gi)
492 {
493 /* Write count1 area */
494 struct huffcodetabcxx . . $ huffcodetab# const *const h = &htcxx . . $ ht.[gi->count1table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1table_select. + 32];
495 int i, bits = 0;
496 #ifdef DEBUG
497 int gegebo = gfc->bs.totbit;
498 #endif
499
500 int const *ix = &gi->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.];
501 FLOATcxx . . $ FLOAT# const *xr = &gi->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.];
502 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->count1table_select < 2);
503
504 for (i = (gi->count1cxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1. - gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.) / 4; i > 0; --i) {
505 int huffbits = 0;
506 int p = 0, v;
507
508 v = ix[0];
509 if (v) {
510 p += 8;
511 if (xr[0] < 0.0f)
512 huffbits++;
513 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(v <= 1);
514 }
515
516 v = ix[1];
517 if (v) {
518 p += 4;
519 huffbits *= 2;
520 if (xr[1] < 0.0f)
521 huffbits++;
522 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(v <= 1);
523 }
524
525 v = ix[2];
526 if (v) {
527 p += 2;
528 huffbits *= 2;
529 if (xr[2] < 0.0f)
530 huffbits++;
531 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(v <= 1);
532 }
533
534 v = ix[3];
535 if (v) {
536 p++;
537 huffbits *= 2;
538 if (xr[3] < 0.0f)
539 huffbits++;
540 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(v <= 1);
541 }
542
543 ix += 4;
544 xr += 4;
545 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, huffbits + h->tablecxx . . $ huffcodetab#table.[p], h->hlencxx . . $ huffcodetab#hlen.[p]);
546 bits += h->hlencxx . . $ huffcodetab#hlen.[p];
547 }
548 #ifdef DEBUG
549 DEBUGF(gfc, "count1: real: %ld counted:%d (bigv %d count1len %d)\n",
550 gfc->bs.totbit - gegebo, gi->count1bits, gi->big_values, gi->count1);
551 #endif
552 return bits;
553 }
554
555
556
557 /*
558 Implements the pseudocode of page 98 of the IS
559 */
560 inlinecxx . . $ `external/lame/machine.h:107:10`! static int
561 Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc, const unsigned int tableindex,
562 int start, int end, gr_infocxx . . $ gr_info# const *gi)
563 {
564 struct huffcodetabcxx . . $ huffcodetab# const *const h = &htcxx . . $ ht.[tableindex];
565 unsigned int const linbits = h->xlencxx . . $ huffcodetab#xlen.;
566 int i, bits = 0;
567
568 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(tableindex < 32u);
569 if (!tableindex)
570 return bits;
571
572 for (i = start; i < end; i += 2) {
573 int16_tcxx . . $ int16_t# cbits = 0;
574 uint16_tcxx . . $ uint16_t# xbits = 0;
575 unsigned int xlen = h->xlencxx . . $ huffcodetab#xlen.;
576 unsigned int ext = 0;
577 unsigned int x1 = gi->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[i];
578 unsigned int x2 = gi->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[i + 1];
579
580 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->l3_enc[i] >= 0);
581 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->l3_enc[i+1] >= 0);
582
583 if (x1 != 0u) {
584 if (gi->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i] < 0.0f)
585 ext++;
586 cbits--;
587 }
588
589 if (tableindex > 15u) {
590 /* use ESC-words */
591 if (x1 >= 15u) {
592 uint16_tcxx . . $ uint16_t# const linbits_x1 = x1 - 15u;
593 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(linbits_x1 <= h->linmax);
594 ext |= linbits_x1 << 1u;
595 xbits = linbits;
596 x1 = 15u;
597 }
598
599 if (x2 >= 15u) {
600 uint16_tcxx . . $ uint16_t# const linbits_x2 = x2 - 15u;
601 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(linbits_x2 <= h->linmax);
602 ext <<= linbits;
603 ext |= linbits_x2;
604 xbits += linbits;
605 x2 = 15u;
606 }
607 xlen = 16;
608 }
609
610 if (x2 != 0u) {
611 ext <<= 1;
612 if (gi->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i + 1] < 0.0f)
613 ext++;
614 cbits--;
615 }
616
617 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((x1 | x2) < 16u);
618
619 x1 = x1 * xlen + x2;
620 xbits -= cbits;
621 cbits += h->hlencxx . . $ huffcodetab#hlen.[x1];
622
623 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cbits <= MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!);
624 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(xbits <= MAX_LENGTHcxx . . $ `external/lame/bitstream.c:50:9`!);
625
626 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, h->tablecxx . . $ huffcodetab#table.[x1], cbits);
627 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, (int)ext, xbits);
628 bits += cbits + xbits;
629 }
630 return bits;
631 }
632
633 /*
634 Note the discussion of huffmancodebits() on pages 28
635 and 29 of the IS, as well as the definitions of the side
636 information on pages 26 and 27.
637 */
638 static int
639 ShortHuffmancodebitscxx . . $ ShortHuffmancodebits(4c3c04bbcbe3c6b7).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# const *gi)
640 {
641 int bits;
642 int region1Start;
643
644 region1Start = 3 * gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[3];
645 if (region1Start > gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.)
646 region1Start = gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.;
647
648 /* short blocks do not have a region2 */
649 bits = Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 0, region1Start, gi);
650 bits += Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], region1Start, gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values., gi);
651 return bits;
652 }
653
654 static int
655 LongHuffmancodebitscxx . . $ LongHuffmancodebits(4c3c04bbcbe3c6b7).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# const *gi)
656 {
657 unsigned int i;
658 int bigvalues, bits;
659 int region1Start, region2Start;
660
661 bigvalues = gi->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values.;
662 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= bigvalues && bigvalues <= 576);
663
664 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->region0_count >= -1);
665 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->region1_count >= -1);
666 i = gi->region0_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region0_count. + 1;
667 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((size_t) i < dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(gfc->scalefac_band.l));
668 region1Start = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[i];
669 i += gi->region1_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region1_count. + 1;
670 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((size_t) i < dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(gfc->scalefac_band.l));
671 region2Start = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[i];
672
673 if (region1Start > bigvalues)
674 region1Start = bigvalues;
675
676 if (region2Start > bigvalues)
677 region2Start = bigvalues;
678
679 bits = Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0], 0, region1Start, gi);
680 bits += Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1], region1Start, region2Start, gi);
681 bits += Huffmancodecxx . . $ Huffmancode(1c0548a2ae8ef53a).(gfc, gi->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2], region2Start, bigvalues, gi);
682 return bits;
683 }
684
685 inlinecxx . . $ `external/lame/machine.h:107:10`! static int
686 writeMainDatacxx . . $ writeMainData(42b75628a052f811).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc)
687 {
688 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
689 III_side_info_tcxx . . $ III_side_info_t# const *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.;
690 int gr, ch, sfb, data_bits, tot_bits = 0;
691
692 if (cfg->versioncxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#version. == 1) {
693 /* MPEG 1 */
694 for (gr = 0; gr < 2; gr++) {
695 for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) {
696 gr_infocxx . . $ gr_info# const *const gi = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch];
697 int const slen1 = slen1_tabcxx . . $ slen1_tab.[gi->scalefac_compresscxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_compress.];
698 int const slen2 = slen2_tabcxx . . $ slen2_tab.[gi->scalefac_compresscxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_compress.];
699 data_bits = 0;
700 #ifdef DEBUG
701 hogege = gfc->bs.totbit;
702 #endif
703 for (sfb = 0; sfb < gi->sfbdividecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbdivide.; sfb++) {
704 if (gi->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb] == -1)
705 continue; /* scfsi is used */
706 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, gi->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb], slen1);
707 data_bits += slen1;
708 }
709 for (; sfb < gi->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb++) {
710 if (gi->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb] == -1)
711 continue; /* scfsi is used */
712 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, gi->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb], slen2);
713 data_bits += slen2;
714 }
715 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(data_bits == gi->part2_length);
716
717 if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) {
718 data_bits += ShortHuffmancodebitscxx . . $ ShortHuffmancodebits(4c3c04bbcbe3c6b7).(gfc, gi);
719 }
720 else {
721 data_bits += LongHuffmancodebitscxx . . $ LongHuffmancodebits(4c3c04bbcbe3c6b7).(gfc, gi);
722 }
723 data_bits += huffman_coder_count1cxx . . $ huffman_coder_count1(4c3c04bbcbe3c6b7).(gfc, gi);
724 #ifdef DEBUG
725 DEBUGF(gfc, "<%ld> ", gfc->bs.totbit - hogege);
726 #endif
727 /* does bitcount in quantize.c agree with actual bit count? */
728 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(data_bits == gi->part2_3_length + gi->part2_length);
729 tot_bits += data_bits;
730 } /* for ch */
731 } /* for gr */
732 }
733 else {
734 /* MPEG 2 */
735 gr = 0;
736 for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) {
737 gr_infocxx . . $ gr_info# const *const gi = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch];
738 int i, sfb_partition, scale_bits = 0;
739 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gi->sfb_partition_table);
740 data_bits = 0;
741 #ifdef DEBUG
742 hogege = gfc->bs.totbit;
743 #endif
744 sfb = 0;
745 sfb_partition = 0;
746
747 if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) {
748 for (; sfb_partition < 4; sfb_partition++) {
749 int const sfbs = gi->sfb_partition_tablecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_partition_table.[sfb_partition] / 3;
750 int const slen = gi->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[sfb_partition];
751 for (i = 0; i < sfbs; i++, sfb++) {
752 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, Maxcxx . . $ `external/lame/util.h:92:17`!(gi->scalefac[sfb * 3 + 0], 0), slen);
753 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, Maxcxx . . $ `external/lame/util.h:92:17`!(gi->scalefac[sfb * 3 + 1], 0), slen);
754 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, Maxcxx . . $ `external/lame/util.h:92:17`!(gi->scalefac[sfb * 3 + 2], 0), slen);
755 scale_bits += 3 * slen;
756 }
757 }
758 data_bits += ShortHuffmancodebitscxx . . $ ShortHuffmancodebits(4c3c04bbcbe3c6b7).(gfc, gi);
759 }
760 else {
761 for (; sfb_partition < 4; sfb_partition++) {
762 int const sfbs = gi->sfb_partition_tablecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_partition_table.[sfb_partition];
763 int const slen = gi->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[sfb_partition];
764 for (i = 0; i < sfbs; i++, sfb++) {
765 putbits2cxx . . $ putbits2(b6022c2330fef37d).(gfc, Maxcxx . . $ `external/lame/util.h:92:17`!(gi->scalefac[sfb], 0), slen);
766 scale_bits += slen;
767 }
768 }
769 data_bits += LongHuffmancodebitscxx . . $ LongHuffmancodebits(4c3c04bbcbe3c6b7).(gfc, gi);
770 }
771 data_bits += huffman_coder_count1cxx . . $ huffman_coder_count1(4c3c04bbcbe3c6b7).(gfc, gi);
772 #ifdef DEBUG
773 DEBUGF(gfc, "<%ld> ", gfc->bs.totbit - hogege);
774 #endif
775 /* does bitcount in quantize.c agree with actual bit count? */
776 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(data_bits == gi->part2_3_length);
777 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(scale_bits == gi->part2_length);
778 tot_bits += scale_bits + data_bits;
779 } /* for ch */
780 } /* for gf */
781 return tot_bits;
782 } /* main_data */
783
784
785
786 /* compute the number of bits required to flush all mp3 frames
787 currently in the buffer. This should be the same as the
788 reservoir size. Only call this routine between frames - i.e.
789 only after all headers and data have been added to the buffer
790 by format_bitstream().
791
792 Also compute total_bits_output =
793 size of mp3 buffer (including frame headers which may not
794 have yet been send to the mp3 buffer) +
795 number of bits needed to flush all mp3 frames.
796
797 total_bytes_output is the size of the mp3 output buffer if
798 lame_encode_flush_nogap() was called right now.
799
800 */
801 int
802 compute_flushbitscxx . . $ compute_flushbits(36af73b8620c595).(const lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int *total_bytes_output)
803 {
804 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
805 EncStateVar_tcxx . . $ EncStateVar_t# const *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
806 int flushbits, remaining_headers;
807 int bitsPerFrame;
808 int last_ptr, first_ptr;
809 first_ptr = esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr.; /* first header to add to bitstream */
810 last_ptr = esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr. - 1; /* last header to add to bitstream */
811 if (last_ptr == -1)
812 last_ptr = MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`! - 1;
813
814 /* add this many bits to bitstream so we can flush all headers */
815 flushbits = esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[last_ptr].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. - gfc->bscxx . . $ lame_internal_flags#bs..totbitcxx . . $ bit_stream_struc#totbit.;
816 *total_bytes_output = flushbits;
817
818 if (flushbits >= 0) {
819 /* if flushbits >= 0, some headers have not yet been written */
820 /* reduce flushbits by the size of the headers */
821 remaining_headers = 1 + last_ptr - first_ptr;
822 if (last_ptr < first_ptr)
823 remaining_headers = 1 + last_ptr - first_ptr + MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`!;
824 flushbits -= remaining_headers * 8 * cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.;
825 }
826
827
828 /* finally, add some bits so that the last frame is complete
829 * these bits are not necessary to decode the last frame, but
830 * some decoders will ignore last frame if these bits are missing
831 */
832 bitsPerFrame = getframebitscxx . . $ getframebits(b815612886108da).(gfc);
833 flushbits += bitsPerFrame;
834 *total_bytes_output += bitsPerFrame;
835 /* round up: */
836 if (*total_bytes_output % 8)
837 *total_bytes_output = 1 + (*total_bytes_output / 8);
838 else
839 *total_bytes_output = (*total_bytes_output / 8);
840 *total_bytes_output += gfc->bscxx . . $ lame_internal_flags#bs..buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx. + 1;
841
842
843 if (flushbits < 0) {
844 #if 0
845 /* if flushbits < 0, this would mean that the buffer looks like:
846 * (data...) last_header (data...) (extra data that should not be here...)
847 */
848 DEBUGF(gfc, "last header write_timing = %i \n", esv->header[last_ptr].write_timing);
849 DEBUGF(gfc, "first header write_timing = %i \n", esv->header[first_ptr].write_timing);
850 DEBUGF(gfc, "bs.totbit: %i \n", gfc->bs.totbit);
851 DEBUGF(gfc, "first_ptr, last_ptr %i %i \n", first_ptr, last_ptr);
852 DEBUGF(gfc, "remaining_headers = %i \n", remaining_headers);
853 DEBUGF(gfc, "bitsperframe: %i \n", bitsPerFrame);
854 DEBUGF(gfc, "sidelen: %i \n", cfg->sideinfo_len);
855 #endif
856 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "strange error flushing buffer ... \n");
857 }
858 return flushbits;
859 }
860
861
862 void
863 flush_bitstreamcxx . . $ flush_bitstream(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc)
864 {
865 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
866 III_side_info_tcxx . . $ III_side_info_t# *l3_side;
867 int nbytes;
868 int flushbits;
869 int last_ptr = esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr. - 1; /* last header to add to bitstream */
870 if (last_ptr == -1)
871 last_ptr = MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`! - 1;
872 l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.;
873
874
875 if ((flushbits = compute_flushbitscxx . . $ compute_flushbits(36af73b8620c595).(gfc, &nbytes)) < 0)
876 return;
877 drain_into_ancillarycxx . . $ drain_into_ancillary(8f5851925078004a).(gfc, flushbits);
878
879 /* check that the 100% of the last frame has been written to bitstream */
880 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(esv->header[last_ptr].write_timing + getframebits(gfc)
881 == gfc->bs.totbit);
882
883 /* we have padded out all frames with ancillary data, which is the
884 same as filling the bitreservoir with ancillary data, so : */
885 esv->ResvSizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvSize. = 0;
886 l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin. = 0;
887 }
888
889
890
891
892 void
893 add_dummy_bytecxx . . $ add_dummy_byte(7645f4bbedf0972b).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, unsigned char val, unsigned int n)
894 {
895 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
896 int i;
897
898 while (n-- > 0u) {
899 putbits_noheaderscxx . . $ putbits_noheaders(b6022c2330fef37d).(gfc, val, 8);
900
901 for (i = 0; i < MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`!; ++i)
902 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[i].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. += 8;
903 }
904 }
905
906
907 /*
908 format_bitstream()
909
910 This is called after a frame of audio has been quantized and coded.
911 It will write the encoded audio to the bitstream. Note that
912 from a layer3 encoder's perspective the bit stream is primarily
913 a series of main_data() blocks, with header and side information
914 inserted at the proper locations to maintain framing. (See Figure A.7
915 in the IS).
916 */
917 int
918 format_bitstreamcxx . . $ format_bitstream(42b75628a052f811).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc)
919 {
920 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
921 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
922 int bits, nbytes;
923 III_side_info_tcxx . . $ III_side_info_t# *l3_side;
924 int bitsPerFrame;
925 l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.;
926
927 bitsPerFrame = getframebitscxx . . $ getframebits(b815612886108da).(gfc);
928 drain_into_ancillarycxx . . $ drain_into_ancillary(8f5851925078004a).(gfc, l3_side->resvDrain_precxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_pre.);
929
930 encodeSideInfo2cxx . . $ encodeSideInfo2(8f5851925078004a).(gfc, bitsPerFrame);
931 bits = 8 * cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.;
932 bits += writeMainDatacxx . . $ writeMainData(42b75628a052f811).(gfc);
933 drain_into_ancillarycxx . . $ drain_into_ancillary(8f5851925078004a).(gfc, l3_side->resvDrain_postcxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_post.);
934 bits += l3_side->resvDrain_postcxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_post.;
935
936 l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin. += (bitsPerFrame - bits) / 8;
937
938 /* compare number of bits needed to clear all buffered mp3 frames
939 * with what we think the resvsize is: */
940 if (compute_flushbitscxx . . $ compute_flushbits(36af73b8620c595).(gfc, &nbytes) != esv->ResvSizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvSize.) {
941 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "Internal buffer inconsistency. flushbits <> ResvSize");
942 }
943
944
945 /* compare main_data_begin for the next frame with what we
946 * think the resvsize is: */
947 if ((l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin. * 8) != esv->ResvSizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvSize.) {
948 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "bit reservoir error: \n"
949 "l3_side->main_data_begin: %i \n"
950 "Resvoir size: %i \n"
951 "resv drain (post) %i \n"
952 "resv drain (pre) %i \n"
953 "header and sideinfo: %i \n"
954 "data bits: %i \n"
955 "total bits: %i (remainder: %i) \n"
956 "bitsperframe: %i \n",
957 8 * l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin.,
958 esv->ResvSizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvSize.,
959 l3_side->resvDrain_postcxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_post.,
960 l3_side->resvDrain_precxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_pre.,
961 8 * cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.,
962 bits - l3_side->resvDrain_postcxx . . $ $anonymous_type_fdda207d22d8fb07_4#resvDrain_post. - 8 * cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len.,
963 bits, bits % 8, bitsPerFrame);
964
965 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "This is a fatal error. It has several possible causes:");
966 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "90%% LAME compiled with buggy version of gcc using advanced optimizations");
967 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, " 9%% Your system is overclocked");
968 ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, " 1%% bug in LAME encoding library");
969
970 esv->ResvSizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvSize. = l3_side->main_data_begincxx . . $ $anonymous_type_fdda207d22d8fb07_4#main_data_begin. * 8;
971 };
972 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gfc->bs.totbit % 8 == 0);
973
974 if (gfc->bscxx . . $ lame_internal_flags#bs..totbitcxx . . $ bit_stream_struc#totbit. > 1000000000) {
975 /* to avoid totbit overflow, (at 8h encoding at 128kbs) lets reset bit counter */
976 int i;
977 for (i = 0; i < MAX_HEADER_BUFcxx . . $ `external/lame/util.h:273:9`!; ++i)
978 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[i].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. -= gfc->bscxx . . $ lame_internal_flags#bs..totbitcxx . . $ bit_stream_struc#totbit.;
979 gfc->bscxx . . $ lame_internal_flags#bs..totbitcxx . . $ bit_stream_struc#totbit. = 0;
980 }
981
982
983 return 0;
984 }
985
986
987 static int
988 do_gain_analysiscxx . . $ do_gain_analysis(b7f21d36da6d437d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, unsigned char* buffer, int minimum)
989 {
990 SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.;
991 RpgStateVar_tcxx . . $ RpgStateVar_t# const *const rsv = &gfc->sv_rpgcxx . . $ lame_internal_flags#sv_rpg.;
992 RpgResult_tcxx . . $ RpgResult_t# *const rov = &gfc->ov_rpgcxx . . $ lame_internal_flags#ov_rpg.;
993 #ifdef DECODE_ON_THE_FLY
994 if (cfg->decode_on_the_fly) { /* decode the frame */
995 sample_t pcm_buf[2][1152];
996 int mp3_in = minimum;
997 int samples_out = -1;
998
999 /* re-synthesis to pcm. Repeat until we get a samples_out=0 */
1000 while (samples_out != 0) {
1001
1002 samples_out = hip_decode1_unclipped(gfc->hip, buffer, mp3_in, pcm_buf[0], pcm_buf[1]);
1003 /* samples_out = 0: need more data to decode
1004 * samples_out = -1: error. Lets assume 0 pcm output
1005 * samples_out = number of samples output */
1006
1007 /* set the lenght of the mp3 input buffer to zero, so that in the
1008 * next iteration of the loop we will be querying mpglib about
1009 * buffered data */
1010 mp3_in = 0;
1011
1012 if (samples_out == -1) {
1013 /* error decoding. Not fatal, but might screw up
1014 * the ReplayGain tag. What should we do? Ignore for now */
1015 samples_out = 0;
1016 }
1017 if (samples_out > 0) {
1018 /* process the PCM data */
1019
1020 /* this should not be possible, and indicates we have
1021 * overflown the pcm_buf buffer */
1022 assert(samples_out <= 1152);
1023
1024 if (cfg->findPeakSample) {
1025 int i;
1026 /* FIXME: is this correct? maybe Max(fabs(pcm),PeakSample) */
1027 for (i = 0; i < samples_out; i++) {
1028 if (pcm_buf[0][i] > rov->PeakSample)
1029 rov->PeakSample = pcm_buf[0][i];
1030 else if (-pcm_buf[0][i] > rov->PeakSample)
1031 rov->PeakSample = -pcm_buf[0][i];
1032 }
1033 if (cfg->channels_out > 1)
1034 for (i = 0; i < samples_out; i++) {
1035 if (pcm_buf[1][i] > rov->PeakSample)
1036 rov->PeakSample = pcm_buf[1][i];
1037 else if (-pcm_buf[1][i] > rov->PeakSample)
1038 rov->PeakSample = -pcm_buf[1][i];
1039 }
1040 }
1041
1042 if (cfg->findReplayGain)
1043 if (AnalyzeSamples
1044 (rsv->rgdata, pcm_buf[0], pcm_buf[1], samples_out,
1045 cfg->channels_out) == GAIN_ANALYSIS_ERROR)
1046 return -6;
1047
1048 } /* if (samples_out>0) */
1049 } /* while (samples_out!=0) */
1050 } /* if (gfc->decode_on_the_fly) */
1051 #endif
1052 return minimum;
1053 }
1054
1055 static int
1056 do_copy_buffercxx . . $ do_copy_buffer(b7f21d36da6d437d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, unsigned char *buffer, int size)
1057 {
1058 Bit_stream_struccxx . . $ Bit_stream_struc# *const bs = &gfc->bscxx . . $ lame_internal_flags#bs.;
1059 int const minimum = bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx. + 1;
1060 if (minimum <= 0)
1061 return 0;
1062 if (minimum > size)
1063 return -1; /* buffer is too small */
1064 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer, bs->bufcxx . . $ bit_stream_struc#buf., minimum);
1065 bs->buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx. = -1;
1066 bs->buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. = 0;
1067 return minimum;
1068 }
1069
1070 /* copy data out of the internal MP3 bit buffer into a user supplied
1071 unsigned char buffer.
1072
1073 mp3data=0 indicates data in buffer is an id3tags and VBR tags
1074 mp3data=1 data is real mp3 frame data.
1075
1076
1077 */
1078 int
1079 copy_buffercxx . . $ copy_buffer(f6fd3c9cde6b7d1d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, unsigned char *buffer, int size, int mp3data)
1080 {
1081 int const minimum = do_copy_buffercxx . . $ do_copy_buffer(b7f21d36da6d437d).(gfc, buffer, size);
1082 if (minimum > 0 && mp3data) {
1083 UpdateMusicCRCcxx . . $ UpdateMusicCRC(3cd8f30c3c91a9ed).(&gfc->nMusicCRCcxx . . $ lame_internal_flags#nMusicCRC., buffer, minimum);
1084
1085 /** sum number of bytes belonging to the mp3 stream
1086 * this info will be written into the Xing/LAME header for seeking
1087 */
1088 gfc->VBR_seek_tablecxx . . $ lame_internal_flags#VBR_seek_table..nBytesWrittencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_1#nBytesWritten. += minimum;
1089
1090 return do_gain_analysiscxx . . $ do_gain_analysis(b7f21d36da6d437d).(gfc, buffer, minimum);
1091 } /* if (mp3data) */
1092 return minimum;
1093 }
1094
1095
1096 void
1097 init_bit_stream_wcxx . . $ init_bit_stream_w(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc)
1098 {
1099 EncStateVar_tcxx . . $ EncStateVar_t# *const esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.;
1100
1101 esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr. = esv->w_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#w_ptr. = 0;
1102 esv->headercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#header.[esv->h_ptrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#h_ptr.].write_timingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#$anonymous_type_8#write_timing. = 0;
1103
1104 gfc->bscxx . . $ lame_internal_flags#bs..bufcxx . . $ bit_stream_struc#buf. = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(unsigned char, BUFFER_SIZEcxx . . $ `external/lame/util.h:89:17`!);
1105 gfc->bscxx . . $ lame_internal_flags#bs..buf_sizecxx . . $ bit_stream_struc#buf_size. = BUFFER_SIZEcxx . . $ `external/lame/util.h:89:17`!;
1106 gfc->bscxx . . $ lame_internal_flags#bs..buf_byte_idxcxx . . $ bit_stream_struc#buf_byte_idx. = -1;
1107 gfc->bscxx . . $ lame_internal_flags#bs..buf_bit_idxcxx . . $ bit_stream_struc#buf_bit_idx. = 0;
1108 gfc->bscxx . . $ lame_internal_flags#bs..totbitcxx . . $ bit_stream_struc#totbit. = 0;
1109 }
1110
1111 /* end of bitstream.c */