]>
Commit | Line | Data |
---|---|---|
964dd0bc JW |
1 | /* JOrbis |
2 | * Copyright (C) 2000 ymnk, JCraft,Inc. | |
3 | * | |
4 | * Written by: 2000 ymnk<ymnk@jcraft.com> | |
5 | * | |
6 | * Many thanks to | |
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. | |
10 | * | |
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. | |
15 | ||
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. | |
20 | * | |
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. | |
24 | */ | |
25 | ||
26 | package com.jcraft.jorbis; | |
27 | ||
28 | import com.jcraft.jogg.*; | |
29 | ||
30 | public class Block{ | |
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(); | |
34 | ||
35 | int lW; | |
36 | int W; | |
37 | int nW; | |
38 | int pcmend; | |
39 | int mode; | |
40 | ||
41 | int eofflag; | |
42 | long granulepos; | |
43 | long sequence; | |
44 | DspState vd; // For read-only access of configuration | |
45 | ||
46 | // local storage to avoid remallocing; it's up to the mapping to | |
47 | // structure it | |
48 | //byte[] localstore; | |
49 | //int localtop; | |
50 | //int localalloc; | |
51 | //int totaluse; | |
52 | //AllocChain reap; | |
53 | ||
54 | // bitmetrics for the frame | |
55 | int glue_bits; | |
56 | int time_bits; | |
57 | int floor_bits; | |
58 | int res_bits; | |
59 | ||
60 | public Block(DspState vd){ | |
61 | this.vd=vd; | |
62 | // localalloc=0; | |
63 | // localstore=null; | |
64 | if(vd.analysisp!=0){ | |
65 | opb.writeinit(); | |
66 | } | |
67 | } | |
68 | ||
69 | public void init(DspState vd){ | |
70 | this.vd=vd; | |
71 | } | |
72 | ||
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; | |
79 | // link.next=reap; | |
80 | // link.ptr=localstore; | |
81 | // reap=link; | |
82 | // } | |
83 | // // highly conservative | |
84 | // localalloc=bytes; | |
85 | // localstore=new byte[localalloc]; | |
86 | // localtop=0; | |
87 | // } | |
88 | // { | |
89 | // int foo=localtop; | |
90 | // //void *ret=(void *)(((char *)vb->localstore)+vb->localtop); | |
91 | // localtop+=bytes; | |
92 | // return foo; | |
93 | // } | |
94 | // } | |
95 | ||
96 | // reap the chain, pull the ripcord | |
97 | // void ripcord(){ | |
98 | // // reap the chain | |
99 | // while(reap!=null){ | |
100 | // AllocChain next=reap.next; | |
101 | // //free(reap->ptr); | |
102 | // reap.ptr=null; | |
103 | // //memset(reap,0,sizeof(struct alloc_chain)); | |
104 | // //free(reap); | |
105 | // reap=next; | |
106 | // } | |
107 | // // consolidate storage | |
108 | // if(totaluse!=0){ | |
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); | |
112 | // localstore=foo; | |
113 | // localalloc+=totaluse; | |
114 | // totaluse=0; | |
115 | // } | |
116 | // // pull the ripcord | |
117 | // localtop=0; | |
118 | // reap=null; | |
119 | // } | |
120 | ||
121 | public int clear(){ | |
122 | if(vd!=null){ | |
123 | if(vd.analysisp!=0){ | |
124 | opb.writeclear(); | |
125 | } | |
126 | } | |
127 | //ripcord(); | |
128 | //if(localstore!=null) | |
129 | // localstore=null; | |
130 | //memset(vb,0,sizeof(vorbis_block)); | |
131 | return(0); | |
132 | } | |
133 | ||
134 | public int synthesis(Packet op){ | |
135 | Info vi=vd.vi; | |
136 | ||
137 | // first things first. Make sure decode is ready | |
138 | // ripcord(); | |
139 | opb.readinit(op.packet_base, op.packet, op.bytes); | |
140 | ||
141 | // Check the packet type | |
142 | if(opb.read(1)!=0){ | |
143 | // Oops. This is not an audio data packet | |
144 | return(-1); | |
145 | } | |
146 | ||
147 | // read our mode and pre/post windowsize | |
148 | int _mode=opb.read(vd.modebits); | |
149 | if(_mode==-1)return(-1); | |
150 | ||
151 | mode=_mode; | |
152 | W=vi.mode_param[mode].blockflag; | |
153 | if(W!=0){ | |
154 | lW=opb.read(1); | |
155 | nW=opb.read(1); | |
156 | if(nW==-1) return(-1); | |
157 | } | |
158 | else{ | |
159 | lW=0; | |
160 | nW=0; | |
161 | } | |
162 | ||
163 | // more setup | |
164 | granulepos=op.granulepos; | |
165 | sequence=op.packetno-3; // first block is third packet | |
166 | eofflag=op.e_o_s; | |
167 | ||
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][]; | |
173 | } | |
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); | |
178 | } | |
179 | else{ | |
180 | for(int j=0;j<pcmend;j++){ pcm[i][j]=0; } | |
181 | } | |
182 | } | |
183 | ||
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])); | |
187 | } | |
188 | } |