public MioDecoder(MioInfoHeader info) { m_nBufLength = 0; m_mioih = info; if (!Initialize()) throw new InvalidFormatException(); }
public MioDecoder(MioInfoHeader info) { m_nBufLength = 0; m_mioih = info; if (!Initialize()) { throw new InvalidFormatException(); } }
public MioInput(Stream file) : base(file) { file.Position = 0x40; using (var erif = new EriFile(file)) { var section = erif.ReadSection(); if (section.Id != "Header " || section.Length <= 0 || section.Length > int.MaxValue) { throw new InvalidFormatException(); } m_stream_pos = 0x50 + section.Length; int header_size = (int)section.Length; while (header_size > 0x10) { section = erif.ReadSection(); header_size -= 0x10; if (section.Length <= 0 || section.Length > header_size) { break; } if ("SoundInf" == section.Id) { m_info = new MioInfoHeader(); m_info.Version = erif.ReadInt32(); m_info.Transformation = (CvType)erif.ReadInt32(); m_info.Architecture = (EriCode)erif.ReadInt32(); m_info.ChannelCount = erif.ReadInt32(); m_info.SamplesPerSec = erif.ReadUInt32(); m_info.BlocksetCount = erif.ReadUInt32(); m_info.SubbandDegree = erif.ReadInt32(); m_info.AllSampleCount = erif.ReadUInt32(); m_info.LappedDegree = erif.ReadUInt32(); m_info.BitsPerSample = erif.ReadUInt32(); break; } header_size -= (int)section.Length; erif.BaseStream.Seek(section.Length, SeekOrigin.Current); } if (null == m_info) { throw new InvalidFormatException("MIO sound header not found"); } erif.BaseStream.Position = m_stream_pos; var stream_size = erif.FindSection("Stream "); m_stream_pos = erif.BaseStream.Position; m_pmiod = new MioDecoder(m_info); if (EriCode.Nemesis != m_info.Architecture) { m_pmioc = new HuffmanDecodeContext(0x10000); } else { throw new NotImplementedException("MIO Nemesis encoding not implemented"); } int pcm_bitrate = (int)(m_info.SamplesPerSec * BitsPerSample * ChannelCount); var format = new GameRes.WaveFormat(); format.FormatTag = 1; format.Channels = (ushort)ChannelCount; format.SamplesPerSecond = m_info.SamplesPerSec; format.BitsPerSample = (ushort)BitsPerSample; format.BlockAlign = (ushort)(BitsPerSample / 8 * format.Channels); format.AverageBytesPerSecond = (uint)pcm_bitrate / 8; this.Format = format; m_decoded_stream = LoadChunks(erif); if (0 != m_total_samples) { m_bitrate = (int)(stream_size * 8 * m_info.SamplesPerSec / m_total_samples); } this.PcmSize = m_total_samples * ChannelCount * BitsPerSample / 8; m_decoded_stream.Position = 0; } }