Esempio n. 1
0
        private int DecodePacket(VorbisStreamDecoder.PacketDecodeInfo pdi)
        {
            VorbisMapping.CouplingStep[] couplingStepArray = pdi.Mode.Mapping.CouplingSteps;
            int num1 = pdi.Mode.BlockSize / 2;

            for (int index1 = couplingStepArray.Length - 1; index1 >= 0; --index1)
            {
                float[] numArray1 = pdi.Residue[couplingStepArray[index1].Magnitude];
                float[] numArray2 = pdi.Residue[couplingStepArray[index1].Angle];
                for (int index2 = 0; index2 < num1; ++index2)
                {
                    float num2;
                    float num3;
                    if ((double)numArray1[index2] > 0.0)
                    {
                        if ((double)numArray2[index2] > 0.0)
                        {
                            num2 = numArray1[index2];
                            num3 = numArray1[index2] - numArray2[index2];
                        }
                        else
                        {
                            num3 = numArray1[index2];
                            num2 = numArray1[index2] + numArray2[index2];
                        }
                    }
                    else if ((double)numArray2[index2] > 0.0)
                    {
                        num2 = numArray1[index2];
                        num3 = numArray1[index2] + numArray2[index2];
                    }
                    else
                    {
                        num3 = numArray1[index2];
                        num2 = numArray1[index2] - numArray2[index2];
                    }
                    numArray1[index2] = num2;
                    numArray2[index2] = num3;
                }
            }
            for (int index = 0; index < this._channels; ++index)
            {
                VorbisFloor.PacketData packetData = pdi.FloorData[index];
                float[] numArray = pdi.Residue[index];
                if (packetData.ExecuteChannel)
                {
                    pdi.Mode.Mapping.ChannelSubmap[index].Floor.Apply(packetData, numArray);
                    Mdct.Reverse(numArray);
                }
            }
            return(this.WindowSamples(pdi));
        }
Esempio n. 2
0
 private void DecodeNextPacket()
 {
     this._sw.Start();
     try
     {
         DataPacket packet = this._getNextPacket();
         if (packet == null)
         {
             this._eosFound = true;
         }
         else
         {
             if (!this._pagesSeen.Contains(this._lastPageSeen = packet.PageSequenceNumber))
             {
                 this._pagesSeen.Add(this._lastPageSeen);
             }
             if (packet.IsResync)
             {
                 this.ResetDecoder();
             }
             VorbisStreamDecoder.PacketDecodeInfo pdi = this.UnpackPacket(packet);
             if (pdi == null)
             {
                 this._wasteBits += (long)(8 * packet.Length);
             }
             else
             {
                 int samplesDecoded = this.DecodePacket(pdi);
                 if (!packet.GranuleCount.HasValue)
                 {
                     packet.GranuleCount = new long?((long)samplesDecoded);
                 }
                 this.UpdatePosition(samplesDecoded, packet);
                 int num = Utils.Sum(this._sampleCountHistory) + samplesDecoded;
                 this._bitsPerPacketHistory.Enqueue((int)packet.BitsRead);
                 this._sampleCountHistory.Enqueue(samplesDecoded);
                 while (num > this._sampleRate)
                 {
                     this._bitsPerPacketHistory.Dequeue();
                     num -= this._sampleCountHistory.Dequeue();
                 }
             }
         }
     }
     finally
     {
         this._sw.Stop();
     }
 }
Esempio n. 3
0
        private int WindowSamples(VorbisStreamDecoder.PacketDecodeInfo pdi)
        {
            float[] window      = pdi.Mode.GetWindow(pdi.PrevFlag, pdi.NextFlag);
            int     num1        = pdi.Mode.BlockSize;
            int     end         = num1;
            int     switchPoint = end >> 1;
            int     start       = 0;
            int     num2        = -switchPoint;
            int     num3        = switchPoint;

            if (pdi.Mode.BlockFlag)
            {
                if (!pdi.PrevFlag)
                {
                    start       = this.Block1Size / 4 - this.Block0Size / 4;
                    switchPoint = start + this.Block0Size / 2;
                    num2        = this.Block0Size / -2 - start;
                }
                if (!pdi.NextFlag)
                {
                    end -= num1 / 4 - this.Block0Size / 4;
                    num3 = num1 / 4 + this.Block0Size / 4;
                }
            }
            int index = this._outputBuffer.Length / this._channels + num2;

            for (int channel = 0; channel < this._channels; ++channel)
            {
                this._outputBuffer.Write(channel, index, start, switchPoint, end, pdi.Residue[channel], window);
            }
            int num4 = this._outputBuffer.Length / this._channels - num3;
            int num5 = num4 - this._preparedLength;

            this._preparedLength = num4;
            return(num5);
        }
Esempio n. 4
0
 private VorbisStreamDecoder.PacketDecodeInfo UnpackPacket(DataPacket packet)
 {
   if (packet.ReadBit())
     return (VorbisStreamDecoder.PacketDecodeInfo) null;
   VorbisStreamDecoder.PacketDecodeInfo packetDecodeInfo = new VorbisStreamDecoder.PacketDecodeInfo();
   int num1 = this._modeFieldBits;
   try
   {
     packetDecodeInfo.Mode = this.Modes[(int) packet.ReadBits(this._modeFieldBits)];
     if (packetDecodeInfo.Mode.BlockFlag)
     {
       packetDecodeInfo.PrevFlag = packet.ReadBit();
       packetDecodeInfo.NextFlag = packet.ReadBit();
       num1 += 2;
     }
   }
   catch (EndOfStreamException ex)
   {
     return (VorbisStreamDecoder.PacketDecodeInfo) null;
   }
   try
   {
     long bitsRead1 = packet.BitsRead;
     packetDecodeInfo.FloorData = ACache.Get<VorbisFloor.PacketData>(this._channels);
     bool[] buffer1 = ACache.Get<bool>(this._channels);
     for (int index = 0; index < this._channels; ++index)
     {
       packetDecodeInfo.FloorData[index] = packetDecodeInfo.Mode.Mapping.ChannelSubmap[index].Floor.UnpackPacket(packet, packetDecodeInfo.Mode.BlockSize);
       buffer1[index] = !packetDecodeInfo.FloorData[index].ExecuteChannel;
     }
     foreach (VorbisMapping.CouplingStep couplingStep in packetDecodeInfo.Mode.Mapping.CouplingSteps)
     {
       if (packetDecodeInfo.FloorData[couplingStep.Angle].ExecuteChannel || packetDecodeInfo.FloorData[couplingStep.Magnitude].ExecuteChannel)
       {
         packetDecodeInfo.FloorData[couplingStep.Angle].ForceEnergy = true;
         packetDecodeInfo.FloorData[couplingStep.Magnitude].ForceEnergy = true;
       }
     }
     long num2 = packet.BitsRead - bitsRead1;
     long bitsRead2 = packet.BitsRead;
     packetDecodeInfo.Residue = ACache.Get<float>(this._channels, packetDecodeInfo.Mode.BlockSize);
     foreach (VorbisMapping.Submap submap in packetDecodeInfo.Mode.Mapping.Submaps)
     {
       for (int index = 0; index < this._channels; ++index)
       {
         if (packetDecodeInfo.Mode.Mapping.ChannelSubmap[index] != submap)
           packetDecodeInfo.FloorData[index].ForceNoEnergy = true;
       }
       float[][] buffer2 = submap.Residue.Decode(packet, buffer1, this._channels, packetDecodeInfo.Mode.BlockSize);
       for (int index1 = 0; index1 < this._channels; ++index1)
       {
         float[] numArray1 = packetDecodeInfo.Residue[index1];
         float[] numArray2 = buffer2[index1];
         for (int index2 = 0; index2 < packetDecodeInfo.Mode.BlockSize; ++index2)
           numArray1[index2] += numArray2[index2];
       }
       ACache.Return<float>(ref buffer2);
     }
     ACache.Return<bool>(ref buffer1);
     ++this._glueBits;
     this._modeBits += (long) num1;
     this._floorBits += num2;
     this._resBits += packet.BitsRead - bitsRead2;
     this._wasteBits += (long) (8 * packet.Length) - packet.BitsRead;
     ++this._packetCount;
   }
   catch (EndOfStreamException ex)
   {
     this.ResetDecoder();
     packetDecodeInfo = (VorbisStreamDecoder.PacketDecodeInfo) null;
   }
   catch (InvalidDataException ex)
   {
     packetDecodeInfo = (VorbisStreamDecoder.PacketDecodeInfo) null;
   }
   packet.Done();
   return packetDecodeInfo;
 }
Esempio n. 5
0
        private VorbisStreamDecoder.PacketDecodeInfo UnpackPacket(DataPacket packet)
        {
            if (packet.ReadBit())
            {
                return((VorbisStreamDecoder.PacketDecodeInfo)null);
            }
            VorbisStreamDecoder.PacketDecodeInfo packetDecodeInfo = new VorbisStreamDecoder.PacketDecodeInfo();
            int num1 = this._modeFieldBits;

            try
            {
                packetDecodeInfo.Mode = this.Modes[(int)packet.ReadBits(this._modeFieldBits)];
                if (packetDecodeInfo.Mode.BlockFlag)
                {
                    packetDecodeInfo.PrevFlag = packet.ReadBit();
                    packetDecodeInfo.NextFlag = packet.ReadBit();
                    num1 += 2;
                }
            }
            catch (EndOfStreamException ex)
            {
                return((VorbisStreamDecoder.PacketDecodeInfo)null);
            }
            try
            {
                long bitsRead1 = packet.BitsRead;
                packetDecodeInfo.FloorData = ACache.Get <VorbisFloor.PacketData>(this._channels);
                bool[] buffer1 = ACache.Get <bool>(this._channels);
                for (int index = 0; index < this._channels; ++index)
                {
                    packetDecodeInfo.FloorData[index] = packetDecodeInfo.Mode.Mapping.ChannelSubmap[index].Floor.UnpackPacket(packet, packetDecodeInfo.Mode.BlockSize);
                    buffer1[index] = !packetDecodeInfo.FloorData[index].ExecuteChannel;
                }
                foreach (VorbisMapping.CouplingStep couplingStep in packetDecodeInfo.Mode.Mapping.CouplingSteps)
                {
                    if (packetDecodeInfo.FloorData[couplingStep.Angle].ExecuteChannel || packetDecodeInfo.FloorData[couplingStep.Magnitude].ExecuteChannel)
                    {
                        packetDecodeInfo.FloorData[couplingStep.Angle].ForceEnergy     = true;
                        packetDecodeInfo.FloorData[couplingStep.Magnitude].ForceEnergy = true;
                    }
                }
                long num2      = packet.BitsRead - bitsRead1;
                long bitsRead2 = packet.BitsRead;
                packetDecodeInfo.Residue = ACache.Get <float>(this._channels, packetDecodeInfo.Mode.BlockSize);
                foreach (VorbisMapping.Submap submap in packetDecodeInfo.Mode.Mapping.Submaps)
                {
                    for (int index = 0; index < this._channels; ++index)
                    {
                        if (packetDecodeInfo.Mode.Mapping.ChannelSubmap[index] != submap)
                        {
                            packetDecodeInfo.FloorData[index].ForceNoEnergy = true;
                        }
                    }
                    float[][] buffer2 = submap.Residue.Decode(packet, buffer1, this._channels, packetDecodeInfo.Mode.BlockSize);
                    for (int index1 = 0; index1 < this._channels; ++index1)
                    {
                        float[] numArray1 = packetDecodeInfo.Residue[index1];
                        float[] numArray2 = buffer2[index1];
                        for (int index2 = 0; index2 < packetDecodeInfo.Mode.BlockSize; ++index2)
                        {
                            numArray1[index2] += numArray2[index2];
                        }
                    }
                    ACache.Return <float>(ref buffer2);
                }
                ACache.Return <bool>(ref buffer1);
                ++this._glueBits;
                this._modeBits  += (long)num1;
                this._floorBits += num2;
                this._resBits   += packet.BitsRead - bitsRead2;
                this._wasteBits += (long)(8 * packet.Length) - packet.BitsRead;
                ++this._packetCount;
            }
            catch (EndOfStreamException ex)
            {
                this.ResetDecoder();
                packetDecodeInfo = (VorbisStreamDecoder.PacketDecodeInfo)null;
            }
            catch (InvalidDataException ex)
            {
                packetDecodeInfo = (VorbisStreamDecoder.PacketDecodeInfo)null;
            }
            packet.Done();
            return(packetDecodeInfo);
        }