csvorbis.Floor1.look C# (CSharp) Method

look() public method

public look ( DspState vd, InfoMode mi, Object i ) : Object
vd DspState
mi InfoMode
i Object
return Object
        public override Object look(DspState vd, InfoMode mi, Object i)
        {
            int _n=0;

            int[] sortpointer=new int[VIF_POSIT+2];

            //    Info vi=vd.vi;

            InfoFloor1 info=(InfoFloor1)i;
            LookFloor1 look=new LookFloor1();
            look.vi=info;
            look.n=info.postlist[1];

            /* we drop each position value in-between already decoded values,
             and use linear interpolation to predict each new value past the
             edges.  The positions are read in the order of the position
             list... we precompute the bounding positions in the lookup.  Of
             course, the neighbors can change (if a position is declined), but
             this is an initial mapping */

            for(int j=0;j<info.partitions;j++)
            {
                _n+=info.class_dim[info.partitionclass[j]];
            }
            _n+=2;
            look.posts=_n;

            /* also store a sorted position index */
            for(int j=0;j<_n;j++)
            {
                sortpointer[j]=j;
            }
            //    qsort(sortpointer,n,sizeof(int),icomp); // !!

            int foo;
            for(int j=0; j<_n-1; j++)
            {
                for(int k=j; k<_n; k++)
                {
                    if(info.postlist[sortpointer[j]]>info.postlist[sortpointer[k]])
                    {
                        foo=sortpointer[k];
                        sortpointer[k]=sortpointer[j];
                        sortpointer[j]=foo;
                    }
                }
            }

            /* points from sort order back to range number */
            for(int j=0;j<_n;j++)
            {
                look.forward_index[j]=sortpointer[j];
            }
            /* points from range order to sorted position */
            for(int j=0;j<_n;j++)
            {
                look.reverse_index[look.forward_index[j]]=j;
            }
            /* we actually need the post values too */
            for(int j=0;j<_n;j++)
            {
                look.sorted_index[j]=info.postlist[look.forward_index[j]];
            }

            /* quantize values to multiplier spec */
            switch(info.mult)
            {
                case 1: /* 1024 -> 256 */
                    look.quant_q=256;
                    break;
                case 2: /* 1024 -> 128 */
                    look.quant_q=128;
                    break;
                case 3: /* 1024 -> 86 */
                    look.quant_q=86;
                    break;
                case 4: /* 1024 -> 64 */
                    look.quant_q=64;
                    break;
                default:
                    look.quant_q=-1;
                    break;
            }

            /* discover our neighbors for decode where we don't use fit flags
               (that would push the neighbors outward) */
            for(int j=0;j<_n-2;j++)
            {
                int lo=0;
                int hi=1;
                int lx=0;
                int hx=look.n;
                int currentx=info.postlist[j+2];
                for(int k=0;k<j+2;k++)
                {
                    int x=info.postlist[k];
                    if(x>lx && x<currentx)
                    {
                        lo=k;
                        lx=x;
                    }
                    if(x<hx && x>currentx)
                    {
                        hi=k;
                        hx=x;
                    }
                }
                look.loneighbor[j]=lo;
                look.hineighbor[j]=hi;
            }

            return look;
        }