public override SoundInput TryOpen(IBinaryStream file) { int packed = file.ReadInt32(); if (packed < 0) { return(null); } byte[] input; if (packed > 12) { if ((packed + 8) != file.Length) { return(null); } int unpacked = file.ReadInt32(); if (unpacked <= 0) { return(null); } using (var reader = new LzssReader(file.AsStream, packed, unpacked)) { reader.Unpack(); if (Binary.AsciiEqual(reader.Data, 0, "RIFF")) { var sound = new WaveInput(new MemoryStream(reader.Data)); file.Dispose(); return(sound); } input = reader.Data; } } else { if (0x46464952 != file.ReadInt32()) // 'RIFF' { return(null); } file.Position = 0; input = new byte[file.Length]; file.Read(input, 0, input.Length); } var wa1 = new Wa1Reader(input); wa1.Unpack(); var wav = new WaveInput(new MemoryStream(wa1.Data)); file.Dispose(); return(wav); }
public CrelicUnitedGameProject DeserializeRelic() { if (!m_read_toc) { m_read_toc = true; m_relic = m_arc.DeserializeRoot() as CrelicUnitedGameProject; if (m_toc != m_input) { m_toc.Dispose(); m_toc = m_input; m_arc.SetSource(m_input); } } return(m_relic); }
public override SoundInput TryOpen(IBinaryStream file) { var header = file.ReadHeader(0x10); int samples = header.ToInt32(4); uint sample_rate = header.ToUInt32(8); if (sample_rate < 8000 || sample_rate > 96000) { return(null); } ushort channels = header.ToUInt16(12); if (channels != 1 && channels != 2) { return(null); } samples *= channels; var output = new byte[2 * samples]; var first = new AdpDecoder(); var second = first; if (channels > 1) { second = new AdpDecoder(); } int dst = 0; while (samples > 0) { int v = file.ReadByte(); if (-1 == v) { break; } LittleEndian.Pack(first.DecodeSample(v), output, dst); if (0 == --samples) { break; } dst += 2; LittleEndian.Pack(second.DecodeSample(v >> 4), output, dst); dst += 2; --samples; } var format = new WaveFormat { FormatTag = 1, Channels = channels, SamplesPerSecond = sample_rate, AverageBytesPerSecond = 2u * channels * sample_rate, BlockAlign = (ushort)(2 * channels), BitsPerSample = 16, }; var pcm = new MemoryStream(output); var sound = new RawPcmInput(pcm, format); file.Dispose(); return(sound); }
public WadyInput(IBinaryStream input) : base(new MemoryStream()) { input.Seek(5, SeekOrigin.Begin); MulValue = input.ReadUInt8(); input.Seek(6, SeekOrigin.Current); int src_size = input.ReadInt32(); input.Seek(16, SeekOrigin.Current); var format = new WaveFormat(); format.FormatTag = input.ReadUInt16(); format.Channels = input.ReadUInt16(); format.SamplesPerSecond = input.ReadUInt32(); format.AverageBytesPerSecond = input.ReadUInt32(); format.BlockAlign = input.ReadUInt16(); format.BitsPerSample = input.ReadUInt16(); format.ExtraSize = 0; this.Format = format; int remaining = (int)(input.Length - input.Position); if (remaining == src_size) { (Source as MemoryStream).Capacity = src_size * 2; Decode(input, src_size, Source); } else { Decode2(input, Source); } Source.Position = 0; this.PcmSize = Source.Length; input.Dispose(); }
public override SoundInput TryOpen(IBinaryStream file) { ushort schema = Binary.BigEndian(file.ReadUInt16()); if (4 == (schema & 0x10F)) { file.Position = 0; schema = 0; } else if (0x10B != schema) { return(null); } var mp3 = new MemoryStream(); try { if (!ConvertToMp3(file, mp3, schema)) { mp3.Dispose(); return(null); } mp3.Position = 0; var sound = new Mp3Input(mp3); file.Dispose(); return(sound); } catch { mp3.Dispose(); throw; } }
public override SoundInput TryOpen(IBinaryStream file) { if (!file.Name.HasExtension("PWV")) { return(null); } var header = file.ReadHeader(0x10); if (!header.AsciiEqual(9, "WAVE")) { return(null); } var output = new MemoryStream((int)file.Length); try { file.Position = 0; Unpack(file, output); output.Position = 0; var wave = new WaveInput(output); file.Dispose(); return(wave); } catch { output.Dispose(); throw; } }
const uint DefaultSampleRate = 44100; // XXX varies public override SoundInput TryOpen(IBinaryStream file) { bool is_adp4 = file.Name.HasExtension(".adp4"); bool is_adps = !is_adp4 && file.Name.HasExtension(".adps"); if (!(is_adp4 || is_adps) || file.Length <= 4) { return(null); } var decoder = new AdpDecoder(file); var pcm = decoder.Decode(is_adps); var format = new WaveFormat { FormatTag = 1, Channels = 2, SamplesPerSecond = DefaultSampleRate, BlockAlign = 4, BitsPerSample = 16, }; format.SetBPS(); var input = new MemoryStream(pcm); var sound = new RawPcmInput(input, format); file.Dispose(); return(sound); }
public override SoundInput TryOpen(IBinaryStream file) { int first = file.ReadByte(); if ((first ^ 0x21) != 0x78) // doesn't look like zlib stream { return(null); } file.Position = 0; using (var input = new XoredStream(file.AsStream, 0x21, true)) using (var zstream = new ZLibStream(input, CompressionMode.Decompress)) { SoundInput sound = null; var wav = new MemoryStream(); try { zstream.CopyTo(wav); wav.Position = 0; sound = new WaveInput(wav); } finally { if (null == sound) { wav.Dispose(); } else { file.Dispose(); } } return(sound); } }
public override SoundInput TryOpen(IBinaryStream file) { var fsb = new Fsb5Decoder(file); var sound = fsb.Convert(); file.Dispose(); return(sound); }
public void Dispose() { if (!m_disposed) { m_index.Dispose(); m_disposed = true; } }
protected virtual void Dispose(bool disposing) { if (disposing && !_disposed) { m_index.Dispose(); _disposed = true; } }
protected virtual void Dispose(bool disposing) { if (!m_disposed) { m_input.Dispose(); m_disposed = true; } }
public void Dispose() { if (!_disposed) { m_input.Dispose(); _disposed = true; } }
public void Dispose() { if (!m_disposed && m_should_dispose) { m_input.Dispose(); m_disposed = true; } }
public void Dispose() { if (!m_disposed) { m_file.Dispose(); m_disposed = true; } }
public override SoundInput TryOpen (IBinaryStream file) { var decoder = new WbcDecoder (file); var data = decoder.Decode(); var pcm = new MemoryStream (data); var sound = new RawPcmInput (pcm, decoder.Format); file.Dispose(); return sound; }
public void Dispose() { if (!_disposed) { m_input.Dispose(); _disposed = true; } GC.SuppressFinalize(this); }
public void Dispose() { if (!m_disposed) { m_input.Dispose(); m_bits.Dispose(); m_disposed = true; } }
public override SoundInput TryOpen(IBinaryStream file) { var decoder = new Wv5Decoder(file); var pcm_data = decoder.Unpack(); var pcm = new MemoryStream(pcm_data); var sound = new RawPcmInput(pcm, decoder.Format); file.Dispose(); return(sound); }
} // 'MKVS' public override SoundInput TryOpen(IBinaryStream file) { using (var reader = new MvDecoder(file)) { reader.Unpack(); var input = new MemoryStream(reader.Data); var sound = new RawPcmInput(input, reader.Format); file.Dispose(); return(sound); } }
public override SoundInput TryOpen(IBinaryStream file) { using (var decoder = new Mv2Decoder(file)) { decoder.Unpack(); var pcm = new MemoryStream(decoder.Data); var sound = new RawPcmInput(pcm, decoder.Format); file.Dispose(); return(sound); } }
protected virtual void Dispose(bool disposing) { if (!m_disposed) { if (disposing && m_should_dispose) { m_input.Dispose(); } m_disposed = true; } }
protected override void Dispose(bool disposing) { if (!m_disposed) { if (m_input != null) { m_input.Dispose(); } m_disposed = true; } }
public override SoundInput TryOpen(IBinaryStream file) { var header = file.ReadHeader(0x30); if (!header.AsciiEqual(0, "WV1.0\0")) { return(null); } var format = new WaveFormat { FormatTag = 1, Channels = header.ToUInt16(0xA), SamplesPerSecond = header.ToUInt32(0xE), BitsPerSample = 16, }; format.BlockAlign = (ushort)(format.Channels * format.BitsPerSample / 8); format.SetBPS(); int sample_count = header.ToInt32(0x26); var pcm = new MemoryStream(2 * sample_count); using (var output = new BinaryWriter(pcm, Encoding.ASCII, true)) { var l_decoder = new Wv1Decoder(); var r_decoder = l_decoder; if (format.Channels > 1) { r_decoder = new Wv1Decoder(); } int input_sample = 0; for (int i = 0; i < sample_count; ++i) { bool odd_sample = (i & 1) != 0; short sample; if (odd_sample) { sample = r_decoder.DecodeSample(input_sample >> 4); } else { input_sample = file.ReadByte(); if (-1 == input_sample) { break; } sample = l_decoder.DecodeSample(input_sample & 0xF); } output.Write(sample); } } file.Dispose(); pcm.Position = 0; return(new RawPcmInput(pcm, format)); }
public override SoundInput TryOpen(IBinaryStream file) { var header = new byte[Math.Min(0xE1F, file.Length)]; if (0x10 != file.Read(header, 0, 0x10)) { return(null); } var signature = LittleEndian.ToUInt32(header, 0); byte[] key; if (!KnownKeys.TryGetValue(signature, out key)) { signature = LittleEndian.ToUInt32(header, 0xC); if (!KnownKeys.TryGetValue(signature, out key)) { return(null); } file.Read(header, 4, 0xC); } header[0] = (byte)'O'; header[1] = (byte)'g'; header[2] = (byte)'g'; header[3] = (byte)'S'; file.Read(header, 0x10, header.Length - 0x10); int k = 0; for (int i = 4; i < header.Length; ++i) { header[i] ^= key[k++]; if (k >= key.Length) { k = 1; } } Stream input; if (header.Length >= file.Length) { input = new MemoryStream(header); } else { input = new PrefixStream(header, new StreamRegion(file.AsStream, file.Position)); } var sound = new OggInput(input); if (header.Length >= file.Length) { file.Dispose(); } return(sound); }
/// <summary> /// Create instance of ImageFormatDecoder from input binary stream. /// In case of error input stream is disposed. /// </summary> public static ImageFormatDecoder Create(IBinaryStream input) { try { return(new ImageFormatDecoder(input)); } catch { input.Dispose(); throw; } }
public void Dispose() { if (!_disposed) { m_input.Dispose(); if (m_toc != m_input) { m_toc.Dispose(); } _disposed = true; } }
public void Dispose() { if (!m_disposed) { if (m_should_dispose) { m_input.Dispose(); } m_disposed = true; } System.GC.SuppressFinalize(this); }
} // 'WST2' public override SoundInput TryOpen(IBinaryStream file) { var adpcm_data = new byte[0x20]; file.Position = 12; if (0x1C != file.Read(adpcm_data, 4, 0x1C)) { return(null); } adpcm_data[0] = 0xF4; adpcm_data[1] = 7; adpcm_data[2] = 7; int data_length = (int)(file.Length - file.Position); int total_size = 0x4E - 8 + data_length; var wav_file = new MemoryStream(total_size + 4); try { using (var wav = new BinaryWriter(wav_file, Encoding.Default, true)) { wav.Write(Wav.Signature); wav.Write(total_size); wav.Write(0x45564157); // 'WAVE' wav.Write(0x20746d66); // 'fmt ' wav.Write(0x32); wav.Write((ushort)2); // ADPCM wav.Write((ushort)2); // channels wav.Write((uint)0xAC44); wav.Write((uint)0xAC44); wav.Write((ushort)0x800); wav.Write((ushort)4); wav.Write((ushort)0x20); wav.Write(adpcm_data, 0, adpcm_data.Length); wav.Write(0x61746164); // 'data' wav.Write(data_length); file.AsStream.CopyTo(wav_file); } wav_file.Position = 0; var sound = new WaveInput(wav_file); file.Dispose(); return(sound); } catch { wav_file.Dispose(); throw; } }
} // 'XPCM' public override SoundInput TryOpen(IBinaryStream file) { file.Position = 4; int src_size = file.ReadInt32(); if (src_size <= 0) { throw new InvalidFormatException(); } int mode = file.ReadInt32(); int extra = (mode >> 8) & 0xff; mode &= 0xff; if (5 == mode) { uint ogg_size = file.ReadUInt32(); var ogg = new StreamRegion(file.AsStream, 0x10, ogg_size); return(new OggInput(ogg)); } var format = new WaveFormat(); format.FormatTag = file.ReadUInt16(); format.Channels = file.ReadUInt16(); format.SamplesPerSecond = file.ReadUInt32(); format.AverageBytesPerSecond = file.ReadUInt32(); format.BlockAlign = file.ReadUInt16(); format.BitsPerSample = file.ReadUInt16(); Stream pcm; if (0 == mode) { pcm = new StreamRegion(file.AsStream, file.Position, src_size); } else if (1 == mode || 3 == mode) { var decoder = new PcmDecoder(file, src_size, extra, (XpcmCompression)mode); pcm = new MemoryStream(decoder.Unpack(), 0, src_size); file.Dispose(); } else { throw new NotSupportedException("Not supported Circus PCM audio compression"); } return(new RawPcmInput(pcm, format)); }