public Layer2(Header h, IAudio audio) {
		super(h, audio);
		header = h;
		channels = h.getChannels();
		bs = new BitStream(4096, 512);

		nbal = new byte[5][];
		// ISO/IEC 11172-3 Table 3-B.2a
		nbal[0] = new byte[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2 };

		// ISO/IEC 11172-3 Table 3-B.2b
		nbal[1] = new byte[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
				3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2 };

		// ISO/IEC 11172-3 Table 3-B.2c
		nbal[2] = new byte[] { 4, 4, 3, 3, 3, 3, 3, 3 };

		// ISO/IEC 11172-3 Table 3-B.2d
		nbal[3] = new byte[] { 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

		// ISO/IEC 13818-3 Table B.1
		nbal[4] = new byte[] { 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2,
				2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
		
		aidx_table = new byte[][][] {
			{{0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0},{0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 }},
			{{0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0},{0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 }},
			{{0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0},{0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 }}};

		// cq_xxx: Layer II classes of quantization, ISO/IEC 11172-3 Table 3-B.4
		cq_steps = new int[] { 3, 5, 7, 9, 15, 31, 63, 127, 255, 511, 1023,
				2047, 4095, 8191, 16383, 32767, 65535 };
		cq_C = new float[] { 1.3333333f, 1.6f, 1.1428571f, 1.77777778f,
				1.0666667f, 1.0322581f, 1.015873f, 1.007874f, 1.0039216f,
				1.0019569f, 1.0009775f, 1.0004885f, 1.0002442f, 1.000122f,
				1.000061f, 1.0000305f, 1.00001525902f };
		cq_D = new float[] { 0.5f, 0.5f, 0.25f, 0.5f, 0.125f, 0.0625f,
				0.03125f, 0.015625f, 0.0078125f, 0.00390625f, 0.001953125f,
				0.0009765625f, 0.00048828125f, 0.00024414063f, 0.00012207031f,
				0.00006103516f, 0.00003051758f };
		cq_bits = new byte[] {5,7,3,10,4,5,6,7,8,9,10,11,12,13,14,15,16};

		sbquant_offset = new byte[][] {
			// ISO/IEC 11172-3 Table 3-B.2a
			{7,7,7,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,3,3,	3,3,3,0,0,0,0},

			// ISO/IEC 11172-3 Table 3-B.2b
			{7,7,7,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,3,3,	3,3,3,0,0,0,0,0,0,0},

			// ISO/IEC 11172-3 Table 3-B.2c
			{5,5,2,2,2,2,2,2},

			// ISO/IEC 11172-3 Table 3-B.2d
			{5,5,2,2,2,2,2,2,2,2,2,2},

			// ISO/IEC 13818-3 Table B.1
			{4,4,4,4,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,	1,1,1,1,1,1,1,1,1,1} };

		bitalloc_offset = new byte[] { 0, 3, 3, 1, 2, 3, 4, 5 };
		offset_table = new byte[][] { { 0, 1, 16 }, { 0, 1, 2, 3, 4, 5, 16 },
				{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
				{ 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
				{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 },
				{ 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } };
		group = new byte[] { 2, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

		allocation = new byte[2][32];
		scfsi = new byte[2][32];
		scalefactor = new byte[2][32][3];
		samplecode = new int[3];
		syin = new float[2][3][32];

		//aidx,sblimit...
		if(header.getVersion() == Header.MPEG2) {
			aidx = 4;
			sblimit = 30;
		} else {
			aidx = aidx_table[header.getSamplingFrequency()][2-channels][header.getBitrateIndex()];
			if(aidx == 0) sblimit = 27;
			else if(aidx == 1) sblimit = 30;
			else if(aidx == 2) sblimit = 8;
			else sblimit = 12;
		}
	}