示例#1
0
        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);
        }
示例#2
0
        internal static VorbisFloor Init(VorbisStreamDecoder vorbis, DataPacket packet)
        {
            int         num         = (int)packet.ReadBits(16);
            VorbisFloor vorbisFloor = (VorbisFloor)null;

            switch (num)
            {
            case 0:
                vorbisFloor = (VorbisFloor) new VorbisFloor.Floor0(vorbis);
                break;

            case 1:
                vorbisFloor = (VorbisFloor) new VorbisFloor.Floor1(vorbis);
                break;
            }
            if (vorbisFloor == null)
            {
                throw new InvalidDataException();
            }
            vorbisFloor.Init(packet);
            return(vorbisFloor);
        }
示例#3
0
        bool LoadBooks(DataPacket packet)
        {
            bool equal = true;

            byte[] sequence = new byte[] { 0x05, 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);
            }

            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);

            return(true);
        }
示例#4
0
        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);
        }
        bool LoadBooks(DataPacket packet)
        {
            if (!CheckForHeader(packet, bookHeader))
            {
                return(false);
            }

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

            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.Create(this, packet, i);
            }

            _bookBits += packet.BitsRead - bits;
            bits       = packet.BitsRead;

            // get times
            Times = new VorbisTime[(int)packet.ReadUBits(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.ReadUBits(6) + 1];
            for (int i = 0; i < Floors.Length; i++)
            {
                Floors[i] = VorbisFloor.Create(this, packet);
            }

            _floorHdrBits += packet.BitsRead - bits;
            bits           = packet.BitsRead;

            // get residue
            Residues = new VorbisResidue[(int)packet.ReadUBits(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.ReadUBits(6) + 1];
            for (int i = 0; i < Maps.Length; i++)
            {
                Maps[i] = VorbisMapping.Create(this, packet);
            }

            _mapHdrBits += packet.BitsRead - bits;
            bits         = packet.BitsRead;

            // get mode settings
            Modes = new VorbisMode[(int)packet.ReadUBits(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);

            return(true);
        }
示例#6
0
        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);
        }
        public bool LoadBooks(DataPacket packet)
        {
            if (!packet.ReadBytes(7).SequenceEqual(new byte[7]
            {
                5,
                118,
                111,
                114,
                98,
                105,
                115
            }))
            {
                return(false);
            }
            if (!_pagesSeen.Contains(_lastPageSeen = packet.PageSequenceNumber))
            {
                _pagesSeen.Add(_lastPageSeen);
            }
            long bitsRead = packet.BitsRead;

            _glueBits += packet.BitsRead;
            Books      = new VorbisCodebook[packet.ReadByte() + 1];
            for (int i = 0; i < Books.Length; i++)
            {
                Books[i] = VorbisCodebook.Init(this, packet, i);
            }
            _bookBits += packet.BitsRead - bitsRead;
            bitsRead   = packet.BitsRead;
            Times      = new VorbisTime[(int)packet.ReadBits(6) + 1];
            for (int j = 0; j < Times.Length; j++)
            {
                Times[j] = VorbisTime.Init(this, packet);
            }
            _timeHdrBits += packet.BitsRead - bitsRead;
            bitsRead      = packet.BitsRead;
            Floors        = new VorbisFloor[(int)packet.ReadBits(6) + 1];
            for (int k = 0; k < Floors.Length; k++)
            {
                Floors[k] = VorbisFloor.Init(this, packet);
            }
            _floorHdrBits += packet.BitsRead - bitsRead;
            bitsRead       = packet.BitsRead;
            Residues       = new VorbisResidue[(int)packet.ReadBits(6) + 1];
            for (int l = 0; l < Residues.Length; l++)
            {
                Residues[l] = VorbisResidue.Init(this, packet);
            }
            _resHdrBits += packet.BitsRead - bitsRead;
            bitsRead     = packet.BitsRead;
            Maps         = new VorbisMapping[(int)packet.ReadBits(6) + 1];
            for (int m = 0; m < Maps.Length; m++)
            {
                Maps[m] = VorbisMapping.Init(this, packet);
            }
            _mapHdrBits += packet.BitsRead - bitsRead;
            bitsRead     = packet.BitsRead;
            Modes        = new VorbisMode[(int)packet.ReadBits(6) + 1];
            for (int n = 0; n < Modes.Length; n++)
            {
                Modes[n] = VorbisMode.Init(this, packet);
            }
            _modeHdrBits += packet.BitsRead - bitsRead;
            if (!packet.ReadBit())
            {
                throw new InvalidDataException();
            }
            _glueBits++;
            _wasteHdrBits += 8 * packet.Length - packet.BitsRead;
            _modeFieldBits = Utils.ilog(Modes.Length - 1);
            return(true);
        }
示例#8
0
 private bool[] UnwrapPosts(VorbisFloor.Floor1.PacketData1 data)
 {
   bool[] flagArray = ACache.Get<bool>(data.PostCount, false);
   flagArray[0] = true;
   flagArray[1] = true;
   int[] buffer = ACache.Get<int>(data.PostCount);
   buffer[0] = data.Posts[0];
   buffer[1] = data.Posts[1];
   for (int index1 = 2; index1 < data.PostCount; ++index1)
   {
     int index2 = this._lNeigh[index1];
     int index3 = this._hNeigh[index1];
     int num1 = this.RenderPoint(this._xList[index2], buffer[index2], this._xList[index3], buffer[index3], this._xList[index1]);
     int num2 = data.Posts[index1];
     int num3 = this._range - num1;
     int num4 = num1;
     int num5 = num3 >= num4 ? num4 * 2 : num3 * 2;
     if (num2 != 0)
     {
       flagArray[index2] = true;
       flagArray[index3] = true;
       flagArray[index1] = true;
       buffer[index1] = num2 < num5 ? (num2 % 2 != 1 ? num1 + num2 / 2 : num1 - (num2 + 1) / 2) : (num3 <= num4 ? num1 - num2 + num3 - 1 : num2 - num4 + num1);
     }
     else
     {
       flagArray[index1] = false;
       buffer[index1] = num1;
     }
   }
   for (int index = 0; index < data.PostCount; ++index)
     data.Posts[index] = buffer[index];
   ACache.Return<int>(ref buffer);
   return flagArray;
 }
示例#9
0
 internal override void Apply(VorbisFloor.PacketData packetData, float[] residue)
 {
   VorbisFloor.Floor1.PacketData1 data = packetData as VorbisFloor.Floor1.PacketData1;
   if (data == null)
     throw new InvalidDataException("Incorrect packet data!");
   if (data.Posts == null)
     return;
   bool[] buffer = this.UnwrapPosts(data);
   int num1 = data.BlockSize / 2;
   int x0 = 0;
   int num2 = data.Posts[0] * this._multiplier;
   for (int index1 = 1; index1 < data.PostCount; ++index1)
   {
     int index2 = this._sortIdx[index1];
     if (buffer[index2])
     {
       int val1 = this._xList[index2];
       int y1 = data.Posts[index2] * this._multiplier;
       if (x0 < num1)
         this.RenderLineMulti(x0, num2, Math.Min(val1, num1), y1, residue);
       x0 = val1;
       num2 = y1;
     }
     if (x0 >= num1)
       break;
   }
   ACache.Return<bool>(ref buffer);
   if (x0 < num1)
     this.RenderLineMulti(x0, num2, num1, num2, residue);
   ACache.Return<int>(ref data.Posts);
 }
示例#10
0
 internal abstract void Apply(VorbisFloor.PacketData packetData, float[] residue);
示例#11
0
      internal override void Apply(VorbisFloor.PacketData packetData, float[] residue)
      {
        VorbisFloor.Floor0.PacketData0 packetData0 = packetData as VorbisFloor.Floor0.PacketData0;
        if (packetData0 == null)
          throw new ArgumentException("Incorrect packet data!");
        if ((double) packetData0.Amp <= 0.0)
          return;
        float[] numArray = this._barkMaps[packetData0.BlockSize];
        int index = 0;
label_9:
        if (index >= packetData0.BlockSize)
          return;
        double d = Math.PI * (double) numArray[index] / (double) this._bark_map_size;
        float num1;
        int num2;
        float num3;
        int num4;
        if (this._order % 2 == 1)
        {
          num1 = (float) (1.0 - Math.Pow(Math.Cos(d), 2.0));
          num2 = 3;
          num3 = 0.25f;
          num4 = 1;
        }
        else
        {
          num1 = (float) (1.0 - Math.Cos(d));
          num2 = 2;
          num3 = (float) (1.0 + Math.Cos(d));
          num4 = 2;
        }
        double num5 = (double) num1 * (double) (this._order - num2) / (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[1]) - Math.Cos(d), 2.0) * (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[3]) - Math.Cos(d), 2.0)) * (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[5]) - Math.Cos(d), 2.0)));
        double num6 = (double) num3 * (double) (this._order - num4) / (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[0]) - Math.Cos(d), 2.0) * (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[2]) - Math.Cos(d), 2.0)) * (4.0 * Math.Pow(Math.Cos((double) packetData0.Coeff[4]) - Math.Cos(d), 2.0)));
        float num7 = (float) Math.Exp(0.11512925 * ((double) packetData0.Amp * (double) this._ampOfs / ((double) ((1 << this._ampBits) - 1) * Math.Sqrt(num5 + num6)) - (double) this._ampOfs));
        float num8;
        do
        {
          num8 = numArray[index];
          residue[index] *= num7;
          ++index;
        }
        while ((double) numArray[index] == (double) num8);
        goto label_9;
      }