Ejemplo n.º 1
0
        /* used to track pcm position without actually performing decode. Useful for sequential 'fast forward' */
        static public int vorbis_synthesis_trackonly(ref vorbis_block vb, ref Ogg.ogg_packet op)
        {
            vorbis_dsp_state vd = vb.vd;
            private_state    b  = vd.backend_state as private_state;
            vorbis_info      vi = vd.vi;
            codec_setup_info ci = vi.codec_setup as codec_setup_info;

            Ogg.oggpack_buffer opb = vb.opb;
            int mode;

            /* first things first.  Make sure decode is ready */
            _vorbis_block_ripcord(ref vb);
            Ogg.oggpack_readinit(ref opb, op.packet, op.bytes);

            /* Check the packet type */
            if (Ogg.oggpack_read(ref opb, 1) != 0)
            {
                /* Oops. This is not an audio data packet */
                return(OV_ENOTAUDIO);
            }

            /* read our mode and pre/post windowsize */
            mode = Ogg.oggpack_read(ref opb, b.modebits);

            if (mode == -1)
            {
                return(OV_EBADPACKET);
            }

            vb.mode = mode;

            vb.W = ci.mode_param[mode].blockflag;
            if (vb.W > 0)
            {
                vb.lW = Ogg.oggpack_read(ref opb, 1);
                vb.nW = Ogg.oggpack_read(ref opb, 1);

                if (vb.nW == -1)
                {
                    return(OV_EBADPACKET);
                }
            }
            else
            {
                vb.lW = 0;
                vb.nW = 0;
            }

            /* more setup */
            vb.granulepos = op.granulepos;
            vb.sequence   = op.packetno;
            vb.eofflag    = op.e_o_s;

            /* no pcm */
            vb.pcmend = 0;
            vb.pcm    = null;

            return(0);
        }
Ejemplo n.º 2
0
        static public int vorbis_analysis(ref vorbis_block vb, ref Ogg.ogg_packet op)
        {
            int ret, i;

            vorbis_block_internal vbi = vb._internal as vorbis_block_internal;

            vb.glue_bits  = 0;
            vb.time_bits  = 0;
            vb.floor_bits = 0;
            vb.res_bits   = 0;

            /* first things first.  Make sure encode is ready */

            for (i = 0; i < PACKETBLOBS; i++)
            {
                Ogg.oggpack_reset(ref vbi.packetblob[i]);
            }

            /* we only have one mapping type (0), and we let the mapping code itself figure out what soft mode to use.
             * This allows easier bitrate management */

            if ((ret = _mapping_P[0].forward(ref vb)) != 0)
            {
                return(ret);
            }

            if (vorbis_bitrate_managed(ref vb) != 0)
            {
                /* The app is using a bitmanaged mode... but not using the
                 * bitrate management interface. */
                return(OV_EINVAL);
            }

            op.packet     = Ogg.oggpack_get_buffer(ref vb.opb);
            op.bytes      = Ogg.oggpack_bytes(ref vb.opb);
            op.b_o_s      = 0;
            op.granulepos = vb.granulepos;
            op.packetno   = vb.sequence; /* for sake of completeness */

            return(0);
        }
Ejemplo n.º 3
0
        /* Is this packet a vorbis ID header? */
        static public int vorbis_synthesis_idheader(ref Ogg.ogg_packet op)
        {
            Ogg.oggpack_buffer opb    = new Ogg.oggpack_buffer();
            char[]             buffer = new char[6];

            if (op == null)
            {
                return(0);
            }

            Ogg.oggpack_readinit(ref opb, op.packet, op.bytes);

            if (op.b_o_s == 0)
            {
                return(0); /* Not the initial packet */
            }

            if (Ogg.oggpack_read(ref opb, 8) != 1)
            {
                return(0); /* Not an ID header */
            }

            _v_readstring(ref opb, ref buffer, 6);

            if
            (
                buffer[0] != 'v' ||
                buffer[1] != 'o' ||
                buffer[2] != 'r' ||
                buffer[3] != 'b' ||
                buffer[4] != 'i' ||
                buffer[5] != 's'
            )
            {
                return(0); /* not vorbis */
            }

            return(1);
        }
Ejemplo n.º 4
0
        static public int vorbis_packet_blocksize(ref vorbis_info vi, ref Ogg.ogg_packet op)
        {
            codec_setup_info ci = vi.codec_setup as codec_setup_info;

            Ogg.oggpack_buffer opb = new Ogg.oggpack_buffer();

            int mode;

            Ogg.oggpack_readinit(ref opb, op.packet, op.bytes);

            /* Check the packet type */
            if (Ogg.oggpack_read(ref opb, 1) != 0)
            {
                /* Oops.  This is not an audio data packet */
                return(OV_ENOTAUDIO);
            }

            {
                int modebits = 0;
                int v        = ci.modes;

                while (v > 1)
                {
                    modebits++;
                    v >>= 1;
                }

                /* read our mode and pre/post windowsize */
                mode = Ogg.oggpack_read(ref opb, modebits);
            }

            if (mode == -1)
            {
                return(OV_EBADPACKET);
            }

            return(ci.blocksizes[ci.mode_param[mode].blockflag]);
        }
Ejemplo n.º 5
0
        static public int vorbis_synthesis(ref vorbis_block vb, ref Ogg.ogg_packet op)
        {
            vorbis_dsp_state vd = (vb != null) ? vb.vd : null;
            private_state    b  = (vd != null) ? (vd.backend_state as private_state) : null;
            vorbis_info      vi = (vd != null) ? vd.vi : null;
            codec_setup_info ci = (vi != null) ? (vi.codec_setup as codec_setup_info) : null;

            Ogg.oggpack_buffer opb = (vb != null) ? vb.opb : null;

            int type, mode, i;

            if (vd == null || b == null || vi == null || ci == null || opb == null)
            {
                return(OV_EBADHEADER);
            }

            /* first things first.  Make sure decode is ready */
            _vorbis_block_ripcord(ref vb);
            Ogg.oggpack_readinit(ref opb, op.packet, op.bytes);

            /* Check the packet type */
            if (Ogg.oggpack_read(ref opb, 1) != 0)
            {
                /* Oops.  This is not an audio data packet */
                return(OV_ENOTAUDIO);
            }

            /* read our mode and pre/post windowsize */
            mode = Ogg.oggpack_read(ref opb, b.modebits);

            if (mode == -1)
            {
                return(OV_EBADPACKET);
            }

            vb.mode = mode;

            if (ci.mode_param[mode] == null)
            {
                return(OV_EBADPACKET);
            }

            vb.W = ci.mode_param[mode].blockflag;

            if (vb.W > 0)
            {
                /* this doesn't get mapped through mode selection as it's used only for window selection */
                vb.lW = Ogg.oggpack_read(ref opb, 1);
                vb.nW = Ogg.oggpack_read(ref opb, 1);

                if (vb.nW == -1)
                {
                    return(OV_EBADPACKET);
                }
            }
            else
            {
                vb.lW = 0;
                vb.nW = 0;
            }

            /* more setup */
            vb.granulepos = op.granulepos;
            vb.sequence   = op.packetno;
            vb.eofflag    = op.e_o_s;

            /* alloc pcm passback storage */
            vb.pcmend = ci.blocksizes[vb.W];
            vb.pcm    = (float **)_vorbis_block_alloc(ref vb, sizeof(float *) * vi.channels);

            for (i = 0; i < vi.channels; i++)
            {
                vb.pcm[i] = (float *)_vorbis_block_alloc(ref vb, sizeof(float) * vb.pcmend);
            }

            /* unpack_header enforces range checking */
            type = ci.map_type[ci.mode_param[mode].mapping];

            return(_mapping_P[type].inverse(ref vb, ci.map_param[ci.mode_param[mode].mapping]));
        }
Ejemplo n.º 6
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. */

        static public int vorbis_synthesis_headerin(ref vorbis_info vi, ref vorbis_comment vc, ref Ogg.ogg_packet op)
        {
            Ogg.oggpack_buffer opb = new Ogg.oggpack_buffer();
            Ogg.oggpack_readinit(ref opb, op.packet, op.bytes);

            /* Which of the three types of header is this? */
            /* Also verify header-ness, vorbis */
            {
                char[] buffer   = new char[6];
                int    packtype = Ogg.oggpack_read(ref opb, 8);

                _v_readstring(ref opb, ref 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(OV_ENOTVORBIS);
                }

                switch (packtype)
                {
                case 0x01:     /* least significant *bit* is read first */
                {
                    if (op.b_o_s == 0)
                    {
                        /* Not the initial packet */
                        return(OV_EBADHEADER);
                    }

                    if (vi.rate != 0)
                    {
                        /* previously initialized info header */
                        return(OV_EBADHEADER);
                    }
                }
                    return(_vorbis_unpack_info(ref vi, ref opb));

                case 0x03:     /* least significant *bit* is read first */
                {
                    if (vi.rate == 0)
                    {
                        /* um... we didn't get the initial header */
                        return(OV_EBADHEADER);
                    }
                }
                    return(_vorbis_unpack_comment(ref vc, ref opb));

                case 0x05:     /* least significant *bit* is read first */
                {
                    if (vi.rate == 0 || vc.vendor == null)
                    {
                        /* um... we didn;t get the initial header or comments yet */
                        return(OV_EBADHEADER);
                    }
                }
                    return(_vorbis_unpack_books(ref vi, ref opb));

                default:
                {
                    /* Not a valid vorbis header type */
                    return(OV_EBADHEADER);
                }
                }
            }
        }