Beispiel #1
0
        //  private csBuffer opb_blocksize=new csBuffer();
        public int blocksize(Packet op)
        {
            //codec_setup_info     *ci=vi->codec_setup;
            csBuffer opb = new csBuffer();

            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(VorbisFile.OV_ENOTAUDIO);
            }

            /* read our mode and pre/post windowsize */
            int modebits = Util.ilog2(modes);
            int mode     = opb.read(modebits);

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

            return(blocksizes[mode_param[mode].blockflag]);
        }
        //  static void v_writestring(csBuffer o, byte[] s){
        //    int i=0;
        //    while(s[i]!=0){
        //      o.write(s[i++],8);
        //    }
        //  }

        //  static void v_readstring(csBuffer o, byte[] buf, int bytes){
        //    int i=0
        //    while(bytes--!=0){
        //      buf[i++]=o.read(8);
        //    }
        //  }

        //  private csBuffer opb_blocksize=new csBuffer();
        public int blocksize(Packet op)
        {
            //codec_setup_info     *ci=vi->codec_setup;
            csBuffer opb = new csBuffer();
            //    synchronized(opb_blocksize){
            int mode;

            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(OV_ENOTAUDIO);
            }
            {
                int modebits = 0;
                int v        = modes;
                while (v > 1)
                {
                    modebits++;
                    v = (int)((uint)v >> 1);
                }

                /* read our mode and pre/post windowsize */
                mode = opb.read(modebits);
            }
            if (mode == -1)
            {
                return(OV_EBADPACKET);
            }
            return(blocksizes[mode_param[mode].blockflag]);
            //    }
        }
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 synthesis_headerin(Comment vc, Packet op)
        {
            csBuffer opb = new csBuffer();

            if (op != null)
            {
                opb.readinit(op.packet_base, op.packet, op.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis

                byte[] buffer   = new byte[6];
                int    packtype = opb.read(8);
                opb.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 (op.b_o_s == 0)
                    {
                        // Not the initial packet
                        return(-1);
                    }
                    if (SamplingRate != 0)
                    {
                        // previously initialized info header
                        return(-1);
                    }
                    return(unpack_info(opb));

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

                case 0x05:                         // least significant *bit* is read first
                    if (SamplingRate == 0 || vc.getVendor() == null)
                    {
                        // um... we didn;t get the initial header or comments yet
                        return(-1);
                    }
                    return(unpack_books(opb));

                default:
                    // Not a valid vorbis header type
                    return(-1);
                }
            }
            return(-1);
        }
Beispiel #4
0
        public int synthesis(Packet op)
        {
            Info vi = vd.vi;

            opb.readinit(op.packet_base, op.packet, op.bytes);
            opb.read(1);
            // read our mode and pre/post windowsize
            mode = opb.read(vd.modebits);
            W    = vi.mode_param[mode].blockflag;
            if (W != 0)
            {
                lW = opb.read(1); nW = opb.read(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
            FuncMapping mapping = vi.map_funcs[vi.mode_param[mode].mapping];

            return(mapping.inverse(this, vd.mode[mode]));
        }
Beispiel #5
0
        public int blocksize(Packet op)
        {
            csBuffer opb = new csBuffer();

            opb.readinit(op.packet_base, op.packet, op.bytes);

            /* Check the packet type */
            if (opb.read(1) != 0)
            {
                return(OV_ENOTAUDIO);
            }

            int modebits = VUtils.ilog2(modes);
            int mode     = opb.read(modebits);

            return(blocksizes[mode_param[mode].blockflag]);
        }
Beispiel #6
0
        public void synthesis_headerin(Comment vc, Packet op)
        {
            if (op == null)
            {
                return;
            }

            csBuffer opb = new csBuffer();

            opb.readinit(op.packet_base, op.packet, op.bytes);
            byte[] buffer   = new byte[6];
            int    packtype = opb.read(8);

            opb.read(buffer, 6);

            if (buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' ||
                buffer[3] != 'b' || buffer[4] != 'i' || buffer[5] != 's')
            {
                throw new InvalidOperationException("Expected vorbis header");
            }

            switch (packtype)
            {
            case 0x01:                     // least significant *bit* is read first
                unpack_info(opb);
                break;

            case 0x03:                     // least significant *bit* is read first
                vc.unpack(opb);
                break;

            case 0x05:                     // least significant *bit* is read first
                unpack_books(opb);
                break;

            default:
                // Not a valid vorbis header type
                break;
            }
        }
Beispiel #7
0
        public int synthesis(Packet op)
        {
            Info vi = vd.vi;

            // first things first.  Make sure decode is ready
            // ripcord();
            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.mode_param[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];
            //pcm=alloc(vi.channels);
            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];
                    //pcm[i]=alloc(pcmend);
                }
                else
                {
                    for (int j = 0; j < pcmend; j++)
                    {
                        pcm[i][j] = 0;
                    }
                }
            }

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

            return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode]));
        }