private static void ReadDataBlock(BinaryReader reader, BrwavStructure structure, bool readAudioData) { reader.BaseStream.Position = structure.BrstmHeader.DataBlockOffset; RwavWaveInfo info = structure.WaveInfo; if (reader.ReadUTF8(4) != "DATA") { throw new InvalidDataException("Unknown or invalid DATA block"); } if (reader.ReadInt32() != structure.BrstmHeader.DataBlockSize) { throw new InvalidDataException("DATA block size in main header doesn't match size in DATA header"); } if (!readAudioData) { return; } int audioDataLength = Common.SamplesToBytes(info.SampleCount, info.Codec); structure.AudioData = CreateJaggedArray <byte[][]>(info.ChannelCount, audioDataLength); int baseOffset = (int)reader.BaseStream.Position; for (int i = 0; i < info.ChannelCount; i++) { reader.BaseStream.Position = baseOffset + info.Channels[i].AudioDataOffset; structure.AudioData[i] = reader.ReadBytes(audioDataLength); } }
private static void ReadInfoBlock(BinaryReader reader, BrwavStructure structure) { reader.BaseStream.Position = structure.BrstmHeader.HeadBlockOffset; if (reader.ReadUTF8(4) != "INFO") { throw new InvalidDataException("Unknown or invalid INFO block"); } if (reader.ReadInt32() != structure.BrstmHeader.HeadBlockSize) { throw new InvalidDataException("HEAD block size in RWAV header doesn't match size in HEAD header"); } RwavWaveInfo info = RwavWaveInfo.ReadBrwav(reader); structure.WaveInfo = info; structure.StreamInfo = info; structure.ChannelInfo = new ChannelInfo(); structure.ChannelInfo.Channels.AddRange(info.Channels.Select(x => x.AdpcmInfo)); }