private static void ReadExtensionParams(BitReader reader, Block block) { // ReSharper disable once RedundantAssignment int bexBand = 0; if (block.BandExtensionEnabled) { int a, b = 0; BandExtension.GetBexBandInfo(out bexBand, out a, out b, block.QuantizationUnitCount); if (block.BlockType == BlockType.Stereo) { ReadHeader(block.Channels[1], reader, bexBand); } else { reader.Position += 1; } } block.HasExtensionData = reader.ReadBool(); if (!block.HasExtensionData) { return; } if (!block.BandExtensionEnabled) { block.BexMode = reader.ReadInt(2); block.BexDataLength = reader.ReadInt(5); reader.Position += block.BexDataLength; return; } ReadHeader(block.Channels[0], reader, bexBand); block.BexDataLength = reader.ReadInt(5); if (block.BexDataLength <= 0) { return; } int bexDataEnd = reader.Position + block.BexDataLength; ReadData(block.Channels[0], reader, bexBand); if (block.BlockType == BlockType.Stereo) { ReadData(block.Channels[1], reader, bexBand); } // Make sure we didn't read too many bits if (reader.Position > bexDataEnd) { throw new InvalidDataException(); } }
private static void DecodeFrame(BitReader reader, Frame frame) { Unpack.UnpackFrame(reader, frame); foreach (Block block in frame.Blocks) { Quantization.DequantizeSpectra(block); Stereo.ApplyIntensityStereo(block); Quantization.ScaleSpectrum(block); BandExtension.ApplyBandExtension(block); ImdctBlock(block); } }
private static void ReadExtensionParams(BitReader reader, Block block) { // ReSharper disable once RedundantAssignment int bexBand = 0; if (block.BandExtensionEnabled) { BandExtension.GetBexBandInfo(out bexBand, out _, out _, block.QuantizationUnitCount); if (block.BlockType == BlockType.Stereo) { ReadHeader(block.Channels[1]); } else { reader.Position += 1; } } block.HasExtensionData = reader.ReadBool(); if (!block.HasExtensionData) { return; } if (!block.BandExtensionEnabled) { block.BexMode = reader.ReadInt(2); block.BexDataLength = reader.ReadInt(5); reader.Position += block.BexDataLength; return; } ReadHeader(block.Channels[0]); block.BexDataLength = reader.ReadInt(5); if (block.BexDataLength <= 0) { return; } int bexDataEnd = reader.Position + block.BexDataLength; ReadData(block.Channels[0]); if (block.BlockType == BlockType.Stereo) { ReadData(block.Channels[1]); } // Make sure we didn't read too many bits if (reader.Position > bexDataEnd) { throw new InvalidDataException(); } void ReadHeader(Channel channel) { int bexMode = reader.ReadInt(2); channel.BexMode = bexBand > 2 ? bexMode : 4; channel.BexValueCount = BandExtension.BexEncodedValueCounts[channel.BexMode][bexBand]; } void ReadData(Channel channel) { for (int i = 0; i < channel.BexValueCount; i++) { int dataLength = BandExtension.BexDataLengths[channel.BexMode][bexBand][i]; channel.BexValues[i] = reader.ReadInt(dataLength); } } }