public override void Build(BitStream bs) { bs.ZeroReadCount(); #if false int tag = bs.ReadBit(); if (tag == 1) { #endif lowTree = new HuffmanTree(); Console.WriteLine("building low tree"); lowTree.Build(bs); Console.WriteLine("low tree ends at {0:x}", bs.ReadCount); #if false } tag = bs.ReadBit(); if (tag == 1) { #endif highTree = new HuffmanTree(); Console.WriteLine("building high tree"); highTree.Build(bs); Console.WriteLine("high tree ends at {0:x}", bs.ReadCount); #if false } #endif markers[0] = bs.ReadWord(); markers[1] = bs.ReadWord(); markers[2] = bs.ReadWord(); Console.WriteLine("markers = {0:x}, {1:x}, {2:x}", markers[0], markers[1], markers[2]); Read(bs); Console.WriteLine("shortest1 = {0}", shortest[0]); Console.WriteLine("shortest2 = {0}", shortest[1]); Console.WriteLine("shortest3 = {0}", shortest[2]); }
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); }
public HuffIter (HuffmanTree tree) { this.tree = tree; this.currentNode = tree.Root; }
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); }
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); }
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); }
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); }
public override void Build (BitStream bs) { bs.ZeroReadCount (); #if false int tag = bs.ReadBit(); if (tag == 1) { #endif lowTree = new HuffmanTree (); Console.WriteLine ("building low tree"); lowTree.Build (bs); Console.WriteLine ("low tree ends at {0:x}", bs.ReadCount); #if false } tag = bs.ReadBit (); if (tag == 1) { #endif highTree = new HuffmanTree (); Console.WriteLine ("building high tree"); highTree.Build (bs); Console.WriteLine ("high tree ends at {0:x}", bs.ReadCount); #if false } #endif markers[0] = bs.ReadWord (); markers[1] = bs.ReadWord (); markers[2] = bs.ReadWord (); Console.WriteLine ("markers = {0:x}, {1:x}, {2:x}", markers[0], markers[1], markers[2]); Read (bs); Console.WriteLine ("shortest1 = {0}", shortest[0]); Console.WriteLine ("shortest2 = {0}", shortest[1]); Console.WriteLine ("shortest3 = {0}", shortest[2]); }
public HuffIter(HuffmanTree tree) { this.tree = tree; this.currentNode = tree.Root; }