2 * Copyright (C) 2000 ymnk, JCraft,Inc.
4 * Written by: 2000 ymnk<ymnk@jcraft.com>
7 * Monty <monty@xiph.org> and
8 * The XIPHOPHORUS Company http://www.xiph.org/ .
9 * JOrbis has been based on their awesome works, Vorbis codec.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 package com.jcraft.jorbis;
28 import com.jcraft.jogg.*;
31 ///necessary stream state for linking to the framing abstraction
32 float[][] pcm=new float[0][]; // this is a pointer into local storage
33 Buffer opb=new Buffer();
44 DspState vd; // For read-only access of configuration
46 // local storage to avoid remallocing; it's up to the mapping to
54 // bitmetrics for the frame
60 public Block(DspState vd){
69 public void init(DspState vd){
73 // int alloc(int bytes){
74 // bytes=(bytes+(8-1))&(~(8-1));
75 // if(bytes+localtop>localalloc){
76 // if(localstore!=null){
77 // AllocChain link=new AllocChain();
78 // totaluse+=localtop;
80 // link.ptr=localstore;
83 // // highly conservative
85 // localstore=new byte[localalloc];
90 // //void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
96 // reap the chain, pull the ripcord
100 // AllocChain next=reap.next;
101 // //free(reap->ptr);
103 // //memset(reap,0,sizeof(struct alloc_chain));
107 // // consolidate storage
109 // //vb->localstore=realloc(vb->localstore,vb->totaluse+vb->localalloc);
110 // byte[] foo=new byte[totaluse+localalloc];
111 // System.arraycopy(localstore, 0, foo, 0, localstore.length);
113 // localalloc+=totaluse;
116 // // pull the ripcord
128 //if(localstore!=null)
130 //memset(vb,0,sizeof(vorbis_block));
134 public int synthesis(Packet op){
137 // first things first. Make sure decode is ready
139 opb.readinit(op.packet_base, op.packet, op.bytes);
141 // Check the packet type
143 // Oops. This is not an audio data packet
147 // read our mode and pre/post windowsize
148 int _mode=opb.read(vd.modebits);
149 if(_mode==-1)return(-1);
152 W=vi.mode_param[mode].blockflag;
156 if(nW==-1) return(-1);
164 granulepos=op.granulepos;
165 sequence=op.packetno-3; // first block is third packet
168 // alloc pcm passback storage
169 pcmend=vi.blocksizes[W];
170 //pcm=alloc(vi.channels);
171 if(pcm.length<vi.channels){
172 pcm=new float[vi.channels][];
174 for(int i=0;i<vi.channels;i++){
175 if(pcm[i]==null || pcm[i].length<pcmend){
176 pcm[i]=new float[pcmend];
177 //pcm[i]=alloc(pcmend);
180 for(int j=0;j<pcmend;j++){ pcm[i][j]=0; }
184 // unpack_header enforces range checking
185 int type=vi.map_type[vi.mode_param[mode].mapping];
186 return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode]));