CSharpRTMP.Common.BitReader.ReadBitsToInt C# (CSharp) Method

ReadBitsToInt() public method

public ReadBitsToInt ( byte count = 32 ) : int
count byte
return int
        public int ReadBitsToInt(byte count = 32)
        {
            var result = 0;
            if (AvailableBits < count) throw new EndOfStreamException();
            for (var i = 0; i < count; i++)
            {
                BitsEnumerator.MoveNext();
                result = (result << 1) | BitsEnumerator.Current;
            }
            return result;
        }
        public short ReadBitsToShort(byte count = 16)

Usage Example

        public bool Init(Stream pBuffer, int length)
        {
            Clear();
            var oldPosition = pBuffer.Position;
            if (length < 2)
            {
                Logger.FATAL("Invalid length:{0}", length);
                return false;
            }
            var bitReader = new BitReader(pBuffer);

            _audioObjectType = bitReader.ReadBitsToByte(5);
            if ((_audioObjectType != 1)
                && (_audioObjectType != 2)
                && (_audioObjectType != 3)
                && (_audioObjectType != 4)
                && (_audioObjectType != 6)
                && (_audioObjectType != 17)
                && (_audioObjectType != 19)
                && (_audioObjectType != 20)
                && (_audioObjectType != 23)
                && (_audioObjectType != 39))
            {
                Logger.FATAL("Invalid _audioObjectType: {0}", _audioObjectType);
                return false;
            }
            //3. Read the sample rate index
            _sampleRateIndex = bitReader.ReadBitsToByte(4);
            if ((_sampleRateIndex == 13)
                    || (_sampleRateIndex == 14))
            {
                Logger.FATAL("Invalid sample rate: {0}", _sampleRateIndex);
                return false;
            }
            if (_sampleRateIndex == 15)
            {
                if (length < 5)
                {
                    Logger.FATAL("Invalid length:{0}", length);
                    return false;
                }
                _sampleRate = (uint)bitReader.ReadBitsToInt(24);
            }
            else
            {
                var rates = new uint[]{
			96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
			12000, 11025, 8000, 7350
		};
                _sampleRate = rates[_sampleRateIndex];
            }

            //4. read the channel configuration index
            _channelConfigurationIndex = bitReader.ReadBitsToByte(4);
            if ((_channelConfigurationIndex == 0)
                    || (_channelConfigurationIndex >= 8))
            {
                Logger.FATAL("Invalid _channelConfigurationIndex: {0}", _channelConfigurationIndex);
                return false;
            }

            pBuffer.Position = oldPosition;
            _pAAC = new byte[length];
            pBuffer.Read(_pAAC, 0, length);
            _aacLength = (uint) length;
            return true;
        }
All Usage Examples Of CSharpRTMP.Common.BitReader::ReadBitsToInt