home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets / Secrets2.iso / Audio / WAV / MaplayP / _SETUP.1 / sublay2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-04  |  44.8 KB  |  922 lines

  1. /* sublay2.cpp
  2.  
  3.    Layer II subband object implementation, now with MPEG-2 LSF support */
  4.  
  5. /*
  6.  *  @(#) subband_layer_2.cc 1.8, last edit: 6/15/94 16:51:50
  7.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  8.  *  @(#) Berlin University of Technology
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. /*
  26.  *  Changes from version 1.1 to 1.2:
  27.  *    - calculation of the 3 samples contained in one groupcode is now done
  28.  *      through lookup tables, no more integer modulo or division required.
  29.  *      table_*_quantizationsteps[] arrays replaced by
  30.  *      table_*_groupingtables[] arrays
  31.  
  32.  *    - scalefactors itself instead of scalefactor indices are stored in
  33.  *      SubbandLayer2... objects
  34.  *    - check for small values in [-1.0E-7, 1.0E-7] removed, because the
  35.  *      test itself was slower than some SynthesisFilter::input_sample() calls
  36.  *    - check for illegal scalefactor index 63 removed
  37.  */
  38.  
  39. #include "sublay2.h"
  40. #include "scalfact.h"
  41.  
  42. static const real grouping_5bits[27 * 3] =
  43. // this table contains 3 requantized samples for each legal codeword
  44. // when grouped in 5 bits, i.e. 3 quantizationsteps per sample
  45. {
  46.   -2.0/3.0, -2.0/3.0, -2.0/3.0,
  47.          0.0, -2.0/3.0, -2.0/3.0,
  48.     2.0/3.0, -2.0/3.0, -2.0/3.0,
  49.   -2.0/3.0,      0.0, -2.0/3.0,
  50.          0.0,      0.0, -2.0/3.0,
  51.     2.0/3.0,      0.0, -2.0/3.0,
  52.   -2.0/3.0,  2.0/3.0, -2.0/3.0,
  53.          0.0,  2.0/3.0, -2.0/3.0,
  54.     2.0/3.0,  2.0/3.0, -2.0/3.0,
  55.   -2.0/3.0, -2.0/3.0,      0.0,
  56.          0.0, -2.0/3.0,      0.0,
  57.     2.0/3.0, -2.0/3.0,      0.0,
  58.   -2.0/3.0,      0.0,      0.0,
  59.          0.0,      0.0,      0.0,
  60.     2.0/3.0,      0.0,      0.0,
  61.   -2.0/3.0,  2.0/3.0,      0.0,
  62.          0.0,  2.0/3.0,      0.0,
  63.     2.0/3.0,  2.0/3.0,      0.0,
  64.   -2.0/3.0, -2.0/3.0,  2.0/3.0,
  65.        0.0, -2.0/3.0,  2.0/3.0,
  66.     2.0/3.0, -2.0/3.0,  2.0/3.0,
  67.   -2.0/3.0,      0.0,  2.0/3.0,
  68.        0.0,      0.0,  2.0/3.0,
  69.    2.0/3.0,      0.0,  2.0/3.0,
  70.   -2.0/3.0,  2.0/3.0,  2.0/3.0,
  71.          0.0,  2.0/3.0,  2.0/3.0,
  72.    2.0/3.0,  2.0/3.0,  2.0/3.0
  73. };
  74.  
  75. static const real grouping_7bits[125 * 3] =
  76. // this table contains 3 requantized samples for each legal codeword
  77. // when grouped in 7 bits, i.e. 5 quantizationsteps per sample
  78. {
  79.   -0.8, -0.8, -0.8,   -0.4, -0.8, -0.8,    0.0, -0.8, -0.8,    0.4, -0.8, -0.8,    0.8, -0.8, -0.8,
  80.   -0.8, -0.4, -0.8,   -0.4, -0.4, -0.8,    0.0, -0.4, -0.8,    0.4, -0.4, -0.8,    0.8, -0.4, -0.8,
  81.   -0.8,  0.0, -0.8,   -0.4,  0.0, -0.8,    0.0,  0.0, -0.8,    0.4,  0.0, -0.8,    0.8,  0.0, -0.8,
  82.   -0.8,  0.4, -0.8,   -0.4,  0.4, -0.8,    0.0,  0.4, -0.8,    0.4,  0.4, -0.8,    0.8,  0.4, -0.8,
  83.   -0.8,  0.8, -0.8,   -0.4,  0.8, -0.8,    0.0,  0.8, -0.8,    0.4,  0.8, -0.8,    0.8,  0.8, -0.8,
  84.   -0.8, -0.8, -0.4,   -0.4, -0.8, -0.4,    0.0, -0.8, -0.4,    0.4, -0.8, -0.4,    0.8, -0.8, -0.4,
  85.   -0.8, -0.4, -0.4,   -0.4, -0.4, -0.4,    0.0, -0.4, -0.4,    0.4, -0.4, -0.4,    0.8, -0.4, -0.4,
  86.   -0.8,  0.0, -0.4,   -0.4,  0.0, -0.4,    0.0,  0.0, -0.4,    0.4,  0.0, -0.4,    0.8,  0.0, -0.4,
  87.   -0.8,  0.4, -0.4,   -0.4,  0.4, -0.4,    0.0,  0.4, -0.4,    0.4,  0.4, -0.4,    0.8,  0.4, -0.4,
  88.   -0.8,  0.8, -0.4,   -0.4,  0.8, -0.4,    0.0,  0.8, -0.4,    0.4,  0.8, -0.4,    0.8,  0.8, -0.4,
  89.   -0.8, -0.8,  0.0,   -0.4, -0.8,  0.0,    0.0, -0.8,  0.0,    0.4, -0.8,  0.0,    0.8, -0.8,  0.0,
  90.   -0.8, -0.4,  0.0,   -0.4, -0.4,  0.0,    0.0, -0.4,  0.0,    0.4, -0.4,  0.0,    0.8, -0.4,  0.0,
  91.   -0.8,  0.0,  0.0,   -0.4,  0.0,  0.0,    0.0,  0.0,  0.0,    0.4,  0.0,  0.0,    0.8,  0.0,  0.0,
  92.   -0.8,  0.4,  0.0,   -0.4,  0.4,  0.0,    0.0,  0.4,  0.0,    0.4,  0.4,  0.0,    0.8,  0.4,  0.0,
  93.   -0.8,  0.8,  0.0,   -0.4,  0.8,  0.0,    0.0,  0.8,  0.0,    0.4,  0.8,  0.0,    0.8,  0.8,  0.0,
  94.   -0.8, -0.8,  0.4,   -0.4, -0.8,  0.4,    0.0, -0.8,  0.4,    0.4, -0.8,  0.4,    0.8, -0.8,  0.4,
  95.   -0.8, -0.4,  0.4,   -0.4, -0.4,  0.4,    0.0, -0.4,  0.4,    0.4, -0.4,  0.4,    0.8, -0.4,  0.4,
  96.   -0.8,  0.0,  0.4,   -0.4,  0.0,  0.4,    0.0,  0.0,  0.4,    0.4,  0.0,  0.4,    0.8,  0.0,  0.4,
  97.   -0.8,  0.4,  0.4,   -0.4,  0.4,  0.4,    0.0,  0.4,  0.4,    0.4,  0.4,  0.4,    0.8,  0.4,  0.4,
  98.   -0.8,  0.8,  0.4,   -0.4,  0.8,  0.4,    0.0,  0.8,  0.4,    0.4,  0.8,  0.4,    0.8,  0.8,  0.4,
  99.   -0.8, -0.8,  0.8,   -0.4, -0.8,  0.8,    0.0, -0.8,  0.8,    0.4, -0.8,  0.8,    0.8, -0.8,  0.8,
  100.   -0.8, -0.4,  0.8,   -0.4, -0.4,  0.8,    0.0, -0.4,  0.8,    0.4, -0.4,  0.8,    0.8, -0.4,  0.8,
  101.   -0.8,  0.0,  0.8,   -0.4,  0.0,  0.8,    0.0,  0.0,  0.8,    0.4,  0.0,  0.8,    0.8,  0.0,  0.8,
  102.   -0.8,  0.4,  0.8,   -0.4,  0.4,  0.8,    0.0,  0.4,  0.8,    0.4,  0.4,  0.8,    0.8,  0.4,  0.8,
  103.   -0.8,  0.8,  0.8,   -0.4,  0.8,  0.8,    0.0,  0.8,  0.8,    0.4,  0.8,  0.8,    0.8,  0.8,  0.8
  104. };
  105.  
  106. static const real grouping_10bits[729 * 3] =
  107. // this table contains 3 requantized samples for each legal codeword
  108. // when grouped in 10 bits, i.e. 9 quantizationsteps per sample
  109. {
  110.   -8.0/9.0, -8.0/9.0, -8.0/9.0,   -6.0/9.0, -8.0/9.0, -8.0/9.0,   -4.0/9.0, -8.0/9.0, -8.0/9.0,
  111.   -2.0/9.0, -8.0/9.0, -8.0/9.0,        0.0, -8.0/9.0, -8.0/9.0,    2.0/9.0, -8.0/9.0, -8.0/9.0,
  112.     4.0/9.0, -8.0/9.0, -8.0/9.0,    6.0/9.0, -8.0/9.0, -8.0/9.0,    8.0/9.0, -8.0/9.0, -8.0/9.0,
  113.   -8.0/9.0, -6.0/9.0, -8.0/9.0,   -6.0/9.0, -6.0/9.0, -8.0/9.0,   -4.0/9.0, -6.0/9.0, -8.0/9.0,
  114.   -2.0/9.0, -6.0/9.0, -8.0/9.0,        0.0, -6.0/9.0, -8.0/9.0,    2.0/9.0, -6.0/9.0, -8.0/9.0,
  115.     4.0/9.0, -6.0/9.0, -8.0/9.0,    6.0/9.0, -6.0/9.0, -8.0/9.0,    8.0/9.0, -6.0/9.0, -8.0/9.0,
  116.   -8.0/9.0, -4.0/9.0, -8.0/9.0,   -6.0/9.0, -4.0/9.0, -8.0/9.0,   -4.0/9.0, -4.0/9.0, -8.0/9.0,
  117.   -2.0/9.0, -4.0/9.0, -8.0/9.0,        0.0, -4.0/9.0, -8.0/9.0,    2.0/9.0, -4.0/9.0, -8.0/9.0,
  118.     4.0/9.0, -4.0/9.0, -8.0/9.0,    6.0/9.0, -4.0/9.0, -8.0/9.0,    8.0/9.0, -4.0/9.0, -8.0/9.0,
  119.   -8.0/9.0, -2.0/9.0, -8.0/9.0,   -6.0/9.0, -2.0/9.0, -8.0/9.0,   -4.0/9.0, -2.0/9.0, -8.0/9.0,
  120.   -2.0/9.0, -2.0/9.0, -8.0/9.0,        0.0, -2.0/9.0, -8.0/9.0,    2.0/9.0, -2.0/9.0, -8.0/9.0,
  121.     4.0/9.0, -2.0/9.0, -8.0/9.0,    6.0/9.0, -2.0/9.0, -8.0/9.0,    8.0/9.0, -2.0/9.0, -8.0/9.0,
  122.   -8.0/9.0,      0.0, -8.0/9.0,   -6.0/9.0,      0.0, -8.0/9.0,   -4.0/9.0,      0.0, -8.0/9.0,
  123.   -2.0/9.0,      0.0, -8.0/9.0,        0.0,      0.0, -8.0/9.0,    2.0/9.0,      0.0, -8.0/9.0,
  124.     4.0/9.0,      0.0, -8.0/9.0,    6.0/9.0,      0.0, -8.0/9.0,    8.0/9.0,      0.0, -8.0/9.0,
  125.   -8.0/9.0,  2.0/9.0, -8.0/9.0,   -6.0/9.0,  2.0/9.0, -8.0/9.0,   -4.0/9.0,  2.0/9.0, -8.0/9.0,
  126.   -2.0/9.0,  2.0/9.0, -8.0/9.0,        0.0,  2.0/9.0, -8.0/9.0,    2.0/9.0,  2.0/9.0, -8.0/9.0,
  127.     4.0/9.0,  2.0/9.0, -8.0/9.0,    6.0/9.0,  2.0/9.0, -8.0/9.0,    8.0/9.0,  2.0/9.0, -8.0/9.0,
  128.   -8.0/9.0,  4.0/9.0, -8.0/9.0,   -6.0/9.0,  4.0/9.0, -8.0/9.0,   -4.0/9.0,  4.0/9.0, -8.0/9.0,
  129.   -2.0/9.0,  4.0/9.0, -8.0/9.0,        0.0,  4.0/9.0, -8.0/9.0,    2.0/9.0,  4.0/9.0, -8.0/9.0,
  130.     4.0/9.0,  4.0/9.0, -8.0/9.0,    6.0/9.0,  4.0/9.0, -8.0/9.0,    8.0/9.0,  4.0/9.0, -8.0/9.0,
  131.   -8.0/9.0,  6.0/9.0, -8.0/9.0,   -6.0/9.0,  6.0/9.0, -8.0/9.0,   -4.0/9.0,  6.0/9.0, -8.0/9.0,
  132.   -2.0/9.0,  6.0/9.0, -8.0/9.0,        0.0,  6.0/9.0, -8.0/9.0,    2.0/9.0,  6.0/9.0, -8.0/9.0,
  133.     4.0/9.0,  6.0/9.0, -8.0/9.0,    6.0/9.0,  6.0/9.0, -8.0/9.0,    8.0/9.0,  6.0/9.0, -8.0/9.0,
  134.   -8.0/9.0,  8.0/9.0, -8.0/9.0,   -6.0/9.0,  8.0/9.0, -8.0/9.0,   -4.0/9.0,  8.0/9.0, -8.0/9.0,
  135.   -2.0/9.0,  8.0/9.0, -8.0/9.0,        0.0,  8.0/9.0, -8.0/9.0,    2.0/9.0,  8.0/9.0, -8.0/9.0,
  136.     4.0/9.0,  8.0/9.0, -8.0/9.0,    6.0/9.0,  8.0/9.0, -8.0/9.0,    8.0/9.0,  8.0/9.0, -8.0/9.0,
  137.   -8.0/9.0, -8.0/9.0, -6.0/9.0,   -6.0/9.0, -8.0/9.0, -6.0/9.0,   -4.0/9.0, -8.0/9.0, -6.0/9.0,
  138.   -2.0/9.0, -8.0/9.0, -6.0/9.0,        0.0, -8.0/9.0, -6.0/9.0,    2.0/9.0, -8.0/9.0, -6.0/9.0,
  139.     4.0/9.0, -8.0/9.0, -6.0/9.0,    6.0/9.0, -8.0/9.0, -6.0/9.0,    8.0/9.0, -8.0/9.0, -6.0/9.0,
  140.   -8.0/9.0, -6.0/9.0, -6.0/9.0,   -6.0/9.0, -6.0/9.0, -6.0/9.0,   -4.0/9.0, -6.0/9.0, -6.0/9.0,
  141.   -2.0/9.0, -6.0/9.0, -6.0/9.0,        0.0, -6.0/9.0, -6.0/9.0,    2.0/9.0, -6.0/9.0, -6.0/9.0,
  142.     4.0/9.0, -6.0/9.0, -6.0/9.0,    6.0/9.0, -6.0/9.0, -6.0/9.0,    8.0/9.0, -6.0/9.0, -6.0/9.0,
  143.   -8.0/9.0, -4.0/9.0, -6.0/9.0,   -6.0/9.0, -4.0/9.0, -6.0/9.0,   -4.0/9.0, -4.0/9.0, -6.0/9.0,
  144.   -2.0/9.0, -4.0/9.0, -6.0/9.0,        0.0, -4.0/9.0, -6.0/9.0,    2.0/9.0, -4.0/9.0, -6.0/9.0,
  145.     4.0/9.0, -4.0/9.0, -6.0/9.0,    6.0/9.0, -4.0/9.0, -6.0/9.0,    8.0/9.0, -4.0/9.0, -6.0/9.0,
  146.   -8.0/9.0, -2.0/9.0, -6.0/9.0,   -6.0/9.0, -2.0/9.0, -6.0/9.0,   -4.0/9.0, -2.0/9.0, -6.0/9.0,
  147.   -2.0/9.0, -2.0/9.0, -6.0/9.0,        0.0, -2.0/9.0, -6.0/9.0,    2.0/9.0, -2.0/9.0, -6.0/9.0,
  148.     4.0/9.0, -2.0/9.0, -6.0/9.0,    6.0/9.0, -2.0/9.0, -6.0/9.0,    8.0/9.0, -2.0/9.0, -6.0/9.0,
  149.   -8.0/9.0,      0.0, -6.0/9.0,   -6.0/9.0,      0.0, -6.0/9.0,   -4.0/9.0,      0.0, -6.0/9.0,
  150.   -2.0/9.0,      0.0, -6.0/9.0,        0.0,      0.0, -6.0/9.0,    2.0/9.0,      0.0, -6.0/9.0,
  151.     4.0/9.0,      0.0, -6.0/9.0,    6.0/9.0,      0.0, -6.0/9.0,    8.0/9.0,      0.0, -6.0/9.0,
  152.   -8.0/9.0,  2.0/9.0, -6.0/9.0,   -6.0/9.0,  2.0/9.0, -6.0/9.0,   -4.0/9.0,  2.0/9.0, -6.0/9.0,
  153.   -2.0/9.0,  2.0/9.0, -6.0/9.0,        0.0,  2.0/9.0, -6.0/9.0,    2.0/9.0,  2.0/9.0, -6.0/9.0,
  154.     4.0/9.0,  2.0/9.0, -6.0/9.0,    6.0/9.0,  2.0/9.0, -6.0/9.0,    8.0/9.0,  2.0/9.0, -6.0/9.0,
  155.   -8.0/9.0,  4.0/9.0, -6.0/9.0,   -6.0/9.0,  4.0/9.0, -6.0/9.0,   -4.0/9.0,  4.0/9.0, -6.0/9.0,
  156.   -2.0/9.0,  4.0/9.0, -6.0/9.0,        0.0,  4.0/9.0, -6.0/9.0,    2.0/9.0,  4.0/9.0, -6.0/9.0,
  157.     4.0/9.0,  4.0/9.0, -6.0/9.0,    6.0/9.0,  4.0/9.0, -6.0/9.0,    8.0/9.0,  4.0/9.0, -6.0/9.0,
  158.   -8.0/9.0,  6.0/9.0, -6.0/9.0,   -6.0/9.0,  6.0/9.0, -6.0/9.0,   -4.0/9.0,  6.0/9.0, -6.0/9.0,
  159.   -2.0/9.0,  6.0/9.0, -6.0/9.0,        0.0,  6.0/9.0, -6.0/9.0,    2.0/9.0,  6.0/9.0, -6.0/9.0,
  160.     4.0/9.0,  6.0/9.0, -6.0/9.0,    6.0/9.0,  6.0/9.0, -6.0/9.0,    8.0/9.0,  6.0/9.0, -6.0/9.0,
  161.   -8.0/9.0,  8.0/9.0, -6.0/9.0,   -6.0/9.0,  8.0/9.0, -6.0/9.0,   -4.0/9.0,  8.0/9.0, -6.0/9.0,
  162.   -2.0/9.0,  8.0/9.0, -6.0/9.0,        0.0,  8.0/9.0, -6.0/9.0,    2.0/9.0,  8.0/9.0, -6.0/9.0,
  163.     4.0/9.0,  8.0/9.0, -6.0/9.0,    6.0/9.0,  8.0/9.0, -6.0/9.0,    8.0/9.0,  8.0/9.0, -6.0/9.0,
  164.   -8.0/9.0, -8.0/9.0, -4.0/9.0,   -6.0/9.0, -8.0/9.0, -4.0/9.0,   -4.0/9.0, -8.0/9.0, -4.0/9.0,
  165.   -2.0/9.0, -8.0/9.0, -4.0/9.0,        0.0, -8.0/9.0, -4.0/9.0,    2.0/9.0, -8.0/9.0, -4.0/9.0,
  166.     4.0/9.0, -8.0/9.0, -4.0/9.0,    6.0/9.0, -8.0/9.0, -4.0/9.0,    8.0/9.0, -8.0/9.0, -4.0/9.0,
  167.   -8.0/9.0, -6.0/9.0, -4.0/9.0,   -6.0/9.0, -6.0/9.0, -4.0/9.0,   -4.0/9.0, -6.0/9.0, -4.0/9.0,
  168.   -2.0/9.0, -6.0/9.0, -4.0/9.0,        0.0, -6.0/9.0, -4.0/9.0,    2.0/9.0, -6.0/9.0, -4.0/9.0,
  169.     4.0/9.0, -6.0/9.0, -4.0/9.0,    6.0/9.0, -6.0/9.0, -4.0/9.0,    8.0/9.0, -6.0/9.0, -4.0/9.0,
  170.   -8.0/9.0, -4.0/9.0, -4.0/9.0,   -6.0/9.0, -4.0/9.0, -4.0/9.0,   -4.0/9.0, -4.0/9.0, -4.0/9.0,
  171.   -2.0/9.0, -4.0/9.0, -4.0/9.0,        0.0, -4.0/9.0, -4.0/9.0,    2.0/9.0, -4.0/9.0, -4.0/9.0,
  172.     4.0/9.0, -4.0/9.0, -4.0/9.0,    6.0/9.0, -4.0/9.0, -4.0/9.0,    8.0/9.0, -4.0/9.0, -4.0/9.0,
  173.   -8.0/9.0, -2.0/9.0, -4.0/9.0,   -6.0/9.0, -2.0/9.0, -4.0/9.0,   -4.0/9.0, -2.0/9.0, -4.0/9.0,
  174.   -2.0/9.0, -2.0/9.0, -4.0/9.0,        0.0, -2.0/9.0, -4.0/9.0,    2.0/9.0, -2.0/9.0, -4.0/9.0,
  175.     4.0/9.0, -2.0/9.0, -4.0/9.0,    6.0/9.0, -2.0/9.0, -4.0/9.0,    8.0/9.0, -2.0/9.0, -4.0/9.0,
  176.   -8.0/9.0,      0.0, -4.0/9.0,   -6.0/9.0,      0.0, -4.0/9.0,   -4.0/9.0,      0.0, -4.0/9.0,
  177.   -2.0/9.0,      0.0, -4.0/9.0,        0.0,      0.0, -4.0/9.0,    2.0/9.0,      0.0, -4.0/9.0,
  178.     4.0/9.0,      0.0, -4.0/9.0,    6.0/9.0,      0.0, -4.0/9.0,    8.0/9.0,      0.0, -4.0/9.0,
  179.   -8.0/9.0,  2.0/9.0, -4.0/9.0,   -6.0/9.0,  2.0/9.0, -4.0/9.0,   -4.0/9.0,  2.0/9.0, -4.0/9.0,
  180.   -2.0/9.0,  2.0/9.0, -4.0/9.0,        0.0,  2.0/9.0, -4.0/9.0,    2.0/9.0,  2.0/9.0, -4.0/9.0,
  181.     4.0/9.0,  2.0/9.0, -4.0/9.0,    6.0/9.0,  2.0/9.0, -4.0/9.0,    8.0/9.0,  2.0/9.0, -4.0/9.0,
  182.   -8.0/9.0,  4.0/9.0, -4.0/9.0,   -6.0/9.0,  4.0/9.0, -4.0/9.0,   -4.0/9.0,  4.0/9.0, -4.0/9.0,
  183.   -2.0/9.0,  4.0/9.0, -4.0/9.0,        0.0,  4.0/9.0, -4.0/9.0,    2.0/9.0,  4.0/9.0, -4.0/9.0,
  184.     4.0/9.0,  4.0/9.0, -4.0/9.0,    6.0/9.0,  4.0/9.0, -4.0/9.0,    8.0/9.0,  4.0/9.0, -4.0/9.0,
  185.   -8.0/9.0,  6.0/9.0, -4.0/9.0,   -6.0/9.0,  6.0/9.0, -4.0/9.0,   -4.0/9.0,  6.0/9.0, -4.0/9.0,
  186.   -2.0/9.0,  6.0/9.0, -4.0/9.0,        0.0,  6.0/9.0, -4.0/9.0,    2.0/9.0,  6.0/9.0, -4.0/9.0,
  187.     4.0/9.0,  6.0/9.0, -4.0/9.0,    6.0/9.0,  6.0/9.0, -4.0/9.0,    8.0/9.0,  6.0/9.0, -4.0/9.0,
  188.   -8.0/9.0,  8.0/9.0, -4.0/9.0,   -6.0/9.0,  8.0/9.0, -4.0/9.0,   -4.0/9.0,  8.0/9.0, -4.0/9.0,
  189.   -2.0/9.0,  8.0/9.0, -4.0/9.0,        0.0,  8.0/9.0, -4.0/9.0,    2.0/9.0,  8.0/9.0, -4.0/9.0,
  190.     4.0/9.0,  8.0/9.0, -4.0/9.0,    6.0/9.0,  8.0/9.0, -4.0/9.0,    8.0/9.0,  8.0/9.0, -4.0/9.0,
  191.   -8.0/9.0, -8.0/9.0, -2.0/9.0,   -6.0/9.0, -8.0/9.0, -2.0/9.0,   -4.0/9.0, -8.0/9.0, -2.0/9.0,
  192.   -2.0/9.0, -8.0/9.0, -2.0/9.0,        0.0, -8.0/9.0, -2.0/9.0,    2.0/9.0, -8.0/9.0, -2.0/9.0,
  193.     4.0/9.0, -8.0/9.0, -2.0/9.0,    6.0/9.0, -8.0/9.0, -2.0/9.0,    8.0/9.0, -8.0/9.0, -2.0/9.0,
  194.   -8.0/9.0, -6.0/9.0, -2.0/9.0,   -6.0/9.0, -6.0/9.0, -2.0/9.0,   -4.0/9.0, -6.0/9.0, -2.0/9.0,
  195.   -2.0/9.0, -6.0/9.0, -2.0/9.0,        0.0, -6.0/9.0, -2.0/9.0,    2.0/9.0, -6.0/9.0, -2.0/9.0,
  196.     4.0/9.0, -6.0/9.0, -2.0/9.0,    6.0/9.0, -6.0/9.0, -2.0/9.0,    8.0/9.0, -6.0/9.0, -2.0/9.0,
  197.   -8.0/9.0, -4.0/9.0, -2.0/9.0,   -6.0/9.0, -4.0/9.0, -2.0/9.0,   -4.0/9.0, -4.0/9.0, -2.0/9.0,
  198.   -2.0/9.0, -4.0/9.0, -2.0/9.0,        0.0, -4.0/9.0, -2.0/9.0,    2.0/9.0, -4.0/9.0, -2.0/9.0,
  199.     4.0/9.0, -4.0/9.0, -2.0/9.0,    6.0/9.0, -4.0/9.0, -2.0/9.0,    8.0/9.0, -4.0/9.0, -2.0/9.0,
  200.   -8.0/9.0, -2.0/9.0, -2.0/9.0,   -6.0/9.0, -2.0/9.0, -2.0/9.0,   -4.0/9.0, -2.0/9.0, -2.0/9.0,
  201.   -2.0/9.0, -2.0/9.0, -2.0/9.0,        0.0, -2.0/9.0, -2.0/9.0,    2.0/9.0, -2.0/9.0, -2.0/9.0,
  202.     4.0/9.0, -2.0/9.0, -2.0/9.0,    6.0/9.0, -2.0/9.0, -2.0/9.0,    8.0/9.0, -2.0/9.0, -2.0/9.0,
  203.   -8.0/9.0,      0.0, -2.0/9.0,   -6.0/9.0,      0.0, -2.0/9.0,   -4.0/9.0,      0.0, -2.0/9.0,
  204.   -2.0/9.0,      0.0, -2.0/9.0,        0.0,      0.0, -2.0/9.0,    2.0/9.0,      0.0, -2.0/9.0,
  205.     4.0/9.0,      0.0, -2.0/9.0,    6.0/9.0,      0.0, -2.0/9.0,    8.0/9.0,      0.0, -2.0/9.0,
  206.   -8.0/9.0,  2.0/9.0, -2.0/9.0,   -6.0/9.0,  2.0/9.0, -2.0/9.0,   -4.0/9.0,  2.0/9.0, -2.0/9.0,
  207.   -2.0/9.0,  2.0/9.0, -2.0/9.0,        0.0,  2.0/9.0, -2.0/9.0,    2.0/9.0,  2.0/9.0, -2.0/9.0,
  208.     4.0/9.0,  2.0/9.0, -2.0/9.0,    6.0/9.0,  2.0/9.0, -2.0/9.0,    8.0/9.0,  2.0/9.0, -2.0/9.0,
  209.   -8.0/9.0,  4.0/9.0, -2.0/9.0,   -6.0/9.0,  4.0/9.0, -2.0/9.0,   -4.0/9.0,  4.0/9.0, -2.0/9.0,
  210.   -2.0/9.0,  4.0/9.0, -2.0/9.0,        0.0,  4.0/9.0, -2.0/9.0,    2.0/9.0,  4.0/9.0, -2.0/9.0,
  211.     4.0/9.0,  4.0/9.0, -2.0/9.0,    6.0/9.0,  4.0/9.0, -2.0/9.0,    8.0/9.0,  4.0/9.0, -2.0/9.0,
  212.   -8.0/9.0,  6.0/9.0, -2.0/9.0,   -6.0/9.0,  6.0/9.0, -2.0/9.0,   -4.0/9.0,  6.0/9.0, -2.0/9.0,
  213.   -2.0/9.0,  6.0/9.0, -2.0/9.0,        0.0,  6.0/9.0, -2.0/9.0,    2.0/9.0,  6.0/9.0, -2.0/9.0,
  214.     4.0/9.0,  6.0/9.0, -2.0/9.0,    6.0/9.0,  6.0/9.0, -2.0/9.0,    8.0/9.0,  6.0/9.0, -2.0/9.0,
  215.   -8.0/9.0,  8.0/9.0, -2.0/9.0,   -6.0/9.0,  8.0/9.0, -2.0/9.0,   -4.0/9.0,  8.0/9.0, -2.0/9.0,
  216.   -2.0/9.0,  8.0/9.0, -2.0/9.0,        0.0,  8.0/9.0, -2.0/9.0,    2.0/9.0,  8.0/9.0, -2.0/9.0,
  217.     4.0/9.0,  8.0/9.0, -2.0/9.0,    6.0/9.0,  8.0/9.0, -2.0/9.0,    8.0/9.0,  8.0/9.0, -2.0/9.0,
  218.   -8.0/9.0, -8.0/9.0,      0.0,   -6.0/9.0, -8.0/9.0,      0.0,   -4.0/9.0, -8.0/9.0,      0.0,
  219.   -2.0/9.0, -8.0/9.0,      0.0,        0.0, -8.0/9.0,      0.0,    2.0/9.0, -8.0/9.0,      0.0,
  220.     4.0/9.0, -8.0/9.0,      0.0,    6.0/9.0, -8.0/9.0,      0.0,    8.0/9.0, -8.0/9.0,      0.0,
  221.   -8.0/9.0, -6.0/9.0,      0.0,   -6.0/9.0, -6.0/9.0,      0.0,   -4.0/9.0, -6.0/9.0,      0.0,
  222.   -2.0/9.0, -6.0/9.0,      0.0,        0.0, -6.0/9.0,      0.0,    2.0/9.0, -6.0/9.0,      0.0,
  223.     4.0/9.0, -6.0/9.0,      0.0,    6.0/9.0, -6.0/9.0,      0.0,    8.0/9.0, -6.0/9.0,      0.0,
  224.   -8.0/9.0, -4.0/9.0,      0.0,   -6.0/9.0, -4.0/9.0,      0.0,   -4.0/9.0, -4.0/9.0,      0.0,
  225.   -2.0/9.0, -4.0/9.0,      0.0,        0.0, -4.0/9.0,      0.0,    2.0/9.0, -4.0/9.0,      0.0,
  226.     4.0/9.0, -4.0/9.0,      0.0,    6.0/9.0, -4.0/9.0,      0.0,    8.0/9.0, -4.0/9.0,      0.0,
  227.   -8.0/9.0, -2.0/9.0,      0.0,   -6.0/9.0, -2.0/9.0,      0.0,   -4.0/9.0, -2.0/9.0,      0.0,
  228.   -2.0/9.0, -2.0/9.0,      0.0,        0.0, -2.0/9.0,      0.0,    2.0/9.0, -2.0/9.0,      0.0,
  229.     4.0/9.0, -2.0/9.0,      0.0,    6.0/9.0, -2.0/9.0,      0.0,    8.0/9.0, -2.0/9.0,      0.0,
  230.   -8.0/9.0,      0.0,      0.0,   -6.0/9.0,      0.0,      0.0,   -4.0/9.0,      0.0,      0.0,
  231.   -2.0/9.0,      0.0,      0.0,        0.0,      0.0,      0.0,    2.0/9.0,      0.0,      0.0,
  232.     4.0/9.0,      0.0,      0.0,    6.0/9.0,      0.0,      0.0,    8.0/9.0,      0.0,      0.0,
  233.   -8.0/9.0,  2.0/9.0,      0.0,   -6.0/9.0,  2.0/9.0,      0.0,   -4.0/9.0,  2.0/9.0,      0.0,
  234.   -2.0/9.0,  2.0/9.0,      0.0,        0.0,  2.0/9.0,      0.0,    2.0/9.0,  2.0/9.0,      0.0,
  235.     4.0/9.0,  2.0/9.0,      0.0,    6.0/9.0,  2.0/9.0,      0.0,    8.0/9.0,  2.0/9.0,      0.0,
  236.   -8.0/9.0,  4.0/9.0,      0.0,   -6.0/9.0,  4.0/9.0,      0.0,   -4.0/9.0,  4.0/9.0,      0.0,
  237.   -2.0/9.0,  4.0/9.0,      0.0,        0.0,  4.0/9.0,      0.0,    2.0/9.0,  4.0/9.0,      0.0,
  238.     4.0/9.0,  4.0/9.0,      0.0,    6.0/9.0,  4.0/9.0,      0.0,    8.0/9.0,  4.0/9.0,      0.0,
  239.   -8.0/9.0,  6.0/9.0,      0.0,   -6.0/9.0,  6.0/9.0,      0.0,   -4.0/9.0,  6.0/9.0,      0.0,
  240.   -2.0/9.0,  6.0/9.0,      0.0,        0.0,  6.0/9.0,      0.0,    2.0/9.0,  6.0/9.0,      0.0,
  241.     4.0/9.0,  6.0/9.0,      0.0,    6.0/9.0,  6.0/9.0,      0.0,    8.0/9.0,  6.0/9.0,      0.0,
  242.   -8.0/9.0,  8.0/9.0,      0.0,   -6.0/9.0,  8.0/9.0,      0.0,   -4.0/9.0,  8.0/9.0,      0.0,
  243.   -2.0/9.0,  8.0/9.0,      0.0,        0.0,  8.0/9.0,      0.0,    2.0/9.0,  8.0/9.0,      0.0,
  244.    4.0/9.0,  8.0/9.0,      0.0,    6.0/9.0,  8.0/9.0,      0.0,    8.0/9.0,  8.0/9.0,      0.0,
  245.   -8.0/9.0, -8.0/9.0,  2.0/9.0,   -6.0/9.0, -8.0/9.0,  2.0/9.0,   -4.0/9.0, -8.0/9.0,  2.0/9.0,
  246.   -2.0/9.0, -8.0/9.0,  2.0/9.0,        0.0, -8.0/9.0,  2.0/9.0,    2.0/9.0, -8.0/9.0,  2.0/9.0,
  247.     4.0/9.0, -8.0/9.0,  2.0/9.0,    6.0/9.0, -8.0/9.0,  2.0/9.0,    8.0/9.0, -8.0/9.0,  2.0/9.0,
  248.   -8.0/9.0, -6.0/9.0,  2.0/9.0,   -6.0/9.0, -6.0/9.0,  2.0/9.0,   -4.0/9.0, -6.0/9.0,  2.0/9.0,
  249.   -2.0/9.0, -6.0/9.0,  2.0/9.0,        0.0, -6.0/9.0,  2.0/9.0,    2.0/9.0, -6.0/9.0,  2.0/9.0,
  250.     4.0/9.0, -6.0/9.0,  2.0/9.0,    6.0/9.0, -6.0/9.0,  2.0/9.0,    8.0/9.0, -6.0/9.0,  2.0/9.0,
  251.   -8.0/9.0, -4.0/9.0,  2.0/9.0,   -6.0/9.0, -4.0/9.0,  2.0/9.0,   -4.0/9.0, -4.0/9.0,  2.0/9.0,
  252.   -2.0/9.0, -4.0/9.0,  2.0/9.0,        0.0, -4.0/9.0,  2.0/9.0,    2.0/9.0, -4.0/9.0,  2.0/9.0,
  253.    4.0/9.0, -4.0/9.0,  2.0/9.0,    6.0/9.0, -4.0/9.0,  2.0/9.0,    8.0/9.0, -4.0/9.0,  2.0/9.0,
  254.   -8.0/9.0, -2.0/9.0,  2.0/9.0,   -6.0/9.0, -2.0/9.0,  2.0/9.0,   -4.0/9.0, -2.0/9.0,  2.0/9.0,
  255.   -2.0/9.0, -2.0/9.0,  2.0/9.0,        0.0, -2.0/9.0,  2.0/9.0,    2.0/9.0, -2.0/9.0,  2.0/9.0,
  256.    4.0/9.0, -2.0/9.0,  2.0/9.0,    6.0/9.0, -2.0/9.0,  2.0/9.0,    8.0/9.0, -2.0/9.0,  2.0/9.0,
  257.   -8.0/9.0,      0.0,  2.0/9.0,   -6.0/9.0,      0.0,  2.0/9.0,   -4.0/9.0,      0.0,  2.0/9.0,
  258.   -2.0/9.0,      0.0,  2.0/9.0,        0.0,      0.0,  2.0/9.0,    2.0/9.0,      0.0,  2.0/9.0,
  259.    4.0/9.0,      0.0,  2.0/9.0,    6.0/9.0,      0.0,  2.0/9.0,    8.0/9.0,      0.0,  2.0/9.0,
  260.   -8.0/9.0,  2.0/9.0,  2.0/9.0,   -6.0/9.0,  2.0/9.0,  2.0/9.0,   -4.0/9.0,  2.0/9.0,  2.0/9.0,
  261.   -2.0/9.0,  2.0/9.0,  2.0/9.0,        0.0,  2.0/9.0,  2.0/9.0,    2.0/9.0,  2.0/9.0,  2.0/9.0,
  262.    4.0/9.0,  2.0/9.0,  2.0/9.0,    6.0/9.0,  2.0/9.0,  2.0/9.0,    8.0/9.0,  2.0/9.0,  2.0/9.0,
  263.   -8.0/9.0,  4.0/9.0,  2.0/9.0,   -6.0/9.0,  4.0/9.0,  2.0/9.0,   -4.0/9.0,  4.0/9.0,  2.0/9.0,
  264.   -2.0/9.0,  4.0/9.0,  2.0/9.0,        0.0,  4.0/9.0,  2.0/9.0,    2.0/9.0,  4.0/9.0,  2.0/9.0,
  265.     4.0/9.0,  4.0/9.0,  2.0/9.0,    6.0/9.0,  4.0/9.0,  2.0/9.0,    8.0/9.0,  4.0/9.0,  2.0/9.0,
  266.   -8.0/9.0,  6.0/9.0,  2.0/9.0,   -6.0/9.0,  6.0/9.0,  2.0/9.0,   -4.0/9.0,  6.0/9.0,  2.0/9.0,
  267.   -2.0/9.0,  6.0/9.0,  2.0/9.0,        0.0,  6.0/9.0,  2.0/9.0,    2.0/9.0,  6.0/9.0,  2.0/9.0,
  268.    4.0/9.0,  6.0/9.0,  2.0/9.0,    6.0/9.0,  6.0/9.0,  2.0/9.0,    8.0/9.0,  6.0/9.0,  2.0/9.0,
  269.   -8.0/9.0,  8.0/9.0,  2.0/9.0,   -6.0/9.0,  8.0/9.0,  2.0/9.0,   -4.0/9.0,  8.0/9.0,  2.0/9.0,
  270.   -2.0/9.0,  8.0/9.0,  2.0/9.0,        0.0,  8.0/9.0,  2.0/9.0,    2.0/9.0,  8.0/9.0,  2.0/9.0,
  271.    4.0/9.0,  8.0/9.0,  2.0/9.0,    6.0/9.0,  8.0/9.0,  2.0/9.0,    8.0/9.0,  8.0/9.0,  2.0/9.0,
  272.   -8.0/9.0, -8.0/9.0,  4.0/9.0,   -6.0/9.0, -8.0/9.0,  4.0/9.0,   -4.0/9.0, -8.0/9.0,  4.0/9.0,
  273.   -2.0/9.0, -8.0/9.0,  4.0/9.0,        0.0, -8.0/9.0,  4.0/9.0,    2.0/9.0, -8.0/9.0,  4.0/9.0,
  274.     4.0/9.0, -8.0/9.0,  4.0/9.0,    6.0/9.0, -8.0/9.0,  4.0/9.0,    8.0/9.0, -8.0/9.0,  4.0/9.0,
  275.   -8.0/9.0, -6.0/9.0,  4.0/9.0,   -6.0/9.0, -6.0/9.0,  4.0/9.0,   -4.0/9.0, -6.0/9.0,  4.0/9.0,
  276.   -2.0/9.0, -6.0/9.0,  4.0/9.0,        0.0, -6.0/9.0,  4.0/9.0,    2.0/9.0, -6.0/9.0,  4.0/9.0,
  277.    4.0/9.0, -6.0/9.0,  4.0/9.0,    6.0/9.0, -6.0/9.0,  4.0/9.0,    8.0/9.0, -6.0/9.0,  4.0/9.0,
  278.   -8.0/9.0, -4.0/9.0,  4.0/9.0,   -6.0/9.0, -4.0/9.0,  4.0/9.0,   -4.0/9.0, -4.0/9.0,  4.0/9.0,
  279.   -2.0/9.0, -4.0/9.0,  4.0/9.0,        0.0, -4.0/9.0,  4.0/9.0,    2.0/9.0, -4.0/9.0,  4.0/9.0,
  280.    4.0/9.0, -4.0/9.0,  4.0/9.0,    6.0/9.0, -4.0/9.0,  4.0/9.0,    8.0/9.0, -4.0/9.0,  4.0/9.0,
  281.   -8.0/9.0, -2.0/9.0,  4.0/9.0,   -6.0/9.0, -2.0/9.0,  4.0/9.0,   -4.0/9.0, -2.0/9.0,  4.0/9.0,
  282.   -2.0/9.0, -2.0/9.0,  4.0/9.0,        0.0, -2.0/9.0,  4.0/9.0,    2.0/9.0, -2.0/9.0,  4.0/9.0,
  283.     4.0/9.0, -2.0/9.0,  4.0/9.0,    6.0/9.0, -2.0/9.0,  4.0/9.0,    8.0/9.0, -2.0/9.0,  4.0/9.0,
  284.   -8.0/9.0,      0.0,  4.0/9.0,   -6.0/9.0,      0.0,  4.0/9.0,   -4.0/9.0,      0.0,  4.0/9.0,
  285.   -2.0/9.0,      0.0,  4.0/9.0,        0.0,      0.0,  4.0/9.0,    2.0/9.0,      0.0,  4.0/9.0,
  286.    4.0/9.0,      0.0,  4.0/9.0,    6.0/9.0,      0.0,  4.0/9.0,    8.0/9.0,      0.0,  4.0/9.0,
  287.   -8.0/9.0,  2.0/9.0,  4.0/9.0,   -6.0/9.0,  2.0/9.0,  4.0/9.0,   -4.0/9.0,  2.0/9.0,  4.0/9.0,
  288.   -2.0/9.0,  2.0/9.0,  4.0/9.0,        0.0,  2.0/9.0,  4.0/9.0,    2.0/9.0,  2.0/9.0,  4.0/9.0,
  289.    4.0/9.0,  2.0/9.0,  4.0/9.0,    6.0/9.0,  2.0/9.0,  4.0/9.0,    8.0/9.0,  2.0/9.0,  4.0/9.0,
  290.   -8.0/9.0,  4.0/9.0,  4.0/9.0,   -6.0/9.0,  4.0/9.0,  4.0/9.0,   -4.0/9.0,  4.0/9.0,  4.0/9.0,
  291.   -2.0/9.0,  4.0/9.0,  4.0/9.0,        0.0,  4.0/9.0,  4.0/9.0,    2.0/9.0,  4.0/9.0,  4.0/9.0,
  292.    4.0/9.0,  4.0/9.0,  4.0/9.0,    6.0/9.0,  4.0/9.0,  4.0/9.0,    8.0/9.0,  4.0/9.0,  4.0/9.0,
  293.   -8.0/9.0,  6.0/9.0,  4.0/9.0,   -6.0/9.0,  6.0/9.0,  4.0/9.0,   -4.0/9.0,  6.0/9.0,  4.0/9.0,
  294.   -2.0/9.0,  6.0/9.0,  4.0/9.0,        0.0,  6.0/9.0,  4.0/9.0,    2.0/9.0,  6.0/9.0,  4.0/9.0,
  295.     4.0/9.0,  6.0/9.0,  4.0/9.0,    6.0/9.0,  6.0/9.0,  4.0/9.0,    8.0/9.0,  6.0/9.0,  4.0/9.0,
  296.   -8.0/9.0,  8.0/9.0,  4.0/9.0,   -6.0/9.0,  8.0/9.0,  4.0/9.0,   -4.0/9.0,  8.0/9.0,  4.0/9.0,
  297.   -2.0/9.0,  8.0/9.0,  4.0/9.0,        0.0,  8.0/9.0,  4.0/9.0,    2.0/9.0,  8.0/9.0,  4.0/9.0,
  298.     4.0/9.0,  8.0/9.0,  4.0/9.0,    6.0/9.0,  8.0/9.0,  4.0/9.0,    8.0/9.0,  8.0/9.0,  4.0/9.0,
  299.   -8.0/9.0, -8.0/9.0,  6.0/9.0,   -6.0/9.0, -8.0/9.0,  6.0/9.0,   -4.0/9.0, -8.0/9.0,  6.0/9.0,
  300.   -2.0/9.0, -8.0/9.0,  6.0/9.0,        0.0, -8.0/9.0,  6.0/9.0,    2.0/9.0, -8.0/9.0,  6.0/9.0,
  301.    4.0/9.0, -8.0/9.0,  6.0/9.0,    6.0/9.0, -8.0/9.0,  6.0/9.0,    8.0/9.0, -8.0/9.0,  6.0/9.0,
  302.   -8.0/9.0, -6.0/9.0,  6.0/9.0,   -6.0/9.0, -6.0/9.0,  6.0/9.0,   -4.0/9.0, -6.0/9.0,  6.0/9.0,
  303.   -2.0/9.0, -6.0/9.0,  6.0/9.0,        0.0, -6.0/9.0,  6.0/9.0,    2.0/9.0, -6.0/9.0,  6.0/9.0,
  304.    4.0/9.0, -6.0/9.0,  6.0/9.0,    6.0/9.0, -6.0/9.0,  6.0/9.0,    8.0/9.0, -6.0/9.0,  6.0/9.0,
  305.   -8.0/9.0, -4.0/9.0,  6.0/9.0,   -6.0/9.0, -4.0/9.0,  6.0/9.0,   -4.0/9.0, -4.0/9.0,  6.0/9.0,
  306.   -2.0/9.0, -4.0/9.0,  6.0/9.0,        0.0, -4.0/9.0,  6.0/9.0,    2.0/9.0, -4.0/9.0,  6.0/9.0,
  307.     4.0/9.0, -4.0/9.0,  6.0/9.0,    6.0/9.0, -4.0/9.0,  6.0/9.0,    8.0/9.0, -4.0/9.0,  6.0/9.0,
  308.   -8.0/9.0, -2.0/9.0,  6.0/9.0,   -6.0/9.0, -2.0/9.0,  6.0/9.0,   -4.0/9.0, -2.0/9.0,  6.0/9.0,
  309.   -2.0/9.0, -2.0/9.0,  6.0/9.0,        0.0, -2.0/9.0,  6.0/9.0,    2.0/9.0, -2.0/9.0,  6.0/9.0,
  310.    4.0/9.0, -2.0/9.0,  6.0/9.0,    6.0/9.0, -2.0/9.0,  6.0/9.0,    8.0/9.0, -2.0/9.0,  6.0/9.0,
  311.   -8.0/9.0,      0.0,  6.0/9.0,   -6.0/9.0,      0.0,  6.0/9.0,   -4.0/9.0,      0.0,  6.0/9.0,
  312.   -2.0/9.0,      0.0,  6.0/9.0,        0.0,      0.0,  6.0/9.0,    2.0/9.0,      0.0,  6.0/9.0,
  313.     4.0/9.0,      0.0,  6.0/9.0,    6.0/9.0,      0.0,  6.0/9.0,    8.0/9.0,      0.0,  6.0/9.0,
  314.   -8.0/9.0,  2.0/9.0,  6.0/9.0,   -6.0/9.0,  2.0/9.0,  6.0/9.0,   -4.0/9.0,  2.0/9.0,  6.0/9.0,
  315.   -2.0/9.0,  2.0/9.0,  6.0/9.0,        0.0,  2.0/9.0,  6.0/9.0,    2.0/9.0,  2.0/9.0,  6.0/9.0,
  316.     4.0/9.0,  2.0/9.0,  6.0/9.0,    6.0/9.0,  2.0/9.0,  6.0/9.0,    8.0/9.0,  2.0/9.0,  6.0/9.0,
  317.   -8.0/9.0,  4.0/9.0,  6.0/9.0,   -6.0/9.0,  4.0/9.0,  6.0/9.0,   -4.0/9.0,  4.0/9.0,  6.0/9.0,
  318.   -2.0/9.0,  4.0/9.0,  6.0/9.0,        0.0,  4.0/9.0,  6.0/9.0,    2.0/9.0,  4.0/9.0,  6.0/9.0,
  319.     4.0/9.0,  4.0/9.0,  6.0/9.0,    6.0/9.0,  4.0/9.0,  6.0/9.0,    8.0/9.0,  4.0/9.0,  6.0/9.0,
  320.   -8.0/9.0,  6.0/9.0,  6.0/9.0,   -6.0/9.0,  6.0/9.0,  6.0/9.0,   -4.0/9.0,  6.0/9.0,  6.0/9.0,
  321.   -2.0/9.0,  6.0/9.0,  6.0/9.0,        0.0,  6.0/9.0,  6.0/9.0,    2.0/9.0,  6.0/9.0,  6.0/9.0,
  322.     4.0/9.0,  6.0/9.0,  6.0/9.0,    6.0/9.0,  6.0/9.0,  6.0/9.0,    8.0/9.0,  6.0/9.0,  6.0/9.0,
  323.   -8.0/9.0,  8.0/9.0,  6.0/9.0,   -6.0/9.0,  8.0/9.0,  6.0/9.0,   -4.0/9.0,  8.0/9.0,  6.0/9.0,
  324.   -2.0/9.0,  8.0/9.0,  6.0/9.0,        0.0,  8.0/9.0,  6.0/9.0,    2.0/9.0,  8.0/9.0,  6.0/9.0,
  325.     4.0/9.0,  8.0/9.0,  6.0/9.0,    6.0/9.0,  8.0/9.0,  6.0/9.0,    8.0/9.0,  8.0/9.0,  6.0/9.0,
  326.   -8.0/9.0, -8.0/9.0,  8.0/9.0,   -6.0/9.0, -8.0/9.0,  8.0/9.0,   -4.0/9.0, -8.0/9.0,  8.0/9.0,
  327.   -2.0/9.0, -8.0/9.0,  8.0/9.0,        0.0, -8.0/9.0,  8.0/9.0,    2.0/9.0, -8.0/9.0,  8.0/9.0,
  328.    4.0/9.0, -8.0/9.0,  8.0/9.0,    6.0/9.0, -8.0/9.0,  8.0/9.0,    8.0/9.0, -8.0/9.0,  8.0/9.0,
  329.   -8.0/9.0, -6.0/9.0,  8.0/9.0,   -6.0/9.0, -6.0/9.0,  8.0/9.0,   -4.0/9.0, -6.0/9.0,  8.0/9.0,
  330.   -2.0/9.0, -6.0/9.0,  8.0/9.0,        0.0, -6.0/9.0,  8.0/9.0,    2.0/9.0, -6.0/9.0,  8.0/9.0,
  331.     4.0/9.0, -6.0/9.0,  8.0/9.0,    6.0/9.0, -6.0/9.0,  8.0/9.0,    8.0/9.0, -6.0/9.0,  8.0/9.0,
  332.   -8.0/9.0, -4.0/9.0,  8.0/9.0,   -6.0/9.0, -4.0/9.0,  8.0/9.0,   -4.0/9.0, -4.0/9.0,  8.0/9.0,
  333.   -2.0/9.0, -4.0/9.0,  8.0/9.0,        0.0, -4.0/9.0,  8.0/9.0,    2.0/9.0, -4.0/9.0,  8.0/9.0,
  334.    4.0/9.0, -4.0/9.0,  8.0/9.0,    6.0/9.0, -4.0/9.0,  8.0/9.0,    8.0/9.0, -4.0/9.0,  8.0/9.0,
  335.   -8.0/9.0, -2.0/9.0,  8.0/9.0,   -6.0/9.0, -2.0/9.0,  8.0/9.0,   -4.0/9.0, -2.0/9.0,  8.0/9.0,
  336.   -2.0/9.0, -2.0/9.0,  8.0/9.0,        0.0, -2.0/9.0,  8.0/9.0,    2.0/9.0, -2.0/9.0,  8.0/9.0,
  337.    4.0/9.0, -2.0/9.0,  8.0/9.0,    6.0/9.0, -2.0/9.0,  8.0/9.0,    8.0/9.0, -2.0/9.0,  8.0/9.0,
  338.   -8.0/9.0,      0.0,  8.0/9.0,   -6.0/9.0,      0.0,  8.0/9.0,   -4.0/9.0,      0.0,  8.0/9.0,
  339.   -2.0/9.0,      0.0,  8.0/9.0,        0.0,      0.0,  8.0/9.0,    2.0/9.0,      0.0,  8.0/9.0,
  340.    4.0/9.0,      0.0,  8.0/9.0,    6.0/9.0,      0.0,  8.0/9.0,    8.0/9.0,      0.0,  8.0/9.0,
  341.   -8.0/9.0,  2.0/9.0,  8.0/9.0,   -6.0/9.0,  2.0/9.0,  8.0/9.0,   -4.0/9.0,  2.0/9.0,  8.0/9.0,
  342.   -2.0/9.0,  2.0/9.0,  8.0/9.0,        0.0,  2.0/9.0,  8.0/9.0,    2.0/9.0,  2.0/9.0,  8.0/9.0,
  343.     4.0/9.0,  2.0/9.0,  8.0/9.0,    6.0/9.0,  2.0/9.0,  8.0/9.0,    8.0/9.0,  2.0/9.0,  8.0/9.0,
  344.   -8.0/9.0,  4.0/9.0,  8.0/9.0,   -6.0/9.0,  4.0/9.0,  8.0/9.0,   -4.0/9.0,  4.0/9.0,  8.0/9.0,
  345.   -2.0/9.0,  4.0/9.0,  8.0/9.0,        0.0,  4.0/9.0,  8.0/9.0,    2.0/9.0,  4.0/9.0,  8.0/9.0,
  346.     4.0/9.0,  4.0/9.0,  8.0/9.0,    6.0/9.0,  4.0/9.0,  8.0/9.0,    8.0/9.0,  4.0/9.0,  8.0/9.0,
  347.   -8.0/9.0,  6.0/9.0,  8.0/9.0,   -6.0/9.0,  6.0/9.0,  8.0/9.0,   -4.0/9.0,  6.0/9.0,  8.0/9.0,
  348.   -2.0/9.0,  6.0/9.0,  8.0/9.0,        0.0,  6.0/9.0,  8.0/9.0,    2.0/9.0,  6.0/9.0,  8.0/9.0,
  349.    4.0/9.0,  6.0/9.0,  8.0/9.0,    6.0/9.0,  6.0/9.0,  8.0/9.0,    8.0/9.0,  6.0/9.0,  8.0/9.0,
  350.   -8.0/9.0,  8.0/9.0,  8.0/9.0,   -6.0/9.0,  8.0/9.0,  8.0/9.0,   -4.0/9.0,  8.0/9.0,  8.0/9.0,
  351.   -2.0/9.0,  8.0/9.0,  8.0/9.0,        0.0,  8.0/9.0,  8.0/9.0,    2.0/9.0,  8.0/9.0,  8.0/9.0,
  352.    4.0/9.0,  8.0/9.0,  8.0/9.0,    6.0/9.0,  8.0/9.0,  8.0/9.0,    8.0/9.0,  8.0/9.0,  8.0/9.0
  353. };
  354.  
  355.  
  356. // data taken from ISO/IEC DIS 11172, Annexes 3-B.2[abcd] and 3-B.4:
  357.  
  358. // subbands 0-2 in tables 3-B.2a and 2b: (index is allocation)
  359. static const uint32 table_ab1_codelength[16] =
  360.   // bits per codeword
  361. { 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
  362.  
  363. static const real *table_ab1_groupingtables[16] =
  364.   // pointer to sample grouping table, or NULL-pointer if ungrouped
  365. { 0, grouping_5bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  366.  
  367. static const real table_ab1_factor[16] =
  368.   // factor for requantization: (real)sample * factor - 1.0 gives requantized sample
  369. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  370.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0,
  371.   1.0/4096.0, 1.0/8192.0, 1.0/16384.0, 1.0/32768.0 };
  372.  
  373. static const real table_ab1_c[16] =
  374.   // factor c for requantization from table 3-B.4
  375. { 0.0,           1.33333333333, 1.14285714286, 1.06666666666, 1.03225806452,
  376.   1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711,
  377.   1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851,
  378.   1.00001525902 };
  379. static const real table_ab1_d[16] =
  380.   // addend d for requantization from table 3-B.4
  381. { 0.0,           0.50000000000, 0.25000000000, 0.12500000000, 0.06250000000,
  382.   0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500,
  383.   0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516,
  384.   0.00003051758 };
  385.  
  386. // subbands 3-... tables 3-B.2a and 2b:
  387. static const real *table_ab234_groupingtables[16] =
  388. { 0, grouping_5bits, grouping_7bits, 0, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  389.  
  390. // subbands 3-10 in tables 3-B.2a and 2b:
  391. static const uint32 table_ab2_codelength[16] =
  392. { 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 };
  393. static const real table_ab2_factor[16] =
  394. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0,
  395.   1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0,
  396.   1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/32768.0 };
  397. static const real table_ab2_c[16] =
  398. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  399.   1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863,
  400.   1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522,
  401.   1.00001525902 };
  402. static const real table_ab2_d[16] =
  403. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  404.   0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000,
  405.   0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063,
  406.   0.00003051758 };
  407.  
  408. // subbands 11-22 in tables 3-B.2a and 2b:
  409. static const uint32 table_ab3_codelength[8] = { 0, 5, 7, 3, 10, 4, 5, 16 };
  410. static const real table_ab3_factor[8] =
  411. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32768.0 };
  412. static const real table_ab3_c[8] =
  413. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  414.   1.06666666666, 1.03225806452, 1.00001525902 };
  415. static const real table_ab3_d[8] =
  416. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  417.   0.12500000000, 0.06250000000, 0.00003051758 };
  418.  
  419. // subbands 23-... in tables 3-B.2a and 2b:
  420. static const uint32 table_ab4_codelength[4] = { 0, 5, 7, 16 };
  421. static const real table_ab4_factor[8] = { 0.0, 1.0/2.0, 1.0/4.0, 1.0/32768.0 };
  422. static const real table_ab4_c[4] = { 0.0, 1.33333333333, 1.60000000000, 1.00001525902 };
  423. static const real table_ab4_d[4] = { 0.0, 0.50000000000, 0.50000000000, 0.00003051758 };
  424.  
  425. // subbands in tables 3-B.2c and 2d:
  426. static const uint32 table_cd_codelength[16] =
  427. { 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  428. static const real *table_cd_groupingtables[16] =
  429. { 0, grouping_5bits, grouping_7bits, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  430. static const real table_cd_factor[16] =
  431. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  432.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0,
  433.   1.0/8192.0, 1.0/16384.0 };
  434. static const real table_cd_c[16] =
  435. { 0.0,           1.33333333333, 1.60000000000, 1.77777777777, 1.06666666666,
  436.   1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716,
  437.   1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888,
  438.   1.00003051851 };
  439. static const real table_cd_d[16] =
  440. { 0.0,           0.50000000000, 0.50000000000, 0.50000000000, 0.12500000000,
  441.   0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000,
  442.   0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031,
  443.   0.00006103516 };
  444.  
  445.  
  446.  
  447. /**********************/    // used for single channel mode
  448. /*** Standard Class ***/    // and in derived class for intensity
  449. /**********************/    // stereo mode
  450.  
  451. SubbandLayer2::SubbandLayer2(uint32 subbandnumber)
  452. {
  453.   this->subbandnumber = subbandnumber;
  454.   groupnumber = samplenumber = 0;
  455. }
  456.  
  457.  
  458. uint32 SubbandLayer2::get_allocationlength(Header *header)
  459. {
  460.  
  461.   if (header->version() == MPEG1) {
  462.  
  463.       uint32 channel_bitrate = header->bitrate_index();
  464.  
  465.       // calculate bitrate per channel:
  466.       if (header->mode() != single_channel)
  467.          if (channel_bitrate == 4)
  468.             channel_bitrate = 1;
  469.          else
  470.             channel_bitrate -= 4;
  471.  
  472.       if (channel_bitrate == 1 || channel_bitrate == 2)
  473.          // table 3-B.2c or 3-B.2d
  474.          if (subbandnumber <= 1)
  475.             return(4);
  476.          else
  477.             return(3);
  478.       else
  479.          // tables 3-B.2a or 3-B.2b
  480.          if (subbandnumber <= 10)
  481.             return(4);
  482.          else if (subbandnumber <= 22)
  483.             return(3);
  484.          else
  485.             return(2);
  486.  
  487.   } else { // MPEG-2 LSF -- Jeff
  488.  
  489.       // table B.1 of ISO/IEC 13818-3
  490.      if (subbandnumber <= 3)
  491.              return(4);
  492.      else if (subbandnumber <= 10)
  493.              return(3);
  494.      else
  495.              return(2);
  496.   }
  497.  
  498. }
  499.  
  500. void SubbandLayer2::prepare_sample_reading(Header *header, uint32 allocation,
  501.                                                           const real **groupingtable,
  502.                                            real *factor, uint32 *codelength,
  503.                                            real *c, real *d)
  504. {
  505.   uint32 channel_bitrate = header->bitrate_index();
  506.  
  507.   // calculate bitrate per channel:
  508.   if (header->mode() != single_channel)
  509.      if (channel_bitrate == 4)
  510.         channel_bitrate = 1;
  511.      else
  512.         channel_bitrate -= 4;
  513.  
  514.   if (channel_bitrate == 1 || channel_bitrate == 2)
  515.   {
  516.      // table 3-B.2c or 3-B.2d
  517.      *groupingtable = table_cd_groupingtables[allocation];
  518.      *factor = table_cd_factor[allocation];
  519.      *codelength = table_cd_codelength[allocation];
  520.      *c = table_cd_c[allocation];
  521.      *d = table_cd_d[allocation];
  522.   }
  523.   else
  524.   {
  525.      // tables 3-B.2a or 3-B.2b
  526.      if (subbandnumber <= 2)
  527.      {
  528.         *groupingtable = table_ab1_groupingtables[allocation];
  529.         *factor = table_ab1_factor[allocation];
  530.         *codelength = table_ab1_codelength[allocation];
  531.       *c = table_ab1_c[allocation];
  532.       *d = table_ab1_d[allocation];
  533.     }
  534.      else
  535.      {
  536.       *groupingtable = table_ab234_groupingtables[allocation];
  537.         if (subbandnumber <= 10)
  538.         {
  539.             *factor = table_ab2_factor[allocation];
  540.             *codelength = table_ab2_codelength[allocation];
  541.             *c = table_ab2_c[allocation];
  542.             *d = table_ab2_d[allocation];
  543.       }
  544.       else if (subbandnumber <= 22)
  545.       {
  546.             *factor = table_ab3_factor[allocation];
  547.             *codelength = table_ab3_codelength[allocation];
  548.             *c = table_ab3_c[allocation];
  549.             *d = table_ab3_d[allocation];
  550.       }
  551.         else
  552.       {
  553.             *factor = table_ab4_factor[allocation];
  554.             *codelength = table_ab4_codelength[allocation];
  555.             *c = table_ab4_c[allocation];
  556.             *d = table_ab4_d[allocation];
  557.       }
  558.     }
  559.   }
  560. }
  561.  
  562.  
  563. void SubbandLayer2::read_allocation(Ibitstream *stream, Header *header, Crc16 *crc)
  564. {
  565.   register uint32 length = get_allocationlength(header);
  566.   allocation = stream->get_bits(length);
  567.   if (crc)
  568.     crc->add_bits(allocation, length);
  569. }
  570.  
  571.  
  572. void SubbandLayer2::read_scalefactor_selection(Ibitstream *stream, Crc16 *crc)
  573. {
  574.   if (allocation)
  575.   {
  576.     scfsi = stream->get_bits(2);
  577.     if (crc)
  578.         crc->add_bits(scfsi, 2);
  579.   }
  580. }
  581.  
  582.  
  583. void SubbandLayer2::read_scalefactor(Ibitstream *stream, Header *header)
  584. {
  585.   if (allocation)
  586.   {
  587.     switch (scfsi)
  588.     {
  589.       case 0:
  590.          scalefactor1 = scalefactors[stream->get_bits(6)];
  591.        scalefactor2 = scalefactors[stream->get_bits(6)];
  592.        scalefactor3 = scalefactors[stream->get_bits(6)];
  593.        break;
  594.  
  595.         case 1:
  596.        scalefactor1 = scalefactor2 = scalefactors[stream->get_bits(6)];
  597.        scalefactor3 = scalefactors[stream->get_bits(6)];
  598.        break;
  599.       case 2:
  600.        scalefactor1 = scalefactor2 = scalefactor3 =
  601.                       scalefactors[stream->get_bits(6)];
  602.         break;
  603.  
  604.         case 3:
  605.        scalefactor1 = scalefactors[stream->get_bits(6)];
  606.        scalefactor2 = scalefactor3 = scalefactors[stream->get_bits(6)];
  607.        break;
  608.     }
  609.     prepare_sample_reading(header, allocation, &groupingtable,
  610.                 &factor, &codelength, &c, &d);
  611.   }
  612. }
  613.  
  614.  
  615. bool SubbandLayer2::read_sampledata(Ibitstream *stream)
  616. {
  617.   if (allocation)
  618.      if (groupingtable)
  619.      {
  620.         uint32 samplecode = stream->get_bits(codelength);
  621.         // create requantized samples:
  622.         samplecode += samplecode << 1;
  623.         register real *target = samples;
  624.         register const real *source = groupingtable + samplecode;
  625.         *target++ = *source++;
  626.         *target++ = *source++;
  627.         *target = *source;
  628.         // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
  629.      }
  630.      else
  631.      {
  632.         samples[0] = real (stream->get_bits(codelength)) * factor - 1.0;
  633.         samples[1] = real (stream->get_bits(codelength)) * factor - 1.0;
  634.         samples[2] = real (stream->get_bits(codelength)) * factor - 1.0;
  635.      }
  636.  
  637.   samplenumber = 0;
  638.   if (++groupnumber == 12)
  639.      return(TRUE);
  640.   else
  641.      return(FALSE);
  642. }
  643.  
  644.  
  645. bool SubbandLayer2::put_next_sample (e_channels channels,
  646.                                                  SynthesisFilter *filter1,
  647.                                      SynthesisFilter *)
  648. {
  649.   if (allocation && channels != right)
  650.   {
  651.      register real sample = samples[samplenumber];
  652.  
  653.      if (!groupingtable)
  654.         sample = (sample + d) * c;
  655.      if (groupnumber <= 4)
  656.         sample *= scalefactor1;
  657.      else if (groupnumber <= 8)
  658.         sample *= scalefactor2;
  659.      else
  660.         sample *= scalefactor3;
  661.      filter1->input_sample(sample, subbandnumber);
  662.   }
  663.  
  664.   if (++samplenumber == 3)
  665.      return(TRUE);
  666.   else
  667.      return(FALSE);
  668. }
  669.  
  670.  
  671.  
  672. /******************************/
  673. /*** Intensity Stereo Class ***/
  674. /******************************/
  675.  
  676. SubbandLayer2IntensityStereo::SubbandLayer2IntensityStereo(uint32 subbandnumber)
  677. : SubbandLayer2(subbandnumber)
  678. {
  679. }
  680.  
  681.  
  682. void SubbandLayer2IntensityStereo::read_scalefactor_selection(Ibitstream *stream,
  683.                                                                                   Crc16 *crc)
  684. {
  685.   if (allocation)
  686.   {
  687.      scfsi = stream->get_bits(2);
  688.      channel2_scfsi = stream->get_bits(2);
  689.      if (crc)
  690.      {
  691.         crc->add_bits(scfsi, 2);
  692.         crc->add_bits(channel2_scfsi, 2);
  693.      }
  694.   }
  695. }
  696.  
  697.  
  698. void SubbandLayer2IntensityStereo::read_scalefactor(Ibitstream *stream, Header *header)
  699. {
  700.   if (allocation)
  701.   {
  702.      SubbandLayer2::read_scalefactor(stream, header);
  703.      switch (channel2_scfsi)
  704.      {
  705.         case 0:
  706.         channel2_scalefactor1 = scalefactors[stream->get_bits(6)];
  707.         channel2_scalefactor2 = scalefactors[stream->get_bits(6)];
  708.         channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  709.         break;
  710.  
  711.         case 1:
  712.         channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  713.         channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  714.         break;
  715.  
  716.         case 2:
  717.         channel2_scalefactor1 = channel2_scalefactor2 =
  718.         channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  719.         break;
  720.  
  721.         case 3:
  722.         channel2_scalefactor1 = scalefactors[stream->get_bits(6)];
  723.         channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  724.         break;
  725.      }
  726.   }
  727. }
  728.  
  729.  
  730. bool SubbandLayer2IntensityStereo::put_next_sample (e_channels channels,
  731.     SynthesisFilter *filter1, SynthesisFilter *filter2)
  732. {
  733.   if (allocation)
  734.   {
  735.      register real sample = samples[samplenumber];
  736.  
  737.      if (!groupingtable)
  738.         sample = (sample + d) * c;
  739.     if (channels == both)
  740.     {
  741.         register float sample2 = sample;
  742.       if (groupnumber <= 4)
  743.       {
  744.     sample *= scalefactor1;
  745.     sample2 *= channel2_scalefactor1;
  746.         }
  747.         else if (groupnumber <= 8)
  748.         {
  749.     sample *= scalefactor2;
  750.     sample2 *= channel2_scalefactor2;
  751.         }
  752.         else
  753.         {
  754.     sample *= scalefactor3;
  755.     sample2 *= channel2_scalefactor3;
  756.         }
  757.         filter1->input_sample(sample, subbandnumber);
  758.       filter2->input_sample(sample2, subbandnumber);
  759.     }
  760.     else if (channels == left)
  761.      {
  762.         if (groupnumber <= 4)
  763.             sample *= scalefactor1;
  764.       else if (groupnumber <= 8)
  765.             sample *= scalefactor2;
  766.         else
  767.             sample *= scalefactor3;
  768.         filter1->input_sample(sample, subbandnumber);
  769.      }
  770.      else
  771.      {
  772.         if (groupnumber <= 4)
  773.             sample *= channel2_scalefactor1;
  774.         else if (groupnumber <= 8)
  775.             sample *= channel2_scalefactor2;
  776.         else
  777.             sample *= channel2_scalefactor3;
  778.         filter1->input_sample(sample, subbandnumber);
  779.      }
  780.   }
  781.  
  782.   if (++samplenumber == 3)
  783.      return(TRUE);
  784.   else
  785.      return(FALSE);
  786. }
  787.  
  788.  
  789.  
  790. /********************/
  791. /*** Stereo Class ***/
  792. /********************/
  793.  
  794. SubbandLayer2Stereo::SubbandLayer2Stereo(uint32 subbandnumber)
  795. : SubbandLayer2(subbandnumber)
  796. {
  797. }
  798.  
  799.  
  800. void SubbandLayer2Stereo::read_allocation(Ibitstream *stream, Header *header, Crc16 *crc)
  801. {
  802.   uint32 length = get_allocationlength(header);
  803.   allocation = stream->get_bits(length);
  804.   channel2_allocation = stream->get_bits(length);
  805.   if (crc)
  806.   {
  807.      crc->add_bits(allocation, length);
  808.      crc->add_bits(channel2_allocation, length);
  809.   }
  810. }
  811.  
  812.  
  813. void SubbandLayer2Stereo::read_scalefactor_selection(Ibitstream *stream, Crc16 *crc)
  814. {
  815.   if (allocation)
  816.   {
  817.      scfsi = stream->get_bits(2);
  818.      if (crc)
  819.         crc->add_bits(scfsi, 2);
  820.   }
  821.   if (channel2_allocation)
  822.   {
  823.      channel2_scfsi = stream->get_bits(2);
  824.      if (crc)
  825.         crc->add_bits(channel2_scfsi, 2);
  826.   }
  827. }
  828.  
  829.  
  830. void SubbandLayer2Stereo::read_scalefactor(Ibitstream *stream, Header *header)
  831. {
  832.   SubbandLayer2::read_scalefactor(stream, header);
  833.   if (channel2_allocation)
  834.   {
  835.      switch (channel2_scfsi)
  836.      {
  837.         case 0:
  838.          channel2_scalefactor1 = scalefactors[stream->get_bits(6)];
  839.        channel2_scalefactor2 = scalefactors[stream->get_bits(6)];
  840.        channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  841.        break;
  842.  
  843.         case 1:
  844.        channel2_scalefactor1 = channel2_scalefactor2 =
  845.                                     scalefactors[stream->get_bits(6)];
  846.        channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  847.        break;
  848.  
  849.         case 2:
  850.        channel2_scalefactor1 = channel2_scalefactor2 =
  851.        channel2_scalefactor3 = scalefactors[stream->get_bits(6)];
  852.        break;
  853.  
  854.         case 3:
  855.        channel2_scalefactor1 = scalefactors[stream->get_bits(6)];
  856.        channel2_scalefactor2 = channel2_scalefactor3 =
  857.                                      scalefactors[stream->get_bits(6)];
  858.          break;
  859.      }
  860.      prepare_sample_reading(header, channel2_allocation, &channel2_groupingtable,
  861.                            &channel2_factor, &channel2_codelength, &channel2_c,
  862.                            &channel2_d);
  863.   }
  864. }
  865.  
  866.  
  867. bool SubbandLayer2Stereo::read_sampledata(Ibitstream *stream)
  868. {
  869.   bool returnvalue = SubbandLayer2::read_sampledata(stream);
  870.  
  871.   if (channel2_allocation)
  872.      if (channel2_groupingtable) {
  873.         uint32 samplecode = stream->get_bits(channel2_codelength);
  874.         // create requantized samples:
  875.         samplecode += samplecode << 1;
  876.         register real *target = channel2_samples;
  877.         register const real *source = channel2_groupingtable + samplecode;
  878.         *target++ = *source++;
  879.         *target++ = *source++;
  880.         *target = *source;
  881.         // memcpy (channel2_samples, channel2_groupingtable + samplecode, 3 * sizeof (real));
  882.     } else {
  883.         channel2_samples[0] = real (stream->get_bits(channel2_codelength)) *
  884.                                    channel2_factor - 1.0;
  885.         channel2_samples[1] = real (stream->get_bits(channel2_codelength)) *
  886.                                    channel2_factor - 1.0;
  887.         channel2_samples[2] = real (stream->get_bits(channel2_codelength)) *
  888.                             channel2_factor - 1.0;
  889.      }
  890.  
  891.   return(returnvalue);
  892. }
  893.  
  894.  
  895. bool SubbandLayer2Stereo::put_next_sample(e_channels channels,
  896.                                                         SynthesisFilter *filter1,
  897.                                           SynthesisFilter *filter2)
  898. {
  899.   bool returnvalue = SubbandLayer2::put_next_sample(channels, filter1, filter2);
  900.   if (channel2_allocation && channels != left)
  901.   {
  902.      register real sample = channel2_samples[samplenumber - 1];
  903.  
  904.      if (!channel2_groupingtable)
  905.         sample = (sample + channel2_d) * channel2_c;
  906.  
  907.      if (groupnumber <= 4)
  908.         sample *= channel2_scalefactor1;
  909.      else if (groupnumber <= 8)
  910.         sample *= channel2_scalefactor2;
  911.      else
  912.         sample *= channel2_scalefactor3;
  913.      if (channels == both)
  914.         filter2->input_sample(sample, subbandnumber);
  915.      else
  916.         filter1->input_sample(sample, subbandnumber);
  917.   }
  918.   return(returnvalue);
  919. }
  920.  
  921.  
  922.