/* JOrbis * Copyright (C) 2000 ymnk, JCraft,Inc. * * Written by: 2000 ymnk * * Many thanks to * Monty and * The XIPHOPHORUS Company http://www.xiph.org/ . * JOrbis has been based on their awesome works, Vorbis codec. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package com.jcraft.jorbis; import com.jcraft.jogg.*; class Residue0 extends FuncResidue{ void pack(Object vr, Buffer opb){ InfoResidue0 info=(InfoResidue0)vr; int acc=0; opb.write(info.begin,24); opb.write(info.end,24); opb.write(info.grouping-1,24); /* residue vectors to group and code with a partitioned book */ opb.write(info.partitions-1,6); /* possible partition choices */ opb.write(info.groupbook,8); /* group huffman book */ /* secondstages is a bitmask; as encoding progresses pass by pass, a bitmask of one indicates this partition class has bits to write this pass */ for(int j=0;j3){ /* yes, this is a minor hack due to not thinking ahead */ opb.write(info.secondstages[j],3); opb.write(1,1); opb.write(info.secondstages[j]>>>3,5); } else{ opb.write(info.secondstages[j],4); /* trailing zero */ } acc+=icount(info.secondstages[j]); } for(int j=0;j=vi.books){ free_info(info); return(null); } for(int j=0;j=vi.books){ free_info(info); return(null); } } return(info); // errout: // free_info(info); // return(NULL); } Object look(DspState vd, InfoMode vm, Object vr){ InfoResidue0 info=(InfoResidue0)vr; LookResidue0 look=new LookResidue0(); int acc=0; int dim; int maxstage=0; look.info=info; look.map=vm.mapping; look.parts=info.partitions; look.fullbooks=vd.fullbooks; look.phrasebook=vd.fullbooks[info.groupbook]; dim=look.phrasebook.dim; look.partbooks=new int[look.parts][]; for(int j=0;jmaxstage)maxstage=stages; look.partbooks[j]=new int[stages]; for(int k=0; k>>=1; } return(ret); } private static int icount(int v){ int ret=0; while(v!=0){ ret+=(v&1); v>>>=1; } return(ret); } } class LookResidue0 { InfoResidue0 info; int map; int parts; int stages; CodeBook[] fullbooks; CodeBook phrasebook; int[][] partbooks; // CodeBook[][] partbooks; int partvals; int[][] decodemap; int postbits; int phrasebits; // int[][] frames; int frames; } class InfoResidue0{ // block-partitioned VQ coded straight residue int begin; int end; // first stage (lossless partitioning) int grouping; // group n vectors per partition int partitions; // possible codebooks for a partition int groupbook; // huffbook for partitioning int[] secondstages=new int[64]; // expanded out to pointers in lookup int[] booklist=new int[256]; // list of second stage books // encode-only heuristic settings float[] entmax=new float[64]; // book entropy threshholds float[] ampmax=new float[64]; // book amp threshholds int[] subgrp=new int[64]; // book heuristic subgroup size int[] blimit=new int[64]; // subgroup position limits }