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); }
private bool ComputeCodewords(bool sparse, int sortedEntries, int[] codewords, int[] codewordLengths, int[] len, int n, int[] values) { int num1 = 0; uint[] numArray = new uint[32]; int index1 = 0; while (index1 < n && len[index1] <= 0) { ++index1; } if (index1 == n) { return(true); } VorbisCodebook vorbisCodebook = this; int num2 = sparse ? 1 : 0; int[] codewords1 = codewords; int[] codewordLengths1 = codewordLengths; int num3 = 0; int symbol1 = index1; int count = num1; int num4 = 1; int num5 = count + num4; int len1 = len[index1]; int[] values1 = values; vorbisCodebook.AddEntry(num2 != 0, codewords1, codewordLengths1, (uint)num3, symbol1, count, len1, values1); for (int index2 = 1; index2 <= len[index1]; ++index2) { numArray[index2] = (uint)(1 << 32 - index2); } for (int symbol2 = index1 + 1; symbol2 < n; ++symbol2) { int index2 = len[symbol2]; if (index2 > 0) { while (index2 > 0 && (int)numArray[index2] == 0) { --index2; } if (index2 == 0) { return(false); } uint n1 = numArray[index2]; numArray[index2] = 0U; this.AddEntry(sparse, codewords, codewordLengths, Utils.BitReverse(n1), symbol2, num5++, len[symbol2], values); if (index2 != len[symbol2]) { for (int index3 = len[symbol2]; index3 > index2; --index3) { numArray[index3] = n1 + (uint)(1 << 32 - index3); } } } } return(true); }
internal static VorbisCodebook Init(VorbisStreamDecoder vorbis, DataPacket packet, int number) { var temp = new VorbisCodebook(); temp.BookNum = number; temp.Init(packet); return temp; }
internal static VorbisCodebook Create(VorbisStreamDecoder vorbis, DataPacket packet, int number) { var tmp = new VorbisCodebook(number); tmp.Init(packet); return(tmp); }
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 static VorbisCodebook Init(VorbisStreamDecoder vorbis, DataPacket packet, int number) { VorbisCodebook vorbisCodebook = new VorbisCodebook(); vorbisCodebook.BookNum = number; vorbisCodebook.Init(packet); return vorbisCodebook; }
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); }
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); }
internal static VorbisCodebook Init(VorbisStreamDecoder vorbis, DataPacket packet, int number) { var temp = new VorbisCodebook(); temp.BookNum = number; temp.Init(packet); return(temp); }
internal static VorbisCodebook Init(VorbisStreamDecoder vorbis, DataPacket packet, int number) { VorbisCodebook vorbisCodebook = new VorbisCodebook(); vorbisCodebook.BookNum = number; vorbisCodebook.Init(packet); return(vorbisCodebook); }
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 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); }
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); }
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; }
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]; } } }
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]; } } }
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); }
public override void Init(DataPacket packet) { _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 InvalidDataException(); } _ampDiv = (1 << _ampBits) - 1; for (int i = 0; i < _books.Length; i++) { int num = (int)packet.ReadBits(8); if (num < 0 || num >= _vorbis.Books.Length) { throw new InvalidDataException(); } VorbisCodebook vorbisCodebook = _vorbis.Books[num]; if (vorbisCodebook.MapType == 0 || vorbisCodebook.Dimensions < 1) { throw new InvalidDataException(); } _books[i] = vorbisCodebook; } _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 j = 0; j < _reusablePacketData.Length; j++) { _reusablePacketData[j] = new PacketData0 { Coeff = new float[_order + 1] }; } }
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); }
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); }
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); }
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); }
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); }
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]; } }
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); }
protected override void Init(DataPacket packet) { // this is pretty well stolen directly from libvorbis... BSD license _begin = (int)packet.ReadBits(24); _end = (int)packet.ReadBits(24); _partitionSize = (int)packet.ReadBits(24) + 1; _classifications = (int)packet.ReadBits(6) + 1; _classBook = _vorbis.Books[(int)packet.ReadBits(8)]; _cascade = new int[_classifications]; var acc = 0; for (int i = 0; i < _classifications; i++) { var low_bits = (int)packet.ReadBits(3); if (packet.ReadBit()) { _cascade[i] = (int)packet.ReadBits(5) << 3 | low_bits; } else { _cascade[i] = low_bits; } acc += icount(_cascade[i]); } var bookNums = new int[acc]; for (var i = 0; i < acc; i++) { bookNums[i] = (int)packet.ReadBits(8); if (_vorbis.Books[bookNums[i]].MapType == 0) throw new Exception(); } var entries = _classBook.Entries; var dim = _classBook.Dimensions; var partvals = 1; while (dim > 0) { partvals *= _classifications; if (partvals > entries) throw new Exception(); --dim; } // now the lookups dim = _classBook.Dimensions; _books = new VorbisCodebook[_classifications][]; acc = 0; var maxstage = 0; int stages; for (int j = 0; j < _classifications; j++) { stages = Utils.ilog(_cascade[j]); _books[j] = new VorbisCodebook[stages]; if (stages > 0) { maxstage = Math.Max(maxstage, stages); for (int k = 0; k < stages; k++) { if ((_cascade[j] & (1 << k)) > 0) { _books[j][k] = _vorbis.Books[bookNums[acc++]]; } } } } _maxStages = maxstage; _decodeMap = new int[partvals][]; for (int j = 0; j < partvals; j++) { var val = j; var mult = partvals / _classifications; _decodeMap[j] = new int[_classBook.Dimensions]; for (int k = 0; k < _classBook.Dimensions; k++) { var deco = val / mult; val -= deco * mult; mult /= _classifications; _decodeMap[j][k] = deco; } } _entryCache = new int[_partitionSize]; _partWordCache = new int[_vorbis._channels][][]; var maxPartWords = ((_end - _begin) / _partitionSize + _classBook.Dimensions - 1) / _classBook.Dimensions; for (int ch = 0; ch < _vorbis._channels; ch++) { _partWordCache[ch] = new int[maxPartWords][]; } }
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; }
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; }
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; }
private void InitTree(DataPacket packet) { int num1 = 0; bool flag; if (packet.ReadBit()) { int num2 = (int)packet.ReadBits(5) + 1; int num3 = 0; while (num3 < this.Entries) { int num4 = (int)packet.ReadBits(Utils.ilog(this.Entries - num3)); while (--num4 >= 0) { this.Lengths[num3++] = num2; } ++num2; } num1 = 0; flag = false; } else { flag = packet.ReadBit(); for (int index = 0; index < this.Entries; ++index) { if (!flag || packet.ReadBit()) { this.Lengths[index] = (int)packet.ReadBits(5) + 1; ++num1; } else { this.Lengths[index] = -1; } } } this.MaxBits = Enumerable.Max((IEnumerable <int>) this.Lengths); int[] numArray1 = (int[])null; if (flag && num1 >= this.Entries >> 2) { numArray1 = new int[this.Entries]; Array.Copy((Array)this.Lengths, (Array)numArray1, this.Entries); flag = false; } int length = !flag ? 0 : num1; int[] numArray2 = (int[])null; int[] codeList = (int[])null; if (!flag) { codeList = new int[this.Entries]; } else if (length != 0) { numArray1 = new int[length]; codeList = new int[length]; numArray2 = new int[length]; } VorbisCodebook vorbisCodebook = this; int[] numArray3 = this.Lengths; int num5 = this.Entries; int[] numArray4 = numArray2; int num6 = flag ? 1 : 0; int sortedEntries = length; int[] codewords = codeList; int[] codewordLengths = numArray1; int[] len = numArray3; int n = num5; int[] values = numArray4; if (!vorbisCodebook.ComputeCodewords(num6 != 0, sortedEntries, codewords, codewordLengths, len, n, values)) { throw new InvalidDataException(); } this.LTree = Huffman.BuildLinkedList <int>(numArray2 ?? Enumerable.ToArray <int>(Enumerable.Range(0, codeList.Length)), numArray1 ?? this.Lengths, codeList); }
protected override void Init(DataPacket packet) { _partitionClass = new int[(int)packet.ReadUBits(5)]; for (int i = 0; i < _partitionClass.Length; i++) { _partitionClass[i] = (int)packet.ReadUBits(4); } int maximum_class = _partitionClass.Max(); _classDimensions = new int[maximum_class + 1]; _classSubclasses = new int[maximum_class + 1]; _classMasterBooks = new VorbisCodebook[maximum_class + 1]; _classMasterBookIndex = new int[maximum_class + 1]; _subclassBooks = new VorbisCodebook[maximum_class + 1][]; _subclassBookIndex = new int[maximum_class + 1][]; for (int i = 0; i <= maximum_class; i++) { _classDimensions[i] = (int)packet.ReadUBits(3) + 1; _classSubclasses[i] = (int)packet.ReadUBits(2); if (_classSubclasses[i] > 0) { _classMasterBookIndex[i] = (int)packet.ReadUBits(8); _classMasterBooks[i] = _vorbis.Books[_classMasterBookIndex[i]]; } _subclassBooks[i] = new VorbisCodebook[1 << _classSubclasses[i]]; _subclassBookIndex[i] = new int[_subclassBooks[i].Length]; for (int j = 0; j < _subclassBooks[i].Length; j++) { int bookNum = (int)packet.ReadUBits(8) - 1; if (bookNum >= 0) { _subclassBooks[i][j] = _vorbis.Books[bookNum]; } _subclassBookIndex[i][j] = bookNum; } } _multiplier = (int)packet.ReadUBits(2); _range = _rangeLookup[_multiplier]; _yBits = _yBitsLookup[_multiplier]; _multiplier++; int rangeBits = (int)packet.ReadUBits(4); int xListIndex = 0; int xListSize = 2; // we always add at least 2 elements for (int i = 0; i < _partitionClass.Length; i++) // precalc size of xList { int classNum = _partitionClass[i]; int dim = _classDimensions[classNum]; xListSize += dim; } _xList = new int[xListSize]; _xList[xListIndex++] = 0; _xList[xListIndex++] = 1 << rangeBits; for (int i = 0; i < _partitionClass.Length; i++) { int classNum = _partitionClass[i]; int dim = _classDimensions[classNum]; for (int j = 0; j < dim; j++) { _xList[xListIndex++] = (int)packet.ReadUBits(rangeBits); } } // precalc the low and high neighbors (and init the sort table) _lNeigh = new int[_xList.Length]; _hNeigh = new int[_xList.Length]; _sortIdx = new int[_xList.Length]; _sortIdx[0] = 0; _sortIdx[1] = 1; for (int i = 2; i < _lNeigh.Length; i++) { _lNeigh[i] = 0; _hNeigh[i] = 1; _sortIdx[i] = i; for (int j = 2; j < i; j++) { int tmp = _xList[j]; if (tmp < _xList[i]) { if (tmp > _xList[_lNeigh[i]]) { _lNeigh[i] = j; } } else { if (tmp < _xList[_hNeigh[i]]) { _hNeigh[i] = j; } } } } // precalc the sort table for (int i = 0; i < _sortIdx.Length - 1; i++) { for (int j = i + 1; j < _sortIdx.Length; j++) { if (_xList[i] == _xList[j]) { throw new InvalidDataException(); } if (_xList[_sortIdx[i]] > _xList[_sortIdx[j]]) { // swap the sort indexes int tmp = _sortIdx[i]; _sortIdx[i] = _sortIdx[j]; _sortIdx[j] = tmp; } } } // pre-create our packet data instances _reusablePacketData = new PacketData1[_vorbis._channels]; for (int i = 0; i < _reusablePacketData.Length; i++) { _reusablePacketData[i] = new PacketData1(); } }
protected override void Init(DataPacket packet) { _partitionClass = new int[(int)packet.ReadBits(5)]; for (int i = 0; i < _partitionClass.Length; i++) { _partitionClass[i] = (int)packet.ReadBits(4); } var maximum_class = _partitionClass.Max(); _classDimensions = new int[maximum_class + 1]; _classSubclasses = new int[maximum_class + 1]; _classMasterbooks = new VorbisCodebook[maximum_class + 1]; _classMasterBookIndex = new int[maximum_class + 1]; _subclassBooks = new VorbisCodebook[maximum_class + 1][]; _subclassBookIndex = new int[maximum_class + 1][]; for (int i = 0; i <= maximum_class; i++) { _classDimensions[i] = (int)packet.ReadBits(3) + 1; _classSubclasses[i] = (int)packet.ReadBits(2); if (_classSubclasses[i] > 0) { _classMasterBookIndex[i] = (int)packet.ReadBits(8); _classMasterbooks[i] = _vorbis.Books[_classMasterBookIndex[i]]; } _subclassBooks[i] = new VorbisCodebook[1 << _classSubclasses[i]]; _subclassBookIndex[i] = new int[_subclassBooks[i].Length]; for (int j = 0; j < _subclassBooks[i].Length; j++) { var bookNum = (int)packet.ReadBits(8) - 1; if (bookNum >= 0) _subclassBooks[i][j] = _vorbis.Books[bookNum]; _subclassBookIndex[i][j] = bookNum; } } _multiplier = (int)packet.ReadBits(2); _range = _rangeLookup[_multiplier]; _yBits = _yBitsLookup[_multiplier]; ++_multiplier; var rangeBits = (int)packet.ReadBits(4); var xList = new List<int>(); xList.Add(0); xList.Add(1 << rangeBits); for (int i = 0; i < _partitionClass.Length; i++) { var classNum = _partitionClass[i]; for (int j = 0; j < _classDimensions[classNum]; j++) { xList.Add((int)packet.ReadBits(rangeBits)); } } _xList = xList.ToArray(); // precalc the low and high neighbors (and init the sort table) _lNeigh = new int[xList.Count]; _hNeigh = new int[xList.Count]; _sortIdx = new int[xList.Count]; _sortIdx[0] = 0; _sortIdx[1] = 1; for (int i = 2; i < _lNeigh.Length; i++) { _lNeigh[i] = 0; _hNeigh[i] = 1; _sortIdx[i] = i; for (int j = 2; j < i; j++) { var temp = _xList[j]; if (temp < _xList[i]) { if (temp > _xList[_lNeigh[i]]) _lNeigh[i] = j; } else { if (temp < _xList[_hNeigh[i]]) _hNeigh[i] = j; } } } // precalc the sort table for (int i = 0; i < _sortIdx.Length - 1; i++) { for (int j = i + 1; j < _sortIdx.Length; j++) { if (_xList[i] == _xList[j]) throw new InvalidDataException(); if (_xList[_sortIdx[i]] > _xList[_sortIdx[j]]) { // swap the sort indexes var temp = _sortIdx[i]; _sortIdx[i] = _sortIdx[j]; _sortIdx[j] = temp; } } } }
protected override void Init(DataPacket packet) { // this is pretty well stolen directly from libvorbis... BSD license _order = (int)packet.ReadUBits(8); _rate = (int)packet.ReadUBits(16); _bark_map_size = (int)packet.ReadUBits(16); _ampBits = (int)packet.ReadUBits(6); _ampOfs = (int)packet.ReadUBits(8); _books = new VorbisCodebook[(int)packet.ReadUBits(4) + 1]; if (_order < 1 || _rate < 1 || _bark_map_size < 1 || _books.Length == 0) { throw new InvalidDataException(); } _ampDiv = (1 << _ampBits) - 1; for (int i = 0; i < _books.Length; i++) { int num = (int)packet.ReadUBits(8); if (num < 0 || num >= _vorbis.Books.Length) { throw new InvalidDataException(); } VorbisCodebook book = _vorbis.Books[num]; if (book.MapType == 0 || book.Dimensions < 1) { throw new InvalidDataException(); } _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] } } ; } int[] SynthesizeBarkCurve(int n) { float scale = _bark_map_size / ToBARK(_rate / 2); int[] map = new int[n + 1]; for (int i = 0; i < n - 1; i++) { map[i] = Math.Min(_bark_map_size - 1, (int)MathF.Floor(ToBARK(_rate / 2f / n * i) * scale)); } map[n] = -1; return(map); }
protected override void Init(DataPacket packet) { // this is pretty well stolen directly from libvorbis... BSD license _begin = (int)packet.ReadBits(24); _end = (int)packet.ReadBits(24); _partitionSize = (int)packet.ReadBits(24) + 1; _classifications = (int)packet.ReadBits(6) + 1; _classBook = _vorbis.Books[(int)packet.ReadBits(8)]; _cascade = new int[_classifications]; var acc = 0; for (int i = 0; i < _classifications; i++) { var low_bits = (int)packet.ReadBits(3); if (packet.ReadBit()) { _cascade[i] = (int)packet.ReadBits(5) << 3 | low_bits; } else { _cascade[i] = low_bits; } acc += icount(_cascade[i]); } var bookNums = new int[acc]; for (var i = 0; i < acc; i++) { bookNums[i] = (int)packet.ReadBits(8); if (_vorbis.Books[bookNums[i]].MapType == 0) { throw new InvalidDataException(); } } var entries = _classBook.Entries; var dim = _classBook.Dimensions; var partvals = 1; while (dim > 0) { partvals *= _classifications; if (partvals > entries) { throw new InvalidDataException(); } --dim; } // now the lookups dim = _classBook.Dimensions; _books = new VorbisCodebook[_classifications][]; acc = 0; var maxstage = 0; int stages; for (int j = 0; j < _classifications; j++) { stages = Utils.ilog(_cascade[j]); _books[j] = new VorbisCodebook[stages]; if (stages > 0) { maxstage = Math.Max(maxstage, stages); for (int k = 0; k < stages; k++) { if ((_cascade[j] & (1 << k)) > 0) { _books[j][k] = _vorbis.Books[bookNums[acc++]]; } } } } _maxStages = maxstage; _decodeMap = new int[partvals][]; for (int j = 0; j < partvals; j++) { var val = j; var mult = partvals / _classifications; _decodeMap[j] = new int[_classBook.Dimensions]; for (int k = 0; k < _classBook.Dimensions; k++) { var deco = val / mult; val -= deco * mult; mult /= _classifications; _decodeMap[j][k] = deco; } } _entryCache = new int[_partitionSize]; _partWordCache = new int[_vorbis._channels][][]; var maxPartWords = ((_end - _begin) / _partitionSize + _classBook.Dimensions - 1) / _classBook.Dimensions; for (int ch = 0; ch < _vorbis._channels; ch++) { _partWordCache[ch] = new int[maxPartWords][]; } }
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); }
protected override void Init(DataPacket packet) { _begin = (int)packet.ReadBits(24); _end = (int)packet.ReadBits(24); _partitionSize = (int)packet.ReadBits(24) + 1; _classifications = (int)packet.ReadBits(6) + 1; _classBookNum = (int)packet.ReadBits(8); _classBook = _vorbis.Books[_classBookNum]; _cascade = new int[_classifications]; var acc = 0; var maxBits = 0; for (int i = 0; i < _classifications; i++) { var high_bits = 0; var low_bits = (int)packet.ReadBits(3); if (packet.ReadBit()) high_bits = (int)packet.ReadBits(5); _cascade[i] = high_bits << 3 | low_bits; acc += icount(_cascade[i]); maxBits = Math.Max(Utils.ilog(_cascade[i]), maxBits); } _maxPasses = maxBits; var bookNums = new int[acc]; for (var i = 0; i < acc; i++) { bookNums[i] = (int)packet.ReadBits(8); } var bookIdx = 0; _books = new VorbisCodebook[_classifications][]; _bookNums = new int[_classifications][]; for (int i = 0; i < _classifications; i++) { _books[i] = new VorbisCodebook[8]; _bookNums[i] = new int[8]; for (int j = 1, idx = 0; j < 256; j <<= 1, idx++) { if ((_cascade[i] & j) == j) { var bookNum = bookNums[bookIdx++]; _books[i][idx] = _vorbis.Books[bookNum]; _bookNums[i][idx] = bookNum; if (_books[i][idx].MapType == 0) throw new InvalidDataException(); } } } _classWordsPerCodeWord = _classBook.Dimensions; _nToRead = _end - _begin; _partsToRead = _nToRead / _partitionSize; _partWords = (_partsToRead + _classWordsPerCodeWord - 1) / _classWordsPerCodeWord; }
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]; } } }
protected override void Init(DataPacket packet) { _partitionClass = new int[(int)packet.ReadBits(5)]; for (int i = 0; i < _partitionClass.Length; i++) { _partitionClass[i] = (int)packet.ReadBits(4); } var maximum_class = _partitionClass.Max(); _classDimensions = new int[maximum_class + 1]; _classSubclasses = new int[maximum_class + 1]; _classMasterbooks = new VorbisCodebook[maximum_class + 1]; _classMasterBookIndex = new int[maximum_class + 1]; _subclassBooks = new VorbisCodebook[maximum_class + 1][]; _subclassBookIndex = new int[maximum_class + 1][]; for (int i = 0; i <= maximum_class; i++) { _classDimensions[i] = (int)packet.ReadBits(3) + 1; _classSubclasses[i] = (int)packet.ReadBits(2); if (_classSubclasses[i] > 0) { _classMasterBookIndex[i] = (int)packet.ReadBits(8); _classMasterbooks[i] = _vorbis.Books[_classMasterBookIndex[i]]; } _subclassBooks[i] = new VorbisCodebook[1 << _classSubclasses[i]]; _subclassBookIndex[i] = new int[_subclassBooks[i].Length]; for (int j = 0; j < _subclassBooks[i].Length; j++) { var bookNum = (int)packet.ReadBits(8) - 1; if (bookNum >= 0) { _subclassBooks[i][j] = _vorbis.Books[bookNum]; } _subclassBookIndex[i][j] = bookNum; } } _multiplier = (int)packet.ReadBits(2); _range = _rangeLookup[_multiplier]; _yBits = _yBitsLookup[_multiplier]; ++_multiplier; var rangeBits = (int)packet.ReadBits(4); var xList = new List <int>(); xList.Add(0); xList.Add(1 << rangeBits); for (int i = 0; i < _partitionClass.Length; i++) { var classNum = _partitionClass[i]; for (int j = 0; j < _classDimensions[classNum]; j++) { xList.Add((int)packet.ReadBits(rangeBits)); } } _xList = xList.ToArray(); // precalc the low and high neighbors (and init the sort table) _lNeigh = new int[xList.Count]; _hNeigh = new int[xList.Count]; _sortIdx = new int[xList.Count]; _sortIdx[0] = 0; _sortIdx[1] = 1; for (int i = 2; i < _lNeigh.Length; i++) { _lNeigh[i] = 0; _hNeigh[i] = 1; _sortIdx[i] = i; for (int j = 2; j < i; j++) { var temp = _xList[j]; if (temp < _xList[i]) { if (temp > _xList[_lNeigh[i]]) { _lNeigh[i] = j; } } else { if (temp < _xList[_hNeigh[i]]) { _hNeigh[i] = j; } } } } // precalc the sort table for (int i = 0; i < _sortIdx.Length - 1; i++) { for (int j = i + 1; j < _sortIdx.Length; j++) { if (_xList[i] == _xList[j]) { throw new InvalidDataException(); } if (_xList[_sortIdx[i]] > _xList[_sortIdx[j]]) { // swap the sort indexes var temp = _sortIdx[i]; _sortIdx[i] = _sortIdx[j]; _sortIdx[j] = temp; } } } // pre-create our packet data instances _reusablePacketData = new PacketData1[_vorbis._channels]; for (int i = 0; i < _reusablePacketData.Length; i++) { _reusablePacketData[i] = new PacketData1(); } }
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]; } } }
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]; } }
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); }
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); }
public override void Init(DataPacket packet) { _begin = (int)packet.ReadBits(24); _end = (int)packet.ReadBits(24); _partitionSize = (int)packet.ReadBits(24) + 1; _classifications = (int)packet.ReadBits(6) + 1; _classBook = _vorbis.Books[(uint)packet.ReadBits(8)]; _cascade = new int[_classifications]; int num = 0; for (int i = 0; i < _classifications; i++) { int num2 = (int)packet.ReadBits(3); if (packet.ReadBit()) { _cascade[i] = ((int)((uint)packet.ReadBits(5) << 3) | num2); } else { _cascade[i] = num2; } num += icount(_cascade[i]); } int[] array = new int[num]; for (int j = 0; j < num; j++) { array[j] = (int)packet.ReadBits(8); if (_vorbis.Books[array[j]].MapType == 0) { throw new InvalidDataException(); } } int entries = _classBook.Entries; int num3 = _classBook.Dimensions; int num4 = 1; while (num3 > 0) { num4 *= _classifications; if (num4 > entries) { throw new InvalidDataException(); } num3--; } num3 = _classBook.Dimensions; _books = new VorbisCodebook[_classifications][]; num = 0; int num5 = 0; for (int k = 0; k < _classifications; k++) { int num6 = Utils.ilog(_cascade[k]); _books[k] = new VorbisCodebook[num6]; if (num6 <= 0) { continue; } num5 = Math.Max(num5, num6); for (int l = 0; l < num6; l++) { if ((_cascade[k] & (1 << l)) > 0) { _books[k][l] = _vorbis.Books[array[num++]]; } } } _maxStages = num5; _decodeMap = new int[num4][]; for (int m = 0; m < num4; m++) { int num7 = m; int num8 = num4 / _classifications; _decodeMap[m] = new int[_classBook.Dimensions]; for (int n = 0; n < _classBook.Dimensions; n++) { int num9 = num7 / num8; num7 -= num9 * num8; num8 /= _classifications; _decodeMap[m][n] = num9; } } _entryCache = new int[_partitionSize]; _partWordCache = new int[_vorbis._channels][][]; int num10 = ((_end - _begin) / _partitionSize + _classBook.Dimensions - 1) / _classBook.Dimensions; for (int num11 = 0; num11 < _vorbis._channels; num11++) { _partWordCache[num11] = new int[num10][]; } }