当前位置: 首页>>代码示例>>C#>>正文


C# DataPacket.ReadBits方法代码示例

本文整理汇总了C#中NVorbis.DataPacket.ReadBits方法的典型用法代码示例。如果您正苦于以下问题:C# DataPacket.ReadBits方法的具体用法?C# DataPacket.ReadBits怎么用?C# DataPacket.ReadBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NVorbis.DataPacket的用法示例。


在下文中一共展示了DataPacket.ReadBits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 internal static VorbisMode Init(VorbisStreamDecoder vorbis, DataPacket packet)
 {
   VorbisMode vorbisMode = new VorbisMode(vorbis);
   vorbisMode.BlockFlag = packet.ReadBit();
   vorbisMode.WindowType = (int) packet.ReadBits(16);
   vorbisMode.TransformType = (int) packet.ReadBits(16);
   int index = (int) packet.ReadBits(8);
   if (vorbisMode.WindowType != 0 || vorbisMode.TransformType != 0 || index >= vorbis.Maps.Length)
     throw new InvalidDataException();
   vorbisMode.Mapping = vorbis.Maps[index];
   vorbisMode.BlockSize = vorbisMode.BlockFlag ? vorbis.Block1Size : vorbis.Block0Size;
   if (vorbisMode.BlockFlag)
   {
     vorbisMode._windows = new float[4][];
     vorbisMode._windows[0] = new float[vorbis.Block1Size];
     vorbisMode._windows[1] = new float[vorbis.Block1Size];
     vorbisMode._windows[2] = new float[vorbis.Block1Size];
     vorbisMode._windows[3] = new float[vorbis.Block1Size];
   }
   else
   {
     vorbisMode._windows = new float[1][];
     vorbisMode._windows[0] = new float[vorbis.Block0Size];
   }
   vorbisMode.CalcWindows();
   return vorbisMode;
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:27,代码来源:VorbisMode.cs

示例2: Init

        internal static VorbisMode Init(VorbisStreamDecoder vorbis, DataPacket packet)
        {
            var mode = new VorbisMode(vorbis);
            mode.BlockFlag = packet.ReadBit();
            mode.WindowType = (int)packet.ReadBits(16);
            mode.TransformType = (int)packet.ReadBits(16);
            var mapping = (int)packet.ReadBits(8);

            if (mode.WindowType != 0 || mode.TransformType != 0 || mapping >= vorbis.Maps.Length) throw new InvalidDataException();

            mode.Mapping = vorbis.Maps[mapping];
            mode.BlockSize = mode.BlockFlag ? vorbis.Block1Size : vorbis.Block0Size;

            // now pre-calc the window(s)...
            if (mode.BlockFlag)
            {
                // long block
                mode._windows = new float[4][];
                mode._windows[0] = new float[vorbis.Block1Size];
                mode._windows[1] = new float[vorbis.Block1Size];
                mode._windows[2] = new float[vorbis.Block1Size];
                mode._windows[3] = new float[vorbis.Block1Size];
            }
            else
            {
                // short block
                mode._windows = new float[1][];
                mode._windows[0] = new float[vorbis.Block0Size];
            }
            mode.CalcWindows();

            return mode;
        }
开发者ID:chen-ye,项目名称:SoundStockUnity,代码行数:33,代码来源:VorbisMode.cs

示例3: Init

 internal void Init(DataPacket packet)
 {
   if ((long) packet.ReadBits(24) != 5653314L)
     throw new InvalidDataException();
   this.Dimensions = (int) packet.ReadBits(16);
   this.Entries = (int) packet.ReadBits(24);
   this.Lengths = new int[this.Entries];
   this.InitTree(packet);
   this.InitLookupTable(packet);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:10,代码来源:VorbisCodebook.cs

示例4: Init

 protected override void Init(DataPacket packet)
 {
   this._order = (int) packet.ReadBits(8);
   this._rate = (int) packet.ReadBits(16);
   this._bark_map_size = (int) packet.ReadBits(16);
   this._ampBits = (int) packet.ReadBits(6);
   this._ampOfs = (int) packet.ReadBits(8);
   this._books = new VorbisCodebook[(int) packet.ReadBits(4) + 1];
   for (int index = 0; index < this._books.Length; ++index)
     this._books[index] = this._vorbis.Books[(int) packet.ReadBits(8)];
   this._bookBits = Utils.ilog(this._books.Length);
   this._barkMaps = new Dictionary<int, float[]>();
   this._barkMaps[this._vorbis.Block0Size] = this.SynthesizeBarkCurve(this._vorbis.Block0Size);
   this._barkMaps[this._vorbis.Block1Size] = this.SynthesizeBarkCurve(this._vorbis.Block1Size);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:15,代码来源:VorbisFloor.cs

示例5: Init

 protected override void Init(DataPacket packet)
 {
   int length1 = 1;
   if (packet.ReadBit())
     length1 += (int) packet.ReadBits(4);
   int length2 = 0;
   if (packet.ReadBit())
     length2 = (int) packet.ReadBits(8) + 1;
   int count = Utils.ilog(this._vorbis._channels - 1);
   this.CouplingSteps = new VorbisMapping.CouplingStep[length2];
   for (int index = 0; index < length2; ++index)
   {
     int num1 = (int) packet.ReadBits(count);
     int num2 = (int) packet.ReadBits(count);
     if (num1 == num2 || num1 > this._vorbis._channels - 1 || num2 > this._vorbis._channels - 1)
       throw new InvalidDataException();
     this.CouplingSteps[index] = new VorbisMapping.CouplingStep()
     {
       Angle = num2,
       Magnitude = num1
     };
   }
   if ((long) packet.ReadBits(2) != 0L)
     throw new InvalidDataException();
   int[] numArray = new int[this._vorbis._channels];
   if (length1 > 1)
   {
     for (int index = 0; index < this.ChannelSubmap.Length; ++index)
     {
       numArray[index] = (int) packet.ReadBits(4);
       if (numArray[index] >= length1)
         throw new InvalidDataException();
     }
   }
   this.Submaps = new VorbisMapping.Submap[length1];
   for (int index1 = 0; index1 < length1; ++index1)
   {
     long num = (long) packet.ReadBits(8);
     int index2 = (int) packet.ReadBits(8);
     if (index2 >= this._vorbis.Floors.Length)
       throw new InvalidDataException();
     if ((int) packet.ReadBits(8) >= this._vorbis.Residues.Length)
       throw new InvalidDataException();
     this.Submaps[index1] = new VorbisMapping.Submap()
     {
       Floor = this._vorbis.Floors[index2],
       Residue = this._vorbis.Residues[index2]
     };
   }
   this.ChannelSubmap = new VorbisMapping.Submap[this._vorbis._channels];
   for (int index = 0; index < this.ChannelSubmap.Length; ++index)
     this.ChannelSubmap[index] = this.Submaps[numArray[index]];
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:53,代码来源:VorbisMapping.cs

示例6: Init

        internal void Init(DataPacket packet)
        {
            // first, check the sync pattern
            var chkVal = packet.ReadBits(24);
            if (chkVal != 0x564342UL) throw new  Exception();

            // get the counts
            Dimensions = (int)packet.ReadBits(16);
            Entries = (int)packet.ReadBits(24);
            
            // init the storage
            Lengths = new int[Entries];

            InitTree(packet);
            InitLookupTable(packet);
        }
开发者ID:YJh2046,项目名称:BlockFun,代码行数:16,代码来源:VorbisCodebook.cs

示例7: Init

 internal static VorbisTime Init(VorbisStreamDecoder vorbis, DataPacket packet)
 {
   int num = (int) packet.ReadBits(16);
   VorbisTime vorbisTime = (VorbisTime) null;
   if (num == 0)
     vorbisTime = (VorbisTime) new VorbisTime.Time0(vorbis);
   if (vorbisTime == null)
     throw new InvalidDataException();
   vorbisTime.Init(packet);
   return vorbisTime;
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:11,代码来源:VorbisTime.cs

示例8: Init

            protected override void Init(DataPacket packet)
            {
                var submapCount = 1;
                if (packet.ReadBit()) submapCount += (int)packet.ReadBits(4);

                // square polar mapping
                var couplingSteps = 0;
                if (packet.ReadBit())
                {
                    couplingSteps = (int)packet.ReadBits(8) + 1;
                }

                var couplingBits = Utils.ilog(_vorbis._channels - 1);
                CouplingSteps = new CouplingStep[couplingSteps];
                for (int j = 0; j < couplingSteps; j++)
                {
                    var magnitude = (int)packet.ReadBits(couplingBits);
                    var angle = (int)packet.ReadBits(couplingBits);
                    if (magnitude == angle || magnitude > _vorbis._channels - 1 || angle > _vorbis._channels - 1)
                        throw new Exception();
                    CouplingSteps[j] = new CouplingStep { Angle = angle, Magnitude = magnitude };
                }

                // reserved bits
                if (packet.ReadBits(2) != 0UL) throw new Exception();

                // channel multiplex
                var mux = new int[_vorbis._channels];
                if (submapCount > 1)
                {
                    for (int c = 0; c < ChannelSubmap.Length; c++)
                    {
                        mux[c] = (int)packet.ReadBits(4);
                        if (mux[c] >= submapCount) throw new Exception();
                    }
                }

                // submaps
                Submaps = new Submap[submapCount];
                for (int j = 0; j < submapCount; j++)
                {
                    packet.ReadBits(8); // unused placeholder
                    var floorNum = (int)packet.ReadBits(8);
                    if (floorNum >= _vorbis.Floors.Length) throw new Exception();
                    var residueNum = (int)packet.ReadBits(8);
                    if (residueNum >= _vorbis.Residues.Length) throw new Exception();

                    Submaps[j] = new Submap
                    {
                        Floor = _vorbis.Floors[floorNum],
                        Residue = _vorbis.Residues[floorNum]
                    };
                }

                ChannelSubmap = new Submap[_vorbis._channels];
                for (int c = 0; c < ChannelSubmap.Length; c++)
                {
                    ChannelSubmap[c] = Submaps[mux[c]];
                }
            }
开发者ID:YJh2046,项目名称:BlockFun,代码行数:60,代码来源:VorbisMapping.cs

示例9: Init

 protected override void Init(DataPacket packet)
 {
   this._begin = (int) packet.ReadBits(24);
   this._end = (int) packet.ReadBits(24);
   this._partitionSize = (int) packet.ReadBits(24) + 1;
   this._classifications = (int) packet.ReadBits(6) + 1;
   this._classBookNum = (int) packet.ReadBits(8);
   this._classBook = this._vorbis.Books[this._classBookNum];
   this._cascade = new int[this._classifications];
   int length = 0;
   int val2 = 0;
   for (int index = 0; index < this._classifications; ++index)
   {
     int num1 = 0;
     int num2 = (int) packet.ReadBits(3);
     if (packet.ReadBit())
       num1 = (int) packet.ReadBits(5);
     this._cascade[index] = num1 << 3 | num2;
     length += VorbisResidue.Residue0.icount(this._cascade[index]);
     val2 = Math.Max(Utils.ilog(this._cascade[index]), val2);
   }
   this._maxPasses = val2;
   int[] numArray = new int[length];
   for (int index = 0; index < length; ++index)
     numArray[index] = (int) packet.ReadBits(8);
   int num3 = 0;
   this._books = new VorbisCodebook[this._classifications][];
   this._bookNums = new int[this._classifications][];
   for (int index1 = 0; index1 < this._classifications; ++index1)
   {
     this._books[index1] = new VorbisCodebook[8];
     this._bookNums[index1] = new int[8];
     int num1 = 1;
     int index2 = 0;
     while (num1 < 256)
     {
       if ((this._cascade[index1] & num1) == num1)
       {
         int index3 = numArray[num3++];
         this._books[index1][index2] = this._vorbis.Books[index3];
         this._bookNums[index1][index2] = index3;
         if (this._books[index1][index2].MapType == 0)
           throw new InvalidDataException();
       }
       num1 <<= 1;
       ++index2;
     }
   }
   this._classWordsPerCodeWord = this._classBook.Dimensions;
   this._nToRead = this._end - this._begin;
   this._partsToRead = this._nToRead / this._partitionSize;
   this._partWords = (this._partsToRead + this._classWordsPerCodeWord - 1) / this._classWordsPerCodeWord;
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:53,代码来源:VorbisResidue.cs

示例10: Init

        internal static VorbisTime Init(VorbisStreamDecoder vorbis, DataPacket packet)
        {
            var type = (int)packet.ReadBits(16);

            VorbisTime time = null;
            switch (type)
            {
                case 0: time = new Time0(vorbis); break;
            }
            if (time == null) throw new InvalidDataException();

            time.Init(packet);
            return time;
        }
开发者ID:reidyd,项目名称:nvorbis,代码行数:14,代码来源:VorbisTime.cs

示例11: Init

        internal static VorbisFloor Init(VorbisStreamDecoder vorbis, DataPacket packet)
        {
            var type = (int)packet.ReadBits(16);

            VorbisFloor floor = null;
            switch (type)
            {
                case 0: floor = new Floor0(vorbis); break;
                case 1: floor = new Floor1(vorbis); break;
            }
            if (floor == null) throw new InvalidDataException();

            floor.Init(packet);
            return floor;
        }
开发者ID:reidyd,项目名称:nvorbis,代码行数:15,代码来源:VorbisFloor.cs

示例12: Init

        internal static VorbisResidue Init(VorbisStreamDecoder vorbis, DataPacket packet)
        {
            var type = (int)packet.ReadBits(16);

            VorbisResidue residue = null;
            switch (type)
            {
                case 0: residue = new Residue0(vorbis); break;
                case 1: residue = new Residue1(vorbis); break;
                case 2: residue = new Residue2(vorbis); break;
            }
            if (residue == null) throw new InvalidDataException();

            residue.Init(packet);
            return residue;
        }
开发者ID:reidyd,项目名称:nvorbis,代码行数:16,代码来源:VorbisResidue.cs

示例13: Init

            protected override void Init(DataPacket packet)
            {
                // this is pretty well stolen directly from libvorbis...  BSD license
                _order = (int)packet.ReadBits(8);
                _rate = (int)packet.ReadBits(16);
                _bark_map_size = (int)packet.ReadBits(16);
                _ampBits = (int)packet.ReadBits(6);
                _ampOfs = (int)packet.ReadBits(8);
                _books = new VorbisCodebook[(int)packet.ReadBits(4) + 1];

                if (_order < 1 || _rate < 1 || _bark_map_size < 1 || _books.Length == 0) throw new Exception();

                _ampDiv = (1 << _ampBits) - 1;

                for (int i = 0; i < _books.Length; i++)
                {
                    var num = (int)packet.ReadBits(8);
                    if (num < 0 || num >= _vorbis.Books.Length) throw new Exception();
                    var book = _vorbis.Books[num];

                    if (book.MapType == 0 || book.Dimensions < 1) throw new Exception();

                    _books[i] = book;
                }
                _bookBits = Utils.ilog(_books.Length);

                _barkMaps = new Dictionary<int, int[]>();
                _barkMaps[_vorbis.Block0Size] = SynthesizeBarkCurve(_vorbis.Block0Size / 2);
                _barkMaps[_vorbis.Block1Size] = SynthesizeBarkCurve(_vorbis.Block1Size / 2);

                _wMap = new Dictionary<int, float[]>();
                _wMap[_vorbis.Block0Size] = SynthesizeWDelMap(_vorbis.Block0Size / 2);
                _wMap[_vorbis.Block1Size] = SynthesizeWDelMap(_vorbis.Block1Size / 2);

                _reusablePacketData = new PacketData0[_vorbis._channels];
                for (int i = 0; i < _reusablePacketData.Length; i++)
                {
                    _reusablePacketData[i] = new PacketData0() { Coeff = new float[_order + 1] };
                }
            }
开发者ID:YJh2046,项目名称:BlockFun,代码行数:40,代码来源:VorbisFloor.cs

示例14: UnpackPacket

            internal override PacketData UnpackPacket(DataPacket packet, int blockSize, int channel)
            {
                var data = _reusablePacketData[channel];
                data.BlockSize = blockSize;
                data.ForceEnergy = false;
                data.ForceNoEnergy = false;
                data.PostCount = 0;
                Array.Clear(data.Posts, 0, 64);

                // hoist ReadPosts to here since that's all we're doing...
                if (packet.ReadBit())
                {
                    var postCount = 2;
                    data.Posts[0] = (int)packet.ReadBits(_yBits);
                    data.Posts[1] = (int)packet.ReadBits(_yBits);

                    for (int i = 0; i < _partitionClass.Length; i++)
                    {
                        var clsNum = _partitionClass[i];
                        var cdim = _classDimensions[clsNum];
                        var cbits = _classSubclasses[clsNum];
                        var csub = (1 << cbits) - 1;
                        var cval = 0U;
                        if (cbits > 0)
                        {
                            if ((cval = (uint)_classMasterbooks[clsNum].DecodeScalar(packet)) == uint.MaxValue)
                            {
                                // we read a bad value...  bail
                                postCount = 0;
                                break;
                            }
                        }
                        for (int j = 0; j < cdim; j++)
                        {
                            var book = _subclassBooks[clsNum][cval & csub];
                            cval >>= cbits;
                            if (book != null)
                            {
                                if ((data.Posts[postCount] = book.DecodeScalar(packet)) == -1)
                                {
                                    // we read a bad value... bail
                                    postCount = 0;
                                    i = _partitionClass.Length;
                                    break;
                                }
                            }
                            ++postCount;
                        }
                    }

                    data.PostCount = postCount;
                }

                return data;
            }
开发者ID:Daramkun,项目名称:Misty,代码行数:55,代码来源:VorbisFloor.cs

示例15: LoadBooks

 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);
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:50,代码来源:VorbisStreamDecoder.cs


注:本文中的NVorbis.DataPacket.ReadBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。