コード例 #1
0
ファイル: VorbisDecoder.cs プロジェクト: dondish/DPlayer.NET
        /// <summary>
        /// Fill the decoder with data
        /// </summary>
        /// <param name="input">MemoryStream with the data</param>
        public unsafe void Fill(MemoryStream input)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("VorbisDecoder");
            }

            ogg_packet packet = new ogg_packet();

            byte[] buffer = input.GetBuffer();
            int    res;

            fixed(byte *buf = buffer)
            {
                packet.packet     = &buf[input.Position];
                packet.bytes      = input.Length - input.Position;
                packet.b_o_s      = 0;
                packet.e_o_s      = 0;
                packet.granulepos = 0;
                packet.packetno   = 0;
                int err = VorbisLibrary.Synth(_block, new IntPtr((void *)&packet));

                if (err != 0)
                {
                    throw new InvalidOperationException("Failed to fill decoder, error - " + err);
                }

                res = VorbisLibrary.BlockIn(_state, _block);
            }

            if (res != 0)
            {
                throw new InvalidOperationException("Failed to fill decoder, error - " + res);
            }
        }
コード例 #2
0
ファイル: VorbisDecoder.cs プロジェクト: dondish/DPlayer.NET
        /// <summary>
        /// Parse a header of the vorbis stream
        /// </summary>
        /// <param name="input">MemoryStream with the header</param>
        /// <param name="length">Length of the header</param>
        /// <param name="bos">Boolean if this is the beginning of the stream</param>
        public unsafe void ProcessHeader(MemoryStream input, int length, bool bos)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("VorbisDecoder");
            }

            ogg_packet packet = new ogg_packet();

            byte[] buffer = input.GetBuffer();
            int    res;

            fixed(byte *buf = buffer)
            {
                packet.packet     = &buf[input.Position];
                packet.bytes      = length;
                packet.b_o_s      = bos ? 1 : 0;
                packet.e_o_s      = 0;
                packet.granulepos = 0;
                packet.packetno   = 0;
                res = VorbisLibrary.HeaderIn(_info, _comment, new IntPtr((void *)&packet));
            }

            input.Position = input.Position + length;

            if (res != 0) // error ocurred
            {
                throw new InvalidOperationException("Failed to process header, error - " + res);
            }
        }