internal override float[][] Decode(DataPacket packet, bool[] doNotDecode, int channels, int blockSize) { float[][] numArray = ACache.Get <float>(doNotDecode.Length, blockSize); if (this._nToRead > 0) { int[][][] buffer = ACache.Get <int>(channels, this._partsToRead, this._classWordsPerCodeWord); for (int index1 = 0; index1 < this._maxPasses; ++index1) { int num1 = 0; int index2 = 0; int num2 = this._begin; while (num1 < this._partsToRead) { if (index1 == 0) { for (int index3 = 0; index3 < channels; ++index3) { if (!doNotDecode[index3]) { int num3 = this._classBook.DecodeScalar(packet); for (int index4 = this._classWordsPerCodeWord - 1; index4 >= 0; --index4) { buffer[index3][index2][index4] = num3 % this._classifications; num3 /= this._classifications; } } } } int index5 = 0; while (index5 < this._classWordsPerCodeWord && num1 < this._partsToRead) { for (int index3 = 0; index3 < channels; ++index3) { if (!doNotDecode[index3]) { VorbisCodebook vorbisCodebook = this._books[buffer[index3][index2][index5]][index1]; if (vorbisCodebook != null && vorbisCodebook.MapType != 0) { VorbisResidue.Residue0 residue0 = this; int num3 = index3; VorbisCodebook codebook = vorbisCodebook; DataPacket packet1 = packet; float[] residue = numArray[index3]; int offset = num2; int channel = num3; residue0.WriteVectors(codebook, packet1, residue, offset, channel); } } } ++index5; ++num1; num2 += this._partitionSize; } ++index2; } } ACache.Return <int>(ref buffer); } return(numArray); }
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); }
internal static T[][][] Get <T>(int firstRankSize, int secondRankSize, int thirdRankSize) { T[][][] objArray = ACache.Get <T[][]>(firstRankSize, false); for (int index = 0; index < firstRankSize; ++index) { objArray[index] = ACache.Get <T>(secondRankSize, thirdRankSize); } return(objArray); }
internal static void Return <T>(ref T[][][] buffer) { for (int index = 0; index < buffer.Length; ++index) { if (buffer[index] != null) { ACache.Return <T>(ref buffer[index]); } } ACache.Return <T[][]>(ref buffer); }
internal int ReadSamples(float[] buffer, int offset, int count) { int num1 = 0; if (this._prevBuffer != null) { int num2 = Math.Min(count, this._prevBuffer.Length); Buffer.BlockCopy((Array)this._prevBuffer, 0, (Array)buffer, offset, num2 * 4); if (num2 < this._prevBuffer.Length) { float[] numArray = ACache.Get <float>(this._prevBuffer.Length - num2, false); Buffer.BlockCopy((Array)this._prevBuffer, num2 * 4, (Array)numArray, 0, (this._prevBuffer.Length - num2) * 4); ACache.Return <float>(ref this._prevBuffer); this._prevBuffer = numArray; } count -= num2; offset += num2; num1 = num2; } this._outputBuffer.EnsureSize(count + this.Block1Size * this._channels); while (this._preparedLength * this._channels < count) { if (!this._eosFound) { try { this.DecodeNextPacket(); } catch (EndOfStreamException ex) { this._eosFound = true; break; } } else { break; } } if (this._preparedLength * this._channels < count) { count = this._preparedLength * this._channels; } this._outputBuffer.CopyTo(buffer, offset, count); this._preparedLength -= count / this._channels; return(num1 + count); }
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); }
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); }
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); }
internal static T[] Get <T>(int elements) { return(ACache.Get <T>(elements, true)); }
private unsafe void CalcReverse(float[] buf) { float[] buffer = ACache.Get <float>(this.n2); fixed(float *numPtr1 = buf) fixed(float *numPtr2 = buffer) { float *e; float *numPtr3; fixed(float *A1 = this.A) { float *numPtr4 = numPtr2 + (this.n2 - 2); float *numPtr5 = A1; float *numPtr6 = numPtr1; float *numPtr7 = numPtr1 + this.n2; while (numPtr6 != numPtr7) { numPtr4[1] = (float)((double)*numPtr6 * (double)*numPtr5 - (double)numPtr6[2] * (double)numPtr5[1]); *numPtr4 = (float)((double)*numPtr6 * (double)numPtr5[1] + (double)numPtr6[2] * (double)*numPtr5); numPtr4 -= 2; numPtr5 += 2; numPtr6 += 4; } float *numPtr8 = numPtr1 + (this.n2 - 3); // ISSUE: cast to a reference type while (numPtr4 >= (float&)numPtr2) { numPtr4[1] = (float)(-(double)numPtr8[2] * (double)*numPtr5 - -(double)*numPtr8 * (double)numPtr5[1]); *numPtr4 = (float)(-(double)numPtr8[2] * (double)numPtr5[1] + -(double)*numPtr8 * (double)*numPtr5); numPtr4 -= 2; numPtr5 += 2; numPtr8 -= 4; } e = numPtr1; numPtr3 = numPtr2; float *numPtr9 = A1 + (this.n2 - 8); float *numPtr10 = numPtr3 + this.n4; float *numPtr11 = numPtr3; float *numPtr12 = e + this.n4; float *numPtr13 = e; // ISSUE: cast to a reference type while (numPtr9 >= (float&)A1) { float num1 = numPtr10[1] - numPtr11[1]; float num2 = *numPtr10 - *numPtr11; numPtr12[1] = numPtr10[1] + numPtr11[1]; *numPtr12 = *numPtr10 + *numPtr11; numPtr13[1] = (float)((double)num1 * (double)numPtr9[4] - (double)num2 * (double)numPtr9[5]); * numPtr13 = (float)((double)num2 * (double)numPtr9[4] + (double)num1 * (double)numPtr9[5]); float num3 = numPtr10[3] - numPtr11[3]; float num4 = numPtr10[2] - numPtr11[2]; numPtr12[3] = numPtr10[3] + numPtr11[3]; numPtr12[2] = numPtr10[2] + numPtr11[2]; numPtr13[3] = (float)((double)num3 * (double)*numPtr9 - (double)num4 * (double)numPtr9[1]); numPtr13[2] = (float)((double)num4 * (double)*numPtr9 + (double)num3 * (double)numPtr9[1]); numPtr9 -= 8; numPtr12 += 4; numPtr13 += 4; numPtr10 += 4; numPtr11 += 4; } this.imdct_step3_iter0_loop(this.n >> 4, e, this.n2 - 1, -(this.n >> 3), A1); this.imdct_step3_iter0_loop(this.n >> 4, e, this.n2 - 1 - this.n4, -(this.n >> 3), A1); this.imdct_step3_inner_r_loop(this.n >> 5, e, this.n2 - 1, -(this.n >> 4), A1, 16); this.imdct_step3_inner_r_loop(this.n >> 5, e, this.n2 - 1 - this.n8, -(this.n >> 4), A1, 16); this.imdct_step3_inner_r_loop(this.n >> 5, e, this.n2 - 1 - this.n8 * 2, -(this.n >> 4), A1, 16); this.imdct_step3_inner_r_loop(this.n >> 5, e, this.n2 - 1 - this.n8 * 3, -(this.n >> 4), A1, 16); int num5; for (num5 = 2; num5 < this.ld - 3 >> 1; ++num5) { int num1 = this.n >> num5 + 2; int num2 = num1 >> 1; int num3 = 1 << num5 + 1; for (int index = 0; index < num3; ++index) { this.imdct_step3_inner_r_loop(this.n >> num5 + 4, e, this.n2 - 1 - num1 * index, -num2, A1, 1 << num5 + 3); } } for (; num5 < this.ld - 6; ++num5) { int k0 = this.n >> num5 + 2; int a_off = 1 << num5 + 3; int num1 = k0 >> 1; int num2 = this.n >> num5 + 6; int n = 1 << num5 + 1; float *A2 = A1; int i_off = this.n2 - 1; for (int index = num2; index > 0; --index) { this.imdct_step3_inner_s_loop(n, e, i_off, -num1, A2, a_off, k0); A2 += a_off * 4; i_off -= 8; } } this.imdct_step3_inner_s_loop_ld654(this.n >> 5, e, this.n2 - 1, A1, this.n); } fixed(ushort *numPtr4 = this.bitrev) { float *numPtr5 = numPtr3 + (this.n4 - 4); float *numPtr6 = numPtr3 + (this.n2 - 4); while (numPtr5 >= numPtr3) { int index1 = (int)numPtr4[0]; numPtr6[3] = e[index1]; numPtr6[2] = e[index1 + 1]; numPtr5[3] = e[index1 + 2]; numPtr5[2] = e[index1 + 3]; int index2 = (int)numPtr4[1]; numPtr6[1] = e[index2]; *numPtr6 = e[index2 + 1]; numPtr5[1] = e[index2 + 2]; *numPtr5 = e[index2 + 3]; numPtr5 -= 4; numPtr6 -= 4; numPtr4 += 2; } } fixed(float *numPtr4 = this.C) { float *numPtr5 = numPtr3; float *numPtr6 = numPtr3 + this.n2 - 4; while (numPtr5 < numPtr6) { float num1 = *numPtr5 - numPtr6[2]; float num2 = numPtr5[1] + numPtr6[3]; float num3 = (float)((double)numPtr4[1] * (double)num1 + (double)numPtr4[0] * (double)num2); float num4 = (float)((double)numPtr4[1] * (double)num2 - (double)numPtr4[0] * (double)num1); float num5 = *numPtr5 + numPtr6[2]; float num6 = numPtr5[1] - numPtr6[3]; * numPtr5 = num5 + num3; numPtr5[1] = num6 + num4; numPtr6[2] = num5 - num3; numPtr6[3] = num4 - num6; float num7 = numPtr5[2] - *numPtr6; float num8 = numPtr5[3] + numPtr6[1]; float num9 = (float)((double)numPtr4[3] * (double)num7 + (double)numPtr4[2] * (double)num8); float num10 = (float)((double)numPtr4[3] * (double)num8 - (double)numPtr4[2] * (double)num7); float num11 = numPtr5[2] + *numPtr6; float num12 = numPtr5[3] - numPtr6[1]; numPtr5[2] = num11 + num9; numPtr5[3] = num12 + num10; *numPtr6 = num11 - num9; numPtr6[1] = num10 - num12; numPtr4 += 4; numPtr5 += 4; numPtr6 -= 4; } } fixed(float *numPtr4 = this.B) { float *numPtr5 = numPtr4 + this.n2 - 8; float *numPtr6 = numPtr2 + this.n2 - 8; float *numPtr7 = numPtr1; float *numPtr8 = numPtr1 + (this.n2 - 4); float *numPtr9 = numPtr1 + this.n2; float *numPtr10 = numPtr1 + (this.n - 4); while (numPtr6 >= numPtr3) { float num1 = (float)((double)numPtr6[6] * (double)numPtr5[7] - (double)numPtr6[7] * (double)numPtr5[6]); float num2 = (float)(-(double)numPtr6[6] * (double)numPtr5[6] - (double)numPtr6[7] * (double)numPtr5[7]); * numPtr7 = num1; numPtr8[3] = -num1; *numPtr9 = num2; numPtr10[3] = num2; float num3 = (float)((double)numPtr6[4] * (double)numPtr5[5] - (double)numPtr6[5] * (double)numPtr5[4]); float num4 = (float)(-(double)numPtr6[4] * (double)numPtr5[4] - (double)numPtr6[5] * (double)numPtr5[5]); numPtr7[1] = num3; numPtr8[2] = -num3; numPtr9[1] = num4; numPtr10[2] = num4; float num5 = (float)((double)numPtr6[2] * (double)numPtr5[3] - (double)numPtr6[3] * (double)numPtr5[2]); float num6 = (float)(-(double)numPtr6[2] * (double)numPtr5[2] - (double)numPtr6[3] * (double)numPtr5[3]); numPtr7[2] = num5; numPtr8[1] = -num5; numPtr9[2] = num6; numPtr10[1] = num6; float num7 = (float)((double)*numPtr6 * (double)numPtr5[1] - (double)numPtr6[1] * (double)*numPtr5); float num8 = (float)(-(double)*numPtr6 * (double)*numPtr5 - (double)numPtr6[1] * (double)numPtr5[1]); numPtr7[3] = num7; *numPtr8 = -num7; numPtr9[3] = num8; *numPtr10 = num8; numPtr5 -= 8; numPtr6 -= 8; numPtr7 += 4; numPtr9 += 4; numPtr8 -= 4; numPtr10 -= 4; } } } ACache.Return <float>(ref buffer); }
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); }
private void SaveBuffer() { float[] buffer = ACache.Get <float>(this._preparedLength * this._channels, false); this.ReadSamples(buffer, 0, buffer.Length); this._prevBuffer = buffer; }