protected WaveDataChunk(RiffParser parser, BinaryReader reader) : base(reader) { if (parser.ReadDataChunk) { Data = reader.ReadBytes(SubChunkSize); } }
public At9DataChunk(RiffParser parser, BinaryReader reader) : base(reader) { // Do not trust the BlockAlign field in the fmt chunk to equal the superframe size. // Some AT9 files have an invalid number in there. // Calculate the size using the ATRAC9 DataConfig instead. At9WaveExtensible ext = parser.GetSubChunk <WaveFmtChunk>("fmt ")?.Ext as At9WaveExtensible; if (ext == null) { throw new InvalidDataException("fmt chunk must come before data chunk"); } At9FactChunk fact = parser.GetSubChunk <At9FactChunk>("fact"); if (fact == null) { throw new InvalidDataException("fact chunk must come before data chunk"); } var config = new LibAtrac9.Atrac9Config(ext.ConfigData); FrameCount = (fact.SampleCount + fact.EncoderDelaySamples).DivideByRoundUp(config.SuperframeSamples); int dataSize = FrameCount * config.SuperframeBytes; if (dataSize > reader.BaseStream.Length - reader.BaseStream.Position) { throw new InvalidDataException("Required AT9 length is greater than the number of bytes remaining in the file."); } AudioData = reader.BaseStream.DeInterleave(dataSize, config.SuperframeBytes, FrameCount); }
protected WaveFmtChunk(RiffParser parser, BinaryReader reader) : base(reader) { FormatTag = reader.ReadUInt16(); ChannelCount = reader.ReadInt16(); SampleRate = reader.ReadInt32(); AvgBytesPerSec = reader.ReadInt32(); BlockAlign = reader.ReadInt16(); BitsPerSample = reader.ReadInt16(); if (FormatTag == WaveFormatTags.WaveFormatExtensible && parser.FormatExtensibleParser != null) { long startOffset = reader.BaseStream.Position + 2; Ext = parser.FormatExtensibleParser(parser, reader); long endOffset = startOffset + Ext.Size; int remainingBytes = (int)Math.Max(endOffset - reader.BaseStream.Position, 0); Ext.Extra = reader.ReadBytes(remainingBytes); } }
public static WaveFormatExtensible Parse(RiffParser parser, BinaryReader reader) => new WaveFormatExtensible(reader);
public static At9DataChunk ParseAt9(RiffParser parser, BinaryReader reader) => new At9DataChunk(parser, reader);
public static At9WaveExtensible ParseAt9(RiffParser parser, BinaryReader reader) => new At9WaveExtensible(reader);
public static At9FactChunk ParseAt9(RiffParser parser, BinaryReader reader) => new At9FactChunk(reader);
public static WaveDataChunk Parse(RiffParser parser, BinaryReader reader) => new WaveDataChunk(parser, reader);
public static WaveFactChunk Parse(RiffParser parser, BinaryReader reader) => new WaveFactChunk(reader);