コード例 #1
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
        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);
        }
コード例 #2
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
        void ReadPaletteChunk(BitStream bs)
        {
            byte[] new_palette = new byte[256 * 3];

            bs.AssertAtByteBoundary();

            bs.ZeroReadCount();

            int paletteLength = bs.ReadByte();

            Console.WriteLine("palette chunk is {0} bytes long", paletteLength * 4);

            //			byte[] palBuf = new byte[paletteLength * 4 - 1];
            //			bs.Read (palBuf, 0, palBuf.Length);
            //			MemoryStream palStream = new MemoryStream (palBuf, false);

            BitStream palStream = bs;
            int       new_index = 0, index = 0;

            while (new_index < 256)
            {
                byte p = (byte)palStream.ReadByte();
                if ((p & 0x80) == 0x80)
                {
                    int count = (p & 0x7f) + 1;
                    //					Console.WriteLine ("copy1 {0} entries, from {1} to {2}", count, index, new_index);
                    Array.Copy(palette, index * 3, new_palette, new_index * 3, count * 3);
                    index     += count;
                    new_index += count;
                }
                else if ((p & 0x40) == 0x40)
                {
                    int count     = (p & 0x3f) + 1;
                    int tmp_index = palStream.ReadByte();
                    //					Console.WriteLine ("copy2 {0} entries, from {1} to {2}", count, tmp_index, new_index);
                    Array.Copy(palette, tmp_index * 3, new_palette, new_index * 3, count * 3);
                    new_index += count;
                }
                else if ((p & 0xc0) == 0x00)
                {
                    int b = p & 0x3f;
                    int g = palStream.ReadByte() & 0x3f;
                    int r = palStream.ReadByte() & 0x3f;
                    new_palette [new_index * 3]     = palmap[r];
                    new_palette [new_index * 3 + 1] = palmap[g];
                    new_palette [new_index * 3 + 2] = palmap[b];
                    //					Console.WriteLine ("Assign palette[{0}] = {1},{2},{3}", new_index,
                    //							   palmap[r], palmap[g], palmap[b]);
                    new_index++;
                }
            }

            palette = new_palette;
            //			Console.WriteLine ("read {0} bytes toward filling the palette", palBuf.Length + 1);
        }
コード例 #3
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
        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);
        }
コード例 #4
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
        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);
        }
コード例 #5
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
        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);
        }
コード例 #6
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		protected virtual void ReadValue (BitStream bs, HuffmanNode node)
		{
			node.value = (uint)bs.ReadByte();
		}
コード例 #7
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		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);
		}
コード例 #8
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		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);
		}
コード例 #9
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		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);
		}
コード例 #10
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		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);
		}
コード例 #11
0
ファイル: Smk.cs プロジェクト: carriercomm/scsharp
		void ReadPaletteChunk (BitStream bs)
		{
			byte[] new_palette = new byte[256 * 3];

			bs.AssertAtByteBoundary ();

			bs.ZeroReadCount ();

			int paletteLength = bs.ReadByte();
			Console.WriteLine ("palette chunk is {0} bytes long", paletteLength * 4);

			//			byte[] palBuf = new byte[paletteLength * 4 - 1];
			//			bs.Read (palBuf, 0, palBuf.Length);
			//			MemoryStream palStream = new MemoryStream (palBuf, false);

			BitStream palStream = bs;
			int new_index = 0, index = 0;
			while (new_index < 256) {
				byte p = (byte)palStream.ReadByte();
				if ((p & 0x80) == 0x80) {
					int count = (p & 0x7f) + 1;
					//					Console.WriteLine ("copy1 {0} entries, from {1} to {2}", count, index, new_index);
					Array.Copy (palette, index * 3, new_palette, new_index * 3, count * 3);
					index += count;
					new_index += count;
				}
				else if ((p & 0x40) == 0x40) {
					int count = (p & 0x3f) + 1;
					int tmp_index = palStream.ReadByte();
					//					Console.WriteLine ("copy2 {0} entries, from {1} to {2}", count, tmp_index, new_index);
					Array.Copy (palette, tmp_index * 3, new_palette, new_index * 3, count * 3);
					new_index += count;
				}
				else if ((p & 0xc0) == 0x00) {
					int b = p & 0x3f;
					int g = palStream.ReadByte() & 0x3f;
					int r = palStream.ReadByte() & 0x3f;
					new_palette [new_index * 3] = palmap[r];
					new_palette [new_index * 3 + 1] = palmap[g];
					new_palette [new_index * 3 + 2] = palmap[b];
					//					Console.WriteLine ("Assign palette[{0}] = {1},{2},{3}", new_index,
					//							   palmap[r], palmap[g], palmap[b]);
					new_index ++;
				}
			}

			palette = new_palette;
			//			Console.WriteLine ("read {0} bytes toward filling the palette", palBuf.Length + 1);
		}
コード例 #12
0
ファイル: Smk.cs プロジェクト: xerohour/scsharp
 protected virtual void ReadValue(BitStream bs, HuffmanNode node)
 {
     node.value = (uint)bs.ReadByte();
 }