ReadInt32() public method

Retrieves the next 32 bits from the packet as a int and advances the position counter.
public ReadInt32 ( ) : int
return int
コード例 #1
0
        bool ProcessStreamHeader(DataPacket packet)
        {
            bool equal = true;

            byte[] sequence = new byte[] { 0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 };
            byte[] packets  = packet.ReadBytes(7);

            for (int i = 0; i < 7; i++)
            {
                if (packets[i] != sequence[i])
                {
                    equal = false;
                    break;
                }
            }

            if (!equal)
            {
                // don't mark the packet as done... it might be used elsewhere
                _glueBits += packet.Length * 8;
                return(false);
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber)))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            var startPos = packet.BitsRead;

            if (packet.ReadInt32() != 0)
            {
                throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
            }

            _channels       = packet.ReadByte();
            _sampleRate     = packet.ReadInt32();
            _upperBitrate   = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate   = packet.ReadInt32();

            Block0Size = 1 << (int)packet.ReadBits(4);
            Block1Size = 1 << (int)packet.ReadBits(4);

            if (_nominalBitrate == 0)
            {
                if (_upperBitrate > 0 && _lowerBitrate > 0)
                {
                    _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
                }
            }

            _metaBits += packet.BitsRead - startPos + 8;

            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #2
0
 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;
 }
コード例 #3
0
        bool LoadComments(DataPacket packet)
        {
            if (!CheckForHeader(packet, commentHeader))
            {
                return(false);
            }

            if (!_pagesSeen.Contains(_lastPageSeen = packet.PageSequenceNumber))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            int vendorSize = packet.ReadInt32();

            _vendor = Encoding.UTF8.GetString(packet.ReadBytes(vendorSize));

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                int commentSize = packet.ReadInt32();
                _comments[i] = Encoding.UTF8.GetString(packet.ReadBytes(commentSize));
            }

            _metaBits     += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #4
0
ファイル: VorbisStreamDecoder.cs プロジェクト: aharit/NVorbis
        bool LoadComments(DataPacket packet)
        {
            if (!ValidateHeader(packet, PacketSignatureComments))
            {
                _glueBits += packet.Length * 8;
                return(false);
            }

            _pagesSeen.Add(packet.PageSequenceNumber);

            _glueBits += 56;

            _vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                _comments[i] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));
            }

            _metaBits     += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
 public bool LoadComments(DataPacket packet)
 {
     if (!packet.ReadBytes(7).SequenceEqual(new byte[7]
     {
         3,
         118,
         111,
         114,
         98,
         105,
         115
     }))
     {
         return(false);
     }
     if (!_pagesSeen.Contains(_lastPageSeen = packet.PageSequenceNumber))
     {
         _pagesSeen.Add(_lastPageSeen);
     }
     _glueBits += 56L;
     byte[] array = packet.ReadBytes(packet.ReadInt32());
     _vendor   = Encoding.UTF8.GetString(array, 0, array.Length);
     _comments = new string[packet.ReadInt32()];
     for (int i = 0; i < _comments.Length; i++)
     {
         byte[] array2 = packet.ReadBytes(packet.ReadInt32());
         _comments[i] = Encoding.UTF8.GetString(array2, 0, array2.Length);
     }
     _metaBits     += packet.BitsRead - 56;
     _wasteHdrBits += 8 * packet.Length - packet.BitsRead;
     return(true);
 }
コード例 #7
0
        void ProcessStreamHeader(DataPacket packet)
        {
            _pagesSeen.Add(packet.PageSequenceNumber);

            var startPos = packet.BitsRead;

            if (packet.ReadInt32() != 0)
            {
                throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
            }

            _channels       = packet.ReadByte();
            _sampleRate     = packet.ReadInt32();
            _upperBitrate   = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate   = packet.ReadInt32();

            Block0Size = 1 << (int)packet.ReadBits(4);
            Block1Size = 1 << (int)packet.ReadBits(4);

            if (_nominalBitrate == 0)
            {
                if (_upperBitrate > 0 && _lowerBitrate > 0)
                {
                    _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
                }
            }

            _metaBits += packet.BitsRead - startPos + 8;

            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;
        }
コード例 #8
0
        bool LoadComments(DataPacket packet)
        {
            if (!packet.ReadBytes(7).SequenceEqual(new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 }))
            {
                return(false);
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber)))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            byte[] vs = packet.ReadBytes(packet.ReadInt32());
            _vendor = Encoding.UTF8.GetString(vs, 0, vs.Length);

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                vs           = packet.ReadBytes(packet.ReadInt32());
                _comments[i] = Encoding.UTF8.GetString(vs, 0, vs.Length);
            }

            _metaBits     += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #9
0
        bool LoadComments(DataPacket packet)
        {
            bool isSequenceEqual = true;

            byte[] packetComparer = new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 };
            byte[] packetData     = packet.ReadBytes(7);

            if (packetComparer.Length != packetData.Length)
            {
                isSequenceEqual = false;
            }
            else
            {
                for (int i = 0; i < packetData.Length; i++)
                {
                    if (packetData[i] != packetComparer[i])
                    {
                        isSequenceEqual = false;
                        break;
                    }
                }
            }

            //if (!packet.ReadBytes(7).SequenceEqual(new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 }))
            //{
            //    return false;
            //}

            if (!isSequenceEqual)
            {
                return(false);
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber)))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            _vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                _comments[i] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));
            }

            _metaBits     += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #10
0
        bool ProcessStreamHeader(DataPacket packet)
        {
            if (!CheckForHeader(packet, streamHeader))
            {
                // don't mark the packet as done... it might be used elsewhere
                _glueBits += packet.Length * 8;
                return(false);
            }

            if (!_pagesSeen.Contains(_lastPageSeen = packet.PageSequenceNumber))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            long startPos = packet.BitsRead;

            if (packet.ReadInt32() != 0)
            {
                throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
            }

            _channels       = packet.ReadByte();
            _sampleRate     = packet.ReadInt32();
            _upperBitrate   = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate   = packet.ReadInt32();

            Block0Size = 1 << (int)packet.ReadUBits(4);
            Block1Size = 1 << (int)packet.ReadUBits(4);

            if (_nominalBitrate == 0)
            {
                if (_upperBitrate > 0 && _lowerBitrate > 0)
                {
                    _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
                }
            }

            _metaBits     += packet.BitsRead - startPos + 8;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #11
0
        public bool ProcessStreamHeader(DataPacket packet)
        {
            if (!packet.ReadBytes(7).SequenceEqual(new byte[7]
            {
                1,
                118,
                111,
                114,
                98,
                105,
                115
            }))
            {
                _glueBits += packet.Length * 8;
                return(false);
            }
            if (!_pagesSeen.Contains(_lastPageSeen = packet.PageSequenceNumber))
            {
                _pagesSeen.Add(_lastPageSeen);
            }
            _glueBits += 56L;
            long bitsRead = packet.BitsRead;

            if (packet.ReadInt32() != 0)
            {
                throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
            }
            _channels       = packet.ReadByte();
            _sampleRate     = packet.ReadInt32();
            _upperBitrate   = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate   = packet.ReadInt32();
            Block0Size      = 1 << (int)packet.ReadBits(4);
            Block1Size      = 1 << (int)packet.ReadBits(4);
            if (_nominalBitrate == 0 && _upperBitrate > 0 && _lowerBitrate > 0)
            {
                _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
            }
            _metaBits     += packet.BitsRead - bitsRead + 8;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;
            return(true);
        }
コード例 #12
0
        bool LoadComments(DataPacket packet)
        {
            bool equal = true;

            byte[] sequence = new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 };
            byte[] packets  = packet.ReadBytes(7);

            for (int i = 0; i < 7; i++)
            {
                if (packets[i] != sequence[i])
                {
                    equal = false;
                    break;
                }
            }

            if (!equal)
            {
                return(false);
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber)))
            {
                _pagesSeen.Add(_lastPageSeen);
            }

            _glueBits += 56;

            _vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                _comments[i] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));
            }

            _metaBits     += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return(true);
        }
コード例 #13
0
        private void ProcessStreamHeader(DataPacket packet)
        {
            this._pagesSeen.Add(packet.PageSequenceNumber);
            long bitsRead = packet.BitsRead;

            if (packet.ReadInt32() != 0)
            {
                throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
            }
            this._channels       = (int)packet.ReadByte();
            this._sampleRate     = packet.ReadInt32();
            this._upperBitrate   = packet.ReadInt32();
            this._nominalBitrate = packet.ReadInt32();
            this._lowerBitrate   = packet.ReadInt32();
            this.Block0Size      = 1 << (int)packet.ReadBits(4);
            this.Block1Size      = 1 << (int)packet.ReadBits(4);
            if (this._nominalBitrate == 0 && this._upperBitrate > 0 && this._lowerBitrate > 0)
            {
                this._nominalBitrate = (this._upperBitrate + this._lowerBitrate) / 2;
            }
            this._metaBits     += packet.BitsRead - bitsRead + 8L;
            this._wasteHdrBits += (long)(8 * packet.Length) - packet.BitsRead;
        }
コード例 #14
0
        bool LoadComments(DataPacket packet)
        {
            bool equal = true;
            byte[] sequence = new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 };
            byte[] packets  = packet.ReadBytes(7);

            for (int i = 0; i < 7; i++)
            {
                if (packets[i] != sequence[i])
                {
                    equal = false;
                    break;
                }
            }

            if (!equal)
            {
                return false;
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber))) _pagesSeen.Add(_lastPageSeen);

            _glueBits += 56;

            _vendor = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                _comments[i] = Encoding.UTF8.GetString(packet.ReadBytes(packet.ReadInt32()));
            }

            _metaBits += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return true;
        }
コード例 #15
0
ファイル: VorbisStreamDecoder.cs プロジェクト: Daramkun/Misty
        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;
        }
コード例 #16
0
ファイル: VorbisStreamDecoder.cs プロジェクト: tanis2000/FEZ
 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;
 }
コード例 #17
0
ファイル: VorbisStreamDecoder.cs プロジェクト: tanis2000/FEZ
 private void ProcessStreamHeader(DataPacket packet)
 {
   this._pagesSeen.Add(packet.PageSequenceNumber);
   long bitsRead = packet.BitsRead;
   if (packet.ReadInt32() != 0)
     throw new InvalidDataException("Only Vorbis stream version 0 is supported.");
   this._channels = (int) packet.ReadByte();
   this._sampleRate = packet.ReadInt32();
   this._upperBitrate = packet.ReadInt32();
   this._nominalBitrate = packet.ReadInt32();
   this._lowerBitrate = packet.ReadInt32();
   this.Block0Size = 1 << (int) packet.ReadBits(4);
   this.Block1Size = 1 << (int) packet.ReadBits(4);
   if (this._nominalBitrate == 0 && this._upperBitrate > 0 && this._lowerBitrate > 0)
     this._nominalBitrate = (this._upperBitrate + this._lowerBitrate) / 2;
   this._metaBits += packet.BitsRead - bitsRead + 8L;
   this._wasteHdrBits += (long) (8 * packet.Length) - packet.BitsRead;
 }
コード例 #18
0
ファイル: VorbisStreamDecoder.cs プロジェクト: Daramkun/Misty
        void ProcessStreamHeader(DataPacket packet)
        {
            _pagesSeen.Add(packet.PageSequenceNumber);

            var startPos = packet.BitsRead;

            if (packet.ReadInt32() != 0) throw new ArgumentException("Only Vorbis stream version 0 is supported.");

            _channels = packet.ReadByte();
            _sampleRate = packet.ReadInt32();
            _upperBitrate = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate = packet.ReadInt32();

            Block0Size = 1 << (int)packet.ReadBits(4);
            Block1Size = 1 << (int)packet.ReadBits(4);

            if (_nominalBitrate == 0)
            {
                if (_upperBitrate > 0 && _lowerBitrate > 0)
                {
                    _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
                }
            }

            _metaBits += packet.BitsRead - startPos + 8;

            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;
        }
コード例 #19
0
        bool ProcessStreamHeader(DataPacket packet)
        {
            bool equal = true;
            byte[] sequence = new byte[] { 0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 };
            byte[] packets  = packet.ReadBytes(7);

            for (int i = 0; i < 7; i++)
            {
                if (packets[i] != sequence[i])
                {
                    equal = false;
                    break;
                }
            }

            if (!equal)
            {
                // don't mark the packet as done... it might be used elsewhere
                _glueBits += packet.Length * 8;
                return false;
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber))) _pagesSeen.Add(_lastPageSeen);

            _glueBits += 56;

            var startPos = packet.BitsRead;

            if (packet.ReadInt32() != 0) throw new InvalidDataException("Only Vorbis stream version 0 is supported.");

            _channels = packet.ReadByte();
            _sampleRate = packet.ReadInt32();
            _upperBitrate = packet.ReadInt32();
            _nominalBitrate = packet.ReadInt32();
            _lowerBitrate = packet.ReadInt32();

            Block0Size = 1 << (int)packet.ReadBits(4);
            Block1Size = 1 << (int)packet.ReadBits(4);

            if (_nominalBitrate == 0)
            {
                if (_upperBitrate > 0 && _lowerBitrate > 0)
                {
                    _nominalBitrate = (_upperBitrate + _lowerBitrate) / 2;
                }
            }

            _metaBits += packet.BitsRead - startPos + 8;

            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return true;
        }
コード例 #20
0
        bool LoadComments(DataPacket packet)
        {
            if (!packet.ReadBytes(7).SequenceEqual(new byte[] { 0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73 }))
            {
                return false;
            }

            if (!_pagesSeen.Contains((_lastPageSeen = packet.PageSequenceNumber))) _pagesSeen.Add(_lastPageSeen);

            _glueBits += 56;

            byte[] vs = packet.ReadBytes(packet.ReadInt32());
            _vendor = Encoding.UTF8.GetString(vs,0,vs.Length);

            _comments = new string[packet.ReadInt32()];
            for (int i = 0; i < _comments.Length; i++)
            {
                vs = packet.ReadBytes(packet.ReadInt32());
                _comments[i] = Encoding.UTF8.GetString(vs,0,vs.Length);
            }

            _metaBits += packet.BitsRead - 56;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;

            return true;
        }