public override Stream OpenEntry(ArcFile arc, Entry entry) { if (ScriptNameRe.IsMatch(entry.Name)) { byte key = (byte)~entry.Offset; var data = arc.File.View.ReadBytes(entry.Offset, entry.Size); Decrypt(data, data.Length, key); return(new BinMemoryStream(data)); } if (AudioNameRe.IsMatch(entry.Name)) { using (var wav = new MemoryStream(0x2C)) { var format = new WaveFormat { FormatTag = 1, Channels = 1, SamplesPerSecond = AudioSampleRate.Get <uint>(), BlockAlign = 2, BitsPerSample = 16, }; format.SetBPS(); WaveAudio.WriteRiffHeader(wav, format, entry.Size); var header = wav.ToArray(); var data = arc.File.CreateStream(entry.Offset, entry.Size); return(new PrefixStream(header, data)); } } var input = arc.File.CreateStream(entry.Offset, entry.Size); if (0x5E6A6A42 == input.Signature) { return(new XoredStream(input, 0xD)); } return(input); }
public override Stream OpenEntry(ArcFile arc, Entry entry) { if (!arc.File.Name.HasExtension(".wda")) { return(base.OpenEntry(arc, entry)); } var format = new WaveFormat { FormatTag = 1, Channels = 1, SamplesPerSecond = 22050, AverageBytesPerSecond = 44100, BlockAlign = 2, BitsPerSample = 16, }; byte[] wav_header; using (var output = new MemoryStream(0x2C)) { WaveAudio.WriteRiffHeader(output, format, entry.Size); wav_header = output.ToArray(); } var pcm_data = arc.File.CreateStream(entry.Offset, entry.Size); return(new PrefixStream(wav_header, pcm_data)); }
public override Stream OpenEntry(ArcFile arc, Entry entry) { var went = (WsmEntry)entry; using (var riff = new MemoryStream(0x2C)) { WaveAudio.WriteRiffHeader(riff, went.Format, entry.Size); var input = arc.File.CreateStream(entry.Offset, entry.Size); return(new PrefixStream(riff.ToArray(), input)); } }
public override Stream OpenEntry(ArcFile arc, Entry entry) { var went = entry as MgsEntry; if (null == went || went.Format != 0) { return(arc.File.CreateStream(entry.Offset, entry.Size)); } var format = new WaveFormat { FormatTag = 1, Channels = (ushort)(went.Channels & 0x7FFF), SamplesPerSecond = went.SamplesPerSecond, }; Stream pcm; uint pcm_size; if (0 != (went.Channels & 0x8000)) { format.BitsPerSample = 0x10; var decoder = new PcmDecoder(went); using (var input = arc.File.CreateStream(entry.Offset, entry.Size)) { var data = decoder.Decode(input); pcm = new MemoryStream(data); pcm_size = (uint)data.Length; } } else { format.BitsPerSample = went.BitsPerSample; pcm = arc.File.CreateStream(entry.Offset, entry.Size); pcm_size = entry.Size; } using (var riff = new MemoryStream(0x2C)) { ushort align = (ushort)(format.Channels * format.BitsPerSample / 8); format.AverageBytesPerSecond = went.SamplesPerSecond * align; format.BlockAlign = align; WaveAudio.WriteRiffHeader(riff, format, pcm_size); return(new PrefixStream(riff.ToArray(), pcm)); } }
Stream OpenAudio(ArcFile arc, Entry entry) { using (var input = arc.File.CreateStream(entry.Offset, entry.Size)) { var header = input.ReadHeader(0x20); int header_size = header.ToUInt16(10); var format = new WaveFormat { FormatTag = header.ToUInt16(0x10), Channels = header.ToUInt16(0x12), SamplesPerSecond = header.ToUInt32(0x14), AverageBytesPerSecond = header.ToUInt32(0x18), BlockAlign = header.ToUInt16(0x1C), BitsPerSample = header.ToUInt16(0x1E), }; input.Position = header_size + 0x10; var data = new byte[header.ToInt32(0)]; KTool.Unpack(input, data, header[8]); var output = new MemoryStream(data.Length); WaveAudio.WriteRiffHeader(output, format, (uint)data.Length); output.Write(data, 0, data.Length); output.Position = 0; return(output); } }
public override Stream OpenEntry(ArcFile arc, Entry entry) { var kent = (KoeEntry)entry; var karc = (KoeArchive)arc; var table = new ushort[kent.SampleCount]; uint packed_size = 0; var offset = kent.Offset; for (int i = 0; i < table.Length; ++i) { table[i] = arc.File.View.ReadUInt16(offset); offset += 2; packed_size += table[i]; } int total_size = kent.SampleCount * 0x1000; var wav = new MemoryStream(total_size); WaveAudio.WriteRiffHeader(wav, karc.Format, (uint)total_size); using (var output = new BinaryWriter(wav, Encoding.ASCII, true)) using (var input = arc.File.CreateStream(offset, packed_size)) { foreach (ushort chunk_length in table) { if (0 == chunk_length) { output.Seek(0x1000, SeekOrigin.Current); } else if (0x400 == chunk_length) { for (int i = 0; i < 0x400; ++i) { ushort sample = SampleTable[input.ReadUInt8()]; output.Write(sample); output.Write(sample); } } else { byte src = 0; for (int i = 0; i < 0x400; i += 2) { byte bits = input.ReadUInt8(); if (0 != ((bits + 1) & 0xF)) { src -= AdjustTable[bits & 0xF]; } else { int idx = bits >> 4; bits = input.ReadUInt8(); idx |= (bits << 4) & 0xF0; src -= AdjustTable[idx]; } ushort sample = SampleTable[src]; output.Write(sample); output.Write(sample); bits >>= 4; if (0 != ((bits + 1) & 0xF)) { src -= AdjustTable[bits & 0xF]; } else { src -= AdjustTable[input.ReadUInt8()]; } sample = SampleTable[src]; output.Write(sample); output.Write(sample); } } } } kent.UnpackedSize = (uint)wav.Length; wav.Position = 0; return(wav); }