コード例 #1
0
ファイル: AudioWMA.cs プロジェクト: zxc120/GARbro
        public WmaInput(Stream file) : base(file)
        {
            var reader = new CustomMediaFoundationReader(file);

            if (reader.Duration != 0)
            {
                m_bitrate = (int)(file.Length * 80000000L / reader.Duration);
            }
            else
            {
                m_bitrate = reader.WaveFormat.AverageBytesPerSecond * 8;
            }
            m_reader = reader;
            var format = new GameRes.WaveFormat {
                FormatTag             = (ushort)m_reader.WaveFormat.Encoding,
                Channels              = (ushort)m_reader.WaveFormat.Channels,
                SamplesPerSecond      = (uint)m_reader.WaveFormat.SampleRate,
                BitsPerSample         = (ushort)m_reader.WaveFormat.BitsPerSample,
                BlockAlign            = (ushort)m_reader.BlockAlign,
                AverageBytesPerSecond = (uint)m_reader.WaveFormat.AverageBytesPerSecond,
            };

            this.Format  = format;
            this.PcmSize = m_reader.Length;
        }
コード例 #2
0
        public OggInput(Stream file) : base(file)
        {
            m_reader = new VorbisReader(Source, false);
            var format = new GameRes.WaveFormat();

            format.FormatTag             = 3;    // WAVE_FORMAT_IEEE_FLOAT
            format.Channels              = (ushort)m_reader.Channels;
            format.SamplesPerSecond      = (uint)m_reader.SampleRate;
            format.BitsPerSample         = 32;
            format.BlockAlign            = (ushort)(4 * format.Channels);
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;
            this.Format  = format;
            this.PcmSize = (long)(m_reader.TotalTime.TotalSeconds * format.SamplesPerSecond * format.Channels * sizeof(float));
        }
コード例 #3
0
ファイル: AudioMP3.cs プロジェクト: tenyuhuang/GARbro
        public Mp3Input(Stream file) : base(file)
        {
            m_reader  = new Mp3FileReader(file);
            m_bitrate = m_reader.Mp3WaveFormat.AverageBytesPerSecond * 8;
            var format = new GameRes.WaveFormat();

            format.FormatTag             = (ushort)m_reader.WaveFormat.Encoding;
            format.Channels              = (ushort)m_reader.WaveFormat.Channels;
            format.SamplesPerSecond      = (uint)m_reader.WaveFormat.SampleRate;
            format.BitsPerSample         = (ushort)m_reader.WaveFormat.BitsPerSample;
            format.BlockAlign            = (ushort)m_reader.BlockAlign;
            format.AverageBytesPerSecond = (uint)m_reader.WaveFormat.AverageBytesPerSecond;
            this.Format  = format;
            this.PcmSize = m_reader.Length;
        }
コード例 #4
0
ファイル: AudioAIFF.cs プロジェクト: zxc120/GARbro
        public AiffInput(Stream file) : base(file)
        {
            m_reader = new AiffFileReader(file);
            var format = new GameRes.WaveFormat {
                FormatTag             = (ushort)m_reader.WaveFormat.Encoding,
                Channels              = (ushort)m_reader.WaveFormat.Channels,
                SamplesPerSecond      = (uint)m_reader.WaveFormat.SampleRate,
                BitsPerSample         = (ushort)m_reader.WaveFormat.BitsPerSample,
                BlockAlign            = (ushort)m_reader.BlockAlign,
                AverageBytesPerSecond = (uint)m_reader.WaveFormat.AverageBytesPerSecond,
            };

            this.Format  = format;
            this.PcmSize = m_reader.Length;
        }
コード例 #5
0
ファイル: AudioWAV.cs プロジェクト: zxc120/GARbro
        public WaveInput(Stream file) : base(file)
        {
            m_reader = new WaveFileReader(file);
            var wf = m_reader.WaveFormat;

            if (ConversionRequired.Contains(wf.Encoding))
            {
                var wav = WaveFormatConversionStream.CreatePcmStream(m_reader);
                wf       = wav.WaveFormat;
                m_reader = wav;
            }
            var format = new GameRes.WaveFormat();

            format.FormatTag             = (ushort)wf.Encoding;
            format.Channels              = (ushort)wf.Channels;
            format.SamplesPerSecond      = (uint)wf.SampleRate;
            format.BitsPerSample         = (ushort)wf.BitsPerSample;
            format.BlockAlign            = (ushort)wf.BlockAlign;
            format.AverageBytesPerSecond = (uint)wf.AverageBytesPerSecond;
            this.Format  = format;
            this.PcmSize = m_reader.Length;
        }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
ファイル: AudioWAV.cs プロジェクト: Casidi/GARbro
 public WaveInput(Stream file)
     : base(file)
 {
     m_reader = new WaveFileReader (file);
     var wf = m_reader.WaveFormat;
     if (ConversionRequired.Contains (wf.Encoding))
     {
         var wav = WaveFormatConversionStream.CreatePcmStream (m_reader);
         wf = wav.WaveFormat;
         m_reader = wav;
     }
     var format = new GameRes.WaveFormat();
     format.FormatTag                = (ushort)wf.Encoding;
     format.Channels                 = (ushort)wf.Channels;
     format.SamplesPerSecond         = (uint)wf.SampleRate;
     format.BitsPerSample            = (ushort)wf.BitsPerSample;
     format.BlockAlign               = (ushort)wf.BlockAlign;
     format.AverageBytesPerSecond    = (uint)wf.AverageBytesPerSecond;
     this.Format = format;
     this.PcmSize = m_reader.Length;
 }
コード例 #8
0
ファイル: AudioMP3.cs プロジェクト: Casidi/GARbro
 public Mp3Input(Stream file)
     : base(file)
 {
     m_reader = new Mp3FileReader (file);
     m_bitrate = m_reader.Mp3WaveFormat.AverageBytesPerSecond*8;
     var format = new GameRes.WaveFormat();
     format.FormatTag                = (ushort)m_reader.WaveFormat.Encoding;
     format.Channels                 = (ushort)m_reader.WaveFormat.Channels;
     format.SamplesPerSecond         = (uint)m_reader.WaveFormat.SampleRate;
     format.BitsPerSample            = (ushort)m_reader.WaveFormat.BitsPerSample;
     format.BlockAlign               = (ushort)m_reader.BlockAlign;
     format.AverageBytesPerSecond    = (uint)m_reader.WaveFormat.AverageBytesPerSecond;
     this.Format = format;
     this.PcmSize = m_reader.Length;
 }