adding a test case
[IRC.git] / Robust / src / Benchmarks / SSJava / MP3DecoderInfer / LayerIIIDecoder.java
1 /*
2  * 11/19/04      1.0 moved to LGPL.
3  * 
4  * 18/06/01  Michael Scheerer,  Fixed bugs which causes
5  *           negative indexes in method huffmann_decode and in method 
6  *           dequanisize_sample.
7  *
8  * 16/07/01  Michael Scheerer, Catched a bug in method
9  *           huffmann_decode, which causes an outOfIndexException.
10  *           Cause : Indexnumber of 24 at SfBandIndex,
11  *           which has only a length of 22. I have simply and dirty 
12  *           fixed the index to <= 22, because I'm not really be able
13  *           to fix the bug. The Indexnumber is taken from the MP3 
14  *           file and the origin Ma-Player with the same code works 
15  *           well.      
16  * 
17  * 02/19/99  Java Conversion by E.B, javalayer@javazoom.net
18  *-----------------------------------------------------------------------
19  *   This program is free software; you can redistribute it and/or modify
20  *   it under the terms of the GNU Library General Public License as published
21  *   by the Free Software Foundation; either version 2 of the License, or
22  *   (at your option) any later version.
23  *
24  *   This program is distributed in the hope that it will be useful,
25  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *   GNU Library General Public License for more details.
28  *
29  *   You should have received a copy of the GNU Library General Public
30  *   License along with this program; if not, write to the Free Software
31  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  *----------------------------------------------------------------------
33  */
34
35 /**
36  * Class Implementing Layer 3 Decoder.
37  * 
38  * @since 0.0
39  */
40 //
41 // 4th line added for hybrid.
42 // 5th added for stereo
43 // 6th added for reorder method
44 // 7th added for huffman_decode method
45 // 8th added for get_LSF_scale_data
46 // 9th added for get_LSF_scale_factors
47 // 10th added for get_scale_factors
48 // llth added for decode
49 //
50
51 final class LayerIIIDecoder implements FrameDecoder {
52   static final double d43 = (4.0 / 3.0);
53
54   public int[] scalefac_buffer;
55
56   // MDM: removed, as this wasn't being used.
57   // private float CheckSumOut1d = 0.0f;
58
59   private int CheckSumHuff = 0;
60
61   private int[] is_1d;
62
63   private float[][][] ro;
64
65   private float[][][] lr;
66
67   private float[] inter; // 576 samples
68
69   private float[] out_1d; // 576 samples
70
71   private float[][] prevblck;
72
73   private float[][] k;
74
75   private int[] nonzero;
76
77   private SynthesisFilter filter1;
78
79   private SynthesisFilter filter2;
80   //
81   // private Obuffer buffer; // output buffer
82
83   private int which_channels;
84
85   private BitReserve br;
86
87   private III_side_info_t si;
88
89   // private temporaire2[] III_scalefac_t;
90
91   private final temporaire2[] scalefac;
92   // private III_scalefac_t scalefac;
93
94   private int max_gr;
95
96   private int frame_start;
97   // private int part2_start;
98
99   private final int channels;
100
101   private int first_channel;
102
103   private int last_channel;
104
105   private int sfreq;
106
107   private int part2_start;
108
109   private boolean initialized = false;
110
111   float[][] raw_full; // 18 left shfited since it will be copied into prevblck!
112
113   // constructor for the linear type system
114   public LayerIIIDecoder(Header h, @DELEGATE SynthesisFilter filtera,
115       @DELEGATE SynthesisFilter filterb, int which_ch0) {
116
117     filter_pos = 11;
118     raw_full = new float[2][SBLIMIT * SSLIMIT];
119
120     filter1 = filtera;
121     filter2 = filterb;
122
123     huffcodetab.inithuff();
124     is_1d = new int[SBLIMIT * SSLIMIT + 4];
125     ro = new float[2][SBLIMIT][SSLIMIT];
126     lr = new float[2][SBLIMIT][SSLIMIT];
127     out_1d = new float[SBLIMIT * SSLIMIT];
128     inter = new float[SBLIMIT * SSLIMIT];
129     prevblck = new float[2][SBLIMIT * SSLIMIT];
130     k = new float[2][SBLIMIT * SSLIMIT];
131     nonzero = new int[2];
132
133     // removes unnecessary aliases
134     // III_scalefact_t
135     // III_scalefac_t = new temporaire2[2];
136     // III_scalefac_t[0] = new temporaire2();
137     // III_scalefac_t[1] = new temporaire2();
138     // scalefac = III_scalefac_t;
139
140     scalefac = new temporaire2[2];
141     scalefac[0] = new temporaire2();
142     scalefac[1] = new temporaire2();
143
144     // L3TABLE INIT
145
146     sfBandIndex = new SBI[9]; // SZD: MPEG2.5 +3 indices
147     int[] l0 = { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576 };
148     int[] s0 = { 0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192 };
149     int[] l1 = { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 330, 394, 464, 540, 576 };
150     int[] s1 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192 };
151     int[] l2 = { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576 };
152     int[] s2 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };
153
154     int[] l3 = { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576 };
155     int[] s3 = { 0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192 };
156     int[] l4 = { 0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576 };
157     int[] s4 = { 0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192 };
158     int[] l5 = { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576 };
159     int[] s5 = { 0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192 };
160     // SZD: MPEG2.5
161     int[] l6 = { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576 };
162     int[] s6 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };
163     int[] l7 = { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576 };
164     int[] s7 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };
165     int[] l8 = { 0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576 };
166     int[] s8 = { 0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192 };
167
168     sfBandIndex[0] = new SBI(l0, s0);
169     sfBandIndex[1] = new SBI(l1, s1);
170     sfBandIndex[2] = new SBI(l2, s2);
171
172     sfBandIndex[3] = new SBI(l3, s3);
173     sfBandIndex[4] = new SBI(l4, s4);
174     sfBandIndex[5] = new SBI(l5, s5);
175     // SZD: MPEG2.5
176     sfBandIndex[6] = new SBI(l6, s6);
177     sfBandIndex[7] = new SBI(l7, s7);
178     sfBandIndex[8] = new SBI(l8, s8);
179     // END OF L3TABLE INIT
180
181     if (reorder_table == null) { // SZD: generate LUT
182       reorder_table = new int[9][];
183       for (int i = 0; i < 9; i++)
184         reorder_table[i] = reorder(sfBandIndex[i].s);
185     }
186
187     // scalefac_buffer
188     scalefac_buffer = new int[54];
189     // END OF scalefac_buffer
190
191     init(h);
192   }
193
194   private void init(Header header) {
195
196     frame_start = 0;
197     channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
198     max_gr = (header.version() == Header.MPEG1) ? 2 : 1;
199
200     sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1) ? 3 : (header.version() == Header.MPEG25_LSF) ? 6 : 0); // SZD
201
202     if (channels == 2) {
203       switch (which_channels) {
204       case OutputChannels.LEFT_CHANNEL:
205       case OutputChannels.DOWNMIX_CHANNELS:
206         first_channel = last_channel = 0;
207         break;
208
209       case OutputChannels.RIGHT_CHANNEL:
210         first_channel = last_channel = 1;
211         break;
212
213       case OutputChannels.BOTH_CHANNELS:
214       default:
215         first_channel = 0;
216         last_channel = 1;
217         break;
218       }
219     } else {
220       first_channel = last_channel = 0;
221     }
222
223     for (int ch = 0; ch < 2; ch++)
224       for (int j = 0; j < 576; j++)
225         prevblck[ch][j] = 0.0f;
226
227     nonzero[0] = nonzero[1] = 576;
228
229     si = new III_side_info_t();
230
231     initialized = true;
232
233   }
234
235   /**
236    * Constructor.
237    */
238   // REVIEW: these constructor arguments should be moved to the
239   // decodeFrame() method, where possible, so that one
240   //
241   // public LayerIIIDecoder( Header header0,
242   // SynthesisFilter filtera,
243   // SynthesisFilter filterb, int which_ch0) {
244   //
245   // huffcodetab.inithuff();
246   // is_1d = new int[SBLIMIT * SSLIMIT + 4];
247   // ro = new float[2][SBLIMIT][SSLIMIT];
248   // lr = new float[2][SBLIMIT][SSLIMIT];
249   // out_1d = new float[SBLIMIT * SSLIMIT];
250   // prevblck = new float[2][SBLIMIT * SSLIMIT];
251   // k = new float[2][SBLIMIT * SSLIMIT];
252   // nonzero = new int[2];
253   //
254   // // removes unnecessary aliases
255   // // III_scalefact_t
256   // // III_scalefac_t = new temporaire2[2];
257   // // III_scalefac_t[0] = new temporaire2();
258   // // III_scalefac_t[1] = new temporaire2();
259   // // scalefac = III_scalefac_t;
260   //
261   // scalefac = new temporaire2[2];
262   // scalefac[0] = new temporaire2();
263   // scalefac[1] = new temporaire2();
264   //
265   // // L3TABLE INIT
266   //
267   // sfBandIndex = new SBI[9]; // SZD: MPEG2.5 +3 indices
268   // int[] l0 =
269   // { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,
270   // 284, 336, 396,
271   // 464, 522, 576 };
272   // int[] s0 = { 0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132,
273   // 174, 192 };
274   // int[] l1 =
275   // { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232,
276   // 278, 330, 394,
277   // 464, 540, 576 };
278   // int[] s1 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136,
279   // 180, 192 };
280   // int[] l2 =
281   // { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,
282   // 284, 336, 396,
283   // 464, 522, 576 };
284   // int[] s2 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134,
285   // 174, 192 };
286   //
287   // int[] l3 =
288   // { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196,
289   // 238, 288, 342,
290   // 418, 576 };
291   // int[] s3 = { 0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136,
292   // 192 };
293   // int[] l4 =
294   // { 0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190,
295   // 230, 276, 330,
296   // 384, 576 };
297   // int[] s4 = { 0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126,
298   // 192 };
299   // int[] l5 =
300   // { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240,
301   // 296, 364, 448,
302   // 550, 576 };
303   // int[] s5 = { 0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138,
304   // 180, 192 };
305   // // SZD: MPEG2.5
306   // int[] l6 =
307   // { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,
308   // 284, 336, 396,
309   // 464, 522, 576 };
310   // int[] s6 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134,
311   // 174, 192 };
312   // int[] l7 =
313   // { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238,
314   // 284, 336, 396,
315   // 464, 522, 576 };
316   // int[] s7 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134,
317   // 174, 192 };
318   // int[] l8 =
319   // { 0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400,
320   // 476, 566, 568,
321   // 570, 572, 574, 576 };
322   // int[] s8 = { 0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164,
323   // 166, 192 };
324   //
325   // sfBandIndex[0] = new SBI(l0, s0);
326   // sfBandIndex[1] = new SBI(l1, s1);
327   // sfBandIndex[2] = new SBI(l2, s2);
328   //
329   // sfBandIndex[3] = new SBI(l3, s3);
330   // sfBandIndex[4] = new SBI(l4, s4);
331   // sfBandIndex[5] = new SBI(l5, s5);
332   // // SZD: MPEG2.5
333   // sfBandIndex[6] = new SBI(l6, s6);
334   // sfBandIndex[7] = new SBI(l7, s7);
335   // sfBandIndex[8] = new SBI(l8, s8);
336   // // END OF L3TABLE INIT
337   //
338   // if (reorder_table == null) { // SZD: generate LUT
339   // reorder_table = new int[9][];
340   // for ( int i = 0; i < 9; i++)
341   // reorder_table[i] = reorder(sfBandIndex[i].s);
342   // }
343   //
344   // // Sftable
345   // int[] ll0 = { 0, 6, 11, 16, 21 };
346   // int[] ss0 = { 0, 6, 12 };
347   // sftable = new Sftable(ll0, ss0);
348   // // END OF Sftable
349   //
350   // // scalefac_buffer
351   // scalefac_buffer = new int[54];
352   // // END OF scalefac_buffer
353   //
354   // // header = header0;
355   // filter1 = filtera;
356   // filter2 = filterb;
357   // // buffer = buffer0;
358   // which_channels = which_ch0;
359   //
360   // frame_start = 0;
361   // channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
362   // max_gr = (header.version() == Header.MPEG1) ? 2 : 1;
363   //
364   // sfreq =
365   // header.sample_frequency()
366   // + ((header.version() == Header.MPEG1) ? 3 : (header.version() ==
367   // Header.MPEG25_LSF) ? 6
368   // : 0); // SZD
369   //
370   // if (channels == 2) {
371   // switch (which_channels) {
372   // case OutputChannels.LEFT_CHANNEL:
373   // case OutputChannels.DOWNMIX_CHANNELS:
374   // first_channel = last_channel = 0;
375   // break;
376   //
377   // case OutputChannels.RIGHT_CHANNEL:
378   // first_channel = last_channel = 1;
379   // break;
380   //
381   // case OutputChannels.BOTH_CHANNELS:
382   // default:
383   // first_channel = 0;
384   // last_channel = 1;
385   // break;
386   // }
387   // } else {
388   // first_channel = last_channel = 0;
389   // }
390   //
391   // for ( int ch = 0; ch < 2; ch++)
392   // for ( int j = 0; j < 576; j++)
393   // prevblck[ch][j] = 0.0f;
394   //
395   // nonzero[0] = nonzero[1] = 576;
396   //
397   // br = new BitReserve();
398   // si = new III_side_info_t();
399   // }
400
401   /**
402    * Notify decoder that a seek is being made.
403    */
404
405   public void seek_notify() {
406     frame_start = 0;
407     for (int ch = 0; ch < 2; ch++)
408       for (int j = 0; j < 576; j++)
409         prevblck[ch][j] = 0.0f;
410     br = new BitReserve();
411   }
412
413   public void decodeFrame(Header header) {
414     decode(header);
415   }
416
417   /**
418    * Decode one frame, filling the buffer with the output samples.
419    */
420
421   // subband samples are buffered and passed to the
422   // SynthesisFilter in one go.
423
424   private float[] samples1 = new float[32];
425
426   private float[] samples2 = new float[32];
427
428   private int filter_pos;
429
430   /*
431    * location hierarchy of decode() {header} {stream} {si} {br, flush_main,
432    * main_data_end,frame_start,nSlots,bytes_to_discard}* {gr,max_gr} // granule
433    * {ch,channels,first_channel, last_channel, which_channels} // channel
434    * {part2_start} {sb18, ss} {out_1d}* {sb}* {samples1,sample2}
435    * {filter1,filter2}
436    */
437   //
438
439   public void decode(Header header) {
440
441     // if (!initialized) {
442     // init(header);
443     // }
444
445     // overwrites once per a loop
446     SSJAVA.arrayinit(samples1, 0);
447     SSJAVA.arrayinit(samples2, 0);
448     SSJAVA.arrayinit(ro, 2, SBLIMIT, SSLIMIT, 0);
449     SSJAVA.arrayinit(lr, 2, SBLIMIT, SSLIMIT, 0);
450     SSJAVA.arrayinit(is_pos, 7);
451     SSJAVA.arrayinit(is_ratio, 0);
452     SSJAVA.arrayinit(out_1d, 0);
453     SSJAVA.arrayinit(inter, 0);
454     SSJAVA.arrayinit(k, 2, SBLIMIT * SSLIMIT, 0);
455     SSJAVA.arrayinit(is_1d, 0);
456     SSJAVA.arrayinit(tsOutCopy, 0);
457     SSJAVA.arrayinit(scalefac_buffer, 0);
458     SSJAVA.arrayinit(nonzero, 576);
459     SSJAVA.arrayinit(new_slen, 0);
460
461     SSJAVA.arrayinit(raw_full, 2, SBLIMIT * SSLIMIT, 0);
462     SSJAVA.arrayinit(rawout, 0);
463     CheckSumHuff = 0;
464     // prevblck = new float[2][SBLIMIT * SSLIMIT];
465     si = new III_side_info_t();
466     //
467
468     int nSlots = header.slots();
469
470     int gr;
471     int ch;
472
473     int ss;
474     int sb;
475     int sb18;
476
477     int main_data_end;
478     int flush_main;
479
480     int bytes_to_discard;
481     int i;
482
483     // modifications for linear type
484     get_side_info(header);
485     br = header.getBitReserve();
486
487     int version = header.version();
488
489     // additional codes for the definitely written property
490     filter_pos = (header.getIdx() * 4) & 0xf;
491     filter1.vidx = 1;
492     filter2.vidx = 1;
493     filter1.actual_write_pos = filter_pos;
494     filter2.actual_write_pos = filter_pos;
495
496     // here 'gr' and 'max_gr' should be higher than 'ch','channels', and more
497     for (gr = 0; gr < max_gr; gr++) { // two granules per channel
498       // in the loop body, access set={part2_start}
499
500       // 'ch', 'channels' should be higher than all locs in the below body
501       for (ch = 0; ch < channels; ch++) {
502         // part2_start = br.hsstell();
503         int part2_start_local = br.hsstell();
504
505         // grab scale factors from the main data.
506         // following the scale factors is the actual compressed data
507         if (version == Header.MPEG1)
508           get_scale_factors(header, ch, gr); // no need to care from this side
509         // here move scale factor data from 'br' buffer to 'scalefac' field
510         else
511           // MPEG-2 LSF, SZD: MPEG-2.5 LSF
512           get_LSF_scale_factors(header, ch, gr); // no need to care from this
513                                                  // side
514
515         // here, decoding the compressed audio data
516         huffman_decode(part2_start_local, ch, gr); // no need to care from this
517                                                    // side
518         // System.out.println("CheckSum HuffMan = " + CheckSumHuff);
519         dequantize_sample(/* ro[ch], */ch, gr); // no need to care from this
520                                                 // side
521       }
522
523       stereo(header, gr); // no need to care from this side
524
525       if ((which_channels == OutputChannels.DOWNMIX_CHANNELS) && (channels > 1)) {
526         do_downmix();
527       }
528
529       for (ch = first_channel; ch <= last_channel; ch++) { // 'ch' and
530                                                            // 'first_channel' >
531                                                            // the body
532
533         reorder(/* lr[ch], */ch, gr);
534         antialias(ch, gr);
535
536         // float CheckSumOut1d=0;
537         // for (int hb = 0;hb<576;hb++) {
538         // CheckSumOut1d = CheckSumOut1d + out_1d[hb];
539         // }
540         // System.out.println("CheckSumOut1d = "+CheckSumOut1d);
541
542         for (int index = 0; index < 576; index++) {
543           out_1d[index] = inter[index];
544         }
545
546         hybrid(ch, gr);
547
548         // float CheckSumOut1d=0;
549         // for (int hb = 0;hb<576;hb++) {
550         // CheckSumOut1d = CheckSumOut1d + out_1d[hb];
551         // }
552         // System.out.println("CheckSumOut1d = "+CheckSumOut1d);
553
554         for (sb18 = 18; sb18 < 576; sb18 += 36) {
555           // sb18 > ss, SSLIMIT, out1d
556           // Frequency inversion
557           for (ss = 1; ss < SSLIMIT; ss += 2) {
558             // 'ss','SSLIMIT' > out_1d
559             out_1d[sb18 + ss] = -out_1d[sb18 + ss]; // out1d*
560           }
561         }
562
563         // 'ch', 'which_channels' should be higher than if/else body!
564         // location set written by if/else body
565         // = {samples1, samples2, filter1, filter2}
566         if ((ch == 0) || (which_channels == OutputChannels.RIGHT_CHANNEL)) {
567           for (ss = 0; ss < SSLIMIT; ss++) { // Polyphase synthesis
568             sb = 0;
569             for (sb18 = 0; sb18 < 576; sb18 += 18) {
570               samples1[sb] = out_1d[sb18 + ss]; // out_1d > samples1
571               // filter1.input_sample(out_1d[sb18+ss], sb);
572               sb++; // sb should be loc*
573             }
574             filter1.input_samples(samples1);
575             // System.out.println("filter1 writepos=" + filter1.actual_write_pos
576             // + " vidx=" + filter1.vidx);
577             filter1.calculate_pcm_samples();
578           }
579         } else {
580           for (ss = 0; ss < SSLIMIT; ss++) { // Polyphase synthesis
581             sb = 0;
582             for (sb18 = 0; sb18 < 576; sb18 += 18) {
583               samples2[sb] = out_1d[sb18 + ss]; // out_1d > samples2
584               // filter2.input_sample(out_1d[sb18+ss], sb);
585               sb++;
586             }
587             filter2.input_samples(samples2);
588             filter2.calculate_pcm_samples();
589           }
590         }
591         // System.out.println("#END CH=" + ch + " actual_write_pos=" +
592         // filter1.actual_write_pos);
593       } // channels
594
595       // TODO
596       if (gr < max_gr - 1) {
597         // init prev
598         SSJAVA.arrayinit(prevblck, 2, SBLIMIT * SSLIMIT, 0);
599         // copy from raw_full to prev
600         SSJAVA.arraycopy(prevblck, raw_full, 2, SBLIMIT * SSLIMIT);
601       }
602       // for (int chidx = 0; chidx < 2; chidx++) {
603       // for (int sidx = 0; sidx < SBLIMIT * SSLIMIT; sidx++) {
604       // prevblck[chidx][sidx] = raw_full[chidx][sidx];
605       // }
606       // }
607       // System.out.println("#END GR=" + gr + " actual_write_pos=" +
608       // filter1.actual_write_pos);
609     } // granule
610
611     // TODO
612     // init prev
613     SSJAVA.arrayinit(prevblck, 2, SBLIMIT * SSLIMIT, 0);
614     // copy from raw_full to prev
615     SSJAVA.arraycopy(prevblck, raw_full, 2, SBLIMIT * SSLIMIT);
616
617     // System.out.println("#END FRAME actual_write_pos=" +
618     // filter1.actual_write_pos);
619
620     filter1.clear();
621     filter2.clear();
622
623     // System.out.println("Counter = ................................."+counter);
624     // if (counter < 609)
625     // {
626     // counter++; // count should be loc*
627     // buffer.write_buffer(1); // buffer!!!
628     // }
629     // else if (counter == 609)
630     // {
631     // buffer.close();
632     // counter++;
633     // }
634     // else
635     // {
636     // }
637
638   }
639
640   /**
641    * Reads the side info from the stream, assuming the entire. frame has been
642    * read already. Mono : 136 bits (= 17 bytes) Stereo : 256 bits (= 32 bytes)
643    */
644
645   private boolean get_side_info(Header header) {
646
647     SideInfoBuffer sib = header.getSideInfoBuffer();
648     int version = header.version();
649
650     int ch;
651     int gr;
652     // System.out.println("#get_side_info");
653     if (version == Header.MPEG1) {
654
655       si.main_data_begin = sib.get_bits(9);
656       if (channels == 1)
657         si.private_bits = sib.get_bits(5);
658       else
659         si.private_bits = sib.get_bits(3);
660
661       for (ch = 0; ch < channels; ch++) {
662         si.ch[ch].scfsi[0] = sib.get_bits(1);
663         si.ch[ch].scfsi[1] = sib.get_bits(1);
664         si.ch[ch].scfsi[2] = sib.get_bits(1);
665         si.ch[ch].scfsi[3] = sib.get_bits(1);
666       }
667
668       // System.out.println("BEFORE GR,CH");
669
670       for (gr = 0; gr < 2; gr++) {
671         // System.out.println("GR=" + gr);
672         for (ch = 0; ch < channels; ch++) {
673           // System.out.println("CH");
674           si.ch[ch].gr[gr].part2_3_length = sib.get_bits(12);
675           si.ch[ch].gr[gr].big_values = sib.get_bits(9);
676           si.ch[ch].gr[gr].global_gain = sib.get_bits(8);
677           si.ch[ch].gr[gr].scalefac_compress = sib.get_bits(4);
678           int cond = sib.get_bits(1);
679           // si.ch[ch].gr[gr].window_switching_flag = sib.get_bits(1);
680           // if ((si.ch[ch].gr[gr].window_switching_flag) != 0) {
681           if (cond != 0) {
682             si.ch[ch].gr[gr].block_type = sib.get_bits(2);
683             si.ch[ch].gr[gr].mixed_block_flag = sib.get_bits(1);
684
685             si.ch[ch].gr[gr].table_select[0] = sib.get_bits(5);
686             si.ch[ch].gr[gr].table_select[1] = sib.get_bits(5);
687
688             si.ch[ch].gr[gr].subblock_gain[0] = sib.get_bits(3);
689             si.ch[ch].gr[gr].subblock_gain[1] = sib.get_bits(3);
690             si.ch[ch].gr[gr].subblock_gain[2] = sib.get_bits(3);
691
692             // Set region_count parameters since they are implicit
693             // in this case.
694
695             if (si.ch[ch].gr[gr].block_type == 0) {
696               // Side info bad: block_type == 0 in split block
697               return false;
698             } else if (si.ch[ch].gr[gr].block_type == 2 && si.ch[ch].gr[gr].mixed_block_flag == 0) {
699               si.ch[ch].gr[gr].region0_count = 8;
700             } else {
701               si.ch[ch].gr[gr].region0_count = 7;
702             }
703             si.ch[ch].gr[gr].region1_count = 20 - si.ch[ch].gr[gr].region0_count;
704           } else {
705             si.ch[ch].gr[gr].table_select[0] = sib.get_bits(5);
706             si.ch[ch].gr[gr].table_select[1] = sib.get_bits(5);
707             si.ch[ch].gr[gr].table_select[2] = sib.get_bits(5);
708             si.ch[ch].gr[gr].region0_count = sib.get_bits(4);
709             si.ch[ch].gr[gr].region1_count = sib.get_bits(3);
710             si.ch[ch].gr[gr].block_type = 0;
711           }
712           //
713           si.ch[ch].gr[gr].window_switching_flag = cond;
714           //
715           si.ch[ch].gr[gr].preflag = sib.get_bits(1);
716           si.ch[ch].gr[gr].scalefac_scale = sib.get_bits(1);
717           si.ch[ch].gr[gr].count1table_select = sib.get_bits(1);
718         }
719       }
720
721     } else { // MPEG-2 LSF, SZD: MPEG-2.5 LSF
722
723       si.main_data_begin = sib.get_bits(8);
724       if (channels == 1)
725         si.private_bits = sib.get_bits(1);
726       else
727         si.private_bits = sib.get_bits(2);
728
729       for (ch = 0; ch < channels; ch++) {
730
731         si.ch[ch].gr[0].part2_3_length = sib.get_bits(12);
732         si.ch[ch].gr[0].big_values = sib.get_bits(9);
733         si.ch[ch].gr[0].global_gain = sib.get_bits(8);
734         si.ch[ch].gr[0].scalefac_compress = sib.get_bits(9);
735
736         int cond = sib.get_bits(1);
737         // si.ch[ch].gr[0].window_switching_flag = sib.get_bits(1);
738         // if ((si.ch[ch].gr[0].window_switching_flag) != 0) {
739         if (cond != 0) {
740
741           si.ch[ch].gr[0].block_type = sib.get_bits(2);
742           si.ch[ch].gr[0].mixed_block_flag = sib.get_bits(1);
743           si.ch[ch].gr[0].table_select[0] = sib.get_bits(5);
744           si.ch[ch].gr[0].table_select[1] = sib.get_bits(5);
745
746           si.ch[ch].gr[0].subblock_gain[0] = sib.get_bits(3);
747           si.ch[ch].gr[0].subblock_gain[1] = sib.get_bits(3);
748           si.ch[ch].gr[0].subblock_gain[2] = sib.get_bits(3);
749
750           // Set region_count parameters since they are implicit in
751           // this case.
752
753           if (si.ch[ch].gr[0].block_type == 0) {
754             // Side info bad: block_type == 0 in split block
755             return false;
756           } else if (si.ch[ch].gr[0].block_type == 2 && si.ch[ch].gr[0].mixed_block_flag == 0) {
757             si.ch[ch].gr[0].region0_count = 8;
758           } else {
759             si.ch[ch].gr[0].region0_count = 7;
760             si.ch[ch].gr[0].region1_count = 20 - si.ch[ch].gr[0].region0_count;
761           }
762
763         } else {
764           si.ch[ch].gr[0].table_select[0] = sib.get_bits(5);
765           si.ch[ch].gr[0].table_select[1] = sib.get_bits(5);
766           si.ch[ch].gr[0].table_select[2] = sib.get_bits(5);
767           si.ch[ch].gr[0].region0_count = sib.get_bits(4);
768           si.ch[ch].gr[0].region1_count = sib.get_bits(3);
769           si.ch[ch].gr[0].block_type = 0;
770         }
771         //
772         si.ch[ch].gr[gr].window_switching_flag = cond;
773         //
774
775         si.ch[ch].gr[0].scalefac_scale = sib.get_bits(1);
776         si.ch[ch].gr[0].count1table_select = sib.get_bits(1);
777       } // for(ch=0; ch<channels; ch++)
778     } // if (header.version() == MPEG1)
779     return true;
780   }
781
782   /**
783          *
784          */
785
786   private void get_scale_factors(Header header, int ch, int gr) {
787
788     // gr_info_s gr_info = (si.ch[ch].gr[gr]); remove alias
789
790     int sfb;
791     int window;
792     int scale_comp = si.ch[ch].gr[gr].scalefac_compress;
793     int length0 = slen[0][scale_comp];
794     int length1 = slen[1][scale_comp];
795
796     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
797       if ((si.ch[ch].gr[gr].mixed_block_flag) != 0) { // MIXED
798         for (sfb = 0; sfb < 8; sfb++)
799           scalefac[ch].l[sfb] = br.hgetbits(slen[0][si.ch[ch].gr[gr].scalefac_compress]);
800         for (sfb = 3; sfb < 6; sfb++)
801           for (window = 0; window < 3; window++)
802             scalefac[ch].s[window][sfb] = br.hgetbits(slen[0][si.ch[ch].gr[gr].scalefac_compress]);
803         for (sfb = 6; sfb < 12; sfb++)
804           for (window = 0; window < 3; window++)
805             scalefac[ch].s[window][sfb] = br.hgetbits(slen[1][si.ch[ch].gr[gr].scalefac_compress]);
806         for (sfb = 12, window = 0; window < 3; window++)
807           scalefac[ch].s[window][sfb] = 0;
808
809       } else { // SHORT
810
811         scalefac[ch].s[0][0] = br.hgetbits(length0);
812         scalefac[ch].s[1][0] = br.hgetbits(length0);
813         scalefac[ch].s[2][0] = br.hgetbits(length0);
814         scalefac[ch].s[0][1] = br.hgetbits(length0);
815         scalefac[ch].s[1][1] = br.hgetbits(length0);
816         scalefac[ch].s[2][1] = br.hgetbits(length0);
817         scalefac[ch].s[0][2] = br.hgetbits(length0);
818         scalefac[ch].s[1][2] = br.hgetbits(length0);
819         scalefac[ch].s[2][2] = br.hgetbits(length0);
820         scalefac[ch].s[0][3] = br.hgetbits(length0);
821         scalefac[ch].s[1][3] = br.hgetbits(length0);
822         scalefac[ch].s[2][3] = br.hgetbits(length0);
823         scalefac[ch].s[0][4] = br.hgetbits(length0);
824         scalefac[ch].s[1][4] = br.hgetbits(length0);
825         scalefac[ch].s[2][4] = br.hgetbits(length0);
826         scalefac[ch].s[0][5] = br.hgetbits(length0);
827         scalefac[ch].s[1][5] = br.hgetbits(length0);
828         scalefac[ch].s[2][5] = br.hgetbits(length0);
829         scalefac[ch].s[0][6] = br.hgetbits(length1);
830         scalefac[ch].s[1][6] = br.hgetbits(length1);
831         scalefac[ch].s[2][6] = br.hgetbits(length1);
832         scalefac[ch].s[0][7] = br.hgetbits(length1);
833         scalefac[ch].s[1][7] = br.hgetbits(length1);
834         scalefac[ch].s[2][7] = br.hgetbits(length1);
835         scalefac[ch].s[0][8] = br.hgetbits(length1);
836         scalefac[ch].s[1][8] = br.hgetbits(length1);
837         scalefac[ch].s[2][8] = br.hgetbits(length1);
838         scalefac[ch].s[0][9] = br.hgetbits(length1);
839         scalefac[ch].s[1][9] = br.hgetbits(length1);
840         scalefac[ch].s[2][9] = br.hgetbits(length1);
841         scalefac[ch].s[0][10] = br.hgetbits(length1);
842         scalefac[ch].s[1][10] = br.hgetbits(length1);
843         scalefac[ch].s[2][10] = br.hgetbits(length1);
844         scalefac[ch].s[0][11] = br.hgetbits(length1);
845         scalefac[ch].s[1][11] = br.hgetbits(length1);
846         scalefac[ch].s[2][11] = br.hgetbits(length1);
847         scalefac[ch].s[0][12] = 0;
848         scalefac[ch].s[1][12] = 0;
849         scalefac[ch].s[2][12] = 0;
850       } // SHORT
851
852     } else { // LONG types 0,1,3
853
854       if ((si.ch[ch].scfsi[0] == 0) || (gr == 0)) {
855         scalefac[ch].l[0] = br.hgetbits(length0);
856         scalefac[ch].l[1] = br.hgetbits(length0);
857         scalefac[ch].l[2] = br.hgetbits(length0);
858         scalefac[ch].l[3] = br.hgetbits(length0);
859         scalefac[ch].l[4] = br.hgetbits(length0);
860         scalefac[ch].l[5] = br.hgetbits(length0);
861       }
862       if ((si.ch[ch].scfsi[1] == 0) || (gr == 0)) {
863         scalefac[ch].l[6] = br.hgetbits(length0);
864         scalefac[ch].l[7] = br.hgetbits(length0);
865         scalefac[ch].l[8] = br.hgetbits(length0);
866         scalefac[ch].l[9] = br.hgetbits(length0);
867         scalefac[ch].l[10] = br.hgetbits(length0);
868       }
869       if ((si.ch[ch].scfsi[2] == 0) || (gr == 0)) {
870         scalefac[ch].l[11] = br.hgetbits(length1);
871         scalefac[ch].l[12] = br.hgetbits(length1);
872         scalefac[ch].l[13] = br.hgetbits(length1);
873         scalefac[ch].l[14] = br.hgetbits(length1);
874         scalefac[ch].l[15] = br.hgetbits(length1);
875       }
876       if ((si.ch[ch].scfsi[3] == 0) || (gr == 0)) {
877         scalefac[ch].l[16] = br.hgetbits(length1);
878         scalefac[ch].l[17] = br.hgetbits(length1);
879         scalefac[ch].l[18] = br.hgetbits(length1);
880         scalefac[ch].l[19] = br.hgetbits(length1);
881         scalefac[ch].l[20] = br.hgetbits(length1);
882       }
883
884       scalefac[ch].l[21] = 0;
885       scalefac[ch].l[22] = 0;
886     }
887   }
888
889   /**
890          *
891          */
892   // MDM: new_slen is fully initialized before use, no need
893   // to reallocate array.
894
895   private int[] new_slen = new int[4];
896
897   // ssjava
898
899   private void get_LSF_scale_data(Header header, int ch, int gr) {
900
901     int mode_ext = header.mode_extension();
902     // gr_info_s gr_info =
903     // (si.ch[ch].gr[gr]); // remove alias
904
905     int scalefac_comp = si.ch[ch].gr[gr].scalefac_compress;
906     int blocktypenumber;
907
908     int int_scalefac_comp;
909     int m;
910     int blocknumber = 0;
911
912     if (si.ch[ch].gr[gr].block_type == 2) {
913       if (si.ch[ch].gr[gr].mixed_block_flag == 0) {
914         blocktypenumber = 1;
915       } else if (si.ch[ch].gr[gr].mixed_block_flag == 1) {
916         blocktypenumber = 2;
917       } else {
918         blocktypenumber = 0;
919       }
920     } else {
921       blocktypenumber = 0;
922     }
923
924     if (!(((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) {
925
926       if (scalefac_comp < 400) {
927
928         new_slen[0] = (scalefac_comp >>> 4) / 5;
929         new_slen[1] = (scalefac_comp >>> 4) % 5;
930         new_slen[2] = (scalefac_comp & 0xF) >>> 2;
931         new_slen[3] = (scalefac_comp & 3);
932         si.ch[ch].gr[gr].preflag = 0;
933         blocknumber = 0;
934
935       } else if (scalefac_comp < 500) {
936
937         new_slen[0] = ((scalefac_comp - 400) >>> 2) / 5;
938         new_slen[1] = ((scalefac_comp - 400) >>> 2) % 5;
939         new_slen[2] = (scalefac_comp - 400) & 3;
940         new_slen[3] = 0;
941         si.ch[ch].gr[gr].preflag = 0;
942         blocknumber = 1;
943
944       } else if (scalefac_comp < 512) {
945
946         new_slen[0] = (scalefac_comp - 500) / 3;
947         new_slen[1] = (scalefac_comp - 500) % 3;
948         new_slen[2] = 0;
949         new_slen[3] = 0;
950         si.ch[ch].gr[gr].preflag = 1;
951         blocknumber = 2;
952       }
953     }
954
955     if ((((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) {
956       int_scalefac_comp = scalefac_comp >>> 1;
957
958       if (int_scalefac_comp < 180) {
959         new_slen[0] = int_scalefac_comp / 36;
960         new_slen[1] = (int_scalefac_comp % 36) / 6;
961         new_slen[2] = (int_scalefac_comp % 36) % 6;
962         new_slen[3] = 0;
963         si.ch[ch].gr[gr].preflag = 0;
964         blocknumber = 3;
965       } else if (int_scalefac_comp < 244) {
966         new_slen[0] = ((int_scalefac_comp - 180) & 0x3F) >>> 4;
967         new_slen[1] = ((int_scalefac_comp - 180) & 0xF) >>> 2;
968         new_slen[2] = (int_scalefac_comp - 180) & 3;
969         new_slen[3] = 0;
970         si.ch[ch].gr[gr].preflag = 0;
971         blocknumber = 4;
972       } else if (int_scalefac_comp < 255) {
973         new_slen[0] = (int_scalefac_comp - 244) / 3;
974         new_slen[1] = (int_scalefac_comp - 244) % 3;
975         new_slen[2] = 0;
976         new_slen[3] = 0;
977         si.ch[ch].gr[gr].preflag = 0;
978         blocknumber = 5;
979       }
980     }
981
982     // for ( int x = 0; x < 45; x++)
983     // // why 45, not 54?
984     // scalefac_buffer[x] = 0;
985
986     m = 0;
987     for (int i = 0; i < 4; i++) {
988       int jmax = nr_of_sfb_block[blocknumber][blocktypenumber][i];
989       for (int j = 0; j < jmax; j++) {
990         scalefac_buffer[m] = (new_slen[i] == 0) ? 0 : br.hgetbits(new_slen[i]);
991         m++;
992
993       } // for (unint32 j ...
994     } // for (uint32 i ...
995   }
996
997   /**
998          *
999          */
1000
1001   private void get_LSF_scale_factors(Header header, int ch, int gr) {
1002
1003     int sfb;
1004     int m = 0;
1005     int window;
1006     // gr_info_s gr_info = (si.ch[ch].gr[gr]); // remove alias
1007
1008     get_LSF_scale_data(header, ch, gr);
1009
1010     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1011       if (si.ch[ch].gr[gr].mixed_block_flag != 0) { // MIXED
1012         for (sfb = 0; sfb < 8; sfb++) {
1013           scalefac[ch].l[sfb] = scalefac_buffer[m];
1014           m++;
1015         }
1016         for (sfb = 3; sfb < 12; sfb++) {
1017           for (window = 0; window < 3; window++) {
1018             scalefac[ch].s[window][sfb] = scalefac_buffer[m];
1019             m++;
1020           }
1021         }
1022         for (window = 0; window < 3; window++)
1023           scalefac[ch].s[window][12] = 0;
1024
1025       } else { // SHORT
1026
1027         for (sfb = 0; sfb < 12; sfb++) {
1028           for (window = 0; window < 3; window++) {
1029             scalefac[ch].s[window][sfb] = scalefac_buffer[m];
1030             m++;
1031           }
1032         }
1033
1034         for (window = 0; window < 3; window++)
1035           scalefac[ch].s[window][12] = 0;
1036       }
1037     } else { // LONG types 0,1,3
1038
1039       for (sfb = 0; sfb < 21; sfb++) {
1040         scalefac[ch].l[sfb] = scalefac_buffer[m];
1041         m++;
1042       }
1043       scalefac[ch].l[21] = 0; // Jeff
1044       scalefac[ch].l[22] = 0;
1045     }
1046   }
1047
1048   /**
1049          *
1050          */
1051   //
1052   // int[] x = { 0 };
1053   //
1054   // int[] y = { 0 };
1055   //
1056   // int[] v = { 0 };
1057   //
1058   // int[] w = { 0 };
1059   //
1060   // int x[] = { 0 };
1061   //
1062   // int y[] = { 0 };
1063   //
1064   // int v[] = { 0 };
1065   //
1066   // int w[] = { 0 };
1067
1068   private void huffman_decode(int part2_start_local, int ch, int gr) {
1069
1070     int[] x = new int[1];
1071     int[] y = new int[1];
1072     int[] v = new int[1];
1073     int[] w = new int[1];
1074
1075     int part2_3_end = part2_start_local + si.ch[ch].gr[gr].part2_3_length;
1076     int num_bits;
1077     int region1Start;
1078     int region2Start;
1079     int index;
1080
1081     int buf;
1082     int buf1;
1083
1084     // Find region boundary for short block case
1085
1086     if (((si.ch[ch].gr[gr].window_switching_flag) != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1087
1088       // Region2.
1089       // MS: Extrahandling for 8KHZ
1090       region1Start = (sfreq == 8) ? 72 : 36; // sfb[9/3]*3=36 or in case
1091                                              // 8KHZ = 72
1092       region2Start = 576; // No Region2 for short block case
1093
1094     } else { // Find region boundary for long block case
1095
1096       buf = si.ch[ch].gr[gr].region0_count + 1;
1097       buf1 = buf + si.ch[ch].gr[gr].region1_count + 1;
1098
1099       if (buf1 > sfBandIndex[sfreq].l.length - 1)
1100         buf1 = sfBandIndex[sfreq].l.length - 1;
1101
1102       region1Start = sfBandIndex[sfreq].l[buf];
1103       region2Start = sfBandIndex[sfreq].l[buf1]; /* MI */
1104     }
1105
1106     index = 0;
1107     // Read bigvalues area
1108     TERMINATE: for (int i = 0; i < (si.ch[ch].gr[gr].big_values << 1); i += 2) {
1109
1110       int htIdx;
1111       if (i < region1Start) {
1112         htIdx = si.ch[ch].gr[gr].table_select[0];
1113         // h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[0]];
1114       } else if (i < region2Start) {
1115         htIdx = si.ch[ch].gr[gr].table_select[1];
1116         // h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[1]];
1117       } else {
1118         htIdx = si.ch[ch].gr[gr].table_select[2];
1119         // h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[2]];
1120       }
1121
1122       huffcodetab.huffman_decoder(htIdx, x, y, v, w, br);
1123       // if (index >= is_1d.length)
1124       // System.out.println("i0="+i+"/"+(si.ch[ch].gr[gr].big_values<<1)+" Index="+index+" is_1d="+is_1d.length);
1125
1126       is_1d[index++] = x[0];
1127       is_1d[index++] = y[0];
1128
1129       CheckSumHuff = CheckSumHuff + x[0] + y[0];
1130       // System.out.println("x = " + x[0] + " y = " + y[0]);
1131     }
1132
1133     // Read count1 area
1134
1135     int htIdx = si.ch[ch].gr[gr].count1table_select + 32;
1136     // h = huffcodetab.ht[si.ch[ch].gr[gr].count1table_select + 32];
1137     num_bits = br.hsstell();
1138
1139     TERMINATE: while ((num_bits < part2_3_end) && (index < 576)) {
1140
1141       huffcodetab.huffman_decoder(htIdx, x, y, v, w, br);
1142
1143       is_1d[index++] = v[0];
1144       is_1d[index++] = w[0];
1145       is_1d[index++] = x[0];
1146       is_1d[index++] = y[0];
1147       CheckSumHuff = CheckSumHuff + v[0] + w[0] + x[0] + y[0];
1148       // System.out.println("v = "+v[0]+" w = "+w[0]);
1149       // System.out.println("x = "+x[0]+" y = "+y[0]);
1150       num_bits = br.hsstell();
1151     }
1152
1153     if (num_bits > part2_3_end) {
1154       br.rewindNbits(num_bits - part2_3_end);
1155       index -= 4;
1156     }
1157
1158     num_bits = br.hsstell();
1159
1160     // Dismiss stuffing bits
1161     if (num_bits < part2_3_end)
1162       br.hgetbits(part2_3_end - num_bits);
1163
1164     // Zero out rest
1165
1166     if (index < 576)
1167       nonzero[ch] = index;
1168     else
1169       nonzero[ch] = 576;
1170
1171     if (index < 0)
1172       index = 0;
1173
1174     // may not be necessary
1175     for (; index < 576; index++)
1176       is_1d[index] = 0;
1177   }
1178
1179   private int huffcodetab_huffman_decoder(int h) {
1180     // TODO need to move huffmancodetab implementation here
1181     return 0;
1182   }
1183
1184   /**
1185          *
1186          */
1187   private void i_stereo_k_values(int is_pos, int io_type, int i) {
1188     if (is_pos == 0) {
1189       k[0][i] = 1.0f;
1190       k[1][i] = 1.0f;
1191     } else if ((is_pos & 1) != 0) {
1192       k[0][i] = io[io_type][(is_pos + 1) >>> 1];
1193       k[1][i] = 1.0f;
1194     } else {
1195       k[0][i] = 1.0f;
1196       k[1][i] = io[io_type][is_pos >>> 1];
1197     }
1198   }
1199
1200   /**
1201          *
1202          */
1203   //
1204
1205   // ssjava
1206   private void dequantize_sample(int ch, int gr) {
1207
1208     // gr_info_s gr_info = (si.ch[ch].gr[gr]); remove alias!
1209     int cb = 0;
1210
1211     int next_cb_boundary;
1212     int cb_begin = 0;
1213     int cb_width = 0;
1214     float g_gain;
1215
1216     int index = 0;
1217     int t_index;
1218     int j;
1219
1220     // float[][] xr_1d = xr;//substituted xr for instances of xr_1d to decrease
1221     // number of areas
1222
1223     // choose correct scalefactor band per block type, initalize boundary
1224
1225     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1226       if (si.ch[ch].gr[gr].mixed_block_flag != 0)
1227         next_cb_boundary = sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3
1228       else {
1229         cb_width = sfBandIndex[sfreq].s[1];
1230         next_cb_boundary = (cb_width << 2) - cb_width;
1231         cb_begin = 0;
1232       }
1233     } else {
1234       next_cb_boundary = sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3
1235     }
1236
1237     // Compute overall (global) scaling.
1238
1239     g_gain = (float) Math.pow(2.0, (0.25 * (si.ch[ch].gr[gr].global_gain - 210.0)));
1240
1241     for (j = 0; j < nonzero[ch]; j++) {
1242       // Modif E.B 02/22/99
1243       int reste = j % SSLIMIT;
1244       int quotien = (int) ((j - reste) / SSLIMIT);
1245       if (is_1d[j] == 0) {
1246         ro[ch][quotien][reste] = 0.0f;
1247       } else {
1248         int abv = is_1d[j];
1249         // Pow Array fix (11/17/04)
1250         if (abv < t_43.length) {
1251           if (is_1d[j] > 0)
1252             ro[ch][quotien][reste] = g_gain * t_43[abv];
1253           else {
1254             if (-abv < t_43.length)
1255               ro[ch][quotien][reste] = -g_gain * t_43[-abv];
1256             else
1257               ro[ch][quotien][reste] = -g_gain * (float) Math.pow(-abv, d43);
1258           }
1259         } else {
1260           if (is_1d[j] > 0)
1261             ro[ch][quotien][reste] = g_gain * (float) Math.pow(abv, d43);
1262           else
1263             ro[ch][quotien][reste] = -g_gain * (float) Math.pow(-abv, d43);
1264         }
1265       }
1266     }
1267
1268     // apply formula per block type
1269     for (j = 0; j < nonzero[ch]; j++) {
1270       // Modif E.B 02/22/99
1271       int reste = j % SSLIMIT;
1272       int quotien = (int) ((j - reste) / SSLIMIT);
1273
1274       if (index == next_cb_boundary) { /* Adjust critical band boundary */
1275         if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1276           if (si.ch[ch].gr[gr].mixed_block_flag != 0) {
1277
1278             if (index == sfBandIndex[sfreq].l[8]) {
1279               next_cb_boundary = sfBandIndex[sfreq].s[4];
1280               next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;
1281               cb = 3;
1282               cb_width = sfBandIndex[sfreq].s[4] - sfBandIndex[sfreq].s[3];
1283
1284               cb_begin = sfBandIndex[sfreq].s[3];
1285               cb_begin = (cb_begin << 2) - cb_begin;
1286
1287             } else if (index < sfBandIndex[sfreq].l[8]) {
1288
1289               next_cb_boundary = sfBandIndex[sfreq].l[(++cb) + 1];
1290
1291             } else {
1292
1293               next_cb_boundary = sfBandIndex[sfreq].s[(++cb) + 1];
1294               next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;
1295
1296               cb_begin = sfBandIndex[sfreq].s[cb];
1297               cb_width = sfBandIndex[sfreq].s[cb + 1] - cb_begin;
1298               cb_begin = (cb_begin << 2) - cb_begin;
1299             }
1300
1301           } else {
1302
1303             next_cb_boundary = sfBandIndex[sfreq].s[(++cb) + 1];
1304             next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;
1305
1306             cb_begin = sfBandIndex[sfreq].s[cb];
1307             cb_width = sfBandIndex[sfreq].s[cb + 1] - cb_begin;
1308             cb_begin = (cb_begin << 2) - cb_begin;
1309           }
1310
1311         } else { // long blocks
1312
1313           next_cb_boundary = sfBandIndex[sfreq].l[(++cb) + 1];
1314
1315         }
1316       }
1317
1318       // Do long/short dependent scaling operations
1319
1320       if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (((si.ch[ch].gr[gr].block_type == 2) && (si.ch[ch].gr[gr].mixed_block_flag == 0)) || ((si.ch[ch].gr[gr].block_type == 2) && (si.ch[ch].gr[gr].mixed_block_flag != 0) && (j >= 36)))) {
1321
1322         t_index = (index - cb_begin) / cb_width;
1323         /*
1324          * xr[sb][ss] *= pow(2.0, ((-2.0 * gr_info.subblock_gain[t_index]) -(0.5
1325          * * (1.0 + gr_info.scalefac_scale) scalefac[ch].s[t_index][cb])));
1326          */
1327         int idx = scalefac[ch].s[t_index][cb] << si.ch[ch].gr[gr].scalefac_scale;
1328         idx += (si.ch[ch].gr[gr].subblock_gain[t_index] << 2);
1329
1330         ro[ch][quotien][reste] *= two_to_negative_half_pow[idx];
1331
1332       } else { // LONG block types 0,1,3 & 1st 2 subbands of switched blocks
1333         /*
1334          * xr[sb][ss] *= pow(2.0, -0.5 * (1.0+gr_info.scalefac_scale)
1335          * (scalefac[ch].l[cb] + gr_info.preflag * pretab[cb]));
1336          */
1337         int idx = scalefac[ch].l[cb];
1338
1339         if (si.ch[ch].gr[gr].preflag != 0)
1340           idx += pretab[cb];
1341
1342         idx = idx << si.ch[ch].gr[gr].scalefac_scale;
1343         ro[ch][quotien][reste] *= two_to_negative_half_pow[idx];
1344       }
1345       index++;
1346     }
1347
1348     for (j = nonzero[ch]; j < 576; j++) {
1349       // Modif E.B 02/22/99
1350       int reste = j % SSLIMIT;
1351       int quotien = (int) ((j - reste) / SSLIMIT);
1352       if (reste < 0)
1353         reste = 0;
1354       if (quotien < 0)
1355         quotien = 0;
1356       ro[ch][quotien][reste] = 0.0f;
1357     }
1358
1359     return;
1360   }
1361
1362   /**
1363          *
1364          */
1365   // ssjava
1366   //
1367
1368   private void reorder(int ch, int gr) {
1369     // the purpose of reordering: move 'short samples' back to their original
1370     // position
1371     // after reorder, the samples are no long ordered by frequency
1372
1373     // the format of input data to reorder:
1374     // three small chunks of 192 samples each are combined to 576 samples
1375     // ordered by frequency
1376
1377     // gr_info_s gr_info = (si.ch[ch].gr[gr]); //remove alias
1378
1379     int index;
1380
1381     int freq;
1382     int freq3;
1383     int sfb;
1384     int sfb_start;
1385     int sfb_lines;
1386     int src_line;
1387     int des_line;
1388     // float[][] xr_1d = xr; subbed in xr for xr_1d so as not to create extra
1389     // areas
1390
1391     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1392
1393       // for (index = 0; index < 576; index++) {
1394       // inter[index] = 0.0f;
1395       // }
1396
1397       if (si.ch[ch].gr[gr].mixed_block_flag != 0) {
1398         // NO REORDER FOR LOW 2 SUBBANDS
1399         for (index = 0; index < 36; index++) {
1400           // Modif E.B 02/22/99
1401           int reste = index % SSLIMIT;
1402           int quotien = (int) ((index - reste) / SSLIMIT);
1403           inter[index] = lr[ch][quotien][reste];
1404         }
1405         // REORDERING FOR REST SWITCHED SHORT
1406         /*
1407          * for( sfb=3,sfb_start=sfBandIndex[sfreq].s[3],
1408          * sfb_lines=sfBandIndex[sfreq].s[4] - sfb_start; sfb < 13;
1409          * sfb++,sfb_start = sfBandIndex[sfreq].s[sfb], sfb_lines =
1410          * sfBandIndex[sfreq].s[sfb+1] - sfb_start ) {
1411          */
1412         for (sfb = 3; sfb < 13; sfb++) {
1413           // System.out.println("sfreq="+sfreq+" sfb="+sfb+" sfBandIndex="+sfBandIndex.length+" sfBandIndex[sfreq].s="+sfBandIndex[sfreq].s.length);
1414           sfb_start = sfBandIndex[sfreq].s[sfb];
1415           sfb_lines = sfBandIndex[sfreq].s[sfb + 1] - sfb_start;
1416
1417           int sfb_start3 = (sfb_start << 2) - sfb_start;
1418
1419           for (freq = 0, freq3 = 0; freq < sfb_lines; freq++, freq3 += 3) {
1420
1421             src_line = sfb_start3 + freq;
1422             des_line = sfb_start3 + freq3;
1423             // Modif E.B 02/22/99
1424             int reste = src_line % SSLIMIT;
1425             int quotien = (int) ((src_line - reste) / SSLIMIT);
1426
1427             inter[des_line] = lr[ch][quotien][reste];
1428             src_line += sfb_lines;
1429             des_line++;
1430
1431             reste = src_line % SSLIMIT;
1432             quotien = (int) ((src_line - reste) / SSLIMIT);
1433
1434             inter[des_line] = lr[ch][quotien][reste];
1435             src_line += sfb_lines;
1436             des_line++;
1437
1438             reste = src_line % SSLIMIT;
1439             quotien = (int) ((src_line - reste) / SSLIMIT);
1440
1441             inter[des_line] = lr[ch][quotien][reste];
1442           }
1443         }
1444
1445       } else { // pure short
1446         for (index = 0; index < 576; index++) {
1447           int j = reorder_table[sfreq][index];
1448           int reste = j % SSLIMIT;
1449           int quotien = (int) ((j - reste) / SSLIMIT);
1450           inter[index] = lr[ch][quotien][reste];
1451         }
1452       }
1453     } else { // long blocks
1454       for (index = 0; index < 576; index++) {
1455         // Modif E.B 02/22/99
1456         int reste = index % SSLIMIT;
1457         int quotien = (int) ((index - reste) / SSLIMIT);
1458         inter[index] = lr[ch][quotien][reste];
1459       }
1460     }
1461   }
1462
1463   /**
1464          *
1465          */
1466
1467   int[] is_pos = new int[576];
1468
1469   float[] is_ratio = new float[576];
1470
1471   // ssjava
1472
1473   private void stereo(Header header, int gr) {
1474     int sb;
1475     int ss;
1476
1477     if (channels == 1) { // mono , bypass xr[0][][] to lr[0][][]
1478
1479       for (sb = 0; sb < SBLIMIT; sb++)
1480         for (ss = 0; ss < SSLIMIT; ss += 3) {
1481           lr[0][sb][ss] = ro[0][sb][ss];
1482           lr[0][sb][ss + 1] = ro[0][sb][ss + 1];
1483           lr[0][sb][ss + 2] = ro[0][sb][ss + 2];
1484         }
1485
1486     } else {
1487
1488       // gr_info_s gr_info = (si.ch[0].gr[gr]); remove alias
1489       int mode_ext = header.mode_extension();
1490
1491       int sfb;
1492       int i;
1493       int lines;
1494       int temp;
1495       int temp2;
1496
1497       boolean ms_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x2) != 0));
1498       boolean i_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x1) != 0));
1499       boolean lsf = ((header.version() == Header.MPEG2_LSF || header.version() == Header.MPEG25_LSF)); // SZD
1500
1501       int io_type = (si.ch[0].gr[gr].scalefac_compress & 1);
1502
1503       // initialization
1504       // for (i = 0; i < 576; i++) {
1505       // is_pos[i] = 7;
1506       // is_ratio[i] = 0.0f;
1507       // }
1508
1509       if (i_stereo) {
1510         if ((si.ch[0].gr[gr].window_switching_flag != 0) && (si.ch[0].gr[gr].block_type == 2)) {
1511           if (si.ch[0].gr[gr].mixed_block_flag != 0) {
1512
1513             int max_sfb = 0;
1514
1515             for (int j = 0; j < 3; j++) {
1516               int sfbcnt;
1517               sfbcnt = 2;
1518               TERMINATE: for (sfb = 12; sfb >= 3; sfb--) {
1519                 i = sfBandIndex[sfreq].s[sfb];
1520                 lines = sfBandIndex[sfreq].s[sfb + 1] - i;
1521                 i = (i << 2) - i + (j + 1) * lines - 1;
1522                 TERMINATE: while (lines > 0) {
1523                   if (ro[1][i / 18][i % 18] != 0.0f) {
1524                     // MDM: in java, array access is very slow.
1525                     // Is quicker to compute div and mod values.
1526                     // if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {
1527                     sfbcnt = sfb;
1528                     sfb = -10;
1529                     lines = -10;
1530                   }
1531
1532                   lines--;
1533                   i--;
1534
1535                 } // while (lines > 0)
1536
1537               } // for (sfb=12 ...
1538               sfb = sfbcnt + 1;
1539
1540               if (sfb > max_sfb)
1541                 max_sfb = sfb;
1542
1543               while (sfb < 12) {
1544                 temp = sfBandIndex[sfreq].s[sfb];
1545                 sb = sfBandIndex[sfreq].s[sfb + 1] - temp;
1546                 i = (temp << 2) - temp + j * sb;
1547
1548                 TERMINATE: for (; sb > 0; sb--) {
1549                   is_pos[i] = scalefac[1].s[j][sfb];
1550                   if (is_pos[i] != 7)
1551                     if (lsf)
1552                       i_stereo_k_values(is_pos[i], io_type, i);
1553                     else
1554                       is_ratio[i] = TAN12[is_pos[i]];
1555
1556                   i++;
1557                 } // for (; sb>0...
1558                 sfb++;
1559               } // while (sfb < 12)
1560               sfb = sfBandIndex[sfreq].s[10];
1561               sb = sfBandIndex[sfreq].s[11] - sfb;
1562               sfb = (sfb << 2) - sfb + j * sb;
1563               temp = sfBandIndex[sfreq].s[11];
1564               sb = sfBandIndex[sfreq].s[12] - temp;
1565               i = (temp << 2) - temp + j * sb;
1566               TERMINATE: for (; sb > 0; sb--) {
1567                 is_pos[i] = is_pos[sfb];
1568
1569                 if (lsf) {
1570                   k[0][i] = k[0][sfb];
1571                   k[1][i] = k[1][sfb];
1572                 } else {
1573                   is_ratio[i] = is_ratio[sfb];
1574                 }
1575                 i++;
1576               } // for (; sb > 0 ...
1577             }
1578             if (max_sfb <= 3) {
1579               i = 2;
1580               ss = 17;
1581               sb = -1;
1582               TERMINATE: while (i >= 0) {
1583                 if (ro[1][i][ss] != 0.0f) {
1584                   sb = (i << 4) + (i << 1) + ss;
1585                   i = -1;
1586                 } else {
1587                   ss--;
1588                   if (ss < 0) {
1589                     i--;
1590                     ss = 17;
1591                   }
1592                 } // if (ro ...
1593               } // while (i>=0)
1594               i = 0;
1595               while (sfBandIndex[sfreq].l[i] <= sb)
1596                 i++;
1597               sfb = i;
1598               i = sfBandIndex[sfreq].l[i];
1599               for (; sfb < 8; sfb++) {
1600                 sb = sfBandIndex[sfreq].l[sfb + 1] - sfBandIndex[sfreq].l[sfb];
1601                 TERMINATE: for (; sb > 0; sb--) {
1602                   is_pos[i] = scalefac[1].l[sfb];
1603                   if (is_pos[i] != 7)
1604                     if (lsf)
1605                       i_stereo_k_values(is_pos[i], io_type, i);
1606                     else
1607                       is_ratio[i] = TAN12[is_pos[i]];
1608                   i++;
1609                 } // for (; sb>0 ...
1610               } // for (; sfb<8 ...
1611             } // for (j=0 ...
1612           } else { // if (gr_info.mixed_block_flag)
1613             for (int j = 0; j < 3; j++) {
1614               int sfbcnt;
1615               sfbcnt = -1;
1616               TERMINATE: for (sfb = 12; sfb >= 0; sfb--) {
1617                 temp = sfBandIndex[sfreq].s[sfb];
1618                 lines = sfBandIndex[sfreq].s[sfb + 1] - temp;
1619                 i = (temp << 2) - temp + (j + 1) * lines - 1;
1620                 TERMINATE: while (lines > 0) {
1621                   if (ro[1][i / 18][i % 18] != 0.0f) {
1622                     // MDM: in java, array access is very slow.
1623                     // Is quicker to compute div and mod values.
1624                     // if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {
1625                     sfbcnt = sfb;
1626                     sfb = -10;
1627                     lines = -10;
1628                   }
1629                   lines--;
1630                   i--;
1631                 } // while (lines > 0) */
1632
1633               } // for (sfb=12 ...
1634               sfb = sfbcnt + 1;
1635               while (sfb < 12) {
1636                 temp = sfBandIndex[sfreq].s[sfb];
1637                 sb = sfBandIndex[sfreq].s[sfb + 1] - temp;
1638                 i = (temp << 2) - temp + j * sb;
1639                 TERMINATE: for (; sb > 0; sb--) {
1640                   is_pos[i] = scalefac[1].s[j][sfb];
1641                   if (is_pos[i] != 7)
1642                     if (lsf)
1643                       i_stereo_k_values(is_pos[i], io_type, i);
1644                     else
1645                       is_ratio[i] = TAN12[is_pos[i]];
1646                   i++;
1647                 } // for (; sb>0 ...
1648                 sfb++;
1649               } // while (sfb<12)
1650
1651               temp = sfBandIndex[sfreq].s[10];
1652               temp2 = sfBandIndex[sfreq].s[11];
1653               sb = temp2 - temp;
1654               sfb = (temp << 2) - temp + j * sb;
1655               sb = sfBandIndex[sfreq].s[12] - temp2;
1656               i = (temp2 << 2) - temp2 + j * sb;
1657               TERMINATE: for (; sb > 0; sb--) {
1658                 is_pos[i] = is_pos[sfb];
1659
1660                 if (lsf) {
1661                   k[0][i] = k[0][sfb];
1662                   k[1][i] = k[1][sfb];
1663                 } else {
1664                   is_ratio[i] = is_ratio[sfb];
1665                 }
1666                 i++;
1667               } // for (; sb>0 ...
1668             } // for (sfb=12
1669           } // for (j=0 ...
1670         } else { // if (gr_info.window_switching_flag ...
1671           i = 31;
1672           ss = 17;
1673           sb = 0;
1674           TERMINATE: while (i >= 0) {
1675             if (ro[1][i][ss] != 0.0f) {
1676               sb = (i << 4) + (i << 1) + ss;
1677               i = -1;
1678             } else {
1679               ss--;
1680               if (ss < 0) {
1681                 i--;
1682                 ss = 17;
1683               }
1684             }
1685           }
1686           i = 0;
1687           while (sfBandIndex[sfreq].l[i] <= sb)
1688             i++;
1689
1690           sfb = i;
1691           i = sfBandIndex[sfreq].l[i];
1692           for (; sfb < 21; sfb++) {
1693             sb = sfBandIndex[sfreq].l[sfb + 1] - sfBandIndex[sfreq].l[sfb];
1694             TERMINATE: for (; sb > 0; sb--) {
1695               is_pos[i] = scalefac[1].l[sfb];
1696               if (is_pos[i] != 7)
1697                 if (lsf)
1698                   i_stereo_k_values(is_pos[i], io_type, i);
1699                 else
1700                   is_ratio[i] = TAN12[is_pos[i]];
1701               i++;
1702             }
1703           }
1704           sfb = sfBandIndex[sfreq].l[20];
1705           TERMINATE: for (sb = 576 - sfBandIndex[sfreq].l[21]; (sb > 0) && (i < 576); sb--) {
1706             is_pos[i] = is_pos[sfb]; // error here : i >=576
1707
1708             if (lsf) {
1709               k[0][i] = k[0][sfb];
1710               k[1][i] = k[1][sfb];
1711             } else {
1712               is_ratio[i] = is_ratio[sfb];
1713             }
1714             i++;
1715           } // if (gr_info.mixed_block_flag)
1716         } // if (gr_info.window_switching_flag ...
1717       } // if (i_stereo)
1718
1719       i = 0;
1720       for (sb = 0; sb < SBLIMIT; sb++)
1721         for (ss = 0; ss < SSLIMIT; ss++) {
1722           if (is_pos[i] == 7) {
1723             if (ms_stereo) {
1724               lr[0][sb][ss] = (ro[0][sb][ss] + ro[1][sb][ss]) * 0.707106781f;
1725               lr[1][sb][ss] = (ro[0][sb][ss] - ro[1][sb][ss]) * 0.707106781f;
1726             } else {
1727               lr[0][sb][ss] = ro[0][sb][ss];
1728               lr[1][sb][ss] = ro[1][sb][ss];
1729             }
1730           } else if (i_stereo) {
1731
1732             if (lsf) {
1733               lr[0][sb][ss] = ro[0][sb][ss] * k[0][i];
1734               lr[1][sb][ss] = ro[0][sb][ss] * k[1][i];
1735             } else {
1736               lr[1][sb][ss] = ro[0][sb][ss] / (float) (1 + is_ratio[i]);
1737               lr[0][sb][ss] = lr[1][sb][ss] * is_ratio[i];
1738             }
1739           }
1740           /*
1741            * else { System.out.println("Error in stereo processing\n"); }
1742            */
1743           i++;
1744         }
1745
1746     } // channels == 2
1747
1748   }
1749
1750   /**
1751          *
1752          */
1753   //
1754
1755   private void antialias(int ch, int gr) {
1756
1757     int sb18;
1758     int ss;
1759     int sb18lim;
1760
1761     //
1762     // gr_info_s gr_info =
1763     // (si.ch[ch].gr[gr]);
1764     // 31 alias-reduction operations between each pair of sub-bands
1765     // with 8 butterflies between each pair
1766
1767     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].block_type == 2) && !(si.ch[ch].gr[gr].mixed_block_flag != 0))
1768       return;
1769
1770     if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].mixed_block_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) {
1771       sb18lim = 18;
1772     } else {
1773       sb18lim = 558;
1774     }
1775
1776     for (sb18 = 0; sb18 < sb18lim; sb18 += 18) {
1777       for (ss = 0; ss < 8; ss++) {
1778         int src_idx1 = sb18 + 17 - ss;
1779         int src_idx2 = sb18 + 18 + ss;
1780         float bu = inter[src_idx1];
1781         float bd = inter[src_idx2];
1782         inter[src_idx1] = (bu * cs[ss]) - (bd * ca[ss]);
1783         inter[src_idx2] = (bd * cs[ss]) + (bu * ca[ss]);
1784       }
1785     }
1786   }
1787
1788   /**
1789          *
1790          */
1791
1792   // MDM: tsOutCopy and rawout do not need initializing, so the arrays
1793   // can be reused.
1794
1795   float[] tsOutCopy = new float[18];
1796
1797   float[] rawout = new float[36];
1798
1799   private void hybrid(int ch, int gr) {
1800
1801     int bt;
1802     int sb18;
1803     // gr_info_s gr_info = (si.ch[ch].gr[gr]); //remove alias
1804     // float[] tsOut; //remove alias
1805
1806     // float[][] prvblk;
1807
1808     for (sb18 = 0; sb18 < 576; sb18 += 18) {
1809       if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].mixed_block_flag != 0) && (sb18 < 36)) {
1810         bt = 0;
1811       } else {
1812         bt = si.ch[ch].gr[gr].block_type;
1813       }
1814
1815       // tsOut = out_1d;
1816       // Modif E.B 02/22/99
1817       for (int cc = 0; cc < 18; cc++) {
1818         // tsOutCopy[cc] = out_1d[cc + sb18];
1819         tsOutCopy[cc] = inter[cc + sb18];
1820       }
1821
1822       inv_mdct(bt);
1823
1824       for (int cc = 0; cc < 18; cc++) {
1825         out_1d[cc + sb18] = tsOutCopy[cc];
1826       }
1827
1828       // Fin Modif
1829
1830       // overlap addition
1831       out_1d[0 + sb18] = rawout[0] + prevblck[ch][sb18 + 0];
1832       out_1d[1 + sb18] = rawout[1] + prevblck[ch][sb18 + 1];
1833       out_1d[2 + sb18] = rawout[2] + prevblck[ch][sb18 + 2];
1834       out_1d[3 + sb18] = rawout[3] + prevblck[ch][sb18 + 3];
1835       out_1d[4 + sb18] = rawout[4] + prevblck[ch][sb18 + 4];
1836       out_1d[5 + sb18] = rawout[5] + prevblck[ch][sb18 + 5];
1837       out_1d[6 + sb18] = rawout[6] + prevblck[ch][sb18 + 6];
1838       out_1d[7 + sb18] = rawout[7] + prevblck[ch][sb18 + 7];
1839       out_1d[8 + sb18] = rawout[8] + prevblck[ch][sb18 + 8];
1840       out_1d[9 + sb18] = rawout[9] + prevblck[ch][sb18 + 9];
1841       out_1d[10 + sb18] = rawout[10] + prevblck[ch][sb18 + 10];
1842       out_1d[11 + sb18] = rawout[11] + prevblck[ch][sb18 + 11];
1843       out_1d[12 + sb18] = rawout[12] + prevblck[ch][sb18 + 12];
1844       out_1d[13 + sb18] = rawout[13] + prevblck[ch][sb18 + 13];
1845       out_1d[14 + sb18] = rawout[14] + prevblck[ch][sb18 + 14];
1846       out_1d[15 + sb18] = rawout[15] + prevblck[ch][sb18 + 15];
1847       out_1d[16 + sb18] = rawout[16] + prevblck[ch][sb18 + 16];
1848       out_1d[17 + sb18] = rawout[17] + prevblck[ch][sb18 + 17];
1849       raw_full[ch][sb18 + 0] = rawout[18];
1850       raw_full[ch][sb18 + 1] = rawout[19];
1851       raw_full[ch][sb18 + 2] = rawout[20];
1852       raw_full[ch][sb18 + 3] = rawout[21];
1853       raw_full[ch][sb18 + 4] = rawout[22];
1854       raw_full[ch][sb18 + 5] = rawout[23];
1855       raw_full[ch][sb18 + 6] = rawout[24];
1856       raw_full[ch][sb18 + 7] = rawout[25];
1857       raw_full[ch][sb18 + 8] = rawout[26];
1858       raw_full[ch][sb18 + 9] = rawout[27];
1859       raw_full[ch][sb18 + 10] = rawout[28];
1860       raw_full[ch][sb18 + 11] = rawout[29];
1861       raw_full[ch][sb18 + 12] = rawout[30];
1862       raw_full[ch][sb18 + 13] = rawout[31];
1863       raw_full[ch][sb18 + 14] = rawout[32];
1864       raw_full[ch][sb18 + 15] = rawout[33];
1865       raw_full[ch][sb18 + 16] = rawout[34];
1866       raw_full[ch][sb18 + 17] = rawout[35];
1867
1868       // original implementation:
1869       // out_1d[0 + sb18] = rawout[0] + prevblck[ch][sb18 + 0];
1870       // prevblck[ch][sb18 + 0] = rawout[18];
1871       // out_1d[1 + sb18] = rawout[1] + prevblck[ch][sb18 + 1];
1872       // prevblck[ch][sb18 + 1] = rawout[19];
1873       // out_1d[2 + sb18] = rawout[2] + prevblck[ch][sb18 + 2];
1874       // prevblck[ch][sb18 + 2] = rawout[20];
1875       // out_1d[3 + sb18] = rawout[3] + prevblck[ch][sb18 + 3];
1876       // prevblck[ch][sb18 + 3] = rawout[21];
1877       // out_1d[4 + sb18] = rawout[4] + prevblck[ch][sb18 + 4];
1878       // prevblck[ch][sb18 + 4] = rawout[22];
1879       // out_1d[5 + sb18] = rawout[5] + prevblck[ch][sb18 + 5];
1880       // prevblck[ch][sb18 + 5] = rawout[23];
1881       // out_1d[6 + sb18] = rawout[6] + prevblck[ch][sb18 + 6];
1882       // prevblck[ch][sb18 + 6] = rawout[24];
1883       // out_1d[7 + sb18] = rawout[7] + prevblck[ch][sb18 + 7];
1884       // prevblck[ch][sb18 + 7] = rawout[25];
1885       // out_1d[8 + sb18] = rawout[8] + prevblck[ch][sb18 + 8];
1886       // prevblck[ch][sb18 + 8] = rawout[26];
1887       // out_1d[9 + sb18] = rawout[9] + prevblck[ch][sb18 + 9];
1888       // prevblck[ch][sb18 + 9] = rawout[27];
1889       // out_1d[10 + sb18] = rawout[10] + prevblck[ch][sb18 + 10];
1890       // prevblck[ch][sb18 + 10] = rawout[28];
1891       // out_1d[11 + sb18] = rawout[11] + prevblck[ch][sb18 + 11];
1892       // prevblck[ch][sb18 + 11] = rawout[29];
1893       // out_1d[12 + sb18] = rawout[12] + prevblck[ch][sb18 + 12];
1894       // prevblck[ch][sb18 + 12] = rawout[30];
1895       // out_1d[13 + sb18] = rawout[13] + prevblck[ch][sb18 + 13];
1896       // prevblck[ch][sb18 + 13] = rawout[31];
1897       // out_1d[14 + sb18] = rawout[14] + prevblck[ch][sb18 + 14];
1898       // prevblck[ch][sb18 + 14] = rawout[32];
1899       // out_1d[15 + sb18] = rawout[15] + prevblck[ch][sb18 + 15];
1900       // prevblck[ch][sb18 + 15] = rawout[33];
1901       // out_1d[16 + sb18] = rawout[16] + prevblck[ch][sb18 + 16];
1902       // prevblck[ch][sb18 + 16] = rawout[34];
1903       // out_1d[17 + sb18] = rawout[17] + prevblck[ch][sb18 + 17];
1904       // prevblck[ch][sb18 + 17] = rawout[35];
1905
1906     }
1907   }
1908
1909   /**
1910          *
1911          */
1912   private void do_downmix() {
1913     for (int sb = 0; sb < SSLIMIT; sb++) {
1914       for (int ss = 0; ss < SSLIMIT; ss += 3) {
1915         lr[0][sb][ss] = (lr[0][sb][ss] + lr[1][sb][ss]) * 0.5f;
1916         lr[0][sb][ss + 1] = (lr[0][sb][ss + 1] + lr[1][sb][ss + 1]) * 0.5f;
1917         lr[0][sb][ss + 2] = (lr[0][sb][ss + 2] + lr[1][sb][ss + 2]) * 0.5f;
1918       }
1919     }
1920   }
1921
1922   /**
1923    * Fast INV_MDCT.
1924    */
1925   //
1926   // public void inv_mdct( float[] in, float[] out,
1927   // int block_type) {//remove alias
1928   // ssjava
1929
1930   public void inv_mdct(int block_type) {
1931     // float[] win_bt;
1932     int i;
1933
1934     float tmpf_0;
1935     float tmpf_1;
1936     float tmpf_2;
1937     float tmpf_3;
1938     float tmpf_4;
1939     float tmpf_5;
1940     float tmpf_6;
1941     float tmpf_7;
1942     float tmpf_8;
1943     float tmpf_9;
1944     float tmpf_10;
1945     float tmpf_11;
1946     float tmpf_12;
1947     float tmpf_13;
1948     float tmpf_14;
1949     float tmpf_15;
1950     float tmpf_16;
1951     float tmpf_17;
1952
1953     tmpf_0 = 0.0f;
1954     tmpf_1 = 0.0f;
1955     tmpf_2 = 0.0f;
1956     tmpf_3 = 0.0f;
1957     tmpf_4 = 0.0f;
1958     tmpf_5 = 0.0f;
1959     tmpf_6 = 0.0f;
1960     tmpf_7 = 0.0f;
1961     tmpf_8 = 0.0f;
1962     tmpf_9 = 0.0f;
1963     tmpf_10 = 0.0f;
1964     tmpf_11 = 0.0f;
1965     tmpf_12 = 0.0f;
1966     tmpf_13 = 0.0f;
1967     tmpf_14 = 0.0f;
1968     tmpf_15 = 0.0f;
1969     tmpf_16 = 0.0f;
1970     tmpf_17 = 0.0f;
1971
1972     if (block_type == 2) {
1973
1974       /*
1975        * 
1976        * Under MicrosoftVM 2922, This causes a GPF, or At best, an
1977        * ArrayIndexOutOfBoundsExceptin. for(int p=0;p<36;p+=9) { out[p] =
1978        * out[p+1] = out[p+2] = out[p+3] = out[p+4] = out[p+5] = out[p+6] =
1979        * out[p+7] = out[p+8] = 0.0f; }
1980        */
1981       rawout[0] = 0.0f;
1982       rawout[1] = 0.0f;
1983       rawout[2] = 0.0f;
1984       rawout[3] = 0.0f;
1985       rawout[4] = 0.0f;
1986       rawout[5] = 0.0f;
1987       rawout[6] = 0.0f;
1988       rawout[7] = 0.0f;
1989       rawout[8] = 0.0f;
1990       rawout[9] = 0.0f;
1991       rawout[10] = 0.0f;
1992       rawout[11] = 0.0f;
1993       rawout[12] = 0.0f;
1994       rawout[13] = 0.0f;
1995       rawout[14] = 0.0f;
1996       rawout[15] = 0.0f;
1997       rawout[16] = 0.0f;
1998       rawout[17] = 0.0f;
1999       rawout[18] = 0.0f;
2000       rawout[19] = 0.0f;
2001       rawout[20] = 0.0f;
2002       rawout[21] = 0.0f;
2003       rawout[22] = 0.0f;
2004       rawout[23] = 0.0f;
2005       rawout[24] = 0.0f;
2006       rawout[25] = 0.0f;
2007       rawout[26] = 0.0f;
2008       rawout[27] = 0.0f;
2009       rawout[28] = 0.0f;
2010       rawout[29] = 0.0f;
2011       rawout[30] = 0.0f;
2012       rawout[31] = 0.0f;
2013       rawout[32] = 0.0f;
2014       rawout[33] = 0.0f;
2015       rawout[34] = 0.0f;
2016       rawout[35] = 0.0f;
2017
2018       int six_i = 0;
2019
2020       for (i = 0; i < 3; i++) {
2021         // 12 point IMDCT
2022         // Begin 12 point IDCT
2023         // Input aliasing for 12 pt IDCT
2024         tsOutCopy[15 + i] += tsOutCopy[12 + i];
2025         tsOutCopy[12 + i] += tsOutCopy[9 + i];
2026         tsOutCopy[9 + i] += tsOutCopy[6 + i];
2027         tsOutCopy[6 + i] += tsOutCopy[3 + i];
2028         tsOutCopy[3 + i] += tsOutCopy[0 + i];
2029
2030         // Input aliasing on odd indices (for 6 point IDCT)
2031         tsOutCopy[15 + i] += tsOutCopy[9 + i];
2032         tsOutCopy[9 + i] += tsOutCopy[3 + i];
2033
2034         // 3 point IDCT on even indices
2035         float pp1;
2036         float pp2;
2037         float sum;
2038         pp2 = tsOutCopy[12 + i] * 0.500000000f;
2039         pp1 = tsOutCopy[6 + i] * 0.866025403f;
2040         sum = tsOutCopy[0 + i] + pp2;
2041         tmpf_1 = tsOutCopy[0 + i] - tsOutCopy[12 + i];
2042         tmpf_0 = sum + pp1;
2043         tmpf_2 = sum - pp1;
2044
2045         // End 3 point IDCT on even indices
2046         // 3 point IDCT on odd indices (for 6 point IDCT)
2047         pp2 = tsOutCopy[15 + i] * 0.500000000f;
2048         pp1 = tsOutCopy[9 + i] * 0.866025403f;
2049         sum = tsOutCopy[3 + i] + pp2;
2050         tmpf_4 = tsOutCopy[3 + i] - tsOutCopy[15 + i];
2051         tmpf_5 = sum + pp1;
2052         tmpf_3 = sum - pp1;
2053         // End 3 point IDCT on odd indices
2054         // Twiddle factors on odd indices (for 6 point IDCT)
2055
2056         tmpf_3 *= 1.931851653f;
2057         tmpf_4 *= 0.707106781f;
2058         tmpf_5 *= 0.517638090f;
2059
2060         // Output butterflies on 2 3 point IDCT's (for 6 point IDCT)
2061         float save = tmpf_0;
2062         tmpf_0 += tmpf_5;
2063         tmpf_5 = save - tmpf_5;
2064         save = tmpf_1;
2065         tmpf_1 += tmpf_4;
2066         tmpf_4 = save - tmpf_4;
2067         save = tmpf_2;
2068         tmpf_2 += tmpf_3;
2069         tmpf_3 = save - tmpf_3;
2070
2071         // End 6 point IDCT
2072         // Twiddle factors on indices (for 12 point IDCT)
2073
2074         tmpf_0 *= 0.504314480f;
2075         tmpf_1 *= 0.541196100f;
2076         tmpf_2 *= 0.630236207f;
2077         tmpf_3 *= 0.821339815f;
2078         tmpf_4 *= 1.306562965f;
2079         tmpf_5 *= 3.830648788f;
2080
2081         // End 12 point IDCT
2082
2083         // Shift to 12 point modified IDCT, multiply by window type 2
2084         tmpf_8 = -tmpf_0 * 0.793353340f;
2085         tmpf_9 = -tmpf_0 * 0.608761429f;
2086         tmpf_7 = -tmpf_1 * 0.923879532f;
2087         tmpf_10 = -tmpf_1 * 0.382683432f;
2088         tmpf_6 = -tmpf_2 * 0.991444861f;
2089         tmpf_11 = -tmpf_2 * 0.130526192f;
2090
2091         tmpf_0 = tmpf_3;
2092         tmpf_1 = tmpf_4 * 0.382683432f;
2093         tmpf_2 = tmpf_5 * 0.608761429f;
2094
2095         tmpf_3 = -tmpf_5 * 0.793353340f;
2096         tmpf_4 = -tmpf_4 * 0.923879532f;
2097         tmpf_5 = -tmpf_0 * 0.991444861f;
2098
2099         tmpf_0 *= 0.130526192f;
2100
2101         rawout[six_i + 6] += tmpf_0;
2102         rawout[six_i + 7] += tmpf_1;
2103         rawout[six_i + 8] += tmpf_2;
2104         rawout[six_i + 9] += tmpf_3;
2105         rawout[six_i + 10] += tmpf_4;
2106         rawout[six_i + 11] += tmpf_5;
2107         rawout[six_i + 12] += tmpf_6;
2108         rawout[six_i + 13] += tmpf_7;
2109         rawout[six_i + 14] += tmpf_8;
2110         rawout[six_i + 15] += tmpf_9;
2111         rawout[six_i + 16] += tmpf_10;
2112         rawout[six_i + 17] += tmpf_11;
2113
2114         six_i += 6;
2115       }
2116     } else {
2117       // 36 point IDCT
2118       // input aliasing for 36 point IDCT
2119       tsOutCopy[17] += tsOutCopy[16];
2120       tsOutCopy[16] += tsOutCopy[15];
2121       tsOutCopy[15] += tsOutCopy[14];
2122       tsOutCopy[14] += tsOutCopy[13];
2123       tsOutCopy[13] += tsOutCopy[12];
2124       tsOutCopy[12] += tsOutCopy[11];
2125       tsOutCopy[11] += tsOutCopy[10];
2126       tsOutCopy[10] += tsOutCopy[9];
2127       tsOutCopy[9] += tsOutCopy[8];
2128       tsOutCopy[8] += tsOutCopy[7];
2129       tsOutCopy[7] += tsOutCopy[6];
2130       tsOutCopy[6] += tsOutCopy[5];
2131       tsOutCopy[5] += tsOutCopy[4];
2132       tsOutCopy[4] += tsOutCopy[3];
2133       tsOutCopy[3] += tsOutCopy[2];
2134       tsOutCopy[2] += tsOutCopy[1];
2135       tsOutCopy[1] += tsOutCopy[0];
2136
2137       // 18 point IDCT for odd indices
2138       // input aliasing for 18 point IDCT
2139       tsOutCopy[17] += tsOutCopy[15];
2140       tsOutCopy[15] += tsOutCopy[13];
2141       tsOutCopy[13] += tsOutCopy[11];
2142       tsOutCopy[11] += tsOutCopy[9];
2143       tsOutCopy[9] += tsOutCopy[7];
2144       tsOutCopy[7] += tsOutCopy[5];
2145       tsOutCopy[5] += tsOutCopy[3];
2146       tsOutCopy[3] += tsOutCopy[1];
2147
2148       float tmp0;
2149       float tmp1;
2150       float tmp2;
2151       float tmp3;
2152       float tmp4;
2153       float tmp0_;
2154       float tmp1_;
2155       float tmp2_;
2156       float tmp3_;
2157       float tmp0o;
2158       float tmp1o;
2159       float tmp2o;
2160       float tmp3o;
2161       float tmp4o;
2162       float tmp0_o;
2163       float tmp1_o;
2164       float tmp2_o;
2165       float tmp3_o;
2166
2167       // Fast 9 Point Inverse Discrete Cosine Transform
2168       //
2169       // By Francois-Raymond Boyer
2170       // mailto:boyerf@iro.umontreal.ca
2171       // http://www.iro.umontreal.ca/~boyerf
2172       //
2173       // The code has been optimized for Intel processors
2174       // (takes a lot of time to convert float to and from iternal FPU
2175       // representation)
2176       //
2177       // It is a simple "factorization" of the IDCT matrix.
2178
2179       // 9 point IDCT on even indices
2180
2181       // 5 points on odd indices (not realy an IDCT)
2182       float i00 = tsOutCopy[0] + tsOutCopy[0];
2183       float iip12 = i00 + tsOutCopy[12];
2184
2185       tmp0 = iip12 + tsOutCopy[4] * 1.8793852415718f + tsOutCopy[8] * 1.532088886238f + tsOutCopy[16] * 0.34729635533386f;
2186       tmp1 = i00 + tsOutCopy[4] - tsOutCopy[8] - tsOutCopy[12] - tsOutCopy[12] - tsOutCopy[16];
2187       tmp2 = iip12 - tsOutCopy[4] * 0.34729635533386f - tsOutCopy[8] * 1.8793852415718f + tsOutCopy[16] * 1.532088886238f;
2188       tmp3 = iip12 - tsOutCopy[4] * 1.532088886238f + tsOutCopy[8] * 0.34729635533386f - tsOutCopy[16] * 1.8793852415718f;
2189       tmp4 = tsOutCopy[0] - tsOutCopy[4] + tsOutCopy[8] - tsOutCopy[12] + tsOutCopy[16];
2190
2191       // 4 points on even indices
2192       float i66_ = tsOutCopy[6] * 1.732050808f; // Sqrt[3]
2193
2194       tmp0_ = tsOutCopy[2] * 1.9696155060244f + i66_ + tsOutCopy[10] * 1.2855752193731f + tsOutCopy[14] * 0.68404028665134f;
2195       tmp1_ = (tsOutCopy[2] - tsOutCopy[10] - tsOutCopy[14]) * 1.732050808f;
2196       tmp2_ = tsOutCopy[2] * 1.2855752193731f - i66_ - tsOutCopy[10] * 0.68404028665134f + tsOutCopy[14] * 1.9696155060244f;
2197       tmp3_ = tsOutCopy[2] * 0.68404028665134f - i66_ + tsOutCopy[10] * 1.9696155060244f - tsOutCopy[14] * 1.2855752193731f;
2198
2199       // 9 point IDCT on odd indices
2200       // 5 points on odd indices (not realy an IDCT)
2201       float i0 = tsOutCopy[0 + 1] + tsOutCopy[0 + 1];
2202       float i0p12 = i0 + tsOutCopy[12 + 1];
2203
2204       tmp0o = i0p12 + tsOutCopy[4 + 1] * 1.8793852415718f + tsOutCopy[8 + 1] * 1.532088886238f + tsOutCopy[16 + 1] * 0.34729635533386f;
2205       tmp1o = i0 + tsOutCopy[4 + 1] - tsOutCopy[8 + 1] - tsOutCopy[12 + 1] - tsOutCopy[12 + 1] - tsOutCopy[16 + 1];
2206       tmp2o = i0p12 - tsOutCopy[4 + 1] * 0.34729635533386f - tsOutCopy[8 + 1] * 1.8793852415718f + tsOutCopy[16 + 1] * 1.532088886238f;
2207       tmp3o = i0p12 - tsOutCopy[4 + 1] * 1.532088886238f + tsOutCopy[8 + 1] * 0.34729635533386f - tsOutCopy[16 + 1] * 1.8793852415718f;
2208       tmp4o = (tsOutCopy[0 + 1] - tsOutCopy[4 + 1] + tsOutCopy[8 + 1] - tsOutCopy[12 + 1] + tsOutCopy[16 + 1]) * 0.707106781f; // Twiddled
2209
2210       // 4 points on even indices
2211       float i6_ = tsOutCopy[6 + 1] * 1.732050808f; // Sqrt[3]
2212
2213       tmp0_o = tsOutCopy[2 + 1] * 1.9696155060244f + i6_ + tsOutCopy[10 + 1] * 1.2855752193731f + tsOutCopy[14 + 1] * 0.68404028665134f;
2214       tmp1_o = (tsOutCopy[2 + 1] - tsOutCopy[10 + 1] - tsOutCopy[14 + 1]) * 1.732050808f;
2215       tmp2_o = tsOutCopy[2 + 1] * 1.2855752193731f - i6_ - tsOutCopy[10 + 1] * 0.68404028665134f + tsOutCopy[14 + 1] * 1.9696155060244f;
2216       tmp3_o = tsOutCopy[2 + 1] * 0.68404028665134f - i6_ + tsOutCopy[10 + 1] * 1.9696155060244f - tsOutCopy[14 + 1] * 1.2855752193731f;
2217
2218       // Twiddle factors on odd indices
2219       // and
2220       // Butterflies on 9 point IDCT's
2221       // and
2222       // twiddle factors for 36 point IDCT
2223
2224       float e;
2225       float o;
2226       e = tmp0 + tmp0_;
2227       o = (tmp0o + tmp0_o) * 0.501909918f;
2228       tmpf_0 = e + o;
2229       tmpf_17 = e - o;
2230       e = tmp1 + tmp1_;
2231       o = (tmp1o + tmp1_o) * 0.517638090f;
2232       tmpf_1 = e + o;
2233       tmpf_16 = e - o;
2234       e = tmp2 + tmp2_;
2235       o = (tmp2o + tmp2_o) * 0.551688959f;
2236       tmpf_2 = e + o;
2237       tmpf_15 = e - o;
2238       e = tmp3 + tmp3_;
2239       o = (tmp3o + tmp3_o) * 0.610387294f;
2240       tmpf_3 = e + o;
2241       tmpf_14 = e - o;
2242       tmpf_4 = tmp4 + tmp4o;
2243       tmpf_13 = tmp4 - tmp4o;
2244       e = tmp3 - tmp3_;
2245       o = (tmp3o - tmp3_o) * 0.871723397f;
2246       tmpf_5 = e + o;
2247       tmpf_12 = e - o;
2248       e = tmp2 - tmp2_;
2249       o = (tmp2o - tmp2_o) * 1.183100792f;
2250       tmpf_6 = e + o;
2251       tmpf_11 = e - o;
2252       e = tmp1 - tmp1_;
2253       o = (tmp1o - tmp1_o) * 1.931851653f;
2254       tmpf_7 = e + o;
2255       tmpf_10 = e - o;
2256       e = tmp0 - tmp0_;
2257       o = (tmp0o - tmp0_o) * 5.736856623f;
2258       tmpf_8 = e + o;
2259       tmpf_9 = e - o;
2260
2261       // end 36 point IDCT */
2262       // shift to modified IDCT
2263       // win_bt = win[block_type]; //substituted this so that a new area does
2264       // not become created
2265
2266       rawout[0] = -tmpf_9 * win[block_type][0];
2267       rawout[1] = -tmpf_10 * win[block_type][1];
2268       rawout[2] = -tmpf_11 * win[block_type][2];
2269       rawout[3] = -tmpf_12 * win[block_type][3];
2270       rawout[4] = -tmpf_13 * win[block_type][4];
2271       rawout[5] = -tmpf_14 * win[block_type][5];
2272       rawout[6] = -tmpf_15 * win[block_type][6];
2273       rawout[7] = -tmpf_16 * win[block_type][7];
2274       rawout[8] = -tmpf_17 * win[block_type][8];
2275       rawout[9] = tmpf_17 * win[block_type][9];
2276       rawout[10] = tmpf_16 * win[block_type][10];
2277       rawout[11] = tmpf_15 * win[block_type][11];
2278       rawout[12] = tmpf_14 * win[block_type][12];
2279       rawout[13] = tmpf_13 * win[block_type][13];
2280       rawout[14] = tmpf_12 * win[block_type][14];
2281       rawout[15] = tmpf_11 * win[block_type][15];
2282       rawout[16] = tmpf_10 * win[block_type][16];
2283       rawout[17] = tmpf_9 * win[block_type][17];
2284       rawout[18] = tmpf_8 * win[block_type][18];
2285       rawout[19] = tmpf_7 * win[block_type][19];
2286       rawout[20] = tmpf_6 * win[block_type][20];
2287       rawout[21] = tmpf_5 * win[block_type][21];
2288       rawout[22] = tmpf_4 * win[block_type][22];
2289       rawout[23] = tmpf_3 * win[block_type][23];
2290       rawout[24] = tmpf_2 * win[block_type][24];
2291       rawout[25] = tmpf_1 * win[block_type][25];
2292       rawout[26] = tmpf_0 * win[block_type][26];
2293       rawout[27] = tmpf_0 * win[block_type][27];
2294       rawout[28] = tmpf_1 * win[block_type][28];
2295       rawout[29] = tmpf_2 * win[block_type][29];
2296       rawout[30] = tmpf_3 * win[block_type][30];
2297       rawout[31] = tmpf_4 * win[block_type][31];
2298       rawout[32] = tmpf_5 * win[block_type][32];
2299       rawout[33] = tmpf_6 * win[block_type][33];
2300       rawout[34] = tmpf_7 * win[block_type][34];
2301       rawout[35] = tmpf_8 * win[block_type][35];
2302     }
2303
2304   }
2305
2306   private int counter = 0;
2307   private static final int SSLIMIT = 18;
2308   private static final int SBLIMIT = 32;
2309
2310   // Size of the table of whole numbers raised to 4/3 power.
2311   // This may be adjusted for performance without any problems.
2312   // public static final int POW_TABLE_LIMIT=512;
2313
2314   private static final int slen[][] = { { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }, { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 } };
2315
2316   public static final int pretab[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 };
2317
2318   private SBI[] sfBandIndex; // Init in the constructor.
2319
2320   public static final float two_to_negative_half_pow[] = { 1.0000000000E+00f, 7.0710678119E-01f, 5.0000000000E-01f, 3.5355339059E-01f, 2.5000000000E-01f, 1.7677669530E-01f, 1.2500000000E-01f, 8.8388347648E-02f, 6.2500000000E-02f, 4.4194173824E-02f, 3.1250000000E-02f, 2.2097086912E-02f, 1.5625000000E-02f, 1.1048543456E-02f, 7.8125000000E-03f, 5.5242717280E-03f, 3.9062500000E-03f, 2.7621358640E-03f, 1.9531250000E-03f, 1.3810679320E-03f, 9.7656250000E-04f, 6.9053396600E-04f, 4.8828125000E-04f, 3.4526698300E-04f, 2.4414062500E-04f, 1.7263349150E-04f, 1.2207031250E-04f, 8.6316745750E-05f, 6.1035156250E-05f, 4.3158372875E-05f, 3.0517578125E-05f, 2.1579186438E-05f, 1.5258789062E-05f, 1.0789593219E-05f, 7.6293945312E-06f, 5.3947966094E-06f, 3.8146972656E-06f, 2.6973983047E-06f, 1.9073486328E-06f, 1.3486991523E-06f, 9.5367431641E-07f, 6.7434957617E-07f, 4.7683715820E-07f, 3.3717478809E-07f, 2.3841857910E-07f, 1.6858739404E-07f, 1.1920928955E-07f, 8.4293697022E-08f, 5.9604644775E-08f, 4.2146848511E-08f, 2.9802322388E-08f, 2.1073424255E-08f, 1.4901161194E-08f, 1.0536712128E-08f, 7.4505805969E-09f, 5.2683560639E-09f, 3.7252902985E-09f, 2.6341780319E-09f, 1.8626451492E-09f, 1.3170890160E-09f, 9.3132257462E-10f, 6.5854450798E-10f, 4.6566128731E-10f, 3.2927225399E-10f };
2321
2322   public static final float t_43[] = create_t_43();
2323
2324   static private float[] create_t_43() {
2325     float[] t43 = new float[8192];
2326     final double d43 = (4.0 / 3.0);
2327
2328     for (int i = 0; i < 8192; i++) {
2329       t43[i] = (float) Math.pow(i, d43);
2330     }
2331     return t43;
2332   }
2333
2334   public static final float io[][] = { { 1.0000000000E+00f, 8.4089641526E-01f, 7.0710678119E-01f, 5.9460355751E-01f, 5.0000000001E-01f, 4.2044820763E-01f, 3.5355339060E-01f, 2.9730177876E-01f, 2.5000000001E-01f, 2.1022410382E-01f, 1.7677669530E-01f, 1.4865088938E-01f, 1.2500000000E-01f, 1.0511205191E-01f, 8.8388347652E-02f, 7.4325444691E-02f, 6.2500000003E-02f, 5.2556025956E-02f, 4.4194173826E-02f, 3.7162722346E-02f, 3.1250000002E-02f, 2.6278012978E-02f, 2.2097086913E-02f, 1.8581361173E-02f, 1.5625000001E-02f, 1.3139006489E-02f, 1.1048543457E-02f, 9.2906805866E-03f, 7.8125000006E-03f, 6.5695032447E-03f, 5.5242717285E-03f, 4.6453402934E-03f }, { 1.0000000000E+00f, 7.0710678119E-01f, 5.0000000000E-01f, 3.5355339060E-01f, 2.5000000000E-01f, 1.7677669530E-01f, 1.2500000000E-01f, 8.8388347650E-02f, 6.2500000001E-02f, 4.4194173825E-02f, 3.1250000001E-02f, 2.2097086913E-02f, 1.5625000000E-02f, 1.1048543456E-02f, 7.8125000002E-03f, 5.5242717282E-03f, 3.9062500001E-03f, 2.7621358641E-03f, 1.9531250001E-03f, 1.3810679321E-03f, 9.7656250004E-04f, 6.9053396603E-04f, 4.8828125002E-04f, 3.4526698302E-04f, 2.4414062501E-04f, 1.7263349151E-04f, 1.2207031251E-04f, 8.6316745755E-05f, 6.1035156254E-05f, 4.3158372878E-05f, 3.0517578127E-05f, 2.1579186439E-05f } };
2335
2336   public static final float TAN12[] = { 0.0f, 0.26794919f, 0.57735027f, 1.0f, 1.73205081f, 3.73205081f, 9.9999999e10f, -3.73205081f, -1.73205081f, -1.0f, -0.57735027f, -0.26794919f, 0.0f, 0.26794919f, 0.57735027f, 1.0f };
2337
2338   // REVIEW: in java, the array lookup may well be slower than
2339   // the actual calculation
2340   // 576 / 18
2341   /*
2342    * private static final int ss_div[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2343    * 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
2344    * 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
2345    * 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2346    * 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
2347    * 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2348    * 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2349    * 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,
2350    * 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
2351    * 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
2352    * 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
2353    * 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
2354    * 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
2355    * 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
2356    * 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
2357    * 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
2358    * 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
2359    * 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
2360    * 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
2361    * 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
2362    * 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
2363    * 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25,
2364    * 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26,
2365    * 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27,
2366    * 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28,
2367    * 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29,
2368    * 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30,
2369    * 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31,
2370    * 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 };
2371    * 
2372    * // 576 % 18 private static final int ss_mod[] = { 0, 1, 2, 3, 4, 5, 6, 7,
2373    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2374    * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2375    * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2376    * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,
2377    * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,
2378    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2379    * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2380    * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2381    * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,
2382    * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,
2383    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2384    * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2385    * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2386    * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,
2387    * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,
2388    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2389    * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2390    * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2391    * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,
2392    * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,
2393    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2394    * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2395    * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2396    * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,
2397    * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,
2398    * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
2399    * 12, 13, 14, 15, 16, 17 };
2400    */
2401
2402   private static final int reorder_table[][]/* = loadReorderTable() */; // SZD:
2403
2404   // will
2405   // be
2406   // generated
2407   // on
2408   // demand
2409
2410   /**
2411    * Loads the data for the reorder
2412    */
2413   /*
2414    * private static int[][] loadReorderTable() // SZD: table will be generated {
2415    * try { Class elemType = int[][].class.getComponentType(); Object o =
2416    * JavaLayerUtils.deserializeArrayResource("l3reorder.ser", elemType, 6);
2417    * return (int[][])o; } catch (IOException ex) { throw new
2418    * ExceptionInInitializerError(ex); } }
2419    */
2420
2421   static int[] reorder(int[] scalefac_band) { // SZD: converted from
2422                                               // LAME
2423     int j = 0;
2424     int ix[] = new int[576];
2425     for (int sfb = 0; sfb < 13; sfb++) {
2426       int start = scalefac_band[sfb];
2427       int end = scalefac_band[sfb + 1];
2428       for (int window = 0; window < 3; window++)
2429         for (int i = start; i < end; i++)
2430           ix[3 * i + window] = j++;
2431     }
2432     return ix;
2433   }
2434
2435   /*
2436    * static final int reorder_table_data[][]; = { { 0, 4, 8, 1, 5, 9, 2, 6, 10,
2437    * 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19, 23, 24, 28, 32, 25,
2438    * 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49, 38, 44, 50, 39, 45,
2439    * 51, 40, 46, 52, 41, 47, 53, 54, 60, 66, 55, 61, 67, 56, 62, 68, 57, 63, 69,
2440    * 58, 64, 70, 59, 65, 71, 72, 80, 88, 73, 81, 89, 74, 82, 90, 75, 83, 91, 76,
2441    * 84, 92, 77, 85, 93, 78, 86, 94, 79, 87, 95, 96,106,116, 97,107,117,
2442    * 98,108,118, 99,109,119,100,110,120,101,
2443    * 111,121,102,112,122,103,113,123,104,114,124,105,115,125,126,140,
2444    * 154,127,141,155,128,142,156,129,143,157,130,144,158,131,145,159,
2445    * 132,146,160,133,147,161,134,148,162,135,149,163,136,150,164,137,
2446    * 151,165,138,152,166,139,153,167,168,186,204,169,187,205,170,188,
2447    * 206,171,189,207,172,190,208,173,191,209,174,192,210,175,193,211,
2448    * 176,194,212,177,195,213,178,196,214,179,197,215,180,198,216,181,
2449    * 199,217,182,200,218,183,201,219,184,202,220,185,203,221,222,248,
2450    * 274,223,249,275,224,250,276,225,251,277,226,252,278,227,253,279,
2451    * 228,254,280,229,255,281,230,256,282,231,257,283,232,258,284,233,
2452    * 259,285,234,260,286,235,261,287,236,262,288,237,263,289,238,264,
2453    * 290,239,265,291,240,266,292,241,267,293,242,268,294,243,269,295,
2454    * 244,270,296,245,271,297,246,272,298,247,273,299,300,332,364,301,
2455    * 333,365,302,334,366,303,335,367,304,336,368,305,337,369,306,338,
2456    * 370,307,339,371,308,340,372,309,341,373,310,342,374,311,343,375,
2457    * 312,344,376,313,345,377,314,346,378,315,347,379,316,348,380,317,
2458    * 349,381,318,350,382,319,351,383,320,352,384,321,353,385,322,354,
2459    * 386,323,355,387,324,356,388,325,357,389,326,358,390,327,359,391,
2460    * 328,360,392,329,361,393,330,362,394,331,363,395,396,438,480,397,
2461    * 439,481,398,440,482,399,441,483,400,442,484,401,443,485,402,444,
2462    * 486,403,445,487,404,446,488,405,447,489,406,448,490,407,449,491,
2463    * 408,450,492,409,451,493,410,452,494,411,453,495,412,454,496,413,
2464    * 455,497,414,456,498,415,457,499,416,458,500,417,459,501,418,460,
2465    * 502,419,461,503,420,462,504,421,463,505,422,464,506,423,465,507,
2466    * 424,466,508,425,467,509,426,468,510,427,469,511,428,470,512,429,
2467    * 471,513,430,472,514,431,473,515,432,474,516,433,475,517,434,476,
2468    * 518,435,477,519,436,478,520,437,479,521,522,540,558,523,541,559,
2469    * 524,542,560,525,543,561,526,544,562,527,545,563,528,546,564,529,
2470    * 547,565,530,548,566,531,549,567,532,550,568,533,551,569,534,552,
2471    * 570,535,553,571,536,554,572,537,555,573,538,556,574,539,557,575}, { 0, 4,
2472    * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,
2473    * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49,
2474    * 38, 44, 50, 39, 45, 51, 40, 46, 52, 41, 47, 53, 54, 62, 70, 55, 63, 71, 56,
2475    * 64, 72, 57, 65, 73, 58, 66, 74, 59, 67, 75, 60, 68, 76, 61, 69, 77, 78, 88,
2476    * 98, 79, 89, 99, 80, 90,100, 81, 91,101, 82, 92,102, 83, 93,103, 84, 94,104,
2477    * 85, 95,105, 86, 96,106, 87, 97,107,108,120,132,109,
2478    * 121,133,110,122,134,111,123,135,112,124,136,113,125,137,114,126,
2479    * 138,115,127,139,116,128,140,117,129,141,118,130,142,119,131,143,
2480    * 144,158,172,145,159,173,146,160,174,147,161,175,148,162,176,149,
2481    * 163,177,150,164,178,151,165,179,152,166,180,153,167,181,154,168,
2482    * 182,155,169,183,156,170,184,157,171,185,186,204,222,187,205,223,
2483    * 188,206,224,189,207,225,190,208,226,191,209,227,192,210,228,193,
2484    * 211,229,194,212,230,195,213,231,196,214,232,197,215,233,198,216,
2485    * 234,199,217,235,200,218,236,201,219,237,202,220,238,203,221,239,
2486    * 240,264,288,241,265,289,242,266,290,243,267,291,244,268,292,245,
2487    * 269,293,246,270,294,247,271,295,248,272,296,249,273,297,250,274,
2488    * 298,251,275,299,252,276,300,253,277,301,254,278,302,255,279,303,
2489    * 256,280,304,257,281,305,258,282,306,259,283,307,260,284,308,261,
2490    * 285,309,262,286,310,263,287,311,312,344,376,313,345,377,314,346,
2491    * 378,315,347,379,316,348,380,317,349,381,318,350,382,319,351,383,
2492    * 320,352,384,321,353,385,322,354,386,323,355,387,324,356,388,325,
2493    * 357,389,326,358,390,327,359,391,328,360,392,329,361,393,330,362,
2494    * 394,331,363,395,332,364,396,333,365,397,334,366,398,335,367,399,
2495    * 336,368,400,337,369,401,338,370,402,339,371,403,340,372,404,341,
2496    * 373,405,342,374,406,343,375,407,408,452,496,409,453,497,410,454,
2497    * 498,411,455,499,412,456,500,413,457,501,414,458,502,415,459,503,
2498    * 416,460,504,417,461,505,418,462,506,419,463,507,420,464,508,421,
2499    * 465,509,422,466,510,423,467,511,424,468,512,425,469,513,426,470,
2500    * 514,427,471,515,428,472,516,429,473,517,430,474,518,431,475,519,
2501    * 432,476,520,433,477,521,434,478,522,435,479,523,436,480,524,437,
2502    * 481,525,438,482,526,439,483,527,440,484,528,441,485,529,442,486,
2503    * 530,443,487,531,444,488,532,445,489,533,446,490,534,447,491,535,
2504    * 448,492,536,449,493,537,450,494,538,451,495,539,540,552,564,541,
2505    * 553,565,542,554,566,543,555,567,544,556,568,545,557,569,546,558,
2506    * 570,547,559,571,548,560,572,549,561,573,550,562,574,551,563,575}, { 0, 4,
2507    * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,
2508    * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49,
2509    * 38, 44, 50, 39, 45, 51, 40, 46, 52, 41, 47, 53, 54, 62, 70, 55, 63, 71, 56,
2510    * 64, 72, 57, 65, 73, 58, 66, 74, 59, 67, 75, 60, 68, 76, 61, 69, 77, 78, 88,
2511    * 98, 79, 89, 99, 80, 90,100, 81, 91,101, 82, 92,102, 83, 93,103, 84, 94,104,
2512    * 85, 95,105, 86, 96,106, 87, 97,107,108,120,132,109,
2513    * 121,133,110,122,134,111,123,135,112,124,136,113,125,137,114,126,
2514    * 138,115,127,139,116,128,140,117,129,141,118,130,142,119,131,143,
2515    * 144,158,172,145,159,173,146,160,174,147,161,175,148,162,176,149,
2516    * 163,177,150,164,178,151,165,179,152,166,180,153,167,181,154,168,
2517    * 182,155,169,183,156,170,184,157,171,185,186,204,222,187,205,223,
2518    * 188,206,224,189,207,225,190,208,226,191,209,227,192,210,228,193,
2519    * 211,229,194,212,230,195,213,231,196,214,232,197,215,233,198,216,
2520    * 234,199,217,235,200,218,236,201,219,237,202,220,238,203,221,239,
2521    * 240,264,288,241,265,289,242,266,290,243,267,291,244,268,292,245,
2522    * 269,293,246,270,294,247,271,295,248,272,296,249,273,297,250,274,
2523    * 298,251,275,299,252,276,300,253,277,301,254,278,302,255,279,303,
2524    * 256,280,304,257,281,305,258,282,306,259,283,307,260,284,308,261,
2525    * 285,309,262,286,310,263,287,311,312,342,372,313,343,373,314,344,
2526    * 374,315,345,375,316,346,376,317,347,377,318,348,378,319,349,379,
2527    * 320,350,380,321,351,381,322,352,382,323,353,383,324,354,384,325,
2528    * 355,385,326,356,386,327,357,387,328,358,388,329,359,389,330,360,
2529    * 390,331,361,391,332,362,392,333,363,393,334,364,394,335,365,395,
2530    * 336,366,396,337,367,397,338,368,398,339,369,399,340,370,400,341,
2531    * 371,401,402,442,482,403,443,483,404,444,484,405,445,485,406,446,
2532    * 486,407,447,487,408,448,488,409,449,489,410,450,490,411,451,491,
2533    * 412,452,492,413,453,493,414,454,494,415,455,495,416,456,496,417,
2534    * 457,497,418,458,498,419,459,499,420,460,500,421,461,501,422,462,
2535    * 502,423,463,503,424,464,504,425,465,505,426,466,506,427,467,507,
2536    * 428,468,508,429,469,509,430,470,510,431,471,511,432,472,512,433,
2537    * 473,513,434,474,514,435,475,515,436,476,516,437,477,517,438,478,
2538    * 518,439,479,519,440,480,520,441,481,521,522,540,558,523,541,559,
2539    * 524,542,560,525,543,561,526,544,562,527,545,563,528,546,564,529,
2540    * 547,565,530,548,566,531,549,567,532,550,568,533,551,569,534,552,
2541    * 570,535,553,571,536,554,572,537,555,573,538,556,574,539,557,575}, { 0, 4,
2542    * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,
2543    * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,
2544    * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,
2545    * 58, 64, 53, 59, 65, 66, 74, 82, 67, 75, 83, 68, 76, 84, 69, 77, 85, 70, 78,
2546    * 86, 71, 79, 87, 72, 80, 88, 73, 81, 89, 90,100,110, 91,101,111, 92,102,112,
2547    * 93,103,113, 94,104,114, 95,105,115, 96,106,116, 97, 107,117, 98,108,118,
2548    * 99,109,119,120,132,144,121,133,145,122,134,
2549    * 146,123,135,147,124,136,148,125,137,149,126,138,150,127,139,151,
2550    * 128,140,152,129,141,153,130,142,154,131,143,155,156,170,184,157,
2551    * 171,185,158,172,186,159,173,187,160,174,188,161,175,189,162,176,
2552    * 190,163,177,191,164,178,192,165,179,193,166,180,194,167,181,195,
2553    * 168,182,196,169,183,197,198,216,234,199,217,235,200,218,236,201,
2554    * 219,237,202,220,238,203,221,239,204,222,240,205,223,241,206,224,
2555    * 242,207,225,243,208,226,244,209,227,245,210,228,246,211,229,247,
2556    * 212,230,248,213,231,249,214,232,250,215,233,251,252,274,296,253,
2557    * 275,297,254,276,298,255,277,299,256,278,300,257,279,301,258,280,
2558    * 302,259,281,303,260,282,304,261,283,305,262,284,306,263,285,307,
2559    * 264,286,308,265,287,309,266,288,310,267,289,311,268,290,312,269,
2560    * 291,313,270,292,314,271,293,315,272,294,316,273,295,317,318,348,
2561    * 378,319,349,379,320,350,380,321,351,381,322,352,382,323,353,383,
2562    * 324,354,384,325,355,385,326,356,386,327,357,387,328,358,388,329,
2563    * 359,389,330,360,390,331,361,391,332,362,392,333,363,393,334,364,
2564    * 394,335,365,395,336,366,396,337,367,397,338,368,398,339,369,399,
2565    * 340,370,400,341,371,401,342,372,402,343,373,403,344,374,404,345,
2566    * 375,405,346,376,406,347,377,407,408,464,520,409,465,521,410,466,
2567    * 522,411,467,523,412,468,524,413,469,525,414,470,526,415,471,527,
2568    * 416,472,528,417,473,529,418,474,530,419,475,531,420,476,532,421,
2569    * 477,533,422,478,534,423,479,535,424,480,536,425,481,537,426,482,
2570    * 538,427,483,539,428,484,540,429,485,541,430,486,542,431,487,543,
2571    * 432,488,544,433,489,545,434,490,546,435,491,547,436,492,548,437,
2572    * 493,549,438,494,550,439,495,551,440,496,552,441,497,553,442,498,
2573    * 554,443,499,555,444,500,556,445,501,557,446,502,558,447,503,559,
2574    * 448,504,560,449,505,561,450,506,562,451,507,563,452,508,564,453,
2575    * 509,565,454,510,566,455,511,567,456,512,568,457,513,569,458,514,
2576    * 570,459,515,571,460,516,572,461,517,573,462,518,574,463,519,575}, { 0, 4,
2577    * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,
2578    * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,
2579    * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,
2580    * 58, 64, 53, 59, 65, 66, 72, 78, 67, 73, 79, 68, 74, 80, 69, 75, 81, 70, 76,
2581    * 82, 71, 77, 83, 84, 94,104, 85, 95,105, 86, 96,106, 87, 97,107, 88, 98,108,
2582    * 89, 99,109, 90,100,110, 91,101,111, 92,102,112, 93,
2583    * 103,113,114,126,138,115,127,139,116,128,140,117,129,141,118,130,
2584    * 142,119,131,143,120,132,144,121,133,145,122,134,146,123,135,147,
2585    * 124,136,148,125,137,149,150,164,178,151,165,179,152,166,180,153,
2586    * 167,181,154,168,182,155,169,183,156,170,184,157,171,185,158,172,
2587    * 186,159,173,187,160,174,188,161,175,189,162,176,190,163,177,191,
2588    * 192,208,224,193,209,225,194,210,226,195,211,227,196,212,228,197,
2589    * 213,229,198,214,230,199,215,231,200,216,232,201,217,233,202,218,
2590    * 234,203,219,235,204,220,236,205,221,237,206,222,238,207,223,239,
2591    * 240,260,280,241,261,281,242,262,282,243,263,283,244,264,284,245,
2592    * 265,285,246,266,286,247,267,287,248,268,288,249,269,289,250,270,
2593    * 290,251,271,291,252,272,292,253,273,293,254,274,294,255,275,295,
2594    * 256,276,296,257,277,297,258,278,298,259,279,299,300,326,352,301,
2595    * 327,353,302,328,354,303,329,355,304,330,356,305,331,357,306,332,
2596    * 358,307,333,359,308,334,360,309,335,361,310,336,362,311,337,363,
2597    * 312,338,364,313,339,365,314,340,366,315,341,367,316,342,368,317,
2598    * 343,369,318,344,370,319,345,371,320,346,372,321,347,373,322,348,
2599    * 374,323,349,375,324,350,376,325,351,377,378,444,510,379,445,511,
2600    * 380,446,512,381,447,513,382,448,514,383,449,515,384,450,516,385,
2601    * 451,517,386,452,518,387,453,519,388,454,520,389,455,521,390,456,
2602    * 522,391,457,523,392,458,524,393,459,525,394,460,526,395,461,527,
2603    * 396,462,528,397,463,529,398,464,530,399,465,531,400,466,532,401,
2604    * 467,533,402,468,534,403,469,535,404,470,536,405,471,537,406,472,
2605    * 538,407,473,539,408,474,540,409,475,541,410,476,542,411,477,543,
2606    * 412,478,544,413,479,545,414,480,546,415,481,547,416,482,548,417,
2607    * 483,549,418,484,550,419,485,551,420,486,552,421,487,553,422,488,
2608    * 554,423,489,555,424,490,556,425,491,557,426,492,558,427,493,559,
2609    * 428,494,560,429,495,561,430,496,562,431,497,563,432,498,564,433,
2610    * 499,565,434,500,566,435,501,567,436,502,568,437,503,569,438,504,
2611    * 570,439,505,571,440,506,572,441,507,573,442,508,574,443,509,575}, { 0, 4,
2612    * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,
2613    * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,
2614    * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,
2615    * 58, 64, 53, 59, 65, 66, 74, 82, 67, 75, 83, 68, 76, 84, 69, 77, 85, 70, 78,
2616    * 86, 71, 79, 87, 72, 80, 88, 73, 81, 89, 90,102,114, 91,103,115, 92,104,116,
2617    * 93,105,117, 94,106,118, 95,107,119, 96,108,120, 97, 109,121, 98,110,122,
2618    * 99,111,123,100,112,124,101,113,125,126,142,
2619    * 158,127,143,159,128,144,160,129,145,161,130,146,162,131,147,163,
2620    * 132,148,164,133,149,165,134,150,166,135,151,167,136,152,168,137,
2621    * 153,169,138,154,170,139,155,171,140,156,172,141,157,173,174,194,
2622    * 214,175,195,215,176,196,216,177,197,217,178,198,218,179,199,219,
2623    * 180,200,220,181,201,221,182,202,222,183,203,223,184,204,224,185,
2624    * 205,225,186,206,226,187,207,227,188,208,228,189,209,229,190,210,
2625    * 230,191,211,231,192,212,232,193,213,233,234,260,286,235,261,287,
2626    * 236,262,288,237,263,289,238,264,290,239,265,291,240,266,292,241,
2627    * 267,293,242,268,294,243,269,295,244,270,296,245,271,297,246,272,
2628    * 298,247,273,299,248,274,300,249,275,301,250,276,302,251,277,303,
2629    * 252,278,304,253,279,305,254,280,306,255,281,307,256,282,308,257,
2630    * 283,309,258,284,310,259,285,311,312,346,380,313,347,381,314,348,
2631    * 382,315,349,383,316,350,384,317,351,385,318,352,386,319,353,387,
2632    * 320,354,388,321,355,389,322,356,390,323,357,391,324,358,392,325,
2633    * 359,393,326,360,394,327,361,395,328,362,396,329,363,397,330,364,
2634    * 398,331,365,399,332,366,400,333,367,401,334,368,402,335,369,403,
2635    * 336,370,404,337,371,405,338,372,406,339,373,407,340,374,408,341,
2636    * 375,409,342,376,410,343,377,411,344,378,412,345,379,413,414,456,
2637    * 498,415,457,499,416,458,500,417,459,501,418,460,502,419,461,503,
2638    * 420,462,504,421,463,505,422,464,506,423,465,507,424,466,508,425,
2639    * 467,509,426,468,510,427,469,511,428,470,512,429,471,513,430,472,
2640    * 514,431,473,515,432,474,516,433,475,517,434,476,518,435,477,519,
2641    * 436,478,520,437,479,521,438,480,522,439,481,523,440,482,524,441,
2642    * 483,525,442,484,526,443,485,527,444,486,528,445,487,529,446,488,
2643    * 530,447,489,531,448,490,532,449,491,533,450,492,534,451,493,535,
2644    * 452,494,536,453,495,537,454,496,538,455,497,539,540,552,564,541,
2645    * 553,565,542,554,566,543,555,567,544,556,568,545,557,569,546,558,
2646    * 570,547,559,571,548,560,572,549,561,573,550,562,574,551,563,575} };
2647    */
2648
2649   private static final float cs[] = { 0.857492925712f, 0.881741997318f, 0.949628649103f, 0.983314592492f, 0.995517816065f, 0.999160558175f, 0.999899195243f, 0.999993155067f };
2650
2651   private static final float ca[] = { -0.5144957554270f, -0.4717319685650f, -0.3133774542040f, -0.1819131996110f, -0.0945741925262f, -0.0409655828852f, -0.0141985685725f, -0.00369997467375f };
2652
2653   /************************************************************/
2654   /* END OF L3TABLE */
2655   /************************************************************/
2656
2657   /************************************************************/
2658   /* L3TYPE */
2659   /************************************************************/
2660
2661   /***************************************************************/
2662   /* END OF L3TYPE */
2663   /***************************************************************/
2664
2665   /***************************************************************/
2666   /* INV_MDCT */
2667   /***************************************************************/
2668   public static final float win[][] = { { -1.6141214951E-02f, -5.3603178919E-02f, -1.0070713296E-01f, -1.6280817573E-01f, -4.9999999679E-01f, -3.8388735032E-01f, -6.2061144372E-01f, -1.1659756083E+00f, -3.8720752656E+00f, -4.2256286556E+00f, -1.5195289984E+00f, -9.7416483388E-01f, -7.3744074053E-01f, -1.2071067773E+00f, -5.1636156596E-01f, -4.5426052317E-01f, -4.0715656898E-01f, -3.6969460527E-01f, -3.3876269197E-01f, -3.1242222492E-01f, -2.8939587111E-01f, -2.6880081906E-01f, -5.0000000266E-01f, -2.3251417468E-01f, -2.1596714708E-01f, -2.0004979098E-01f, -1.8449493497E-01f, -1.6905846094E-01f, -1.5350360518E-01f, -1.3758624925E-01f, -1.2103922149E-01f, -2.0710679058E-01f, -8.4752577594E-02f, -6.4157525656E-02f, -4.1131172614E-02f, -1.4790705759E-02f },
2669
2670   { -1.6141214951E-02f, -5.3603178919E-02f, -1.0070713296E-01f, -1.6280817573E-01f, -4.9999999679E-01f, -3.8388735032E-01f, -6.2061144372E-01f, -1.1659756083E+00f, -3.8720752656E+00f, -4.2256286556E+00f, -1.5195289984E+00f, -9.7416483388E-01f, -7.3744074053E-01f, -1.2071067773E+00f, -5.1636156596E-01f, -4.5426052317E-01f, -4.0715656898E-01f, -3.6969460527E-01f, -3.3908542600E-01f, -3.1511810350E-01f, -2.9642226150E-01f, -2.8184548650E-01f, -5.4119610000E-01f, -2.6213228100E-01f, -2.5387916537E-01f, -2.3296291359E-01f, -1.9852728987E-01f, -1.5233534808E-01f, -9.6496400054E-02f, -3.3423828516E-02f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f },
2671
2672   { -4.8300800645E-02f, -1.5715656932E-01f, -2.8325045177E-01f, -4.2953747763E-01f, -1.2071067795E+00f, -8.2426483178E-01f, -1.1451749106E+00f, -1.7695290101E+00f, -4.5470225061E+00f, -3.4890531002E+00f, -7.3296292804E-01f, -1.5076514758E-01f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f },
2673
2674   { 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, -1.5076513660E-01f, -7.3296291107E-01f, -3.4890530566E+00f, -4.5470224727E+00f, -1.7695290031E+00f, -1.1451749092E+00f, -8.3137738100E-01f, -1.3065629650E+00f, -5.4142014250E-01f, -4.6528974900E-01f, -4.1066990750E-01f, -3.7004680800E-01f, -3.3876269197E-01f, -3.1242222492E-01f, -2.8939587111E-01f, -2.6880081906E-01f, -5.0000000266E-01f, -2.3251417468E-01f, -2.1596714708E-01f, -2.0004979098E-01f, -1.8449493497E-01f, -1.6905846094E-01f, -1.5350360518E-01f, -1.3758624925E-01f, -1.2103922149E-01f, -2.0710679058E-01f, -8.4752577594E-02f, -6.4157525656E-02f, -4.1131172614E-02f, -1.4790705759E-02f } };
2675
2676   /***************************************************************/
2677   /* END OF INV_MDCT */
2678   /***************************************************************/
2679
2680   public static final int nr_of_sfb_block[][][] = { { { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } }, { { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } }, { { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } }, { { 7, 7, 7, 0 }, { 12, 12, 12, 0 }, { 6, 15, 12, 0 } }, { { 6, 6, 6, 3 }, { 12, 9, 9, 6 }, { 6, 12, 9, 6 } }, { { 8, 8, 5, 0 }, { 15, 12, 9, 0 }, { 6, 18, 9, 0 } } };
2681
2682 }
2683
2684 /************************************************************/
2685 /* L3TABLE */
2686 /************************************************************/
2687
2688 class SBI {
2689
2690   public int[] l;
2691
2692   public int[] s;
2693
2694   public SBI() {
2695     l = new int[23];
2696     s = new int[14];
2697   }
2698
2699   public SBI(@DELEGATE int[] thel, @DELEGATE int[] thes) {
2700     l = thel;
2701     s = thes;
2702   }
2703 }
2704
2705 class gr_info_s {
2706
2707   public int part2_3_length = 0;
2708
2709   public int big_values = 0;
2710
2711   public int global_gain = 0;
2712
2713   public int scalefac_compress = 0;
2714
2715   public int window_switching_flag = 0;
2716
2717   public int block_type = 0;
2718
2719   public int mixed_block_flag = 0;
2720
2721   public int[] table_select;
2722
2723   public int[] subblock_gain;
2724
2725   public int region0_count = 0;
2726
2727   public int region1_count = 0;
2728
2729   public int preflag = 0;
2730
2731   public int scalefac_scale = 0;
2732
2733   public int count1table_select = 0;
2734
2735   /**
2736    * Dummy Constructor
2737    */
2738   public gr_info_s() {
2739     table_select = new int[3];
2740     subblock_gain = new int[3];
2741   }
2742 }
2743
2744 class temporaire {
2745
2746   public int[] scfsi;
2747
2748   public gr_info_s[] gr;
2749
2750   /**
2751    * Dummy Constructor
2752    */
2753   public temporaire() {
2754     scfsi = new int[4];
2755     gr = new gr_info_s[2];
2756     gr[0] = new gr_info_s();
2757     gr[1] = new gr_info_s();
2758   }
2759 }
2760
2761 class III_side_info_t {
2762
2763   public int main_data_begin = 0;
2764
2765   public int private_bits = 0;
2766
2767   public temporaire[] ch;
2768
2769   /**
2770    * Dummy Constructor
2771    */
2772   public III_side_info_t() {
2773     ch = new temporaire[2];
2774     ch[0] = new temporaire();
2775     ch[1] = new temporaire();
2776   }
2777 }
2778
2779 class temporaire2 {
2780
2781   public int[] l; /* [cb] */
2782
2783   public int[][] s; /* [window][cb] */
2784
2785   /**
2786    * Dummy Constructor
2787    */
2788   public temporaire2() {
2789     l = new int[23];
2790     s = new int[3][13];
2791   }
2792 }
2793
2794 // class III_scalefac_t
2795 // {
2796 // public temporaire2[] tab;
2797 // /**
2798 // * Dummy Constructor
2799 // */
2800 // public III_scalefac_t()
2801 // {
2802 // tab = new temporaire2[2];
2803 // }
2804 // }