/* 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 csogg; using csvorbis; namespace csvorbis { public class DspState { static float M_PI=3.1415926539f; static int VI_TRANSFORMB=1; static int VI_WINDOWB=1; internal int analysisp; internal Info vi; internal int modebits; float[][] pcm; //float[][] pcmret; int pcm_storage; int pcm_current; int pcm_returned; float[] multipliers; int envelope_storage; int envelope_current; int eofflag; int lW; int W; int nW; int centerW; long granulepos; public long sequence; long glue_bits; long time_bits; long floor_bits; long res_bits; // local lookup storage //!! Envelope ve=new Envelope(); // envelope //float **window[2][2][2]; // block, leadin, leadout, type internal float[][][][][] wnd; // block, leadin, leadout, type //vorbis_look_transform **transform[2]; // block, type internal Object[][] transform; internal CodeBook[] fullbooks; // backend lookups are tied to the mode, not the backend or naked mapping internal Object[] mode; // local storage, only used on the encoding side. This way the // application does not need to worry about freeing some packets' // memory and not others'; packet storage is always tracked. // Cleared next call to a _dsp_ function byte[] header; byte[] header1; byte[] header2; public DspState() { transform=new Object[2][]; wnd=new float[2][][][][]; wnd[0]=new float[2][][][]; wnd[0][0]=new float[2][][]; wnd[0][1]=new float[2][][]; wnd[0][0][0]=new float[2][]; wnd[0][0][1]=new float[2][]; wnd[0][1][0]=new float[2][]; wnd[0][1][1]=new float[2][]; wnd[1]=new float[2][][][]; wnd[1][0]=new float[2][][]; wnd[1][1]=new float[2][][]; wnd[1][0][0]=new float[2][]; wnd[1][0][1]=new float[2][]; wnd[1][1][0]=new float[2][]; wnd[1][1][1]=new float[2][]; } private static int ilog2(int v) { int ret=0; while(v>1) { ret++; v = (int)((uint)v >> 1); } return(ret); } internal static float[] window(int type, int wnd, int left, int right) { float[] ret=new float[wnd]; switch(type) { case 0: // The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) { int leftbegin=wnd/4-left/2; int rightbegin=wnd-wnd/4-right/2; for(int i=0;ivi.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_returnedpcm_storage) { // expand the storage pcm_storage=endW+vi.blocksizes[1]; for(int i=0;igranulepos. // // 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); } // pcm==NULL indicates we just want the pending samples, no more public int synthesis_pcmout(float[][][] _pcm, int[] index) { if(pcm_returnedcenterW)return(-1); pcm_returned+=bytes; return(0); } public void clear() { } } }