Beispiel #1
0
		override public int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
		{
			//System.err.println("Residue0.inverse");
			int i=0;
			for(i=0;i<ch;i++)if(nonzero[i]!=0)break;
			if(i==ch)return(0); /* no nonzero vectors */

			return(_2inverse(vb, vl, fin, ch));
		}
Beispiel #2
0
 public override int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
 {
     //System.err.println("Residue0.inverse");
     int used=0;
     for(int i=0; i<ch; i++) {
         if(nonzero[i]!=0) {
             fin[used++]=fin[i];
         }
     }
     if(used!=0) {
         return(_01inverse(vb, vl, fin, used, 1));
     }
     else {
         return 0;
     }
 }
Beispiel #3
0
        public override Object inverse1(Block vb, Object i, Object memo)
        {
            //System.err.println("Floor0.inverse "+i.getClass()+"]");
            LookFloor0 look=(LookFloor0)i;
            InfoFloor0 info=look.vi;
            float[] lsp=null;
            if(memo is float[]) {
                lsp=(float[])memo;
            }

            int ampraw=vb.opb.read(info.ampbits);
            if(ampraw>0) {
                // also handles the -1 out of data case
                int maxval=(1<<info.ampbits)-1;
                float amp=(float)ampraw/maxval*info.ampdB;
                int booknum=vb.opb.read(ilog(info.numbooks));

                if(booknum!=-1 && booknum<info.numbooks) {
                    CodeBook b=vb.vd.fullbooks[info.books[booknum]];
                    float last=0.0f;

                    if(lsp==null||lsp.Length<look.m+1) {
                        lsp=new float[look.m+1];
                    }
                    else {
                        for(int j=0; j<lsp.Length; j++) { lsp[j]=0.0f; }
                    }

                    for(int j=0; j<look.m; j+=b.dim) {
                        if(b.decodev_set(lsp, j, vb.opb, b.dim)==-1) {
                            //goto eop;
                            return(null);
                        }
                    }

                    for(int j=0; j<look.m;) {
                        for(int k=0; k<b.dim; k++,j++) { lsp[j]+=last; }
                        last=lsp[j-1];
                    }
                    lsp[look.m]=amp;
                    return(lsp);
                }
            }
            //  eop:
            return(null);
        }
Beispiel #4
0
 public abstract Object inverse1(Block vb, Object i, Object memo);
Beispiel #5
0
 public abstract int forward(Block vb, Object i, float[] fin, float[] fout, Object vs);
Beispiel #6
0
		override public int inverse2(Block vb, Object i, Object memo, float[] fout)
		{
			LookFloor1 look=(LookFloor1)i;
			InfoFloor1 info=look.vi;
			int n=vb.vd.vi.blocksizes[vb.mode]/2;

			if(memo!=null)
			{
				/* render the lines */
				int[] fit_value=(int[] )memo;
				int hx=0;
				int lx=0;
				int ly=fit_value[0]*info.mult;
				for(int j=1;j<look.posts;j++)
				{
					int current=look.forward_index[j];
					int hy=fit_value[current]&0x7fff;
					if(hy==fit_value[current])
					{
						hy*=info.mult;
						hx=info.postlist[current];

						render_line(lx,hx,ly,hy,fout);

						lx=hx;
						ly=hy;
					}
				}
				for(int j=hx;j<n;j++)
				{
					fout[j]*=fout[j-1]; /* be certain */
				}
				return(1);
			}
			for(int j=0; j<n; j++)
			{
				fout[j]=0.0f;
			} 
			return(0);
		}
Beispiel #7
0
		public abstract int inverse(Block vb, Object vl, float[][] fin, int[] nonzero,int ch);
Beispiel #8
0
        internal static int _2inverse(Block vb, Object vl, float[][] fin, int ch)
        {
            int i,k,l,s;
            LookResidue0 look=(LookResidue0 )vl;
            InfoResidue0 info=look.info;

            // move all this setup out later
            int samples_per_partition=info.grouping;
            int partitions_per_word=look.phrasebook.dim;
            int n=info.end-info.begin;

            int partvals=n/samples_per_partition;
            int partwords=(partvals+partitions_per_word-1)/partitions_per_word;

            int[][] partword=new int[partwords][];
            for(s=0; s<look.stages; s++) {
                for(i=0,l=0; i<partvals; l++) {
                    if(s==0) {
                        // fetch the partition word for each channel
                        int temp=look.phrasebook.decode(vb.opb);
                        if(temp==-1) {
                            // goto eopbreak;
                            return(0);
                        }
                        partword[l]=look.decodemap[temp];
                        if(partword[l]==null) {
                            // goto errout;
                            return(0);
                        }
                    }

                    // now we decode residual values for the partitions
                    for(k=0; k<partitions_per_word && i<partvals; k++,i++) {
                        int offset=info.begin+i*samples_per_partition;
                        if((info.secondstages[partword[l][k]]&(1<<s))!=0) {
                            CodeBook stagebook=look.fullbooks[look.partbooks[partword[l][k]][s]];
                            if(stagebook!=null) {
                                if(stagebook.decodevv_add(fin, offset, ch, vb.opb,samples_per_partition)==-1) {
                                    // goto errout;
                                    return(0);
                                }
                            }
                        }
                    }
                }
            }
            //  errout:
            //  eopbreak:
            return(0);
        }
Beispiel #9
0
 public abstract int inverse(Block vd, Object lm);
Beispiel #10
0
 public override int forward(Block vb, Object i)
 {
     return 0;
 }
Beispiel #11
0
 public override int forward(Block vb, Object i,  float[] fin, float[] fout, Object vs)
 {
     return 0;
 }
Beispiel #12
0
        int inverse(Block vb, Object i, float[] fout)
        {
            //System.err.println("Floor0.inverse "+i.getClass()+"]");
            LookFloor0 look=(LookFloor0)i;
            InfoFloor0 info=look.vi;
            int ampraw=vb.opb.read(info.ampbits);
            if(ampraw>0) {
                // also handles the -1 out of data case
                int maxval=(1<<info.ampbits)-1;
                float amp=(float)ampraw/maxval*info.ampdB;
                int booknum=vb.opb.read(ilog(info.numbooks));

                if(booknum!=-1 && booknum<info.numbooks) {

                    lock(this) {
                        if(lsp==null||lsp.Length<look.m) {
                            lsp=new float[look.m];
                        }
                        else {
                            for(int j=0; j<look.m; j++) { lsp[j]=0.0f; }
                        }

                        CodeBook b=vb.vd.fullbooks[info.books[booknum]];
                        float last=0.0f;

                        //memset(out,0,sizeof(float)*look->m);
                        for(int j=0; j<look.m; j++) { fout[j]=0.0f; }

                        for(int j=0; j<look.m; j+=b.dim) {
                            if(b.decodevs(lsp, j, vb.opb, 1, -1)==-1) {
                                //goto eop;
                                // memset(out,0,sizeof(float)*look->n);
                                for(int k=0; k<look.n; k++) { fout[k]=0.0f; }
                                return(0);
                            }
                        }
                        for(int j=0; j<look.m;) {
                            for(int k=0; k<b.dim; k++,j++) { lsp[j]+=last; }
                            last=lsp[j-1];
                        }
                        // take the coefficients back to a spectral envelope curve
                        /*
                        lsp_to_lpc(out,out,look.m);
                        lpc_to_curve(out,out,amp,look,"",0);
                        for(int j=0;j<look.n;j++){
                          out[j]=fromdB(out[j]-info.ampdB);
                        }
                        */
                        Lsp.lsp_to_curve(fout,look.linearmap,look.n,look.ln,
                                         lsp,look.m,amp,info.ampdB);

                        return(1);
                    }
                }
            }
            //  eop:
            //    memset(out,0,sizeof(float)*look->n);
            return(0);
        }
Beispiel #13
0
        public override int inverse2(Block vb, Object i, Object memo, float[] fout)
        {
            //System.err.println("Floor0.inverse "+i.getClass()+"]");
            LookFloor0 look=(LookFloor0)i;
            InfoFloor0 info=look.vi;

            if(memo!=null) {
                float[] lsp=(float[])memo;
                float amp=lsp[look.m];

                Lsp.lsp_to_curve(fout,look.linearmap,look.n,look.ln,
                                 lsp,look.m,amp,info.ampdB);
                return(1);
            }
            //  eop:
            //    memset(out,0,sizeof(float)*look->n);
            for(int j=0; j<look.n; j++) {
                fout[j]=0.0f;
            }
            return(0);
        }
Beispiel #14
0
 public abstract int inverse2(Block vb, Object i, Object memo, float[] fout);
Beispiel #15
0
 public override int inverse(Block vb, Object i, float[] fin, float[] fout)
 {
     return 0;
 }
Beispiel #16
0
        // Unike in analysis, the window is only partially applied for each
        // block.  The time domain envelope is not yet handled at the point of
        // calling (as it relies on the previous block).
        public int synthesis_blockin(Block vb)
        {
            // Shift out any PCM/multipliers that we returned previously
            // centerW is currently the center of the last block added
            if(centerW>vi.blocksizes[1]/2 && pcm_returned>8192) {
                // don't shift too much; we need to have a minimum PCM buffer of
                // 1/2 long block

                int shiftPCM=centerW-vi.blocksizes[1]/2;
                shiftPCM=(pcm_returned<shiftPCM?pcm_returned:shiftPCM);

                pcm_current-=shiftPCM;
                centerW-=shiftPCM;
                pcm_returned-=shiftPCM;
                if(shiftPCM!=0) {
                    for(int i=0; i<vi.channels; i++) {
                        Array.Copy(pcm[i], shiftPCM, pcm[i], 0, pcm_current);
                    }
                }
            }

            lW=W;
            W=vb.W;
            nW=-1;

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

            if(sequence+1 != vb.sequence) { granulepos=-1; } // out of sequence; lose count

            sequence=vb.sequence;

            {
                int sizeW=vi.blocksizes[W];
                int _centerW=centerW+vi.blocksizes[lW]/4+sizeW/4;
                int beginW=_centerW-sizeW/2;
                int endW=beginW+sizeW;
                int beginSl=0;
                int endSl=0;

                // Do we have enough PCM/mult storage for the block?
                if(endW>pcm_storage) {
                    // expand the storage
                    pcm_storage=endW+vi.blocksizes[1];
                    for(int i=0; i<vi.channels; i++) {
                        float[] foo=new float[pcm_storage];
                        Array.Copy(pcm[i], 0, foo, 0, pcm[i].Length);
                        pcm[i]=foo;
                    }
                }

                // overlap/add PCM
                switch(W) {
                case 0:
                    beginSl=0;
                    endSl=vi.blocksizes[0]/2;
                    break;
                case 1:
                    beginSl=vi.blocksizes[1]/4-vi.blocksizes[lW]/4;
                    endSl=beginSl+vi.blocksizes[lW]/2;
                    break;
                }

                for(int j=0; j<vi.channels; j++) {
                    int _pcm=beginW;
                    // the overlap/add section
                    int i=0;
                    for(i=beginSl; i<endSl; i++) {
                        pcm[j][_pcm+i]+=vb.pcm[j][i];
                    }
                    // the remaining section
                    for(; i<sizeW; i++) {
                        pcm[j][_pcm+i]=vb.pcm[j][i];
                    }
                }

                // track the frame number... This is for convenience, but also
                // making sure our last packet doesn't end with added padding.  If
                // the last packet is partial, the number of samples we'll have to
                // return will be past the vb->granulepos.
                //
                // This is not foolproof!  It will be confused if we begin
                // decoding at the last page after a seek or hole.  In that case,
                // we don't have a starting point to judge where the last frame
                // is.  For this reason, vorbisfile will always try to make sure
                // it reads the last two marked pages in proper sequence

                if(granulepos==-1) {
                    granulepos=vb.granulepos;
                }
                else {
                    granulepos+=(_centerW-centerW);
                    if(vb.granulepos!=-1 && granulepos!=vb.granulepos) {
                        if(granulepos>vb.granulepos && vb.eofflag!=0) {
                            // partial last frame.  Strip the padding off
                            _centerW = _centerW - (int)(granulepos-vb.granulepos);
                        }// else{ Shouldn't happen *unless* the bitstream is out of
                        // spec.  Either way, believe the bitstream }
                        granulepos=vb.granulepos;
                    }
                }

                // Update, cleanup

                centerW=_centerW;
                pcm_current=endW;
                if(vb.eofflag!=0) { eofflag=1; }
            }
            return(0);
        }
Beispiel #17
0
		public abstract int forward(Block vb, Object i);
Beispiel #18
0
        internal static int _01inverse(Block vb, Object vl, float[][] fin, int ch, int decodepart)
        {
            {
                int i,j,k,l,s;
                LookResidue0 look=(LookResidue0 )vl;
                InfoResidue0 info=look.info;

                // move all this setup out later
                int samples_per_partition=info.grouping;
                int partitions_per_word=look.phrasebook.dim;
                int n=info.end-info.begin;

                int partvals=n/samples_per_partition;
                int partwords=(partvals+partitions_per_word-1)/partitions_per_word;

                if(partword.Length<ch) {
                    partword=new int[ch][][];
                    for(j=0; j<ch; j++) {
                        partword[j]=new int[partwords][];
                    }
                }
                else {
                    for(j=0; j<ch; j++) {
                        if(partword[j]==null || partword[j].Length<partwords) {
                            partword[j]=new int[partwords][];
                        }
                    }
                }

                for(s=0; s<look.stages; s++) {
                    // each loop decodes on partition codeword containing
                    // partitions_pre_word partitions
                    for(i=0,l=0; i<partvals; l++) {
                        if(s==0) {
                            // fetch the partition word for each channel
                            for(j=0; j<ch; j++) {
                                int temp=look.phrasebook.decode(vb.opb);
                                if(temp==-1) {
                                    //goto eopbreak;
                                    return(0);
                                }
                                partword[j][l]=look.decodemap[temp];
                                if(partword[j][l]==null) {
                                    //	      goto errout;
                                    return(0);
                                }
                            }
                        }

                        // now we decode residual values for the partitions
                        for(k=0; k<partitions_per_word && i<partvals; k++,i++)
                            for(j=0; j<ch; j++) {
                                int offset=info.begin+i*samples_per_partition;
                                if((info.secondstages[partword[j][l][k]]&(1<<s))!=0) {
                                    CodeBook stagebook=look.fullbooks[look.partbooks[partword[j][l][k]][s]];
                                    //	      CodeBook stagebook=look.partbooks[partword[j][l][k]][s];
                                    if(stagebook!=null) {
                                        if(decodepart==0) {
                                            if(stagebook.decodevs_add(fin[j],offset,vb.opb,samples_per_partition)==-1) {
                                                // goto errout;
                                                return(0);
                                            }
                                        }
                                        else if(decodepart==1) {
                                            if(stagebook.decodev_add(fin[j], offset, vb.opb,samples_per_partition)==-1) {
                                                // goto errout;
                                                return(0);
                                            }
                                        }
                                    }
                                }
                            }
                    }
                }
                return(0);
            }
        }
Beispiel #19
0
		public abstract int inverse(Block vb, Object i, float[] fin, float[] fout);
Beispiel #20
0
		override public int forward(Block vb,Object vl, float[][] fin, int ch)
		{
			return 0;
		}
Beispiel #21
0
        public override int inverse(Block vb, Object l)
        {
            lock(this) {
                //System.err.println("Mapping0.inverse");
                DspState vd=vb.vd;
                Info vi=vd.vi;
                LookMapping0 look=(LookMapping0)l;
                InfoMapping0 info=look.map;
                InfoMode mode=look.mode;
                int n=vb.pcmend=vi.blocksizes[vb.W];

                float[] window=vd.wnd[vb.W][vb.lW][vb.nW][mode.windowtype];
                // float[][] pcmbundle=new float[vi.channels][];
                // int[] nonzero=new int[vi.channels];
                if(pcmbundle==null || pcmbundle.Length<vi.channels) {
                    pcmbundle=new float[vi.channels][];
                    nonzero=new int[vi.channels];
                    zerobundle=new int[vi.channels];
                    floormemo=new Object[vi.channels];
                }

                // time domain information decode (note that applying the
                // information would have to happen later; we'll probably add a
                // function entry to the harness for that later
                // NOT IMPLEMENTED

                // recover the spectral envelope; store it in the PCM vector for now
                for(int i=0; i<vi.channels; i++) {
                    float[] pcm=vb.pcm[i];
                    int submap=info.chmuxlist[i];

                    floormemo[i]=look.floor_func[submap].inverse1(vb,look.
                                 floor_look[submap],
                                 floormemo[i]
                                                                 );
                    if(floormemo[i]!=null) { nonzero[i]=1; }
                    else { nonzero[i]=0; }
                    for(int j=0; j<n/2; j++) {
                        pcm[j]=0;
                    }

                    //_analysis_output("ifloor",seq+i,pcm,n/2,0,1);
                }

                for(int i=0; i<info.coupling_steps; i++) {
                    if(nonzero[info.coupling_mag[i]]!=0 ||
                            nonzero[info.coupling_ang[i]]!=0) {
                        nonzero[info.coupling_mag[i]]=1;
                        nonzero[info.coupling_ang[i]]=1;
                    }
                }

                // recover the residue, apply directly to the spectral envelope

                for(int i=0; i<info.submaps; i++) {
                    int ch_in_bundle=0;
                    for(int j=0; j<vi.channels; j++) {
                        if(info.chmuxlist[j]==i) {
                            if(nonzero[j]!=0) {
                                zerobundle[ch_in_bundle]=1;
                            }
                            else {
                                zerobundle[ch_in_bundle]=0;
                            }
                            pcmbundle[ch_in_bundle++]=vb.pcm[j];
                        }
                    }

                    look.residue_func[i].inverse(vb,look.residue_look[i],
                                                 pcmbundle,zerobundle,ch_in_bundle);
                }

                for(int i=info.coupling_steps-1; i>=0; i--) {
                    float[] pcmM=vb.pcm[info.coupling_mag[i]];
                    float[] pcmA=vb.pcm[info.coupling_ang[i]];

                    for(int j=0; j<n/2; j++) {
                        float mag=pcmM[j];
                        float ang=pcmA[j];

                        if(mag>0) {
                            if(ang>0) {
                                pcmM[j]=mag;
                                pcmA[j]=mag-ang;
                            }
                            else {
                                pcmA[j]=mag;
                                pcmM[j]=mag+ang;
                            }
                        }
                        else {
                            if(ang>0) {
                                pcmM[j]=mag;
                                pcmA[j]=mag+ang;
                            }
                            else {
                                pcmA[j]=mag;
                                pcmM[j]=mag-ang;
                            }
                        }
                    }
                }

                //    /* compute and apply spectral envelope */

                for(int i=0; i<vi.channels; i++) {
                    float[] pcm=vb.pcm[i];
                    int submap=info.chmuxlist[i];
                    look.floor_func[submap].inverse2(vb,look.floor_look[submap],floormemo[i],pcm);
                }

                // transform the PCM data; takes PCM vector, vb; modifies PCM vector
                // only MDCT right now....

                for(int i=0; i<vi.channels; i++) {
                    float[] pcm=vb.pcm[i];
                    //_analysis_output("out",seq+i,pcm,n/2,0,0);
                    ((Mdct)vd.transform[vb.W][0]).backward(pcm,pcm);
                }

                // now apply the decoded pre-window time information
                // NOT IMPLEMENTED

                // window the data
                for(int i=0; i<vi.channels; i++) {
                    float[] pcm=vb.pcm[i];
                    if(nonzero[i]!=0) {
                        for(int j=0; j<n; j++) {
                            pcm[j]*=window[j];
                        }
                    }
                    else {
                        for(int j=0; j<n; j++) {
                            pcm[j]=0.0f;
                        }
                    }
                    //_analysis_output("final",seq++,pcm,n,0,0);
                }

                // now apply the decoded post-window time information
                // NOT IMPLEMENTED
                // all done!
                return(0);
            }
        }
Beispiel #22
0
		public abstract int forward(Block vb,Object vl, float[][] fin, int ch);
Beispiel #23
0
 private VorbisFile()
 {
     os=new StreamState(); // take physical pages, weld into a logical
     // stream of packets
     vd=new DspState(); // central working state for
     // the packet->PCM decoder
     vb=new Block(vd);     // local working space for packet->PCM decode
 }
Beispiel #24
0
 new int forward(Block vb,Object vl, float[][] fin, int ch)
 {
     return 0;
 }
Beispiel #25
0
		override public Object inverse1(Block vb, Object ii, Object memo)
		{
			LookFloor1 look=(LookFloor1)ii;
			InfoFloor1 info=look.vi;
			CodeBook[] books=vb.vd.fullbooks;

			/* unpack wrapped/predicted values from stream */
			if(vb.opb.read(1)==1)
			{
				int[] fit_value=null;
				if(memo is int[])
				{
					fit_value=(int[])memo;
				}
				if(fit_value==null || fit_value.Length<look.posts)
				{
					fit_value=new int[look.posts];
				}
				else
				{
					for(int i=0; i<fit_value.Length; i++) fit_value[i]=0;
				}

				fit_value[0]=vb.opb.read(ilog(look.quant_q-1));
				fit_value[1]=vb.opb.read(ilog(look.quant_q-1));

				/* partition by partition */
				for(int i=0,j=2;i<info.partitions;i++)
				{
					int clss=info.partitionclass[i];
					int cdim=info.class_dim[clss];
					int csubbits=info.class_subs[clss];
					int csub=1<<csubbits;
					int cval=0;

					/* decode the partition's first stage cascade value */
					if(csubbits!=0)
					{
						cval=books[info.class_book[clss]].decode(vb.opb);

						if(cval==-1)
						{
							//goto eop;
							return(null);
						}
					}

					for(int k=0;k<cdim;k++)
					{
						int book=info.class_subbook[clss][cval&(csub-1)];
						cval = (int)((uint)cval >> csubbits);
						if(book>=0)
						{
							if((fit_value[j+k]=books[book].decode(vb.opb))==-1)
							{
								return(null);
							}
						}
						else
						{
							fit_value[j+k]=0;
						}
					}
					j+=cdim;
				}

				/* unwrap positive values and reconsitute via linear interpolation */
				for(int i=2;i<look.posts;i++)
				{
					int predicted=render_point(info.postlist[look.loneighbor[i-2]],
						info.postlist[look.hineighbor[i-2]],
						fit_value[look.loneighbor[i-2]],
						fit_value[look.hineighbor[i-2]],
						info.postlist[i]);
					int hiroom=look.quant_q-predicted;
					int loroom=predicted;
					int room=(hiroom<loroom?hiroom:loroom)<<1;
					int val=fit_value[i];

					if(val!=0)
					{
						if(val>=room)
						{
							if(hiroom>loroom)
							{
								val = val-loroom;
							}
							else
							{
								val = -1-(val-hiroom);
							}
						}
						else
						{
							if((val&1)!=0)
							{
								val= (int)(-((uint)(val+1) >> 1));
							}
							else
							{
								val>>=1;
							}
						}

						fit_value[i]=val+predicted;
						fit_value[look.loneighbor[i-2]]&=0x7fff;
						fit_value[look.hineighbor[i-2]]&=0x7fff;
					}
					else
					{
						fit_value[i]=predicted|0x8000;
					}
				}
				return(fit_value);
			}

			//  eop:
			//    return(NULL);
			return(null);
		}