public WwaInput(Stream file, int count, int dir_size) : base(null) { file.Position = 0x10; var header = new byte[count * dir_size]; if (header.Length != file.Read(header, 0, header.Length)) { throw new InvalidFormatException(); } var section = WpxSection.Find(header, 0x20, count, dir_size); if (null == section || section.UnpackedSize < 0x10 || section.DataFormat != 0x80) { throw new InvalidFormatException(); } file.Position = section.Offset; Format = ReadFormat(file); section = WpxSection.Find(header, 0x21, count, dir_size); if (null == section) { throw new InvalidFormatException(); } var reader = new WwaReader(file, section); var data = reader.Unpack(section.DataFormat); if (null == data) { throw new InvalidFormatException(); } Source = new MemoryStream(data); file.Dispose(); }
} // 'WPX' public override SoundInput TryOpen(IBinaryStream file) { var header = file.ReadHeader(0x10); if (!header.AsciiEqual(4, "WAV")) { return(null); } int count = header[0xE]; int dir_size = header[0xF]; if (1 != header[0xC] || 0 == count || 0 == dir_size) { return(null); } file.Position = 0x10; var index = file.ReadBytes(count * dir_size); var section = WpxSection.Find(index, 0x20, count, dir_size); if (null == section || section.UnpackedSize < 0x10 || section.DataFormat != 0x80) { throw new InvalidFormatException(); } file.Position = section.Offset; var fmt = file.ReadBytes(section.UnpackedSize); section = WpxSection.Find(index, 0x21, count, dir_size); if (null == section) { throw new InvalidFormatException(); } var reader = new WwaReader(file.AsStream, section); var data = reader.Unpack(section.DataFormat); if (null == data) { throw new InvalidFormatException(); } int total_size = 20 + fmt.Length + data.Length; using (var wav_file = new MemoryStream(20 + fmt.Length)) using (var wav = new BinaryWriter(wav_file)) { wav.Write(Wav.Signature); wav.Write(total_size); wav.Write(0x45564157); // 'WAVE' wav.Write(0x20746d66); // 'fmt ' wav.Write(fmt.Length); wav.Write(fmt); wav.Write(0x61746164); // 'data' wav.Write(data.Length); var wav_header = wav_file.ToArray(); var data_stream = new MemoryStream(data); var source = new PrefixStream(wav_header, data_stream); var sound = new WaveInput(source); file.Dispose(); return(sound); } }