Beispiel #1
0
        public int BlockSize(Packet Packet)
        {
            //codec_setup_info
            var Buffer = new NVorbis.Ogg.BBuffer();

            int mode;

            Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes);

            /* Check the packet type */
            if (Buffer.Read(1) != 0)
            {
                /* Oops.  This is not an audio data packet */
                return(OV_ENOTAUDIO);
            }
            {
                int  modebits = 0;
                uint v        = (uint)Modes;
                while (v > 1)
                {
                    modebits++;
                    v >>= 1;
                }

                /* read our mode and pre/post windowsize */
                mode = Buffer.Read(modebits);
            }
            if (mode == -1)
            {
                return(OV_EBADPACKET);
            }
            return(blocksizes[ModeParam[mode].blockflag]);
        }
Beispiel #2
0
        // The Vorbis header is in three packets; the initial small packet in
        // the first page that identifies basic parameters, a second packet
        // with bitstream comments and a third packet that holds the
        // codebook.

        public int SynthesisHeaderIn(Comment Comment, Packet Packet)
        {
            var Buffer = new NVorbis.Ogg.BBuffer();

            if (Packet != null)
            {
                Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis
                {
                    byte[] buffer   = new byte[6];
                    int    packtype = Buffer.Read(8);
                    Buffer.Read(buffer, 6);
                    if (buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' || buffer[3] != 'b' ||
                        buffer[4] != 'i' || buffer[5] != 's')
                    {
                        // not a vorbis header
                        return(-1);
                    }
                    switch (packtype)
                    {
                    case 0x01:                             // least significant *bit* is read first
                        if (Packet.b_o_s == 0)
                        {
                            // Not the initial packet
                            return(-1);
                        }
                        if (Rate != 0)
                        {
                            // previously initialized info header
                            return(-1);
                        }
                        return(UnpackInfo(Buffer));

                    case 0x03:                             // least significant *bit* is read first
                        if (Rate == 0)
                        {
                            // um... we didn't get the initial header
                            return(-1);
                        }
                        return(Comment.unpack(Buffer));

                    case 0x05:                             // least significant *bit* is read first
                        if (Rate == 0 || Comment.vendor == null)
                        {
                            // um... we didn;t get the initial header or comments yet
                            return(-1);
                        }
                        return(UnpackBooks(Buffer));

                    default:
                        // Not a valid vorbis header type
                        //return(-1);
                        break;
                    }
                }
            }
            return(-1);
        }
Beispiel #3
0
        // The Vorbis header is in three packets; the initial small packet in
        // the first page that identifies basic parameters, a second packet
        // with bitstream comments and a third packet that holds the
        // codebook.
        public int SynthesisHeaderIn(Comment Comment, Packet Packet)
        {
            var Buffer = new NVorbis.Ogg.BBuffer();

            if (Packet != null)
            {
                Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis
                {
                    byte[] buffer = new byte[6];
                    int packtype = Buffer.Read(8);
                    Buffer.Read(buffer, 6);
                    if (buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' || buffer[3] != 'b'
                        || buffer[4] != 'i' || buffer[5] != 's')
                    {
                        // not a vorbis header
                        return (-1);
                    }
                    switch (packtype)
                    {
                        case 0x01: // least significant *bit* is read first
                            if (Packet.b_o_s == 0)
                            {
                                // Not the initial packet
                                return (-1);
                            }
                            if (Rate != 0)
                            {
                                // previously initialized info header
                                return (-1);
                            }
                            return (UnpackInfo(Buffer));
                        case 0x03: // least significant *bit* is read first
                            if (Rate == 0)
                            {
                                // um... we didn't get the initial header
                                return (-1);
                            }
                            return (Comment.unpack(Buffer));
                        case 0x05: // least significant *bit* is read first
                            if (Rate == 0 || Comment.vendor == null)
                            {
                                // um... we didn;t get the initial header or comments yet
                                return (-1);
                            }
                            return (UnpackBooks(Buffer));
                        default:
                            // Not a valid vorbis header type
                            //return(-1);
                            break;
                    }
                }
            }
            return (-1);
        }
Beispiel #4
0
        public int synthesis(Packet op)
        {
            Info vi = vd.vi;

            // first things first.  Make sure decode is ready
            opb.ReadInit(op.packet_base, op.packet, op.bytes);

            // Check the packet type
            if (opb.Read(1) != 0)
            {
                // Oops.  This is not an audio data packet
                return(-1);
            }

            // read our mode and pre/post windowsize
            int _mode = opb.Read(vd.modebits);

            if (_mode == -1)
            {
                return(-1);
            }

            mode = _mode;
            W    = vi.ModeParam[mode].blockflag;
            if (W != 0)
            {
                lW = opb.Read(1);
                nW = opb.Read(1);
                if (nW == -1)
                {
                    return(-1);
                }
            }
            else
            {
                lW = 0;
                nW = 0;
            }

            // more setup
            granulepos = op.granulepos;
            sequence   = op.packetno - 3;           // first block is third packet
            eofflag    = op.e_o_s;

            // alloc pcm passback storage
            pcmend = vi.blocksizes[W];
            if (pcm.Length < vi.Channels)
            {
                pcm = new float[vi.Channels][];
            }
            for (int i = 0; i < vi.Channels; i++)
            {
                if (pcm[i] == null || pcm[i].Length < pcmend)
                {
                    pcm[i] = new float[pcmend];
                }
                else
                {
                    for (int j = 0; j < pcmend; j++)
                    {
                        pcm[i][j] = 0;
                    }
                }
            }

            // unpack_header enforces range checking
            int type = vi.map_type[vi.ModeParam[mode].mapping];

            return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode]));
        }
Beispiel #5
0
        public int BlockSize(Packet Packet)
        {
            //codec_setup_info
            var Buffer = new NVorbis.Ogg.BBuffer();

            int mode;

            Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes);

            /* Check the packet type */
            if (Buffer.Read(1) != 0)
            {
                /* Oops.  This is not an audio data packet */
                return (OV_ENOTAUDIO);
            }
            {
                int modebits = 0;
                uint v = (uint)Modes;
                while (v > 1)
                {
                    modebits++;
                    v >>= 1;
                }

                /* read our mode and pre/post windowsize */
                mode = Buffer.Read(modebits);
            }
            if (mode == -1)
                return (OV_EBADPACKET);
            return (blocksizes[ModeParam[mode].blockflag]);
        }