/* csvorbis * Copyright (C) 2000 ymnk, JCraft,Inc. * * Written by: 2000 ymnk * Ported to C# from JOrbis by: Mark Crichton * * Thanks go to the JOrbis team, for licencing the code under the * LGPL, making my job a lot easier. * * 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. */ using System; using System.Runtime.CompilerServices; using csogg; namespace csvorbis { class Residue0 : FuncResidue { override public void pack(Object vr, csBuffer 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); } override public 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); } internal static int icount(int v) { int ret=0; while(v!=0) { ret+=(v&1); v = (int)((uint)v >> 1); } return(ret); } } class LookResidue0 { internal InfoResidue0 info; internal int map; internal int parts; internal int stages; internal CodeBook[] fullbooks; internal CodeBook phrasebook; internal int[][] partbooks; // CodeBook[][] partbooks; internal int partvals; internal int[][] decodemap; //internal int postbits; //internal int phrasebits; // int[][] frames; //internal int frames; } class InfoResidue0 { // block-partitioned VQ coded straight residue internal int begin; internal int end; // first stage (lossless partitioning) internal int grouping; // group n vectors per partition internal int partitions; // possible codebooks for a partition internal int groupbook; // huffbook for partitioning internal int[] secondstages=new int[64]; // expanded out to pointers in lookup internal int[] booklist=new int[256]; // list of second stage books // encode-only heuristic settings internal float[] entmax=new float[64]; // book entropy threshholds internal float[] ampmax=new float[64]; // book amp threshholds internal int[] subgrp=new int[64]; // book heuristic subgroup size internal int[] blimit=new int[64]; // subgroup position limits } }