Example #1
0
        void Decompress8Mono(BitStream bs, Stream outputStream)
        {
            int flag;

            flag = bs.ReadBit();             /* DataPresent */
            Console.WriteLine(flag == 1 ? "data present" : "data not present");
            flag = bs.ReadBit();             /* Is16Bits */
            Console.WriteLine(flag == 1 ? "16 bits" : "8 bits");
            flag = bs.ReadBit();             /* IsStereo */
            Console.WriteLine(flag == 1 ? "stereo" : "mono");

            HuffmanTree t = new HuffmanTree();
            byte        _base;

            t.Build(bs);

            _base = (byte)bs.ReadByte();

            OutputSample(outputStream, _base);

            while (bs.ReadCount < bs.Length)
            {
                /* read the huffman encoded deltas */
                int d = (int)t.Decode(bs);

                _base = (byte)(_base + d);

                OutputSample(outputStream, _base);
            }
            Console.WriteLine("outputted {0} bytes in samples for this frame.", outputStream.Position);
        }
Example #2
0
        void Decompress16Stereo(BitStream bs, Stream outputStream)
        {
            int flag;

            flag = bs.ReadBit();             /* DataPresent */
            Console.WriteLine(flag == 1 ? "data present" : "data not present");
            flag = bs.ReadBit();             /* IsStereo */
            Console.WriteLine(flag == 1 ? "stereo" : "mono");
            flag = bs.ReadBit();             /* Is16Bits */
            Console.WriteLine(flag == 1 ? "16 bits" : "8 bits");

            HuffmanTree ll = new HuffmanTree();
            HuffmanTree lh = new HuffmanTree();
            HuffmanTree rl = new HuffmanTree();
            HuffmanTree rh = new HuffmanTree();

            ll.Build(bs);
            lh.Build(bs);
            rl.Build(bs);
            rh.Build(bs);

            byte[] tmp = new byte[2];
            short  rightbase;
            short  leftbase;

            tmp[1]    = (byte)bs.ReadByte();
            tmp[0]    = (byte)bs.ReadByte();
            rightbase = BitConverter.ToInt16(tmp, 0);

            tmp[1]   = (byte)bs.ReadByte();
            tmp[0]   = (byte)bs.ReadByte();
            leftbase = BitConverter.ToInt16(tmp, 0);

            Console.WriteLine("initial bases = {0}, {1}", leftbase, rightbase);
            OutputSample(outputStream, leftbase, rightbase);

            while (bs.ReadCount < bs.Length)
            {
                /* read the huffman encoded deltas */
                tmp[0] = (byte)(ll == null ? 0 : ll.Decode(bs));
                tmp[1] = (byte)(lh == null ? 0 : lh.Decode(bs));

                short leftdelta = BitConverter.ToInt16(tmp, 0);

                tmp[0] = (byte)(rl == null ? 0 : rl.Decode(bs));
                tmp[1] = (byte)(rh == null ? 0 : rh.Decode(bs));

                short rightdelta = BitConverter.ToInt16(tmp, 0);

                rightbase += rightdelta;
                leftbase  += leftdelta;

                OutputSample(outputStream, leftbase, rightbase);
            }

            Console.WriteLine("outputted {0} bytes in samples for this frame.", outputStream.Position);
        }
Example #3
0
        void Decompress16Mono(BitStream bs, Stream outputStream)
        {
            int flag;

            flag = bs.ReadBit();             /* DataPresent */
            Console.WriteLine(flag == 1 ? "data present" : "data not present");
            flag = bs.ReadBit();             /* Is16Bits */
            Console.WriteLine(flag == 1 ? "16 bits" : "8 bits");
            flag = bs.ReadBit();             /* IsStereo */
            Console.WriteLine(flag == 1 ? "stereo" : "mono");

            HuffmanTree h = new HuffmanTree();
            HuffmanTree l = new HuffmanTree();

            byte[] _base = new byte[2];

            l.Build(bs);
            h.Build(bs);

            _base[1] = (byte)bs.ReadByte();
            _base[0] = (byte)bs.ReadByte();

            OutputSample(outputStream, _base);

            while (bs.ReadCount < bs.Length)
            {
                /* read the huffman encoded deltas */
                int ld = (int)l.Decode(bs);
                int hd = (int)h.Decode(bs);

                if (ld + _base[0] > 255)
                {
                    _base[1] += 1;
                    _base[0]  = (byte)(ld + _base[0] - 255);
                }
                else
                {
                    _base[0] = (byte)(hd + _base[0]);
                }
                _base[1] = (byte)(hd + _base[1]);

                OutputSample(outputStream, _base);
            }
            Console.WriteLine("outputted {0} bytes in samples for this frame.", outputStream.Position);
        }
Example #4
0
        uint DecodeValue(BitStream bs)
        {
            uint lowValue, highValue;

            lowValue = 0;
            if (lowTree != null)
            {
                lowValue = lowTree.Decode(bs);
            }

            highValue = 0;
            if (highTree != null)
            {
                highValue = highTree.Decode(bs);
            }

            return(lowValue | (highValue << 8));
        }
Example #5
0
        void Decompress8Stereo(BitStream bs, Stream outputStream)
        {
            int flag;

            flag = bs.ReadBit();             /* DataPresent */
            Console.WriteLine(flag == 1 ? "data present" : "data not present");
            flag = bs.ReadBit();             /* Is16Bits */
            Console.WriteLine(flag == 1 ? "16 bits" : "8 bits");
            flag = bs.ReadBit();             /* IsStereo */
            Console.WriteLine(flag == 1 ? "stereo" : "mono");

            HuffmanTree r = new HuffmanTree();
            HuffmanTree l = new HuffmanTree();
            byte        leftbase;
            byte        rightbase;

            l.Build(bs);
            r.Build(bs);

            rightbase = (byte)bs.ReadByte();
            leftbase  = (byte)bs.ReadByte();

            OutputSample(outputStream, leftbase, rightbase);

            while (bs.ReadCount < bs.Length)
            {
                /* read the huffman encoded deltas */
                int rd = (int)r.Decode(bs);
                int ld = (int)l.Decode(bs);

                rightbase = (byte)(rightbase + rd);
                leftbase  = (byte)(leftbase + ld);

                OutputSample(outputStream, leftbase, rightbase);
            }
            Console.WriteLine("outputted {0} bytes in samples for this frame.", outputStream.Position);
        }
Example #6
0
		void Decompress8Mono (BitStream bs, Stream outputStream)
		{
			int flag;

			flag = bs.ReadBit(); /* DataPresent */
			Console.WriteLine (flag == 1 ? "data present" : "data not present");
			flag = bs.ReadBit(); /* Is16Bits */
			Console.WriteLine (flag == 1 ? "16 bits" : "8 bits");
			flag = bs.ReadBit(); /* IsStereo */
			Console.WriteLine (flag == 1 ? "stereo" : "mono");

			HuffmanTree t = new HuffmanTree();
			byte _base;

			t.Build (bs);

			_base = (byte)bs.ReadByte();

			OutputSample (outputStream, _base);

			while (bs.ReadCount < bs.Length) {
				/* read the huffman encoded deltas */
				int d = (int)t.Decode (bs);

				_base = (byte)(_base + d);

				OutputSample (outputStream, _base);
			}
			Console.WriteLine ("outputted {0} bytes in samples for this frame.", outputStream.Position);
		}
Example #7
0
		void Decompress8Stereo (BitStream bs, Stream outputStream)
		{
			int flag;

			flag = bs.ReadBit(); /* DataPresent */
			Console.WriteLine (flag == 1 ? "data present" : "data not present");
			flag = bs.ReadBit(); /* Is16Bits */
			Console.WriteLine (flag == 1 ? "16 bits" : "8 bits");
			flag = bs.ReadBit(); /* IsStereo */
			Console.WriteLine (flag == 1 ? "stereo" : "mono");

			HuffmanTree r = new HuffmanTree();
			HuffmanTree l = new HuffmanTree();
			byte leftbase;
			byte rightbase;

			l.Build (bs);
			r.Build (bs);

			rightbase = (byte)bs.ReadByte();
			leftbase = (byte)bs.ReadByte();

			OutputSample (outputStream, leftbase, rightbase);

			while (bs.ReadCount < bs.Length) {
				/* read the huffman encoded deltas */
				int rd = (int)r.Decode (bs);
				int ld = (int)l.Decode (bs);

				rightbase = (byte)(rightbase + rd);
				leftbase = (byte)(leftbase + ld);

				OutputSample (outputStream, leftbase, rightbase);
			}
			Console.WriteLine ("outputted {0} bytes in samples for this frame.", outputStream.Position);
		}
Example #8
0
		void Decompress16Mono (BitStream bs, Stream outputStream)
		{
			int flag;

			flag = bs.ReadBit(); /* DataPresent */
			Console.WriteLine (flag == 1 ? "data present" : "data not present");
			flag = bs.ReadBit(); /* Is16Bits */
			Console.WriteLine (flag == 1 ? "16 bits" : "8 bits");
			flag = bs.ReadBit(); /* IsStereo */
			Console.WriteLine (flag == 1 ? "stereo" : "mono");

			HuffmanTree h = new HuffmanTree();
			HuffmanTree l = new HuffmanTree();
			byte[] _base = new byte[2];

			l.Build (bs);
			h.Build (bs);

			_base[1] = (byte)bs.ReadByte();
			_base[0] = (byte)bs.ReadByte();

			OutputSample (outputStream, _base);

			while (bs.ReadCount < bs.Length) {
				/* read the huffman encoded deltas */
				int ld = (int)l.Decode (bs);
				int hd = (int)h.Decode (bs);

				if (ld + _base[0] > 255) {
					_base[1] += 1;
					_base[0] = (byte)(ld + _base[0] - 255);
				}
				else
					_base[0] = (byte)(hd + _base[0]);
				_base[1] = (byte)(hd + _base[1]);

				OutputSample (outputStream, _base);
			}
			Console.WriteLine ("outputted {0} bytes in samples for this frame.", outputStream.Position);
		}
Example #9
0
		void Decompress16Stereo (BitStream bs, Stream outputStream)
		{
			int flag;

			flag = bs.ReadBit(); /* DataPresent */
			Console.WriteLine (flag == 1 ? "data present" : "data not present");
			flag = bs.ReadBit(); /* IsStereo */
			Console.WriteLine (flag == 1 ? "stereo" : "mono");
			flag = bs.ReadBit(); /* Is16Bits */
			Console.WriteLine (flag == 1 ? "16 bits" : "8 bits");

			HuffmanTree ll = new HuffmanTree();
			HuffmanTree lh = new HuffmanTree();
			HuffmanTree rl = new HuffmanTree();
			HuffmanTree rh = new HuffmanTree();

			ll.Build (bs);
			lh.Build (bs);
			rl.Build (bs);
			rh.Build (bs);

			byte[] tmp = new byte[2];
			short rightbase;
			short leftbase;

			tmp[1] = (byte)bs.ReadByte();
			tmp[0] = (byte)bs.ReadByte();
			rightbase = BitConverter.ToInt16 (tmp, 0);

			tmp[1] = (byte)bs.ReadByte();
			tmp[0] = (byte)bs.ReadByte();
			leftbase = BitConverter.ToInt16 (tmp, 0);

			Console.WriteLine ("initial bases = {0}, {1}", leftbase, rightbase);
			OutputSample (outputStream, leftbase, rightbase);

			while (bs.ReadCount < bs.Length) {
				/* read the huffman encoded deltas */
				tmp[0] = (byte)(ll == null ? 0 : ll.Decode (bs));
				tmp[1] = (byte)(lh == null ? 0 : lh.Decode (bs));

				short leftdelta = BitConverter.ToInt16 (tmp, 0);

				tmp[0] = (byte)(rl == null ? 0 : rl.Decode (bs));
				tmp[1] = (byte)(rh == null ? 0 : rh.Decode (bs));

				short rightdelta = BitConverter.ToInt16 (tmp, 0);

				rightbase += rightdelta;
				leftbase += leftdelta;

				OutputSample (outputStream, leftbase, rightbase);
			}

			Console.WriteLine ("outputted {0} bytes in samples for this frame.", outputStream.Position);
		}