internal int DecodeScalar(DataPacket packet) { int index = (int)packet.TryPeekBits(PrefixBitLength, out int bitsRead); if (bitsRead == 0) { return(-1); } HuffmanListNode huffmanListNode = PrefixList[index]; if (huffmanListNode != null) { packet.SkipBits(huffmanListNode.Length); return(huffmanListNode.Value); } index = (int)packet.TryPeekBits(MaxBits, out bitsRead); huffmanListNode = PrefixOverflowTree; do { if (huffmanListNode.Bits == (index & huffmanListNode.Mask)) { packet.SkipBits(huffmanListNode.Length); return(huffmanListNode.Value); } }while ((huffmanListNode = huffmanListNode.Next) != null); return(-1); }
internal int DecodeScalar(DataPacket packet) { int bitCnt; var bits = (int)packet.TryPeekBits(PrefixBitLength, out bitCnt); if (bitCnt == 0) { return(-1); } // try to get the value from the prefix list... var node = PrefixList[bits]; if (node != null) { packet.SkipBits(node.Length); return(node.Value); } // nope, not possible... run the tree bits = (int)packet.TryPeekBits(MaxBits, out bitCnt); node = PrefixOverflowTree; do { if (node.Bits == (bits & node.Mask)) { packet.SkipBits(node.Length); return(node.Value); } } while ((node = node.Next) != null); return(-1); }
void LoadComments(DataPacket packet) { packet.SkipBits(8); if (!packet.ReadBytes(6).SequenceEqual(new byte[] { 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 })) { throw new InvalidDataException("Corrupted comment header!"); } _glueBits += 56; { byte[] vendorBytes = packet.ReadBytes(packet.ReadInt32()); _vendor = Encoding.UTF8.GetString(vendorBytes, 0, vendorBytes.Length); } _comments = new string[packet.ReadInt32()]; for (int i = 0; i < _comments.Length; i++) { byte[] commentBytes = packet.ReadBytes(packet.ReadInt32()); _comments[i] = Encoding.UTF8.GetString(commentBytes, 0, commentBytes.Length); } _metaBits += packet.BitsRead - 56; _wasteHdrBits += 8 * packet.Length - packet.BitsRead; }
internal int DecodeScalar(DataPacket packet) { int bitCnt; var bits = (int)packet.TryPeekBits(PrefixBitLength, out bitCnt); if (bitCnt == 0) return -1; // try to get the value from the prefix list... var node = PrefixList[bits]; if (node != null) { packet.SkipBits(node.Length); return node.Value; } // nope, not possible... run the tree bits = (int)packet.TryPeekBits(MaxBits, out bitCnt); node = PrefixOverflowTree; do { if (node.Bits == (bits & node.Mask)) { packet.SkipBits(node.Length); return node.Value; } } while ((node = node.Next) != null); return -1; }
private void LoadComments(DataPacket packet) { packet.SkipBits(8); if (!Enumerable.SequenceEqual <byte>((IEnumerable <byte>)packet.ReadBytes(6), (IEnumerable <byte>) new byte[6] { (byte)118, (byte)111, (byte)114, (byte)98, (byte)105, (byte)115 })) { throw new InvalidDataException("Corrupted comment header!"); } this._glueBits += 56L; this._vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32())); this._comments = new string[packet.ReadInt32()]; for (int index = 0; index < this._comments.Length; ++index) { this._comments[index] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32())); } this._metaBits += packet.BitsRead - 56L; this._wasteHdrBits += (long)(8 * packet.Length) - packet.BitsRead; }
internal int DecodeScalar(DataPacket packet) { // try to get as many bits as possible... int bitCnt; // we really don't care how many bits were read; try to decode anyway... var bits = (int)packet.TryPeekBits(MaxBits, out bitCnt); if (bitCnt == 0) { return(-1); } // now go through the list and find the matching entry var node = LTree; while (node != null) { if (node.Bits == (bits & node.Mask)) { node.HitCount++; packet.SkipBits(node.Length); return(node.Value); } node = node.Next; } return(-1); }
internal int DecodeScalar(DataPacket packet) { int bitsRead; int num = (int)packet.TryPeekBits(this.MaxBits, out bitsRead); if (bitsRead == 0) { throw new InvalidDataException(); } for (HuffmanListNode <int> huffmanListNode = this.LTree; huffmanListNode != null; huffmanListNode = huffmanListNode.Next) { if (huffmanListNode.Bits == (num & huffmanListNode.Mask)) { ++huffmanListNode.HitCount; packet.SkipBits(huffmanListNode.Length); return(huffmanListNode.Value); } } throw new InvalidDataException(); }
internal int DecodeScalar(DataPacket packet) { // try to get as many bits as possible... int bitCnt; // we really don't care how many bits were read; try to decode anyway... var bits = (int)packet.TryPeekBits(MaxBits, out bitCnt); if (bitCnt == 0) throw new InvalidDataException(); // now go through the list and find the matching entry var node = LTree; while (node != null) { if (node.Bits == (bits & node.Mask)) { node.HitCount++; packet.SkipBits(node.Length); return node.Value; } node = node.Next; } throw new InvalidDataException(); }
void LoadBooks(DataPacket packet) { packet.SkipBits(8); if (!packet.ReadBytes(6).SequenceEqual(new byte[] { 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 })) { throw new InvalidDataException("Corrupted book header!"); } var bits = packet.BitsRead; _glueBits += packet.BitsRead; // get books Books = new VorbisCodebook[packet.ReadByte() + 1]; for (int i = 0; i < Books.Length; i++) { Books[i] = VorbisCodebook.Init(this, packet, i); } _bookBits += packet.BitsRead - bits; bits = packet.BitsRead; // get times Times = new VorbisTime[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Times.Length; i++) { Times[i] = VorbisTime.Init(this, packet); } _timeHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get floor Floors = new VorbisFloor[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Floors.Length; i++) { Floors[i] = VorbisFloor.Init(this, packet); } _floorHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get residue Residues = new VorbisResidue[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Residues.Length; i++) { Residues[i] = VorbisResidue.Init(this, packet); } _resHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get map Maps = new VorbisMapping[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Maps.Length; i++) { Maps[i] = VorbisMapping.Init(this, packet); } _mapHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get mode settings Modes = new VorbisMode[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Modes.Length; i++) { Modes[i] = VorbisMode.Init(this, packet); } _modeHdrBits += packet.BitsRead - bits; // check the framing bit if (!packet.ReadBit()) { throw new InvalidDataException(); } ++_glueBits; _wasteHdrBits += 8 * packet.Length - packet.BitsRead; _modeFieldBits = Utils.ilog(Modes.Length - 1); }
private void LoadBooks(DataPacket packet) { packet.SkipBits(8); if (!Enumerable.SequenceEqual<byte>((IEnumerable<byte>) packet.ReadBytes(6), (IEnumerable<byte>) new byte[6] { (byte) 118, (byte) 111, (byte) 114, (byte) 98, (byte) 105, (byte) 115 })) throw new InvalidDataException("Corrupted book header!"); long bitsRead1 = packet.BitsRead; this._glueBits += packet.BitsRead; this.Books = new VorbisCodebook[(int) packet.ReadByte() + 1]; for (int number = 0; number < this.Books.Length; ++number) this.Books[number] = VorbisCodebook.Init(this, packet, number); this._bookBits += packet.BitsRead - bitsRead1; long bitsRead2 = packet.BitsRead; this.Times = new VorbisTime[(int) packet.ReadBits(6) + 1]; for (int index = 0; index < this.Times.Length; ++index) this.Times[index] = VorbisTime.Init(this, packet); this._timeHdrBits += packet.BitsRead - bitsRead2; long bitsRead3 = packet.BitsRead; this.Floors = new VorbisFloor[(int) packet.ReadBits(6) + 1]; for (int index = 0; index < this.Floors.Length; ++index) this.Floors[index] = VorbisFloor.Init(this, packet); this._floorHdrBits += packet.BitsRead - bitsRead3; long bitsRead4 = packet.BitsRead; this.Residues = new VorbisResidue[(int) packet.ReadBits(6) + 1]; for (int index = 0; index < this.Residues.Length; ++index) this.Residues[index] = VorbisResidue.Init(this, packet); this._resHdrBits += packet.BitsRead - bitsRead4; long bitsRead5 = packet.BitsRead; this.Maps = new VorbisMapping[(int) packet.ReadBits(6) + 1]; for (int index = 0; index < this.Maps.Length; ++index) this.Maps[index] = VorbisMapping.Init(this, packet); this._mapHdrBits += packet.BitsRead - bitsRead5; long bitsRead6 = packet.BitsRead; this.Modes = new VorbisMode[(int) packet.ReadBits(6) + 1]; for (int index = 0; index < this.Modes.Length; ++index) this.Modes[index] = VorbisMode.Init(this, packet); this._modeHdrBits += packet.BitsRead - bitsRead6; if (!packet.ReadBit()) throw new InvalidDataException(); ++this._glueBits; this._wasteHdrBits += (long) (8 * packet.Length) - packet.BitsRead; this._modeFieldBits = Utils.ilog(this.Modes.Length - 1); }
private void LoadComments(DataPacket packet) { packet.SkipBits(8); if (!Enumerable.SequenceEqual<byte>((IEnumerable<byte>) packet.ReadBytes(6), (IEnumerable<byte>) new byte[6] { (byte) 118, (byte) 111, (byte) 114, (byte) 98, (byte) 105, (byte) 115 })) throw new InvalidDataException("Corrupted comment header!"); this._glueBits += 56L; this._vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32())); this._comments = new string[packet.ReadInt32()]; for (int index = 0; index < this._comments.Length; ++index) this._comments[index] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32())); this._metaBits += packet.BitsRead - 56L; this._wasteHdrBits += (long) (8 * packet.Length) - packet.BitsRead; }
void LoadComments(DataPacket packet) { byte [] temp; packet.SkipBits(8); if (!packet.ReadBytes(6).SequenceEqual(new byte[] { 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 })) throw new ArgumentException("Corrupted comment header!"); _glueBits += 56; temp = packet.ReadBytes ( packet.ReadInt32 () ); _vendor = Encoding.UTF8.GetString ( temp, 0, temp.Length ); _comments = new string[packet.ReadInt32()]; for (int i = 0; i < _comments.Length; i++) { temp = packet.ReadBytes ( packet.ReadInt32 () ); _comments[i] = Encoding.UTF8.GetString( temp, 0, temp.Length ); } _metaBits += packet.BitsRead - 56; _wasteHdrBits += 8 * packet.Length - packet.BitsRead; }
void LoadBooks(DataPacket packet) { packet.SkipBits(8); if ( !packet.ReadBytes ( 6 ).SequenceEqual ( new byte [] { 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 } ) ) throw new ArgumentException ( "Corrupted book header!" ); var bits = packet.BitsRead; _glueBits += packet.BitsRead; // get books Books = new VorbisCodebook[packet.ReadByte() + 1]; for (int i = 0; i < Books.Length; i++) { Books[i] = VorbisCodebook.Init(this, packet, i); } _bookBits += packet.BitsRead - bits; bits = packet.BitsRead; // get times Times = new VorbisTime[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Times.Length; i++) { Times[i] = VorbisTime.Init(this, packet); } _timeHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get floor Floors = new VorbisFloor[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Floors.Length; i++) { Floors[i] = VorbisFloor.Init(this, packet); } _floorHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get residue Residues = new VorbisResidue[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Residues.Length; i++) { Residues[i] = VorbisResidue.Init(this, packet); } _resHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get map Maps = new VorbisMapping[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Maps.Length; i++) { Maps[i] = VorbisMapping.Init(this, packet); } _mapHdrBits += packet.BitsRead - bits; bits = packet.BitsRead; // get mode settings Modes = new VorbisMode[(int)packet.ReadBits(6) + 1]; for (int i = 0; i < Modes.Length; i++) { Modes[i] = VorbisMode.Init(this, packet); } _modeHdrBits += packet.BitsRead - bits; // check the framing bit if ( !packet.ReadBit () ) throw new ArgumentException (); ++_glueBits; _wasteHdrBits += 8 * packet.Length - packet.BitsRead; _modeFieldBits = Utils.ilog(Modes.Length - 1); }
internal int DecodeScalar(DataPacket packet) { int bitsRead; int num = (int) packet.TryPeekBits(this.MaxBits, out bitsRead); if (bitsRead == 0) throw new InvalidDataException(); for (HuffmanListNode<int> huffmanListNode = this.LTree; huffmanListNode != null; huffmanListNode = huffmanListNode.Next) { if (huffmanListNode.Bits == (num & huffmanListNode.Mask)) { ++huffmanListNode.HitCount; packet.SkipBits(huffmanListNode.Length); return huffmanListNode.Value; } } throw new InvalidDataException(); }
private void LoadBooks(DataPacket packet) { packet.SkipBits(8); if (!Enumerable.SequenceEqual <byte>((IEnumerable <byte>)packet.ReadBytes(6), (IEnumerable <byte>) new byte[6] { (byte)118, (byte)111, (byte)114, (byte)98, (byte)105, (byte)115 })) { throw new InvalidDataException("Corrupted book header!"); } long bitsRead1 = packet.BitsRead; this._glueBits += packet.BitsRead; this.Books = new VorbisCodebook[(int)packet.ReadByte() + 1]; for (int number = 0; number < this.Books.Length; ++number) { this.Books[number] = VorbisCodebook.Init(this, packet, number); } this._bookBits += packet.BitsRead - bitsRead1; long bitsRead2 = packet.BitsRead; this.Times = new VorbisTime[(int)packet.ReadBits(6) + 1]; for (int index = 0; index < this.Times.Length; ++index) { this.Times[index] = VorbisTime.Init(this, packet); } this._timeHdrBits += packet.BitsRead - bitsRead2; long bitsRead3 = packet.BitsRead; this.Floors = new VorbisFloor[(int)packet.ReadBits(6) + 1]; for (int index = 0; index < this.Floors.Length; ++index) { this.Floors[index] = VorbisFloor.Init(this, packet); } this._floorHdrBits += packet.BitsRead - bitsRead3; long bitsRead4 = packet.BitsRead; this.Residues = new VorbisResidue[(int)packet.ReadBits(6) + 1]; for (int index = 0; index < this.Residues.Length; ++index) { this.Residues[index] = VorbisResidue.Init(this, packet); } this._resHdrBits += packet.BitsRead - bitsRead4; long bitsRead5 = packet.BitsRead; this.Maps = new VorbisMapping[(int)packet.ReadBits(6) + 1]; for (int index = 0; index < this.Maps.Length; ++index) { this.Maps[index] = VorbisMapping.Init(this, packet); } this._mapHdrBits += packet.BitsRead - bitsRead5; long bitsRead6 = packet.BitsRead; this.Modes = new VorbisMode[(int)packet.ReadBits(6) + 1]; for (int index = 0; index < this.Modes.Length; ++index) { this.Modes[index] = VorbisMode.Init(this, packet); } this._modeHdrBits += packet.BitsRead - bitsRead6; if (!packet.ReadBit()) { throw new InvalidDataException(); } ++this._glueBits; this._wasteHdrBits += (long)(8 * packet.Length) - packet.BitsRead; this._modeFieldBits = Utils.ilog(this.Modes.Length - 1); }