DecodeScalar() 개인적인 메소드

private DecodeScalar ( DataPacket packet ) : int
packet DataPacket
리턴 int
예제 #1
0
 internal override VorbisFloor.PacketData UnpackPacket(DataPacket packet, int blockSize)
 {
     VorbisFloor.Floor0.PacketData0 packetData0_1 = new VorbisFloor.Floor0.PacketData0();
     packetData0_1.BlockSize = blockSize;
     VorbisFloor.Floor0.PacketData0 packetData0_2 = packetData0_1;
     packetData0_2.Amp = (float)packet.ReadBits(this._ampBits);
     if ((double)packetData0_2.Amp > 0.0)
     {
         try
         {
             List <float> list = new List <float>();
             uint         num  = (uint)packet.ReadBits(this._bookBits);
             if ((long)num >= (long)this._books.Length)
             {
                 throw new InvalidDataException();
             }
             VorbisCodebook vorbisCodebook = this._books[(IntPtr)num];
             for (int index1 = 0; index1 < this._order; ++index1)
             {
                 int index2 = vorbisCodebook.DecodeScalar(packet);
                 for (int index3 = 0; index3 < vorbisCodebook.Dimensions; ++index3)
                 {
                     list.Add(vorbisCodebook[index2, index3]);
                 }
             }
             packetData0_2.Coeff = list.ToArray();
         }
         catch (EndOfStreamException ex)
         {
             packetData0_2.Amp = 0.0f;
         }
     }
     return((VorbisFloor.PacketData)packetData0_2);
 }
예제 #2
0
            public override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                int num = 0;

                offset /= _channels;
                int num2 = 0;

                while (num2 < partitionSize)
                {
                    int num3 = codebook.DecodeScalar(packet);
                    if (num3 == -1)
                    {
                        return(true);
                    }
                    int num4 = 0;
                    while (num4 < codebook.Dimensions)
                    {
                        residue[num][offset] += codebook[num3, num4];
                        if (++num == _channels)
                        {
                            num = 0;
                            offset++;
                        }
                        num4++;
                        num2++;
                    }
                }
                return(false);
            }
예제 #3
0
            protected override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var chPtr = 0;

                offset /= _channels;
                for (int c = 0; c < partitionSize;)
                {
                    var entry = codebook.DecodeScalar(packet);
                    if (entry == -1)
                    {
                        return(true);
                    }
                    for (var d = 0; d < codebook.Dimensions; d++, c++)
                    {
                        residue[chPtr][offset] += codebook[entry, d];
                        if (++chPtr == _channels)
                        {
                            chPtr = 0;
                            offset++;
                        }
                    }
                }

                return(false);
            }
예제 #4
0
            internal override float[][] Decode(DataPacket packet, bool[] doNotDecode, int channels, int blockSize)
            {
                float[][] numArray = ACache.Get <float>(channels, blockSize);
                int       num1     = this._partitionSize / channels;

                if (Enumerable.Contains <bool>((IEnumerable <bool>)doNotDecode, false) && this._nToRead > 0)
                {
                    int[][] buffer = ACache.Get <int>(this._partWords, this._classWordsPerCodeWord);
                    for (int index1 = 0; index1 < this._maxPasses; ++index1)
                    {
                        int num2   = 0;
                        int index2 = 0;
                        int num3   = this._begin;
                        while (num2 < this._partsToRead)
                        {
                            if (index1 == 0)
                            {
                                int num4 = this._classBook.DecodeScalar(packet);
                                for (int index3 = this._classWordsPerCodeWord - 1; index3 >= 0 && num4 > 0; --index3)
                                {
                                    buffer[index2][index3] = num4 % this._classifications;
                                    num4 /= this._classifications;
                                }
                            }
                            for (int index3 = 0; index3 < this._classWordsPerCodeWord && num2 < this._partsToRead; ++index3)
                            {
                                VorbisCodebook vorbisCodebook = this._books[buffer[index2][index3]][index1];
                                if (vorbisCodebook != null && vorbisCodebook.MapType != 0)
                                {
                                    int index4 = 0;
                                    int num4   = vorbisCodebook.Dimensions;
                                    int num5   = 0;
                                    int index5 = num3 / channels;
                                    while (num5 < num1)
                                    {
                                        int index6 = vorbisCodebook.DecodeScalar(packet);
                                        for (int index7 = 0; index7 < num4; ++index7)
                                        {
                                            numArray[index4][index5] += vorbisCodebook[index6, index7];
                                            if (++index4 == channels)
                                            {
                                                index4 = 0;
                                                ++num5;
                                                ++index5;
                                            }
                                        }
                                    }
                                }
                                ++num2;
                                num3 += this._partitionSize;
                            }
                            ++index2;
                        }
                    }
                    ACache.Return <int>(ref buffer);
                }
                return(numArray);
            }
예제 #5
0
            internal override PacketData UnpackPacket(DataPacket packet, int blockSize, int channel)
            {
                var data = _reusablePacketData[channel];

                data.BlockSize     = blockSize;
                data.ForceEnergy   = false;
                data.ForceNoEnergy = false;

                data.Amp = packet.ReadUBits(_ampBits);
                if (data.Amp > 0f)
                {
                    // this is pretty well stolen directly from libvorbis...  BSD license
                    Array.Clear(data.Coeff, 0, data.Coeff.Length);

                    data.Amp = data.Amp / _ampDiv * _ampOfs;

                    uint bookNum = (uint)packet.ReadUBits(_bookBits);
                    if (bookNum >= _books.Length)
                    {
                        // we ran out of data or the packet is corrupt...  0 the floor and return
                        data.Amp = 0;
                        return(data);
                    }
                    VorbisCodebook book = _books[bookNum];

                    // first, the book decode...
                    for (int i = 0; i < _order;)
                    {
                        int entry = book.DecodeScalar(packet);
                        if (entry == -1)
                        {
                            // we ran out of data or the packet is corrupt...  0 the floor and return
                            data.Amp = 0;
                            return(data);
                        }

                        for (int j = 0; i < _order && j < book.Dimensions; j++, i++)
                        {
                            data.Coeff[i] = book[entry, j];
                        }
                    }

                    // then, the "averaging"
                    float last = 0f;
                    for (int j = 0; j < _order;)
                    {
                        for (int k = 0; j < _order && k < book.Dimensions; j++, k++)
                        {
                            data.Coeff[j] += last;
                        }

                        last = data.Coeff[j - 1];
                    }
                }
                return(data);
            }
예제 #6
0
            internal override PacketData UnpackPacket(DataPacket packet, int blockSize, int channel)
            {
                PacketData0 packetData = _reusablePacketData[channel];

                packetData.BlockSize     = blockSize;
                packetData.ForceEnergy   = false;
                packetData.ForceNoEnergy = false;
                packetData.Amp           = (float)(double)packet.ReadBits(_ampBits);
                if (packetData.Amp > 0f)
                {
                    Array.Clear(packetData.Coeff, 0, packetData.Coeff.Length);
                    packetData.Amp = packetData.Amp / (float)_ampDiv * (float)_ampOfs;
                    uint num = (uint)packet.ReadBits(_bookBits);
                    if (num >= _books.Length)
                    {
                        packetData.Amp = 0f;
                        return(packetData);
                    }
                    VorbisCodebook vorbisCodebook = _books[num];
                    int            i = 0;
                    while (i < _order)
                    {
                        int num2 = vorbisCodebook.DecodeScalar(packet);
                        if (num2 == -1)
                        {
                            packetData.Amp = 0f;
                            return(packetData);
                        }
                        int num3 = 0;
                        for (; i < _order; i++)
                        {
                            if (num3 >= vorbisCodebook.Dimensions)
                            {
                                break;
                            }
                            packetData.Coeff[i] = vorbisCodebook[num2, num3];
                            num3++;
                        }
                    }
                    float num4 = 0f;
                    int   num5 = 0;
                    while (num5 < _order)
                    {
                        int num6 = 0;
                        while (num5 < _order && num6 < vorbisCodebook.Dimensions)
                        {
                            packetData.Coeff[num5] += num4;
                            num5++;
                            num6++;
                        }
                        num4 = packetData.Coeff[num5 - 1];
                    }
                }
                return(packetData);
            }
예제 #7
0
            protected override void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
            {
                int num = 0;

                while (num < this._partitionSize)
                {
                    int index1 = codebook.DecodeScalar(packet);
                    for (int index2 = 0; index2 < codebook.Dimensions; ++index2)
                    {
                        residue[offset + num++] += codebook[index1, index2];
                    }
                }
            }
예제 #8
0
            protected virtual void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
            {
                int num1 = this._nToRead / codebook.Dimensions;

                for (int index1 = 0; index1 < num1; ++index1)
                {
                    int num2   = 0;
                    int index2 = codebook.DecodeScalar(packet);
                    for (int index3 = 0; index3 < codebook.Dimensions; ++index3)
                    {
                        residue[offset + index1 + num2++ *num1] += codebook[index2, index3];
                    }
                }
            }
예제 #9
0
 internal override VorbisFloor.PacketData UnpackPacket(DataPacket packet, int blockSize)
 {
     VorbisFloor.Floor1.PacketData1 packetData1_1 = new VorbisFloor.Floor1.PacketData1();
     packetData1_1.BlockSize = blockSize;
     VorbisFloor.Floor1.PacketData1 packetData1_2 = packetData1_1;
     if (packet.ReadBit())
     {
         try
         {
             int   index1   = 2;
             int[] numArray = ACache.Get <int>(64);
             numArray[0] = (int)packet.ReadBits(this._yBits);
             numArray[1] = (int)packet.ReadBits(this._yBits);
             for (int index2 = 0; index2 < this._partitionClass.Length; ++index2)
             {
                 int  index3 = this._partitionClass[index2];
                 int  num1   = this._classDimensions[index3];
                 int  num2   = this._classSubclasses[index3];
                 int  num3   = (1 << num2) - 1;
                 uint num4   = 0U;
                 if (num2 > 0)
                 {
                     num4 = (uint)this._classMasterbooks[index3].DecodeScalar(packet);
                 }
                 for (int index4 = 0; index4 < num1; ++index4)
                 {
                     VorbisCodebook vorbisCodebook = this._subclassBooks[index3][(long)num4 & (long)num3];
                     num4 >>= num2;
                     if (vorbisCodebook != null)
                     {
                         numArray[index1] = vorbisCodebook.DecodeScalar(packet);
                     }
                     ++index1;
                 }
             }
             packetData1_2.Posts     = numArray;
             packetData1_2.PostCount = index1;
         }
         catch (EndOfStreamException ex)
         {
         }
     }
     return((VorbisFloor.PacketData)packetData1_2);
 }
예제 #10
0
            protected override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var res = residue[channel];

                for (int i = 0; i < partitionSize;)
                {
                    var entry = codebook.DecodeScalar(packet);
                    if (entry == -1)
                    {
                        return(true);
                    }
                    for (int j = 0; j < codebook.Dimensions; i++, j++)
                    {
                        res[offset + i] += codebook[entry, j];
                    }
                }

                return(false);
            }
예제 #11
0
            internal override PacketData UnpackPacket(DataPacket packet, int blockSize, int channel)
            {
                PacketData1 packetData = _reusablePacketData[channel];

                packetData.BlockSize     = blockSize;
                packetData.ForceEnergy   = false;
                packetData.ForceNoEnergy = false;
                packetData.PostCount     = 0;
                Array.Clear(packetData.Posts, 0, 64);
                if (packet.ReadBit())
                {
                    int num = 2;
                    packetData.Posts[0] = (int)packet.ReadBits(_yBits);
                    packetData.Posts[1] = (int)packet.ReadBits(_yBits);
                    for (int i = 0; i < _partitionClass.Length; i++)
                    {
                        int  num2 = _partitionClass[i];
                        int  num3 = _classDimensions[num2];
                        int  num4 = _classSubclasses[num2];
                        int  num5 = (1 << num4) - 1;
                        uint num6 = 0u;
                        if (num4 > 0 && (num6 = (uint)_classMasterbooks[num2].DecodeScalar(packet)) == uint.MaxValue)
                        {
                            num = 0;
                            break;
                        }
                        for (int j = 0; j < num3; j++)
                        {
                            VorbisCodebook vorbisCodebook = _subclassBooks[num2][num6 & num5];
                            num6 >>= num4;
                            if (vorbisCodebook != null && (packetData.Posts[num] = vorbisCodebook.DecodeScalar(packet)) == -1)
                            {
                                num = 0;
                                i   = _partitionClass.Length;
                                break;
                            }
                            num++;
                        }
                    }
                    packetData.PostCount = num;
                }
                return(packetData);
            }
예제 #12
0
            public override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                float[] array = residue[channel];
                int     num   = 0;

                while (num < partitionSize)
                {
                    int num2 = codebook.DecodeScalar(packet);
                    if (num2 == -1)
                    {
                        return(true);
                    }
                    for (int i = 0; i < codebook.Dimensions; i++)
                    {
                        array[offset + num] += codebook[num2, i];
                        num++;
                    }
                }
                return(false);
            }
예제 #13
0
            virtual protected bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var res  = residue[channel];
                var step = partitionSize / codebook.Dimensions;

                for (int i = 0; i < step; i++)
                {
                    if ((_entryCache[i] = codebook.DecodeScalar(packet)) == -1)
                    {
                        return(true);
                    }
                }
                for (int i = 0; i < codebook.Dimensions; i++)
                {
                    for (int j = 0; j < step; j++, offset++)
                    {
                        res[offset] += codebook[_entryCache[j], i];
                    }
                }
                return(false);
            }
예제 #14
0
            public virtual bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                float[] array = residue[channel];
                int     num   = partitionSize / codebook.Dimensions;

                for (int i = 0; i < num; i++)
                {
                    if ((_entryCache[i] = codebook.DecodeScalar(packet)) == -1)
                    {
                        return(true);
                    }
                }
                for (int j = 0; j < codebook.Dimensions; j++)
                {
                    int num2 = 0;
                    while (num2 < num)
                    {
                        array[offset] += codebook[_entryCache[num2], j];
                        num2++;
                        offset++;
                    }
                }
                return(false);
            }
예제 #15
0
            internal override float[][] Decode(DataPacket packet, bool[] doNotDecode, int channels, int blockSize)
            {
                var residue = GetResidueBuffer(doNotDecode.Length);

                // this is pretty well stolen directly from libvorbis...  BSD license
                var end = _end < blockSize / 2 ? _end : blockSize / 2;
                var n   = end - _begin;

                if (n > 0 && doNotDecode.Contains(false))
                {
                    var partVals = n / _partitionSize;

                    var partWords = (partVals + _classBook.Dimensions - 1) / _classBook.Dimensions;
                    for (int j = 0; j < channels; j++)
                    {
                        Array.Clear(_partWordCache[j], 0, partWords);
                    }

                    for (int s = 0; s < _maxStages; s++)
                    {
                        for (int i = 0, l = 0; i < partVals; l++)
                        {
                            if (s == 0)
                            {
                                for (int j = 0; j < channels; j++)
                                {
                                    try
                                    {
                                        _partWordCache[j][l] = _decodeMap[_classBook.DecodeScalar(packet)];
                                    }
                                    catch (IndexOutOfRangeException)
                                    {
                                        i = partVals;
                                        s = _maxStages;
                                        break;
                                    }
                                }
                            }
                            for (int k = 0; i < partVals && k < _classBook.Dimensions; k++, i++)
                            {
                                var offset = _begin + i * _partitionSize;
                                for (int j = 0; j < channels; j++)
                                {
                                    var idx = _partWordCache[j][l][k];
                                    if ((_cascade[idx] & (1 << s)) != 0)
                                    {
                                        var book = _books[idx][s];
                                        if (book != null)
                                        {
                                            if (WriteVectors(book, packet, residue, j, offset, _partitionSize))
                                            {
                                                // bad packet...  exit now and try to use what we already have
                                                i = partVals;
                                                s = _maxStages;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(residue);
            }
예제 #16
0
 protected override void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
 {
     for (int i = 0; i < _partitionSize;)
     {
         var entry = codebook.DecodeScalar(packet);
         for (var d = 0; d < codebook.Dimensions; d++)
         {
             residue[offset + i++] += codebook[entry, d];
         }
     }
 }
예제 #17
0
            protected virtual void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
            {
                var step = _nToRead / codebook.Dimensions;

                for (int i = 0; i < step; i++)
                {
                    var j = 0;
                    var entry = codebook.DecodeScalar(packet);
                    for (var d = 0; d < codebook.Dimensions; d++)
                    {
                        residue[offset + i + j++ * step] += codebook[entry, d];
                    }
                }
            }
예제 #18
0
            protected override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var chPtr = 0;

                offset /= _channels;
                for (int c = 0; c < partitionSize; )
                {
                    var entry = codebook.DecodeScalar(packet);
                    if (entry == -1)
                    {
                        return true;
                    }
                    for (var d = 0; d < codebook.Dimensions; d++, c++)
                    {
                        residue[chPtr][offset] += codebook[entry, d];
                        if (++chPtr == _channels)
                        {
                            chPtr = 0;
                            offset++;
                        }
                    }
                }

                return false;
            }
예제 #19
0
            protected override bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var res = residue[channel];

                for (int i = 0; i < partitionSize; )
                {
                    var entry = codebook.DecodeScalar(packet);
                    if (entry == -1)
                    {
                        return true;
                    }
                    for (int j = 0; j < codebook.Dimensions; i++, j++)
                    {
                        res[offset + i] += codebook[entry, j];
                    }
                }

                return false;
            }
예제 #20
0
 protected virtual void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
 {
   int num1 = this._nToRead / codebook.Dimensions;
   for (int index1 = 0; index1 < num1; ++index1)
   {
     int num2 = 0;
     int index2 = codebook.DecodeScalar(packet);
     for (int index3 = 0; index3 < codebook.Dimensions; ++index3)
       residue[offset + index1 + num2++ * num1] += codebook[index2, index3];
   }
 }
예제 #21
0
            internal override float[][] Decode(DataPacket packet, bool[] doNotDecode, int channels, int blockSize)
            {
                float[][] residueBuffer = GetResidueBuffer(doNotDecode.Length);
                int       num           = ((_end < blockSize / 2) ? _end : (blockSize / 2)) - _begin;

                if (num > 0 && doNotDecode.Contains(value: false))
                {
                    int num2   = num / _partitionSize;
                    int length = (num2 + _classBook.Dimensions - 1) / _classBook.Dimensions;
                    for (int i = 0; i < channels; i++)
                    {
                        Array.Clear(_partWordCache[i], 0, length);
                    }
                    for (int j = 0; j < _maxStages; j++)
                    {
                        int k    = 0;
                        int num3 = 0;
                        while (k < num2)
                        {
                            if (j == 0)
                            {
                                for (int l = 0; l < channels; l++)
                                {
                                    int num4 = _classBook.DecodeScalar(packet);
                                    if (num4 >= 0 && num4 < _decodeMap.Length)
                                    {
                                        _partWordCache[l][num3] = _decodeMap[num4];
                                        continue;
                                    }
                                    k = num2;
                                    j = _maxStages;
                                    break;
                                }
                            }
                            int num5 = 0;
                            for (; k < num2; k++)
                            {
                                if (num5 >= _classBook.Dimensions)
                                {
                                    break;
                                }
                                int offset = _begin + k * _partitionSize;
                                for (int m = 0; m < channels; m++)
                                {
                                    int num6 = _partWordCache[m][num3][num5];
                                    if ((_cascade[num6] & (1 << j)) != 0)
                                    {
                                        VorbisCodebook vorbisCodebook = _books[num6][j];
                                        if (vorbisCodebook != null && WriteVectors(vorbisCodebook, packet, residueBuffer, m, offset, _partitionSize))
                                        {
                                            k = num2;
                                            j = _maxStages;
                                            break;
                                        }
                                    }
                                }
                                num5++;
                            }
                            num3++;
                        }
                    }
                }
                return(residueBuffer);
            }
예제 #22
0
 protected override void WriteVectors(VorbisCodebook codebook, DataPacket packet, float[] residue, int offset, int channel)
 {
   int num = 0;
   while (num < this._partitionSize)
   {
     int index1 = codebook.DecodeScalar(packet);
     for (int index2 = 0; index2 < codebook.Dimensions; ++index2)
       residue[offset + num++] += codebook[index1, index2];
   }
 }
예제 #23
0
            virtual protected bool WriteVectors(VorbisCodebook codebook, DataPacket packet, float[][] residue, int channel, int offset, int partitionSize)
            {
                var res = residue[channel];
                var step = partitionSize / codebook.Dimensions;

                for (int i = 0; i < step; i++)
                {
                    if ((_entryCache[i] = codebook.DecodeScalar(packet)) == -1)
                    {
                        return true;
                    }
                }
                for (int i = 0; i < codebook.Dimensions; i++)
                {
                    for (int j = 0; j < step; j++, offset++)
                    {
                        res[offset] += codebook[_entryCache[j], i];
                    }
                }
                return false;
            }