Exemplo n.º 1
0
        public override Object unpack(Info vi, csBuffer opb)
        {
            // also responsible for range checking
            InfoMapping0 info=new InfoMapping0();

            // !!!!
            if(opb.Read(1)!=0)
            {
                info.submaps=opb.Read(4)+1;
            }
            else
            {
                info.submaps=1;
            }

            if(opb.Read(1)!=0)
            {
                info.coupling_steps=opb.Read(8)+1;

                for(int i=0;i<info.coupling_steps;i++)
                {
                    int testM=info.coupling_mag[i]=opb.Read(ilog2(vi.channels));
                    int testA=info.coupling_ang[i]=opb.Read(ilog2(vi.channels));

                    if(testM<0 ||
                        testA<0 ||
                        testM==testA ||
                        testM>=vi.channels ||
                        testA>=vi.channels)
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }

            if(opb.Read(2)>0)
            { /* 2,3:reserved */
                //goto err_out;
                info.free();
                return(null);
            }

            if(info.submaps>1)
            {
                for(int i=0;i<vi.channels;i++)
                {
                    info.chmuxlist[i]=opb.Read(4);
                    if(info.chmuxlist[i]>=info.submaps)
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }

            for(int i=0;i<info.submaps;i++)
            {
                info.timesubmap[i]=opb.Read(8);
                if(info.timesubmap[i]>=vi.times)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.floorsubmap[i]=opb.Read(8);
                if(info.floorsubmap[i]>=vi.floors)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.residuesubmap[i]=opb.Read(8);
                if(info.residuesubmap[i]>=vi.residues)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
            }
            return info;
            //err_out:
            //free_info(info);
            //return(NULL);
        }
Exemplo n.º 2
0
        public override Object unpack(Info vi , csBuffer opb)
        {
            int count=0,maxclass=-1,rangebits;
            InfoFloor1 info=new InfoFloor1();

            /* read partitions */
            info.partitions=opb.Read(5);            /* only 0 to 31 legal */
            for(int j=0;j<info.partitions;j++)
            {
                info.partitionclass[j]=opb.Read(4); /* only 0 to 15 legal */
                if(maxclass<info.partitionclass[j])
                    maxclass=info.partitionclass[j];
            }

            /* read partition classes */
            for(int j=0;j<maxclass+1;j++)
            {
                info.class_dim[j]=opb.Read(3)+1; /* 1 to 8 */
                info.class_subs[j]=opb.Read(2);  /* 0,1,2,3 bits */
                if(info.class_subs[j]<0)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                if(info.class_subs[j]!=0)
                {
                    info.class_book[j]=opb.Read(8);
                }
                if(info.class_book[j]<0 || info.class_book[j]>=vi.books)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                for(int k=0;k<(1<<info.class_subs[j]);k++)
                {
                    info.class_subbook[j][k]=opb.Read(8)-1;
                    if(info.class_subbook[j][k]<-1 || info.class_subbook[j][k]>=vi.books)
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }

            /* read the post list */
            info.mult=opb.Read(2)+1;     /* only 1,2,3,4 legal now */
            rangebits=opb.Read(4);

            for(int j=0,k=0;j<info.partitions;j++)
            {
                count+=info.class_dim[info.partitionclass[j]];
                for(;k<count;k++)
                {
                    int t=info.postlist[k+2]=opb.Read(rangebits);
                    if(t<0 || t>=(1<<rangebits))
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }
            info.postlist[0]=0;
            info.postlist[1]=1<<rangebits;

            return(info);
            //  err_out:
            //    info.free();
            //    return(null);
        }
Exemplo n.º 3
0
        internal int unpack(csBuffer opb)
        {
            int vendorlen=opb.Read(32);
            if(vendorlen<0)
            {
                //goto err_out;
                clear();
                return(-1);
            }
            vendor=new byte[vendorlen+1];
            opb.Read(vendor,vendorlen);
            comments=opb.Read(32);
            if(comments<0)
            {
                //goto err_out;
                clear();
                return(-1);
            }
            user_comments=new byte[comments+1][];
            comment_lengths=new int[comments+1];

            for(int i=0;i<comments;i++)
            {
                int len=opb.Read(32);
                if(len<0)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
                comment_lengths[i]=len;
                user_comments[i]=new byte[len+1];
                opb.Read(user_comments[i], len);
            }
            if(opb.Read(1)!=1)
            {
                //goto err_out; // EOP check
                clear();
                return(-1);

            }
            return(0);
            //  err_out:
            //    comment_clear(vc);
            //    return(-1);
        }
Exemplo n.º 4
0
        // all of the real encoding details are here.  The modes, books,
        // everything
        int unpack_books(csBuffer opb)
        {
            //d* codebooks
            books=opb.Read(8)+1;

            if(book_param==null || book_param.Length!=books)
                book_param=new StaticCodeBook[books];
            for(int i=0;i<books;i++)
            {
                book_param[i]=new StaticCodeBook();
                if(book_param[i].unpack(opb)!=0)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // time backend settings
            times=opb.Read(6)+1;
            if(time_type==null || time_type.Length!=times) time_type=new int[times];
            if(time_param==null || time_param.Length!=times)
                time_param=new Object[times];
            for(int i=0;i<times;i++)
            {
                time_type[i]=opb.Read(16);
                if(time_type[i]<0 || time_type[i]>=VI_TIMEB)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
                time_param[i]=FuncTime.time_P[time_type[i]].unpack(this, opb);
                if(time_param[i]==null)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // floor backend settings
            floors=opb.Read(6)+1;
            if(floor_type==null || floor_type.Length!=floors)
                floor_type=new int[floors];
            if(floor_param==null || floor_param.Length!=floors)
                floor_param=new Object[floors];

            for(int i=0;i<floors;i++)
            {
                floor_type[i]=opb.Read(16);
                if(floor_type[i]<0 || floor_type[i]>=VI_FLOORB)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }

                floor_param[i]=FuncFloor.floor_P[floor_type[i]].unpack(this,opb);
                if(floor_param[i]==null)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // residue backend settings
            residues=opb.Read(6)+1;

            if(residue_type==null || residue_type.Length!=residues)
                residue_type=new int[residues];

            if(residue_param==null || residue_param.Length!=residues)
                residue_param=new Object[residues];

            for(int i=0;i<residues;i++)
            {
                residue_type[i]=opb.Read(16);
                if(residue_type[i]<0 || residue_type[i]>=VI_RESB)
                {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
                residue_param[i]=FuncResidue.residue_P[residue_type[i]].unpack(this,opb);
                if(residue_param[i]==null)
                {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
            }

            // map backend settings
            maps=opb.Read(6)+1;
            if(map_type==null || map_type.Length!=maps)  map_type=new int[maps];
            if(map_param==null || map_param.Length!=maps)  map_param=new Object[maps];
            for(int i=0;i<maps;i++)
            {
                map_type[i]=opb.Read(16);
                if(map_type[i]<0 || map_type[i]>=VI_MAPB)
                {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
                map_param[i]=FuncMapping.mapping_P[map_type[i]].unpack(this,opb);
                if(map_param[i]==null)
                {
                    //    goto err_out;
                    clear();
                    return(-1);
                }
            }

            // mode settings
            modes=opb.Read(6)+1;
            if(mode_param==null || mode_param.Length!=modes)
                mode_param=new InfoMode[modes];
            for(int i=0;i<modes;i++)
            {
                mode_param[i]=new InfoMode();
                mode_param[i].blockflag=opb.Read(1);
                mode_param[i].windowtype=opb.Read(16);
                mode_param[i].transformtype=opb.Read(16);
                mode_param[i].mapping=opb.Read(8);

                if((mode_param[i].windowtype>=VI_WINDOWB)||
                    (mode_param[i].transformtype>=VI_WINDOWB)||
                    (mode_param[i].mapping>=maps))
                {
                    //      goto err_out;
                    clear();
                    return(-1);
                }
            }

            if(opb.Read(1)!=1)
            {
                //goto err_out; // top level EOP check
                clear();
                return(-1);
            }

            return(0);
            // err_out:
            //  vorbis_info_clear(vi);
            //  return(-1);
        }
Exemplo n.º 5
0
        // Header packing/unpacking
        int unpack_info(csBuffer opb)
        {
            version=opb.Read(32);
            if(version!=0)return(-1);

            channels=opb.Read(8);
            rate=opb.Read(32);

            bitrate_upper=opb.Read(32);
            bitrate_nominal=opb.Read(32);
            bitrate_lower=opb.Read(32);

            blocksizes[0]=1<<opb.Read(4);
            blocksizes[1]=1<<opb.Read(4);

            if((rate<1) ||
                (channels<1)||
                (blocksizes[0]<8)||
                (blocksizes[1]<blocksizes[0]) ||
                (opb.Read(1)!=1))
            {
                //goto err_out; // EOP check
                clear();
                return(-1);
            }
            return(0);
            // err_out:
            // vorbis_info_clear(vi);
            // return(-1);
        }
Exemplo 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.
        public int synthesis_headerin(Comment vc, Packet op)
        {
            csBuffer opb=new csBuffer();

            if(op!=null)
            {
                opb.ReadInitialize(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);
                //memset(buffer,0,6);
                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(rate!=0)
                        {
                            // previously initialized info header
                            return(-1);
                        }
                        return(unpack_info(opb));
                    case 0x03: // least significant *bit* is read first
                        if(rate==0)
                        {
                            // um... we didn't get the initial header
                            return(-1);
                        }
                        return(vc.unpack(opb));
                    case 0x05: // least significant *bit* is read first
                        if(rate==0 || vc.vendor==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);
                        break;
                }
            }
            }
            return(-1);
        }
Exemplo n.º 7
0
        //  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.ReadInitialize(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]);
            //    }
        }
Exemplo n.º 8
0
        public override Object unpack(Info vi, csBuffer opb)
        {
            int acc=0;
            InfoResidue0 info=new InfoResidue0();

            info.begin=opb.Read(24);
            info.end=opb.Read(24);
            info.grouping=opb.Read(24)+1;
            info.partitions=opb.Read(6)+1;
            info.groupbook=opb.Read(8);

            for(int j=0;j<info.partitions;j++)
            {
                int cascade=opb.Read(3);
                if(opb.Read(1)!=0)
                {
                    cascade|=(opb.Read(5)<<3);
                }
                info.secondstages[j]=cascade;
                acc+=icount(cascade);
            }

            for(int j=0;j<acc;j++)
            {
                info.booklist[j]=opb.Read(8);
                //    if(info.booklist[j]==255)info.booklist[j]=-1;
            }

            if(info.groupbook>=vi.books)
            {
                free_info(info);
                return(null);
            }

            for(int j=0;j<acc;j++)
            {
                if(info.booklist[j]>=vi.books)
                {
                    free_info(info);
                    return(null);
                }
            }
            return(info);
            //  errout:
            //    free_info(info);
            //    return(NULL);
        }
Exemplo n.º 9
0
        public override Object unpack(Info vi , csBuffer opb)
        {
            InfoFloor0 info=new InfoFloor0();
            info.order=opb.Read(8);
            info.rate=opb.Read(16);
            info.barkmap=opb.Read(16);
            info.ampbits=opb.Read(6);
            info.ampdB=opb.Read(8);
            info.numbooks=opb.Read(4)+1;

            if((info.order<1)||
                (info.rate<1)||
                (info.barkmap<1)||
                (info.numbooks<1))
            {
                //free_info(info);
                return(null);
            }

            for(int j=0;j<info.numbooks;j++)
            {
                info.books[j]=opb.Read(8);
                if(info.books[j]<0 || info.books[j]>=vi.books)
                {
                    //free_info(info);
                    return(null);
                }
            }
            return(info);
            //  err_out:
            //    free_info(info);
            //    return(NULL);
        }
Exemplo n.º 10
0
        /*
        */
        // unpacks a codebook from the packet buffer into the codebook struct,
        // readies the codebook auxiliary structures for decode
        internal int unpack(csBuffer opb)
        {
            int i;
            //memset(s,0,sizeof(static_codebook));

            // make sure alignment is correct
            if(opb.Read(24)!=0x564342)
            {
                //    goto _eofout;
                clear();
                return(-1);
            }

            // first the basic parameters
            dim=opb.Read(16);
            entries=opb.Read(24);
            if(entries==-1)
            {
                //    goto _eofout;
                clear();
                return(-1);
            }

            // codeword ordering.... length ordered or unordered?
            switch(opb.Read(1))
            {
                case 0:
                    // unordered
                    lengthlist=new int[entries];

                    // allocated but unused entries?
                    if(opb.Read(1)!=0)
                    {
                        // yes, unused entries

                        for(i=0;i<entries;i++)
                        {
                            if(opb.Read(1)!=0)
                            {
                                int num=opb.Read(5);
                                if(num==-1)
                                {
                                    //            goto _eofout;
                                    clear();
                                    return(-1);
                                }
                                lengthlist[i]=num+1;
                            }
                            else
                            {
                                lengthlist[i]=0;
                            }
                        }
                    }
                    else
                    {
                        // all entries used; no tagging
                        for(i=0;i<entries;i++)
                        {
                            int num=opb.Read(5);
                            if(num==-1)
                            {
                                //          goto _eofout;
                                clear();
                                return(-1);
                            }
                            lengthlist[i]=num+1;
                        }
                    }
                    break;
                case 1:
                    // ordered
                {
                    int length=opb.Read(5)+1;
                    lengthlist=new int[entries];

                    for(i=0;i<entries;)
                    {
                        int num=opb.Read(ilog(entries-i));
                        if(num==-1)
                        {
                            //          goto _eofout;
                            clear();
                            return(-1);
                        }
                        for(int j=0;j<num;j++,i++)
                        {
                            lengthlist[i]=length;
                        }
                        length++;
                    }
                }
                    break;
                default:
                    // EOF
                    return(-1);
            }

            // Do we have a mapping to unpack?
            switch((maptype=opb.Read(4)))
            {
                case 0:
                    // no mapping
                    break;
                case 1:
                case 2:
                    // implicitly populated value mapping
                    // explicitly populated value mapping
                    q_min=opb.Read(32);
                    q_delta=opb.Read(32);
                    q_quant=opb.Read(4)+1;
                    q_sequencep=opb.Read(1);

                {
                    int quantvals=0;
                    switch(maptype)
                    {
                        case 1:
                            quantvals=maptype1_quantvals();
                            break;
                        case 2:
                            quantvals=entries*dim;
                            break;
                    }

                    // quantized values
                    quantlist=new int[quantvals];
                    for(i=0;i<quantvals;i++)
                    {
                        quantlist[i]=opb.Read(q_quant);
                    }
                    if(quantlist[quantvals-1]==-1)
                    {
                        //        goto _eofout;
                        clear();
                        return(-1);
                    }
                }
                    break;
                default:
                    //    goto _eofout;
                    clear();
                    return(-1);
            }
            // all set
            return(0);
            //    _errout:
            //    _eofout:
            //    vorbis_staticbook_clear(s);
            //    return(-1);
        }