home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09964.iso / sound / mpw32-5s.zip / SUBLAY2.CPP < prev    next >
C/C++ Source or Header  |  1996-07-13  |  46KB  |  944 lines

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