public bool[] UnwrapPosts(PacketData1 data) { Array.Clear(_stepFlags, 2, 62); _stepFlags[0] = true; _stepFlags[1] = true; Array.Clear(_finalY, 2, 62); _finalY[0] = data.Posts[0]; _finalY[1] = data.Posts[1]; for (int i = 2; i < data.PostCount; i++) { int num = _lNeigh[i]; int num2 = _hNeigh[i]; int num3 = RenderPoint(_xList[num], _finalY[num], _xList[num2], _finalY[num2], _xList[i]); int num4 = data.Posts[i]; int num5 = _range - num3; int num6 = num3; int num7 = (num5 >= num6) ? (num6 * 2) : (num5 * 2); if (num4 != 0) { _stepFlags[num] = true; _stepFlags[num2] = true; _stepFlags[i] = true; if (num4 >= num7) { if (num5 > num6) { _finalY[i] = num4 - num6 + num3; } else { _finalY[i] = num3 - num4 + num5 - 1; } } else if (num4 % 2 == 1) { _finalY[i] = num3 - (num4 + 1) / 2; } else { _finalY[i] = num3 + num4 / 2; } } else { _stepFlags[i] = false; _finalY[i] = num3; } } for (int j = 0; j < data.PostCount; j++) { data.Posts[j] = _finalY[j]; } return(_stepFlags); }
internal override void Apply(PacketData packetData, float[] residue) { PacketData1 packetData2 = packetData as PacketData1; if (packetData2 == null) { throw new ArgumentException("Incorrect packet data!", "packetData"); } int num = packetData2.BlockSize / 2; if (packetData2.PostCount > 0) { bool[] array = UnwrapPosts(packetData2); int num2 = 0; int num3 = packetData2.Posts[0] * _multiplier; for (int i = 1; i < packetData2.PostCount; i++) { int num4 = _sortIdx[i]; if (array[num4]) { int num5 = _xList[num4]; int num6 = packetData2.Posts[num4] * _multiplier; if (num2 < num) { RenderLineMulti(num2, num3, Math.Min(num5, num), num6, residue); } num2 = num5; num3 = num6; } if (num2 >= num) { break; } } if (num2 < num) { RenderLineMulti(num2, num3, num, num3, residue); } } else { Array.Clear(residue, 0, num); } }
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); }
bool[] UnwrapPosts(PacketData1 data) { Array.Clear(_stepFlags, 2, 62); _stepFlags[0] = true; _stepFlags[1] = true; Array.Clear(_finalY, 2, 62); _finalY[0] = data.Posts[0]; _finalY[1] = data.Posts[1]; for (int i = 2; i < data.PostCount; i++) { var lowOfs = _lNeigh[i]; var highOfs = _hNeigh[i]; var predicted = RenderPoint(_xList[lowOfs], _finalY[lowOfs], _xList[highOfs], _finalY[highOfs], _xList[i]); var val = data.Posts[i]; var highroom = _range - predicted; var lowroom = predicted; int room; if (highroom < lowroom) { room = highroom * 2; } else { room = lowroom * 2; } if (val != 0) { _stepFlags[lowOfs] = true; _stepFlags[highOfs] = true; _stepFlags[i] = true; if (val >= room) { if (highroom > lowroom) { _finalY[i] = val - lowroom + predicted; } else { _finalY[i] = predicted - val + highroom - 1; } } else { if ((val % 2) == 1) { // odd _finalY[i] = predicted - ((val + 1) / 2); } else { // even _finalY[i] = predicted + (val / 2); } } } else { _stepFlags[i] = false; _finalY[i] = predicted; } } for (int i = 0; i < data.PostCount; i++) { data.Posts[i] = _finalY[i]; } return(_stepFlags); }
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(); } }
bool[] UnwrapPosts(PacketData1 data) { var stepFlags = ACache.Get<bool>(data.PostCount, false); stepFlags[0] = true; stepFlags[1] = true; var finalY = ACache.Get<int>(data.PostCount); finalY[0] = data.Posts[0]; finalY[1] = data.Posts[1]; for (int i = 2; i < data.PostCount; i++) { var lowOfs = _lNeigh[i]; var highOfs = _hNeigh[i]; var predicted = RenderPoint(_xList[lowOfs], finalY[lowOfs], _xList[highOfs], finalY[highOfs], _xList[i]); var val = data.Posts[i]; var highroom = _range - predicted; var lowroom = predicted; int room; if (highroom < lowroom) { room = highroom * 2; } else { room = lowroom * 2; } if (val != 0) { stepFlags[lowOfs] = true; stepFlags[highOfs] = true; stepFlags[i] = true; if (val >= room) { if (highroom > lowroom) { finalY[i] = val - lowroom + predicted; } else { finalY[i] = predicted - val + highroom - 1; } } else { if ((val % 2) == 1) { // odd finalY[i] = predicted - ((val + 1) / 2); } else { // even finalY[i] = predicted + (val / 2); } } } else { stepFlags[i] = false; finalY[i] = predicted; } } for (int i = 0; i < data.PostCount; i++) { data.Posts[i] = finalY[i]; } ACache.Return(ref finalY); return stepFlags; }
internal override PacketData UnpackPacket(DataPacket packet, int blockSize) { var data = new PacketData1 { BlockSize = blockSize }; // hoist ReadPosts to here since that's all we're doing... if (packet.ReadBit()) { try { var postCount = 2; var posts = ACache.Get<int>(64); posts[0] = (int)packet.ReadBits(_yBits); posts[1] = (int)packet.ReadBits(_yBits); for (int i = 0; i < _partitionClass.Length; i++) { var clsNum = _partitionClass[i]; var cdim = _classDimensions[clsNum]; var cbits = _classSubclasses[clsNum]; var csub = (1 << cbits) - 1; var cval = 0U; if (cbits > 0) { cval = (uint)_classMasterbooks[clsNum].DecodeScalar(packet); } for (int j = 0; j < cdim; j++) { var book = _subclassBooks[clsNum][cval & csub]; cval >>= cbits; if (book != null) { posts[postCount] = (int)book.DecodeScalar(packet); } ++postCount; } } data.Posts = posts; data.PostCount = postCount; } catch (EndOfStreamException) { } } return data; }
bool[] UnwrapPosts(PacketData1 data) { Array.Clear(_stepFlags, 2, 62); _stepFlags[0] = true; _stepFlags[1] = true; Array.Clear(_finalY, 2, 62); _finalY[0] = data.Posts[0]; _finalY[1] = data.Posts[1]; for (int i = 2; i < data.PostCount; i++) { var lowOfs = _lNeigh[i]; var highOfs = _hNeigh[i]; var predicted = RenderPoint(_xList[lowOfs], _finalY[lowOfs], _xList[highOfs], _finalY[highOfs], _xList[i]); var val = data.Posts[i]; var highroom = _range - predicted; var lowroom = predicted; int room; if (highroom < lowroom) { room = highroom * 2; } else { room = lowroom * 2; } if (val != 0) { _stepFlags[lowOfs] = true; _stepFlags[highOfs] = true; _stepFlags[i] = true; if (val >= room) { if (highroom > lowroom) { _finalY[i] = val - lowroom + predicted; } else { _finalY[i] = predicted - val + highroom - 1; } } else { if ((val % 2) == 1) { // odd _finalY[i] = predicted - ((val + 1) / 2); } else { // even _finalY[i] = predicted + (val / 2); } } } else { _stepFlags[i] = false; _finalY[i] = predicted; } } for (int i = 0; i < data.PostCount; i++) { data.Posts[i] = _finalY[i]; } return _stepFlags; }
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 ArgumentException (); 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 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(); } }
public override void Init(DataPacket packet) { _partitionClass = new int[(uint)packet.ReadBits(5)]; for (int i = 0; i < _partitionClass.Length; i++) { _partitionClass[i] = (int)packet.ReadBits(4); } int num = _partitionClass.Max(); _classDimensions = new int[num + 1]; _classSubclasses = new int[num + 1]; _classMasterbooks = new VorbisCodebook[num + 1]; _classMasterBookIndex = new int[num + 1]; _subclassBooks = new VorbisCodebook[num + 1][]; _subclassBookIndex = new int[num + 1][]; for (int j = 0; j <= num; j++) { _classDimensions[j] = (int)packet.ReadBits(3) + 1; _classSubclasses[j] = (int)packet.ReadBits(2); if (_classSubclasses[j] > 0) { _classMasterBookIndex[j] = (int)packet.ReadBits(8); _classMasterbooks[j] = _vorbis.Books[_classMasterBookIndex[j]]; } _subclassBooks[j] = new VorbisCodebook[1 << _classSubclasses[j]]; _subclassBookIndex[j] = new int[_subclassBooks[j].Length]; for (int k = 0; k < _subclassBooks[j].Length; k++) { int num2 = (int)packet.ReadBits(8) - 1; if (num2 >= 0) { _subclassBooks[j][k] = _vorbis.Books[num2]; } _subclassBookIndex[j][k] = num2; } } _multiplier = (int)packet.ReadBits(2); _range = _rangeLookup[_multiplier]; _yBits = _yBitsLookup[_multiplier]; _multiplier++; int num3 = (int)packet.ReadBits(4); List <int> list = new List <int>(); list.Add(0); list.Add(1 << num3); for (int l = 0; l < _partitionClass.Length; l++) { int num4 = _partitionClass[l]; for (int m = 0; m < _classDimensions[num4]; m++) { list.Add((int)packet.ReadBits(num3)); } } _xList = list.ToArray(); _lNeigh = new int[list.Count]; _hNeigh = new int[list.Count]; _sortIdx = new int[list.Count]; _sortIdx[0] = 0; _sortIdx[1] = 1; for (int n = 2; n < _lNeigh.Length; n++) { _lNeigh[n] = 0; _hNeigh[n] = 1; _sortIdx[n] = n; for (int num5 = 2; num5 < n; num5++) { int num6 = _xList[num5]; if (num6 < _xList[n]) { if (num6 > _xList[_lNeigh[n]]) { _lNeigh[n] = num5; } } else if (num6 < _xList[_hNeigh[n]]) { _hNeigh[n] = num5; } } } for (int num7 = 0; num7 < _sortIdx.Length - 1; num7++) { for (int num8 = num7 + 1; num8 < _sortIdx.Length; num8++) { if (_xList[num7] == _xList[num8]) { throw new InvalidDataException(); } if (_xList[_sortIdx[num7]] > _xList[_sortIdx[num8]]) { int num9 = _sortIdx[num7]; _sortIdx[num7] = _sortIdx[num8]; _sortIdx[num8] = num9; } } } _reusablePacketData = new PacketData1[_vorbis._channels]; for (int num10 = 0; num10 < _reusablePacketData.Length; num10++) { _reusablePacketData[num10] = new PacketData1(); } }