├── .gitignore
├── README.md
├── player-demo
├── AndroidManifest.xml
├── pom.xml
├── proguard-project.txt
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── net
│ └── droidlabs
│ └── audio
│ └── ogg
│ └── demo
│ └── DemoActivity.java
├── player
├── pom.xml
└── src
│ ├── com
│ └── jcraft
│ │ ├── jogg
│ │ ├── Buffer.java
│ │ ├── Packet.java
│ │ ├── Page.java
│ │ ├── StreamState.java
│ │ └── SyncState.java
│ │ └── jorbis
│ │ ├── Block.java
│ │ ├── ChainingExample.java
│ │ ├── CodeBook.java
│ │ ├── Comment.java
│ │ ├── DecodeExample.java
│ │ ├── Drft.java
│ │ ├── DspState.java
│ │ ├── Floor0.java
│ │ ├── Floor1.java
│ │ ├── FuncFloor.java
│ │ ├── FuncMapping.java
│ │ ├── FuncResidue.java
│ │ ├── FuncTime.java
│ │ ├── Info.java
│ │ ├── InfoMode.java
│ │ ├── JOrbisException.java
│ │ ├── Lookup.java
│ │ ├── Lpc.java
│ │ ├── Lsp.java
│ │ ├── Mapping0.java
│ │ ├── Mdct.java
│ │ ├── PsyInfo.java
│ │ ├── PsyLook.java
│ │ ├── Residue0.java
│ │ ├── Residue1.java
│ │ ├── Residue2.java
│ │ ├── StaticCodeBook.java
│ │ ├── Time0.java
│ │ ├── Util.java
│ │ └── VorbisFile.java
│ └── net
│ └── droidlabs
│ └── audio
│ └── ogg
│ ├── OggStreamPlayer.java
│ └── OggStreamPlayerCallback.java
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Local configuration file (sdk path, etc)
17 | local.properties
18 |
19 | # Eclipse project files
20 | .classpath
21 | .project
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [Android Ogg Stream Player](http://radzio.github.com/AndroidOggStreamPlayer/)
2 | =========================
3 |
4 | ## Introduction ##
5 |
6 | This library allows you to play Ogg Live Streams on any Android device. It is based on JOrbis so everything is written in Java code.
7 |
8 | ## Usage ##
9 |
10 | ```java
11 | OggStreamPlayer player = new OggStreamPlayer("http://78.28.48.14:8000/stream.ogg");
12 | player.start();
13 | ```
14 |
15 | ## Goal ##
16 |
17 | Implement API similar to the native Android audio player.
--------------------------------------------------------------------------------
/player-demo/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/player-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | net.droidlabs.android.audio.ogg
8 | parent
9 | 1.0.1-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | player-demo
14 | Android Ogg Stream Player Library Demo
15 | apk
16 |
17 |
18 |
19 |
20 | com.google.android
21 | android
22 | provided
23 |
24 |
25 |
26 | com.google.android
27 | support-v4
28 |
29 |
30 |
31 | net.droidlabs.android.audio.ogg
32 | player
33 | compile
34 | 1.0.1-SNAPSHOT
35 |
36 |
37 |
38 |
39 | junit
40 | junit
41 | test
42 |
43 |
44 |
45 | org.easytesting
46 | fest-assert-core
47 | test
48 |
49 |
50 |
51 | org.robolectric
52 | robolectric
53 | test
54 |
55 |
56 |
57 |
58 | src
59 | test
60 |
61 |
62 |
63 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | org.eclipse.m2e
126 | lifecycle-mapping
127 | 1.0.0
128 |
129 |
130 |
131 |
132 |
133 | com.google.code.maven-replacer-plugin
134 | maven-replacer-plugin
135 | [1.4.0,)
136 |
137 | replace
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/player-demo/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/player-demo/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/radzio/AndroidOggStreamPlayer/dca9b5ce84982810ae90fb1ea303d96b65e5670e/player-demo/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/player-demo/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/radzio/AndroidOggStreamPlayer/dca9b5ce84982810ae90fb1ea303d96b65e5670e/player-demo/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/player-demo/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/radzio/AndroidOggStreamPlayer/dca9b5ce84982810ae90fb1ea303d96b65e5670e/player-demo/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/player-demo/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/radzio/AndroidOggStreamPlayer/dca9b5ce84982810ae90fb1ea303d96b65e5670e/player-demo/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/player-demo/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
21 |
22 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/player-demo/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Ogg Stream Player
4 |
5 |
--------------------------------------------------------------------------------
/player-demo/src/net/droidlabs/audio/ogg/demo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package net.droidlabs.audio.ogg.demo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import net.droidlabs.audio.ogg.OggStreamPlayer;
7 |
8 | public class DemoActivity extends Activity
9 | {
10 | private OggStreamPlayer player;
11 |
12 | /**
13 | * Called when the activity is first created.
14 | */
15 | @Override
16 | public void onCreate(Bundle savedInstanceState)
17 | {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.main);
20 |
21 | player = new OggStreamPlayer();
22 |
23 | }
24 |
25 | public void playAsync(View view)
26 | {
27 | player.playAsync("http://78.28.48.14:8000/stream.ogg");
28 | }
29 |
30 | public void stop(View view)
31 | {
32 | player.stop();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/player/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | net.droidlabs.android.audio.ogg
8 | parent
9 | 1.0.1-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | player
14 | Android Ogg Stream Player Library
15 | jar
16 |
17 |
18 |
19 | com.google.android
20 | android
21 | provided
22 |
23 |
24 | com.google.android
25 | support-v4
26 |
27 |
28 |
29 | junit
30 | junit
31 | test
32 |
33 |
34 | org.easytesting
35 | fest-assert-core
36 | test
37 |
38 |
39 | org.robolectric
40 | robolectric
41 | test
42 |
43 |
44 |
45 |
46 | src
47 | test
48 |
49 |
50 |
51 |
52 |
53 | org.eclipse.m2e
54 | lifecycle-mapping
55 | 1.0.0
56 |
57 |
58 |
59 |
60 |
61 | com.google.code.maven-replacer-plugin
62 | maven-replacer-plugin
63 | [1.4.0,)
64 |
65 | replace
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jogg/Buffer.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jogg;
28 |
29 | public class Buffer{
30 | private static final int BUFFER_INCREMENT=256;
31 |
32 | private static final int[] mask= {0x00000000, 0x00000001, 0x00000003,
33 | 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
34 | 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
35 | 0x00007fff, 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
36 | 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff, 0x01ffffff, 0x03ffffff,
37 | 0x07ffffff, 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
38 |
39 | int ptr=0;
40 | byte[] buffer=null;
41 | int endbit=0;
42 | int endbyte=0;
43 | int storage=0;
44 |
45 | public void writeinit(){
46 | buffer=new byte[BUFFER_INCREMENT];
47 | ptr=0;
48 | buffer[0]=(byte)'\0';
49 | storage=BUFFER_INCREMENT;
50 | }
51 |
52 | public void write(byte[] s){
53 | for(int i=0; i=storage){
90 | byte[] foo=new byte[storage+BUFFER_INCREMENT];
91 | System.arraycopy(buffer, 0, foo, 0, storage);
92 | buffer=foo;
93 | storage+=BUFFER_INCREMENT;
94 | }
95 |
96 | value&=mask[bits];
97 | bits+=endbit;
98 | buffer[ptr]|=(byte)(value<=8){
101 | buffer[ptr+1]=(byte)(value>>>(8-endbit));
102 | if(bits>=16){
103 | buffer[ptr+2]=(byte)(value>>>(16-endbit));
104 | if(bits>=24){
105 | buffer[ptr+3]=(byte)(value>>>(24-endbit));
106 | if(bits>=32){
107 | if(endbit>0)
108 | buffer[ptr+4]=(byte)(value>>>(32-endbit));
109 | else
110 | buffer[ptr+4]=0;
111 | }
112 | }
113 | }
114 | }
115 |
116 | endbyte+=bits/8;
117 | ptr+=bits/8;
118 | endbit=bits&7;
119 | }
120 |
121 | public int look(int bits){
122 | int ret;
123 | int m=mask[bits];
124 |
125 | bits+=endbit;
126 |
127 | if(endbyte+4>=storage){
128 | if(endbyte+(bits-1)/8>=storage)
129 | return (-1);
130 | }
131 |
132 | ret=((buffer[ptr])&0xff)>>>endbit;
133 | if(bits>8){
134 | ret|=((buffer[ptr+1])&0xff)<<(8-endbit);
135 | if(bits>16){
136 | ret|=((buffer[ptr+2])&0xff)<<(16-endbit);
137 | if(bits>24){
138 | ret|=((buffer[ptr+3])&0xff)<<(24-endbit);
139 | if(bits>32&&endbit!=0){
140 | ret|=((buffer[ptr+4])&0xff)<<(32-endbit);
141 | }
142 | }
143 | }
144 | }
145 | return (m&ret);
146 | }
147 |
148 | public int look1(){
149 | if(endbyte>=storage)
150 | return (-1);
151 | return ((buffer[ptr]>>endbit)&1);
152 | }
153 |
154 | public void adv(int bits){
155 | bits+=endbit;
156 | ptr+=bits/8;
157 | endbyte+=bits/8;
158 | endbit=bits&7;
159 | }
160 |
161 | public void adv1(){
162 | ++endbit;
163 | if(endbit>7){
164 | endbit=0;
165 | ptr++;
166 | endbyte++;
167 | }
168 | }
169 |
170 | public int read(int bits){
171 | int ret;
172 | int m=mask[bits];
173 |
174 | bits+=endbit;
175 |
176 | if(endbyte+4>=storage){
177 | ret=-1;
178 | if(endbyte+(bits-1)/8>=storage){
179 | ptr+=bits/8;
180 | endbyte+=bits/8;
181 | endbit=bits&7;
182 | return (ret);
183 | }
184 | }
185 |
186 | ret=((buffer[ptr])&0xff)>>>endbit;
187 | if(bits>8){
188 | ret|=((buffer[ptr+1])&0xff)<<(8-endbit);
189 | if(bits>16){
190 | ret|=((buffer[ptr+2])&0xff)<<(16-endbit);
191 | if(bits>24){
192 | ret|=((buffer[ptr+3])&0xff)<<(24-endbit);
193 | if(bits>32&&endbit!=0){
194 | ret|=((buffer[ptr+4])&0xff)<<(32-endbit);
195 | }
196 | }
197 | }
198 | }
199 |
200 | ret&=m;
201 |
202 | ptr+=bits/8;
203 | endbyte+=bits/8;
204 | endbit=bits&7;
205 | return (ret);
206 | }
207 |
208 | public int readB(int bits){
209 | int ret;
210 | int m=32-bits;
211 |
212 | bits+=endbit;
213 |
214 | if(endbyte+4>=storage){
215 | /* not the main path */
216 | ret=-1;
217 | if(endbyte*8+bits>storage*8){
218 | ptr+=bits/8;
219 | endbyte+=bits/8;
220 | endbit=bits&7;
221 | return (ret);
222 | }
223 | }
224 |
225 | ret=(buffer[ptr]&0xff)<<(24+endbit);
226 | if(bits>8){
227 | ret|=(buffer[ptr+1]&0xff)<<(16+endbit);
228 | if(bits>16){
229 | ret|=(buffer[ptr+2]&0xff)<<(8+endbit);
230 | if(bits>24){
231 | ret|=(buffer[ptr+3]&0xff)<<(endbit);
232 | if(bits>32&&(endbit!=0))
233 | ret|=(buffer[ptr+4]&0xff)>>(8-endbit);
234 | }
235 | }
236 | }
237 | ret=(ret>>>(m>>1))>>>((m+1)>>1);
238 |
239 | ptr+=bits/8;
240 | endbyte+=bits/8;
241 | endbit=bits&7;
242 | return (ret);
243 | }
244 |
245 | public int read1(){
246 | int ret;
247 | if(endbyte>=storage){
248 | ret=-1;
249 | endbit++;
250 | if(endbit>7){
251 | endbit=0;
252 | ptr++;
253 | endbyte++;
254 | }
255 | return (ret);
256 | }
257 |
258 | ret=(buffer[ptr]>>endbit)&1;
259 |
260 | endbit++;
261 | if(endbit>7){
262 | endbit=0;
263 | ptr++;
264 | endbyte++;
265 | }
266 | return (ret);
267 | }
268 |
269 | public int bytes(){
270 | return (endbyte+(endbit+7)/8);
271 | }
272 |
273 | public int bits(){
274 | return (endbyte*8+endbit);
275 | }
276 |
277 | public byte[] buffer(){
278 | return (buffer);
279 | }
280 |
281 | public static int ilog(int v){
282 | int ret=0;
283 | while(v>0){
284 | ret++;
285 | v>>>=1;
286 | }
287 | return (ret);
288 | }
289 |
290 | public static void report(String in){
291 | System.err.println(in);
292 | System.exit(1);
293 | }
294 | }
295 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jogg/Packet.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jogg;
28 |
29 | public class Packet{
30 | public byte[] packet_base;
31 | public int packet;
32 | public int bytes;
33 | public int b_o_s;
34 | public int e_o_s;
35 |
36 | public long granulepos;
37 |
38 | /**
39 | * sequence number for decode; the framing
40 | * knows where there's a hole in the data,
41 | * but we need coupling so that the codec
42 | * (which is in a seperate abstraction
43 | * layer) also knows about the gap
44 | */
45 | public long packetno;
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jogg/Page.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jogg;
28 |
29 | public class Page{
30 | private static int[] crc_lookup=new int[256];
31 | static{
32 | for(int i=0; i>>24)&0xff)^(header_base[header+i]&0xff)];
106 | }
107 | for(int i=0; i>>24)&0xff)^(body_base[body+i]&0xff)];
110 | }
111 | header_base[header+22]=(byte)crc_reg;
112 | header_base[header+23]=(byte)(crc_reg>>>8);
113 | header_base[header+24]=(byte)(crc_reg>>>16);
114 | header_base[header+25]=(byte)(crc_reg>>>24);
115 | }
116 |
117 | public Page copy(){
118 | return copy(new Page());
119 | }
120 |
121 | public Page copy(Page p){
122 | byte[] tmp=new byte[header_len];
123 | System.arraycopy(header_base, header, tmp, 0, header_len);
124 | p.header_len=header_len;
125 | p.header_base=tmp;
126 | p.header=0;
127 | tmp=new byte[body_len];
128 | System.arraycopy(body_base, body, tmp, 0, body_len);
129 | p.body_len=body_len;
130 | p.body_base=tmp;
131 | p.body=0;
132 | return p;
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jogg/StreamState.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jogg;
28 |
29 | public class StreamState{
30 | byte[] body_data; /* bytes from packet bodies */
31 | int body_storage; /* storage elements allocated */
32 | int body_fill; /* elements stored; fill mark */
33 | private int body_returned; /* elements of fill returned */
34 |
35 | int[] lacing_vals; /* The values that will go to the segment table */
36 | long[] granule_vals; /* pcm_pos values for headers. Not compact
37 | this way, but it is simple coupled to the
38 | lacing fifo */
39 | int lacing_storage;
40 | int lacing_fill;
41 | int lacing_packet;
42 | int lacing_returned;
43 |
44 | byte[] header=new byte[282]; /* working space for header encode */
45 | int header_fill;
46 |
47 | public int e_o_s; /* set when we have buffered the last packet in the
48 | logical bitstream */
49 | int b_o_s; /* set after we've written the initial page
50 | of a logical bitstream */
51 | int serialno;
52 | int pageno;
53 | long packetno; /* sequence number for decode; the framing
54 | knows where there's a hole in the data,
55 | but we need coupling so that the codec
56 | (which is in a seperate abstraction
57 | layer) also knows about the gap */
58 | long granulepos;
59 |
60 | public StreamState(){
61 | init();
62 | }
63 |
64 | StreamState(int serialno){
65 | this();
66 | init(serialno);
67 | }
68 |
69 | void init(){
70 | body_storage=16*1024;
71 | body_data=new byte[body_storage];
72 | lacing_storage=1024;
73 | lacing_vals=new int[lacing_storage];
74 | granule_vals=new long[lacing_storage];
75 | }
76 |
77 | public void init(int serialno){
78 | if(body_data==null){
79 | init();
80 | }
81 | else{
82 | for(int i=0; i0)
277 | return (-1);
278 |
279 | lacing_expand(segments+1);
280 |
281 | // are we in sequence?
282 | if(_pageno!=pageno){
283 | int i;
284 |
285 | // unroll previous partial packet (if any)
286 | for(i=lacing_packet; i0)
351 | lacing_vals[lacing_fill-1]|=0x200;
352 | }
353 |
354 | pageno=_pageno+1;
355 | return (0);
356 | }
357 |
358 | /* This will flush remaining packets into a page (returning nonzero),
359 | even if there is not enough data to trigger a flush normally
360 | (undersized page). If there are no packets or partial packets to
361 | flush, ogg_stream_flush returns 0. Note that ogg_stream_flush will
362 | try to flush a normal sized page like ogg_stream_pageout; a call to
363 | ogg_stream_flush does not gurantee that all packets have flushed.
364 | Only a return value of 0 from ogg_stream_flush indicates all packet
365 | data is flushed into pages.
366 |
367 | ogg_stream_page will flush the last page in a stream even if it's
368 | undersized; you almost certainly want to use ogg_stream_pageout
369 | (and *not* ogg_stream_flush) unless you need to flush an undersized
370 | page in the middle of a stream for some reason. */
371 |
372 | public int flush(Page og){
373 |
374 | int i;
375 | int vals=0;
376 | int maxvals=(lacing_fill>255 ? 255 : lacing_fill);
377 | int bytes=0;
378 | int acc=0;
379 | long granule_pos=granule_vals[0];
380 |
381 | if(maxvals==0)
382 | return (0);
383 |
384 | /* construct a page */
385 | /* decide how many segments to include */
386 |
387 | /* If this is the initial header case, the first page must only include
388 | the initial header packet */
389 | if(b_o_s==0){ /* 'initial header page' case */
390 | granule_pos=0;
391 | for(vals=0; vals4096)
401 | break;
402 | acc+=(lacing_vals[vals]&0x0ff);
403 | granule_pos=granule_vals[vals];
404 | }
405 | }
406 |
407 | /* construct the header in temp storage */
408 | System.arraycopy("OggS".getBytes(), 0, header, 0, 4);
409 |
410 | /* stream structure version */
411 | header[4]=0x00;
412 |
413 | /* continued packet flag? */
414 | header[5]=0x00;
415 | if((lacing_vals[0]&0x100)==0)
416 | header[5]|=0x01;
417 | /* first page flag? */
418 | if(b_o_s==0)
419 | header[5]|=0x02;
420 | /* last page flag? */
421 | if(e_o_s!=0&&lacing_fill==vals)
422 | header[5]|=0x04;
423 | b_o_s=1;
424 |
425 | /* 64 bits of PCM position */
426 | for(i=6; i<14; i++){
427 | header[i]=(byte)granule_pos;
428 | granule_pos>>>=8;
429 | }
430 |
431 | /* 32 bits of stream serial number */
432 | {
433 | int _serialno=serialno;
434 | for(i=14; i<18; i++){
435 | header[i]=(byte)_serialno;
436 | _serialno>>>=8;
437 | }
438 | }
439 |
440 | /* 32 bits of page counter (we have both counter and page header
441 | because this val can roll over) */
442 | if(pageno==-1)
443 | pageno=0; /* because someone called
444 | stream_reset; this would be a
445 | strange thing to do in an
446 | encode stream, but it has
447 | plausible uses */
448 | {
449 | int _pageno=pageno++;
450 | for(i=18; i<22; i++){
451 | header[i]=(byte)_pageno;
452 | _pageno>>>=8;
453 | }
454 | }
455 |
456 | /* zero for computation; filled in later */
457 | header[22]=0;
458 | header[23]=0;
459 | header[24]=0;
460 | header[25]=0;
461 |
462 | /* segment table */
463 | header[26]=(byte)vals;
464 | for(i=0; i4096|| /* 'page nominal size' case */
498 | lacing_fill>=255|| /* 'segment table full' case */
499 | (lacing_fill!=0&&b_o_s==0)){ /* 'initial header page' case */
500 | return flush(og);
501 | }
502 | return 0;
503 | }
504 |
505 | public int eof(){
506 | return e_o_s;
507 | }
508 |
509 | public int reset(){
510 | body_fill=0;
511 | body_returned=0;
512 |
513 | lacing_fill=0;
514 | lacing_packet=0;
515 | lacing_returned=0;
516 |
517 | header_fill=0;
518 |
519 | e_o_s=0;
520 | b_o_s=0;
521 | pageno=-1;
522 | packetno=0;
523 | granulepos=0;
524 | return (0);
525 | }
526 | }
527 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jogg/SyncState.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jogg;
28 |
29 | // DECODING PRIMITIVES: packet streaming layer
30 |
31 | // This has two layers to place more of the multi-serialno and paging
32 | // control in the application's hands. First, we expose a data buffer
33 | // using ogg_decode_buffer(). The app either copies into the
34 | // buffer, or passes it directly to read(), etc. We then call
35 | // ogg_decode_wrote() to tell how many bytes we just added.
36 | //
37 | // Pages are returned (pointers into the buffer in ogg_sync_state)
38 | // by ogg_decode_stream(). The page is then submitted to
39 | // ogg_decode_page() along with the appropriate
40 | // ogg_stream_state* (ie, matching serialno). We then get raw
41 | // packets out calling ogg_stream_packet() with a
42 | // ogg_stream_state. See the 'frame-prog.txt' docs for details and
43 | // example code.
44 |
45 | public class SyncState{
46 |
47 | public byte[] data;
48 | int storage;
49 | int fill;
50 | int returned;
51 |
52 | int unsynced;
53 | int headerbytes;
54 | int bodybytes;
55 |
56 | public int clear(){
57 | data=null;
58 | return (0);
59 | }
60 |
61 | public int buffer(int size){
62 | // first, clear out any space that has been previously returned
63 | if(returned!=0){
64 | fill-=returned;
65 | if(fill>0){
66 | System.arraycopy(data, returned, data, 0, fill);
67 | }
68 | returned=0;
69 | }
70 |
71 | if(size>storage-fill){
72 | // We need to extend the internal buffer
73 | int newsize=size+fill+4096; // an extra page to be nice
74 | if(data!=null){
75 | byte[] foo=new byte[newsize];
76 | System.arraycopy(data, 0, foo, 0, data.length);
77 | data=foo;
78 | }
79 | else{
80 | data=new byte[newsize];
81 | }
82 | storage=newsize;
83 | }
84 |
85 | return (fill);
86 | }
87 |
88 | public int wrote(int bytes){
89 | if(fill+bytes>storage)
90 | return (-1);
91 | fill+=bytes;
92 | return (0);
93 | }
94 |
95 | // sync the stream. This is meant to be useful for finding page
96 | // boundaries.
97 | //
98 | // return values for this:
99 | // -n) skipped n bytes
100 | // 0) page not ready; more data (no bytes skipped)
101 | // n) page synced at current location; page length n bytes
102 | private Page pageseek=new Page();
103 | private byte[] chksum=new byte[4];
104 |
105 | public int pageseek(Page og){
106 | int page=returned;
107 | int next;
108 | int bytes=fill-returned;
109 |
110 | if(headerbytes==0){
111 | int _headerbytes, i;
112 | if(bytes<27)
113 | return (0); // not enough for a header
114 |
115 | /* verify capture pattern */
116 | if(data[page]!='O'||data[page+1]!='g'||data[page+2]!='g'
117 | ||data[page+3]!='S'){
118 | headerbytes=0;
119 | bodybytes=0;
120 |
121 | // search for possible capture
122 | next=0;
123 | for(int ii=0; iibytes)
149 | return (0);
150 |
151 | // The whole test page is buffered. Verify the checksum
152 | synchronized(chksum){
153 | // Grab the checksum bytes, set the header field to zero
154 |
155 | System.arraycopy(data, page+22, chksum, 0, 4);
156 | data[page+22]=0;
157 | data[page+23]=0;
158 | data[page+24]=0;
159 | data[page+25]=0;
160 |
161 | // set up a temp page struct and recompute the checksum
162 | Page log=pageseek;
163 | log.header_base=data;
164 | log.header=page;
165 | log.header_len=headerbytes;
166 |
167 | log.body_base=data;
168 | log.body=page+headerbytes;
169 | log.body_len=bodybytes;
170 | log.checksum();
171 |
172 | // Compare
173 | if(chksum[0]!=data[page+22]||chksum[1]!=data[page+23]
174 | ||chksum[2]!=data[page+24]||chksum[3]!=data[page+25]){
175 | // D'oh. Mismatch! Corrupt page (or miscapture and not a page at all)
176 | // replace the computed checksum with the one actually read in
177 | System.arraycopy(chksum, 0, data, page+22, 4);
178 | // Bad checksum. Lose sync */
179 |
180 | headerbytes=0;
181 | bodybytes=0;
182 | // search for possible capture
183 | next=0;
184 | for(int ii=0; ii0){
238 | // have a page
239 | return (1);
240 | }
241 | if(ret==0){
242 | // need more data
243 | return (0);
244 | }
245 |
246 | // head did not start a synced page... skipped some bytes
247 | if(unsynced==0){
248 | unsynced=1;
249 | return (-1);
250 | }
251 | // loop. keep looking
252 | }
253 | }
254 |
255 | // clear things to an initial state. Good to call, eg, before seeking
256 | public int reset(){
257 | fill=0;
258 | returned=0;
259 | unsynced=0;
260 | headerbytes=0;
261 | bodybytes=0;
262 | return (0);
263 | }
264 |
265 | public void init(){
266 | }
267 |
268 | public int getDataOffset(){
269 | return returned;
270 | }
271 |
272 | public int getBufferOffset(){
273 | return fill;
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Block.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | public class Block{
32 | ///necessary stream state for linking to the framing abstraction
33 | float[][] pcm=new float[0][]; // this is a pointer into local storage
34 | Buffer opb=new Buffer();
35 |
36 | int lW;
37 | int W;
38 | int nW;
39 | int pcmend;
40 | int mode;
41 |
42 | int eofflag;
43 | long granulepos;
44 | long sequence;
45 | DspState vd; // For read-only access of configuration
46 |
47 | // bitmetrics for the frame
48 | int glue_bits;
49 | int time_bits;
50 | int floor_bits;
51 | int res_bits;
52 |
53 | public Block(DspState vd){
54 | this.vd=vd;
55 | if(vd.analysisp!=0){
56 | opb.writeinit();
57 | }
58 | }
59 |
60 | public void init(DspState vd){
61 | this.vd=vd;
62 | }
63 |
64 | public int clear(){
65 | if(vd!=null){
66 | if(vd.analysisp!=0){
67 | opb.writeclear();
68 | }
69 | }
70 | return (0);
71 | }
72 |
73 | public int synthesis(Packet op){
74 | Info vi=vd.vi;
75 |
76 | // first things first. Make sure decode is ready
77 | opb.readinit(op.packet_base, op.packet, op.bytes);
78 |
79 | // Check the packet type
80 | if(opb.read(1)!=0){
81 | // Oops. This is not an audio data packet
82 | return (-1);
83 | }
84 |
85 | // read our mode and pre/post windowsize
86 | int _mode=opb.read(vd.modebits);
87 | if(_mode==-1)
88 | return (-1);
89 |
90 | mode=_mode;
91 | W=vi.mode_param[mode].blockflag;
92 | if(W!=0){
93 | lW=opb.read(1);
94 | nW=opb.read(1);
95 | if(nW==-1)
96 | return (-1);
97 | }
98 | else{
99 | lW=0;
100 | nW=0;
101 | }
102 |
103 | // more setup
104 | granulepos=op.granulepos;
105 | sequence=op.packetno-3; // first block is third packet
106 | eofflag=op.e_o_s;
107 |
108 | // alloc pcm passback storage
109 | pcmend=vi.blocksizes[W];
110 | if(pcm.length
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class ChainingExample{
30 | public static void main(String[] arg){
31 | VorbisFile ov=null;
32 |
33 | try{
34 | if(arg.length>0){
35 | ov=new VorbisFile(arg[0]);
36 | }
37 | else{
38 | ov=new VorbisFile(System.in, null, -1);
39 | }
40 | }
41 | catch(Exception e){
42 | System.err.println(e);
43 | return;
44 | }
45 |
46 | if(ov.seekable()){
47 | System.out.println("Input bitstream contained "+ov.streams()
48 | +" logical bitstream section(s).");
49 | System.out.println("Total bitstream playing time: "+ov.time_total(-1)
50 | +" seconds\n");
51 | }
52 | else{
53 | System.out.println("Standard input was not seekable.");
54 | System.out.println("First logical bitstream information:\n");
55 | }
56 |
57 | for(int i=0; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class CodeBook{
32 | int dim; // codebook dimensions (elements per vector)
33 | int entries; // codebook entries
34 | StaticCodeBook c=new StaticCodeBook();
35 |
36 | float[] valuelist; // list of dim*entries actual entry values
37 | int[] codelist; // list of bitstream codewords for each entry
38 | DecodeAux decode_tree;
39 |
40 | // returns the number of bits
41 | int encode(int a, Buffer b){
42 | b.write(codelist[a], c.lengthlist[a]);
43 | return (c.lengthlist[a]);
44 | }
45 |
46 | // One the encode side, our vector writers are each designed for a
47 | // specific purpose, and the encoder is not flexible without modification:
48 | //
49 | // The LSP vector coder uses a single stage nearest-match with no
50 | // interleave, so no step and no error return. This is specced by floor0
51 | // and doesn't change.
52 | //
53 | // Residue0 encoding interleaves, uses multiple stages, and each stage
54 | // peels of a specific amount of resolution from a lattice (thus we want
55 | // to match by threshhold, not nearest match). Residue doesn't *have* to
56 | // be encoded that way, but to change it, one will need to add more
57 | // infrastructure on the encode side (decode side is specced and simpler)
58 |
59 | // floor0 LSP (single stage, non interleaved, nearest match)
60 | // returns entry number and *modifies a* to the quantization value
61 | int errorv(float[] a){
62 | int best=best(a, 1);
63 | for(int k=0; k8){
115 | for(i=0; i declarative (set the value)
205 | // stage==1 -> additive
206 | // stage==2 -> multiplicitive
207 |
208 | // returns the entry number or -1 on eof
209 | int decode(Buffer b){
210 | int ptr=0;
211 | DecodeAux t=decode_tree;
212 | int lok=b.look(t.tabn);
213 |
214 | if(lok>=0){
215 | ptr=t.tab[lok];
216 | b.adv(t.tabl[lok]);
217 | if(ptr<=0){
218 | return -ptr;
219 | }
220 | }
221 | do{
222 | switch(b.read1()){
223 | case 0:
224 | ptr=t.ptr0[ptr];
225 | break;
226 | case 1:
227 | ptr=t.ptr1[ptr];
228 | break;
229 | case -1:
230 | default:
231 | return (-1);
232 | }
233 | }
234 | while(ptr>0);
235 | return (-ptr);
236 | }
237 |
238 | // returns the entry number or -1 on eof
239 | int decodevs(float[] a, int index, Buffer b, int step, int addmul){
240 | int entry=decode(b);
241 | if(entry==-1)
242 | return (-1);
243 | switch(addmul){
244 | case -1:
245 | for(int i=0, o=0; i=u1&&u1>='A')
89 | u1=(byte)(u1-'A'+'a');
90 | if('Z'>=u2&&u2>='A')
91 | u2=(byte)(u2-'A'+'a');
92 | if(u1!=u2){
93 | return false;
94 | }
95 | c++;
96 | }
97 | return true;
98 | }
99 |
100 | public String query(String tag){
101 | return query(tag, 0);
102 | }
103 |
104 | public String query(String tag, int count){
105 | int foo=query(tag.getBytes(), count);
106 | if(foo==-1)
107 | return null;
108 | byte[] comment=user_comments[foo];
109 | for(int i=0; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | // Takes a vorbis bitstream from stdin and writes raw stereo PCM to
32 | // stdout. Decodes simple and chained OggVorbis files from beginning
33 | // to end. Vorbisfile.a is somewhat more complex than the code below.
34 |
35 | class DecodeExample{
36 | static int convsize=4096*2;
37 | static byte[] convbuffer=new byte[convsize]; // take 8k out of the data segment, not the stack
38 |
39 | public static void main(String[] arg){
40 | java.io.InputStream input=System.in;
41 | if(arg.length>0){
42 | try{
43 | input=new java.io.FileInputStream(arg[0]);
44 | }
45 | catch(Exception e){
46 | System.err.println(e);
47 | }
48 | }
49 |
50 | SyncState oy=new SyncState(); // sync and verify incoming physical bitstream
51 | StreamState os=new StreamState(); // take physical pages, weld into a logical stream of packets
52 | Page og=new Page(); // one Ogg bitstream page. Vorbis packets are inside
53 | Packet op=new Packet(); // one raw packet of data for decode
54 |
55 | Info vi=new Info(); // struct that stores all the static vorbis bitstream settings
56 | Comment vc=new Comment(); // struct that stores all the bitstream user comments
57 | DspState vd=new DspState(); // central working state for the packet->PCM decoder
58 | Block vb=new Block(vd); // local working space for packet->PCM decode
59 |
60 | byte[] buffer;
61 | int bytes=0;
62 |
63 | // Decode setup
64 |
65 | oy.init(); // Now we can read pages
66 |
67 | while(true){ // we repeat if the bitstream is chained
68 | int eos=0;
69 |
70 | // grab some data at the head of the stream. We want the first page
71 | // (which is guaranteed to be small and only contain the Vorbis
72 | // stream initial header) We need the first page to get the stream
73 | // serialno.
74 |
75 | // submit a 4k block to libvorbis' Ogg layer
76 | int index=oy.buffer(4096);
77 | buffer=oy.data;
78 | try{
79 | bytes=input.read(buffer, index, 4096);
80 | }
81 | catch(Exception e){
82 | System.err.println(e);
83 | System.exit(-1);
84 | }
85 | oy.wrote(bytes);
86 |
87 | // Get the first page.
88 | if(oy.pageout(og)!=1){
89 | // have we simply run out of data? If so, we're done.
90 | if(bytes<4096)
91 | break;
92 |
93 | // error case. Must not be Vorbis data
94 | System.err.println("Input does not appear to be an Ogg bitstream.");
95 | System.exit(1);
96 | }
97 |
98 | // Get the serial number and set up the rest of decode.
99 | // serialno first; use it to set up a logical stream
100 | os.init(og.serialno());
101 |
102 | // extract the initial header from the first page and verify that the
103 | // Ogg bitstream is in fact Vorbis data
104 |
105 | // I handle the initial header first instead of just having the code
106 | // read all three Vorbis headers at once because reading the initial
107 | // header is an easy way to identify a Vorbis bitstream and it's
108 | // useful to see that functionality seperated out.
109 |
110 | vi.init();
111 | vc.init();
112 | if(os.pagein(og)<0){
113 | // error; stream version mismatch perhaps
114 | System.err.println("Error reading first page of Ogg bitstream data.");
115 | System.exit(1);
116 | }
117 |
118 | if(os.packetout(op)!=1){
119 | // no page? must not be vorbis
120 | System.err.println("Error reading initial header packet.");
121 | System.exit(1);
122 | }
123 |
124 | if(vi.synthesis_headerin(vc, op)<0){
125 | // error case; not a vorbis header
126 | System.err
127 | .println("This Ogg bitstream does not contain Vorbis audio data.");
128 | System.exit(1);
129 | }
130 |
131 | // At this point, we're sure we're Vorbis. We've set up the logical
132 | // (Ogg) bitstream decoder. Get the comment and codebook headers and
133 | // set up the Vorbis decoder
134 |
135 | // The next two packets in order are the comment and codebook headers.
136 | // They're likely large and may span multiple pages. Thus we reead
137 | // and submit data until we get our two pacakets, watching that no
138 | // pages are missing. If a page is missing, error out; losing a
139 | // header page is the only place where missing data is fatal. */
140 |
141 | int i=0;
142 | while(i<2){
143 | while(i<2){
144 |
145 | int result=oy.pageout(og);
146 | if(result==0)
147 | break; // Need more data
148 | // Don't complain about missing or corrupt data yet. We'll
149 | // catch it at the packet output phase
150 |
151 | if(result==1){
152 | os.pagein(og); // we can ignore any errors here
153 | // as they'll also become apparent
154 | // at packetout
155 | while(i<2){
156 | result=os.packetout(op);
157 | if(result==0)
158 | break;
159 | if(result==-1){
160 | // Uh oh; data at some point was corrupted or missing!
161 | // We can't tolerate that in a header. Die.
162 | System.err.println("Corrupt secondary header. Exiting.");
163 | System.exit(1);
164 | }
165 | vi.synthesis_headerin(vc, op);
166 | i++;
167 | }
168 | }
169 | }
170 | // no harm in not checking before adding more
171 | index=oy.buffer(4096);
172 | buffer=oy.data;
173 | try{
174 | bytes=input.read(buffer, index, 4096);
175 | }
176 | catch(Exception e){
177 | System.err.println(e);
178 | System.exit(1);
179 | }
180 | if(bytes==0&&i<2){
181 | System.err.println("End of file before finding all Vorbis headers!");
182 | System.exit(1);
183 | }
184 | oy.wrote(bytes);
185 | }
186 |
187 | // Throw the comments plus a few lines about the bitstream we're
188 | // decoding
189 | {
190 | byte[][] ptr=vc.user_comments;
191 | for(int j=0; jPCM decoder.
206 | vd.synthesis_init(vi); // central decode state
207 | vb.init(vd); // local state for most of the decode
208 | // so multiple block decodes can
209 | // proceed in parallel. We could init
210 | // multiple vorbis_block structures
211 | // for vd here
212 |
213 | float[][][] _pcm=new float[1][][];
214 | int[] _index=new int[vi.channels];
215 | // The rest is just a straight decode loop until end of stream
216 | while(eos==0){
217 | while(eos==0){
218 |
219 | int result=oy.pageout(og);
220 | if(result==0)
221 | break; // need more data
222 | if(result==-1){ // missing or corrupt data at this page position
223 | System.err
224 | .println("Corrupt or missing data in bitstream; continuing...");
225 | }
226 | else{
227 | os.pagein(og); // can safely ignore errors at
228 | // this point
229 | while(true){
230 | result=os.packetout(op);
231 |
232 | if(result==0)
233 | break; // need more data
234 | if(result==-1){ // missing or corrupt data at this page position
235 | // no reason to complain; already complained above
236 | }
237 | else{
238 | // we have a packet. Decode it
239 | int samples;
240 | if(vb.synthesis(op)==0){ // test for success!
241 | vd.synthesis_blockin(vb);
242 | }
243 |
244 | // **pcm is a multichannel float vector. In stereo, for
245 | // example, pcm[0] is left, and pcm[1] is right. samples is
246 | // the size of each channel. Convert the float values
247 | // (-1.<=range<=1.) to whatever PCM format and write it out
248 |
249 | while((samples=vd.synthesis_pcmout(_pcm, _index))>0){
250 | float[][] pcm=_pcm[0];
251 | int bout=(samples32767){
265 | val=32767;
266 | }
267 | if(val<-32768){
268 | val=-32768;
269 | }
270 | if(val<0)
271 | val=val|0x8000;
272 | convbuffer[ptr]=(byte)(val);
273 | convbuffer[ptr+1]=(byte)(val>>>8);
274 | ptr+=2*(vi.channels);
275 | }
276 | }
277 |
278 | System.out.write(convbuffer, 0, 2*vi.channels*bout);
279 |
280 | // tell libvorbis how
281 | // many samples we
282 | // actually consumed
283 | vd.synthesis_read(bout);
284 | }
285 | }
286 | }
287 | if(og.eos()!=0)
288 | eos=1;
289 | }
290 | }
291 | if(eos==0){
292 | index=oy.buffer(4096);
293 | buffer=oy.data;
294 | try{
295 | bytes=input.read(buffer, index, 4096);
296 | }
297 | catch(Exception e){
298 | System.err.println(e);
299 | System.exit(1);
300 | }
301 | oy.wrote(bytes);
302 | if(bytes==0)
303 | eos=1;
304 | }
305 | }
306 |
307 | // clean up this logical bitstream; before exit we see if we're
308 | // followed by another [chained]
309 |
310 | os.clear();
311 |
312 | // ogg_page and ogg_packet structs always point to storage in
313 | // libvorbis. They're never freed or manipulated directly
314 |
315 | vb.clear();
316 | vd.clear();
317 | vi.clear(); // must be called last
318 | }
319 |
320 | // OK, clean up the framer
321 | oy.clear();
322 | System.err.println("Done.");
323 | }
324 | }
325 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/DspState.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | public class DspState{
30 | static final float M_PI=3.1415926539f;
31 | static final int VI_TRANSFORMB=1;
32 | static final int VI_WINDOWB=1;
33 |
34 | int analysisp;
35 | Info vi;
36 | int modebits;
37 |
38 | float[][] pcm;
39 | int pcm_storage;
40 | int pcm_current;
41 | int pcm_returned;
42 |
43 | float[] multipliers;
44 | int envelope_storage;
45 | int envelope_current;
46 |
47 | int eofflag;
48 |
49 | int lW;
50 | int W;
51 | int nW;
52 | int centerW;
53 |
54 | long granulepos;
55 | long sequence;
56 |
57 | long glue_bits;
58 | long time_bits;
59 | long floor_bits;
60 | long res_bits;
61 |
62 | // local lookup storage
63 | float[][][][][] window; // block, leadin, leadout, type
64 | Object[][] transform;
65 | CodeBook[] fullbooks;
66 | // backend lookups are tied to the mode, not the backend or naked mapping
67 | Object[] mode;
68 |
69 | // local storage, only used on the encoding side. This way the
70 | // application does not need to worry about freeing some packets'
71 | // memory and not others'; packet storage is always tracked.
72 | // Cleared next call to a _dsp_ function
73 | byte[] header;
74 | byte[] header1;
75 | byte[] header2;
76 |
77 | public DspState(){
78 | transform=new Object[2][];
79 | window=new float[2][][][][];
80 | window[0]=new float[2][][][];
81 | window[0][0]=new float[2][][];
82 | window[0][1]=new float[2][][];
83 | window[0][0][0]=new float[2][];
84 | window[0][0][1]=new float[2][];
85 | window[0][1][0]=new float[2][];
86 | window[0][1][1]=new float[2][];
87 | window[1]=new float[2][][][];
88 | window[1][0]=new float[2][][];
89 | window[1][1]=new float[2][][];
90 | window[1][0][0]=new float[2][];
91 | window[1][0][1]=new float[2][];
92 | window[1][1][0]=new float[2][];
93 | window[1][1][1]=new float[2][];
94 | }
95 |
96 | static float[] window(int type, int window, int left, int right){
97 | float[] ret=new float[window];
98 | switch(type){
99 | case 0:
100 | // The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi)
101 | {
102 | int leftbegin=window/4-left/2;
103 | int rightbegin=window-window/4-right/2;
104 |
105 | for(int i=0; ivi.blocksizes[1]/2&&pcm_returned>8192){
243 | // don't shift too much; we need to have a minimum PCM buffer of
244 | // 1/2 long block
245 |
246 | int shiftPCM=centerW-vi.blocksizes[1]/2;
247 | shiftPCM=(pcm_returnedpcm_storage){
283 | // expand the storage
284 | pcm_storage=endW+vi.blocksizes[1];
285 | for(int i=0; igranulepos.
321 | //
322 | // This is not foolproof! It will be confused if we begin
323 | // decoding at the last page after a seek or hole. In that case,
324 | // we don't have a starting point to judge where the last frame
325 | // is. For this reason, vorbisfile will always try to make sure
326 | // it reads the last two marked pages in proper sequence
327 |
328 | if(granulepos==-1){
329 | granulepos=vb.granulepos;
330 | }
331 | else{
332 | granulepos+=(_centerW-centerW);
333 | if(vb.granulepos!=-1&&granulepos!=vb.granulepos){
334 | if(granulepos>vb.granulepos&&vb.eofflag!=0){
335 | // partial last frame. Strip the padding off
336 | _centerW-=(granulepos-vb.granulepos);
337 | }// else{ Shouldn't happen *unless* the bitstream is out of
338 | // spec. Either way, believe the bitstream }
339 | granulepos=vb.granulepos;
340 | }
341 | }
342 |
343 | // Update, cleanup
344 |
345 | centerW=_centerW;
346 | pcm_current=endW;
347 | if(vb.eofflag!=0)
348 | eofflag=1;
349 | }
350 | return (0);
351 | }
352 |
353 | // pcm==NULL indicates we just want the pending samples, no more
354 | public int synthesis_pcmout(float[][][] _pcm, int[] index){
355 | if(pcm_returnedcenterW)
369 | return (-1);
370 | pcm_returned+=bytes;
371 | return (0);
372 | }
373 |
374 | public void clear(){
375 | }
376 | }
377 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Floor0.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class Floor0 extends FuncFloor{
32 |
33 | void pack(Object i, Buffer opb){
34 | InfoFloor0 info=(InfoFloor0)i;
35 | opb.write(info.order, 8);
36 | opb.write(info.rate, 16);
37 | opb.write(info.barkmap, 16);
38 | opb.write(info.ampbits, 6);
39 | opb.write(info.ampdB, 8);
40 | opb.write(info.numbooks-1, 4);
41 | for(int j=0; j=vi.books){
61 | return (null);
62 | }
63 | }
64 | return (info);
65 | }
66 |
67 | Object look(DspState vd, InfoMode mi, Object i){
68 | float scale;
69 | Info vi=vd.vi;
70 | InfoFloor0 info=(InfoFloor0)i;
71 | LookFloor0 look=new LookFloor0();
72 | look.m=info.order;
73 | look.n=vi.blocksizes[mi.blockflag]/2;
74 | look.ln=info.barkmap;
75 | look.vi=info;
76 | look.lpclook.init(look.ln, look.m);
77 |
78 | // we choose a scaling constant so that:
79 | scale=look.ln/toBARK((float)(info.rate/2.));
80 |
81 | // the mapping from a linear scale to a smaller bark scale is
82 | // straightforward. We do *not* make sure that the linear mapping
83 | // does not skip bark-scale bins; the decoder simply skips them and
84 | // the encoder may do what it wishes in filling them. They're
85 | // necessary in some mapping combinations to keep the scale spacing
86 | // accurate
87 | look.linearmap=new int[look.n];
88 | for(int j=0; j=look.ln)
91 | val=look.ln; // guard against the approximation
92 | look.linearmap[j]=val;
93 | }
94 | return look;
95 | }
96 |
97 | static float toBARK(float f){
98 | return (float)(13.1*Math.atan(.00074*(f))+2.24*Math.atan((f)*(f)*1.85e-8)+1e-4*(f));
99 | }
100 |
101 | Object state(Object i){
102 | EchstateFloor0 state=new EchstateFloor0();
103 | InfoFloor0 info=(InfoFloor0)i;
104 |
105 | // a safe size if usually too big (dim==1)
106 | state.codewords=new int[info.order];
107 | state.curve=new float[info.barkmap];
108 | state.frameno=-1;
109 | return (state);
110 | }
111 |
112 | void free_info(Object i){
113 | }
114 |
115 | void free_look(Object i){
116 | }
117 |
118 | void free_state(Object vs){
119 | }
120 |
121 | int forward(Block vb, Object i, float[] in, float[] out, Object vs){
122 | return 0;
123 | }
124 |
125 | float[] lsp=null;
126 |
127 | int inverse(Block vb, Object i, float[] out){
128 | //System.err.println("Floor0.inverse "+i.getClass()+"]");
129 | LookFloor0 look=(LookFloor0)i;
130 | InfoFloor0 info=look.vi;
131 | int ampraw=vb.opb.read(info.ampbits);
132 | if(ampraw>0){ // also handles the -1 out of data case
133 | int maxval=(1<0){ // also handles the -1 out of data case
187 | int maxval=(1<m+1 must be less than l->ln, but guard in case we get a bad stream
294 | float[] lcurve=new float[Math.max(l.ln*2, l.m*2+2)];
295 |
296 | if(amp==0){
297 | for(int j=0; j
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | abstract class FuncFloor{
32 |
33 | public static FuncFloor[] floor_P= {new Floor0(), new Floor1()};
34 |
35 | abstract void pack(Object i, Buffer opb);
36 |
37 | abstract Object unpack(Info vi, Buffer opb);
38 |
39 | abstract Object look(DspState vd, InfoMode mi, Object i);
40 |
41 | abstract void free_info(Object i);
42 |
43 | abstract void free_look(Object i);
44 |
45 | abstract void free_state(Object vs);
46 |
47 | abstract int forward(Block vb, Object i, float[] in, float[] out, Object vs);
48 |
49 | abstract Object inverse1(Block vb, Object i, Object memo);
50 |
51 | abstract int inverse2(Block vb, Object i, Object memo, float[] out);
52 | }
53 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/FuncMapping.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | abstract class FuncMapping{
32 | public static FuncMapping[] mapping_P= {new Mapping0()};
33 |
34 | abstract void pack(Info info, Object imap, Buffer buffer);
35 |
36 | abstract Object unpack(Info info, Buffer buffer);
37 |
38 | abstract Object look(DspState vd, InfoMode vm, Object m);
39 |
40 | abstract void free_info(Object imap);
41 |
42 | abstract void free_look(Object imap);
43 |
44 | abstract int inverse(Block vd, Object lm);
45 | }
46 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/FuncResidue.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | abstract class FuncResidue{
32 | public static FuncResidue[] residue_P= {new Residue0(), new Residue1(),
33 | new Residue2()};
34 |
35 | abstract void pack(Object vr, Buffer opb);
36 |
37 | abstract Object unpack(Info vi, Buffer opb);
38 |
39 | abstract Object look(DspState vd, InfoMode vm, Object vr);
40 |
41 | abstract void free_info(Object i);
42 |
43 | abstract void free_look(Object i);
44 |
45 | abstract int inverse(Block vb, Object vl, float[][] in, int[] nonzero, int ch);
46 | }
47 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/FuncTime.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | abstract class FuncTime{
32 | public static FuncTime[] time_P= {new Time0()};
33 |
34 | abstract void pack(Object i, Buffer opb);
35 |
36 | abstract Object unpack(Info vi, Buffer opb);
37 |
38 | abstract Object look(DspState vd, InfoMode vm, Object i);
39 |
40 | abstract void free_info(Object i);
41 |
42 | abstract void free_look(Object i);
43 |
44 | abstract int inverse(Block vb, Object i, float[] in, float[] out);
45 | }
46 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Info.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | public class Info{
32 | private static final int OV_EBADPACKET=-136;
33 | private static final int OV_ENOTAUDIO=-135;
34 |
35 | private static byte[] _vorbis="vorbis".getBytes();
36 | private static final int VI_TIMEB=1;
37 | // private static final int VI_FLOORB=1;
38 | private static final int VI_FLOORB=2;
39 | // private static final int VI_RESB=1;
40 | private static final int VI_RESB=3;
41 | private static final int VI_MAPB=1;
42 | private static final int VI_WINDOWB=1;
43 |
44 | public int version;
45 | public int channels;
46 | public int rate;
47 |
48 | // The below bitrate declarations are *hints*.
49 | // Combinations of the three values carry the following implications:
50 | //
51 | // all three set to the same value:
52 | // implies a fixed rate bitstream
53 | // only nominal set:
54 | // implies a VBR stream that averages the nominal bitrate. No hard
55 | // upper/lower limit
56 | // upper and or lower set:
57 | // implies a VBR bitstream that obeys the bitrate limits. nominal
58 | // may also be set to give a nominal rate.
59 | // none set:
60 | // the coder does not care to speculate.
61 |
62 | int bitrate_upper;
63 | int bitrate_nominal;
64 | int bitrate_lower;
65 |
66 | // Vorbis supports only short and long blocks, but allows the
67 | // encoder to choose the sizes
68 |
69 | int[] blocksizes=new int[2];
70 |
71 | // modes are the primary means of supporting on-the-fly different
72 | // blocksizes, different channel mappings (LR or mid-side),
73 | // different residue backends, etc. Each mode consists of a
74 | // blocksize flag and a mapping (along with the mapping setup
75 |
76 | int modes;
77 | int maps;
78 | int times;
79 | int floors;
80 | int residues;
81 | int books;
82 | int psys; // encode only
83 |
84 | InfoMode[] mode_param=null;
85 |
86 | int[] map_type=null;
87 | Object[] map_param=null;
88 |
89 | int[] time_type=null;
90 | Object[] time_param=null;
91 |
92 | int[] floor_type=null;
93 | Object[] floor_param=null;
94 |
95 | int[] residue_type=null;
96 | Object[] residue_param=null;
97 |
98 | StaticCodeBook[] book_param=null;
99 |
100 | PsyInfo[] psy_param=new PsyInfo[64]; // encode only
101 |
102 | // for block long/sort tuning; encode only
103 | int envelopesa;
104 | float preecho_thresh;
105 | float preecho_clamp;
106 |
107 | // used by synthesis, which has a full, alloced vi
108 | public void init(){
109 | rate=0;
110 | }
111 |
112 | public void clear(){
113 | for(int i=0; ibook_param)free(vi->book_param);
150 | book_param=null;
151 |
152 | for(int i=0; i=VI_TIMEB){
207 | clear();
208 | return (-1);
209 | }
210 | time_param[i]=FuncTime.time_P[time_type[i]].unpack(this, opb);
211 | if(time_param[i]==null){
212 | clear();
213 | return (-1);
214 | }
215 | }
216 |
217 | // floor backend settings
218 | floors=opb.read(6)+1;
219 | if(floor_type==null||floor_type.length!=floors)
220 | floor_type=new int[floors];
221 | if(floor_param==null||floor_param.length!=floors)
222 | floor_param=new Object[floors];
223 |
224 | for(int i=0; i=VI_FLOORB){
227 | clear();
228 | return (-1);
229 | }
230 |
231 | floor_param[i]=FuncFloor.floor_P[floor_type[i]].unpack(this, opb);
232 | if(floor_param[i]==null){
233 | clear();
234 | return (-1);
235 | }
236 | }
237 |
238 | // residue backend settings
239 | residues=opb.read(6)+1;
240 |
241 | if(residue_type==null||residue_type.length!=residues)
242 | residue_type=new int[residues];
243 |
244 | if(residue_param==null||residue_param.length!=residues)
245 | residue_param=new Object[residues];
246 |
247 | for(int i=0; i=VI_RESB){
250 | clear();
251 | return (-1);
252 | }
253 | residue_param[i]=FuncResidue.residue_P[residue_type[i]].unpack(this, opb);
254 | if(residue_param[i]==null){
255 | clear();
256 | return (-1);
257 | }
258 | }
259 |
260 | // map backend settings
261 | maps=opb.read(6)+1;
262 | if(map_type==null||map_type.length!=maps)
263 | map_type=new int[maps];
264 | if(map_param==null||map_param.length!=maps)
265 | map_param=new Object[maps];
266 | for(int i=0; i=VI_MAPB){
269 | clear();
270 | return (-1);
271 | }
272 | map_param[i]=FuncMapping.mapping_P[map_type[i]].unpack(this, opb);
273 | if(map_param[i]==null){
274 | clear();
275 | return (-1);
276 | }
277 | }
278 |
279 | // mode settings
280 | modes=opb.read(6)+1;
281 | if(mode_param==null||mode_param.length!=modes)
282 | mode_param=new InfoMode[modes];
283 | for(int i=0; i=VI_WINDOWB)
291 | ||(mode_param[i].transformtype>=VI_WINDOWB)
292 | ||(mode_param[i].mapping>=maps)){
293 | clear();
294 | return (-1);
295 | }
296 | }
297 |
298 | if(opb.read(1)!=1){
299 | clear();
300 | return (-1);
301 | }
302 |
303 | return (0);
304 | }
305 |
306 | // The Vorbis header is in three packets; the initial small packet in
307 | // the first page that identifies basic parameters, a second packet
308 | // with bitstream comments and a third packet that holds the
309 | // codebook.
310 |
311 | public int synthesis_headerin(Comment vc, Packet op){
312 | Buffer opb=new Buffer();
313 |
314 | if(op!=null){
315 | opb.readinit(op.packet_base, op.packet, op.bytes);
316 |
317 | // Which of the three types of header is this?
318 | // Also verify header-ness, vorbis
319 | {
320 | byte[] buffer=new byte[6];
321 | int packtype=opb.read(8);
322 | opb.read(buffer, 6);
323 | if(buffer[0]!='v'||buffer[1]!='o'||buffer[2]!='r'||buffer[3]!='b'
324 | ||buffer[4]!='i'||buffer[5]!='s'){
325 | // not a vorbis header
326 | return (-1);
327 | }
328 | switch(packtype){
329 | case 0x01: // least significant *bit* is read first
330 | if(op.b_o_s==0){
331 | // Not the initial packet
332 | return (-1);
333 | }
334 | if(rate!=0){
335 | // previously initialized info header
336 | return (-1);
337 | }
338 | return (unpack_info(opb));
339 | case 0x03: // least significant *bit* is read first
340 | if(rate==0){
341 | // um... we didn't get the initial header
342 | return (-1);
343 | }
344 | return (vc.unpack(opb));
345 | case 0x05: // least significant *bit* is read first
346 | if(rate==0||vc.vendor==null){
347 | // um... we didn;t get the initial header or comments yet
348 | return (-1);
349 | }
350 | return (unpack_books(opb));
351 | default:
352 | // Not a valid vorbis header type
353 | //return(-1);
354 | break;
355 | }
356 | }
357 | }
358 | return (-1);
359 | }
360 |
361 | // pack side
362 | int pack_info(Buffer opb){
363 | // preamble
364 | opb.write(0x01, 8);
365 | opb.write(_vorbis);
366 |
367 | // basic information about the stream
368 | opb.write(0x00, 32);
369 | opb.write(channels, 8);
370 | opb.write(rate, 32);
371 |
372 | opb.write(bitrate_upper, 32);
373 | opb.write(bitrate_nominal, 32);
374 | opb.write(bitrate_lower, 32);
375 |
376 | opb.write(Util.ilog2(blocksizes[0]), 4);
377 | opb.write(Util.ilog2(blocksizes[1]), 4);
378 | opb.write(1, 1);
379 | return (0);
380 | }
381 |
382 | int pack_books(Buffer opb){
383 | opb.write(0x05, 8);
384 | opb.write(_vorbis);
385 |
386 | // books
387 | opb.write(books-1, 8);
388 | for(int i=0; i1){
452 | modebits++;
453 | v>>>=1;
454 | }
455 |
456 | /* read our mode and pre/post windowsize */
457 | mode=opb.read(modebits);
458 | }
459 | if(mode==-1)
460 | return (OV_EBADPACKET);
461 | return (blocksizes[mode_param[mode].blockflag]);
462 | }
463 |
464 | public String toString(){
465 | return "version:"+new Integer(version)+", channels:"+new Integer(channels)
466 | +", rate:"+new Integer(rate)+", bitrate:"+new Integer(bitrate_upper)
467 | +","+new Integer(bitrate_nominal)+","+new Integer(bitrate_lower);
468 | }
469 | }
470 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/InfoMode.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class InfoMode{
30 | int blockflag;
31 | int windowtype;
32 | int transformtype;
33 | int mapping;
34 | }
35 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/JOrbisException.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | public class JOrbisException extends Exception{
30 |
31 | private static final long serialVersionUID=1L;
32 |
33 | public JOrbisException(){
34 | super();
35 | }
36 |
37 | public JOrbisException(String s){
38 | super("JOrbis: "+s);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Lookup.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class Lookup{
30 | static final int COS_LOOKUP_SZ=128;
31 | static final float[] COS_LOOKUP= {+1.0000000000000f, +0.9996988186962f,
32 | +0.9987954562052f, +0.9972904566787f, +0.9951847266722f,
33 | +0.9924795345987f, +0.9891765099648f, +0.9852776423889f,
34 | +0.9807852804032f, +0.9757021300385f, +0.9700312531945f,
35 | +0.9637760657954f, +0.9569403357322f, +0.9495281805930f,
36 | +0.9415440651830f, +0.9329927988347f, +0.9238795325113f,
37 | +0.9142097557035f, +0.9039892931234f, +0.8932243011955f,
38 | +0.8819212643484f, +0.8700869911087f, +0.8577286100003f,
39 | +0.8448535652497f, +0.8314696123025f, +0.8175848131516f,
40 | +0.8032075314806f, +0.7883464276266f, +0.7730104533627f,
41 | +0.7572088465065f, +0.7409511253550f, +0.7242470829515f,
42 | +0.7071067811865f, +0.6895405447371f, +0.6715589548470f,
43 | +0.6531728429538f, +0.6343932841636f, +0.6152315905806f,
44 | +0.5956993044924f, +0.5758081914178f, +0.5555702330196f,
45 | +0.5349976198871f, +0.5141027441932f, +0.4928981922298f,
46 | +0.4713967368260f, +0.4496113296546f, +0.4275550934303f,
47 | +0.4052413140050f, +0.3826834323651f, +0.3598950365350f,
48 | +0.3368898533922f, +0.3136817403989f, +0.2902846772545f,
49 | +0.2667127574749f, +0.2429801799033f, +0.2191012401569f,
50 | +0.1950903220161f, +0.1709618887603f, +0.1467304744554f,
51 | +0.1224106751992f, +0.0980171403296f, +0.0735645635997f,
52 | +0.0490676743274f, +0.0245412285229f, +0.0000000000000f,
53 | -0.0245412285229f, -0.0490676743274f, -0.0735645635997f,
54 | -0.0980171403296f, -0.1224106751992f, -0.1467304744554f,
55 | -0.1709618887603f, -0.1950903220161f, -0.2191012401569f,
56 | -0.2429801799033f, -0.2667127574749f, -0.2902846772545f,
57 | -0.3136817403989f, -0.3368898533922f, -0.3598950365350f,
58 | -0.3826834323651f, -0.4052413140050f, -0.4275550934303f,
59 | -0.4496113296546f, -0.4713967368260f, -0.4928981922298f,
60 | -0.5141027441932f, -0.5349976198871f, -0.5555702330196f,
61 | -0.5758081914178f, -0.5956993044924f, -0.6152315905806f,
62 | -0.6343932841636f, -0.6531728429538f, -0.6715589548470f,
63 | -0.6895405447371f, -0.7071067811865f, -0.7242470829515f,
64 | -0.7409511253550f, -0.7572088465065f, -0.7730104533627f,
65 | -0.7883464276266f, -0.8032075314806f, -0.8175848131516f,
66 | -0.8314696123025f, -0.8448535652497f, -0.8577286100003f,
67 | -0.8700869911087f, -0.8819212643484f, -0.8932243011955f,
68 | -0.9039892931234f, -0.9142097557035f, -0.9238795325113f,
69 | -0.9329927988347f, -0.9415440651830f, -0.9495281805930f,
70 | -0.9569403357322f, -0.9637760657954f, -0.9700312531945f,
71 | -0.9757021300385f, -0.9807852804032f, -0.9852776423889f,
72 | -0.9891765099648f, -0.9924795345987f, -0.9951847266722f,
73 | -0.9972904566787f, -0.9987954562052f, -0.9996988186962f,
74 | -1.0000000000000f,};
75 |
76 | /* interpolated lookup based cos function, domain 0 to PI only */
77 | static float coslook(float a){
78 | double d=a*(.31830989*(float)COS_LOOKUP_SZ);
79 | int i=(int)d;
80 | return COS_LOOKUP[i]+((float)(d-i))*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
81 | }
82 |
83 | static final int INVSQ_LOOKUP_SZ=32;
84 | static final float[] INVSQ_LOOKUP= {1.414213562373f, 1.392621247646f,
85 | 1.371988681140f, 1.352246807566f, 1.333333333333f, 1.315191898443f,
86 | 1.297771369046f, 1.281025230441f, 1.264911064067f, 1.249390095109f,
87 | 1.234426799697f, 1.219988562661f, 1.206045378311f, 1.192569588000f,
88 | 1.179535649239f, 1.166919931983f, 1.154700538379f, 1.142857142857f,
89 | 1.131370849898f, 1.120224067222f, 1.109400392450f, 1.098884511590f,
90 | 1.088662107904f, 1.078719779941f, 1.069044967650f, 1.059625885652f,
91 | 1.050451462878f, 1.041511287847f, 1.032795558989f, 1.024295039463f,
92 | 1.016001016002f, 1.007905261358f, 1.000000000000f,};
93 |
94 | /* interpolated 1./sqrt(p) where .5 <= p < 1. */
95 | static float invsqlook(float a){
96 | double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
97 | int i=(int)d;
98 | return INVSQ_LOOKUP[i]+((float)(d-i))*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
99 | }
100 |
101 | static final int INVSQ2EXP_LOOKUP_MIN=-32;
102 | static final int INVSQ2EXP_LOOKUP_MAX=32;
103 | static final float[] INVSQ2EXP_LOOKUP= {65536.f, 46340.95001f, 32768.f,
104 | 23170.47501f, 16384.f, 11585.2375f, 8192.f, 5792.618751f, 4096.f,
105 | 2896.309376f, 2048.f, 1448.154688f, 1024.f, 724.0773439f, 512.f,
106 | 362.038672f, 256.f, 181.019336f, 128.f, 90.50966799f, 64.f, 45.254834f,
107 | 32.f, 22.627417f, 16.f, 11.3137085f, 8.f, 5.656854249f, 4.f,
108 | 2.828427125f, 2.f, 1.414213562f, 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
109 | 0.25f, 0.1767766953f, 0.125f, 0.08838834765f, 0.0625f, 0.04419417382f,
110 | 0.03125f, 0.02209708691f, 0.015625f, 0.01104854346f, 0.0078125f,
111 | 0.005524271728f, 0.00390625f, 0.002762135864f, 0.001953125f,
112 | 0.001381067932f, 0.0009765625f, 0.000690533966f, 0.00048828125f,
113 | 0.000345266983f, 0.000244140625f, 0.0001726334915f, 0.0001220703125f,
114 | 8.631674575e-05f, 6.103515625e-05f, 4.315837288e-05f, 3.051757812e-05f,
115 | 2.157918644e-05f, 1.525878906e-05f,};
116 |
117 | /* interpolated 1./sqrt(p) where .5 <= p < 1. */
118 | static float invsq2explook(int a){
119 | return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
120 | }
121 |
122 | static final int FROMdB_LOOKUP_SZ=35;
123 | static final int FROMdB2_LOOKUP_SZ=32;
124 | static final int FROMdB_SHIFT=5;
125 | static final int FROMdB2_SHIFT=3;
126 | static final int FROMdB2_MASK=31;
127 | static final float[] FROMdB_LOOKUP= {1.f, 0.6309573445f, 0.3981071706f,
128 | 0.2511886432f, 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
129 | 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f, 0.003981071706f,
130 | 0.002511886432f, 0.001584893192f, 0.001f, 0.0006309573445f,
131 | 0.0003981071706f, 0.0002511886432f, 0.0001584893192f, 0.0001f,
132 | 6.309573445e-05f, 3.981071706e-05f, 2.511886432e-05f, 1.584893192e-05f,
133 | 1e-05f, 6.309573445e-06f, 3.981071706e-06f, 2.511886432e-06f,
134 | 1.584893192e-06f, 1e-06f, 6.309573445e-07f, 3.981071706e-07f,
135 | 2.511886432e-07f, 1.584893192e-07f,};
136 | static final float[] FROMdB2_LOOKUP= {0.9928302478f, 0.9786445908f,
137 | 0.9646616199f, 0.9508784391f, 0.9372921937f, 0.92390007f, 0.9106992942f,
138 | 0.8976871324f, 0.8848608897f, 0.8722179097f, 0.8597555737f,
139 | 0.8474713009f, 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
140 | 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f, 0.7445176537f,
141 | 0.7338799116f, 0.7233941627f, 0.7130582353f, 0.7028699885f,
142 | 0.6928273125f, 0.6829281272f, 0.6731703824f, 0.6635520573f,
143 | 0.6540711597f, 0.6447257262f, 0.6355138211f,};
144 |
145 | /* interpolated lookup based fromdB function, domain -140dB to 0dB only */
146 | static float fromdBlook(float a){
147 | int i=(int)(a*((float)(-(1<=(FROMdB_LOOKUP_SZ<>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Lpc.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class Lpc{
30 | // en/decode lookups
31 | Drft fft=new Drft();;
32 |
33 | int ln;
34 | int m;
35 |
36 | // Autocorrelation LPC coeff generation algorithm invented by
37 | // N. Levinson in 1947, modified by J. Durbin in 1959.
38 |
39 | // Input : n elements of time doamin data
40 | // Output: m lpc coefficients, excitation energy
41 |
42 | static float lpc_from_data(float[] data, float[] lpc, int n, int m){
43 | float[] aut=new float[m+1];
44 | float error;
45 | int i, j;
46 |
47 | // autocorrelation, p+1 lag coefficients
48 |
49 | j=m+1;
50 | while(j--!=0){
51 | float d=0;
52 | for(i=j; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | /*
30 | function: LSP (also called LSF) conversion routines
31 |
32 | The LSP generation code is taken (with minimal modification) from
33 | "On the Computation of the LSP Frequencies" by Joseph Rothweiler
34 | , available at:
35 |
36 | http://www2.xtdl.com/~rothwlr/lsfpaper/lsfpage.html
37 | ********************************************************************/
38 |
39 | class Lsp{
40 |
41 | static final float M_PI=(float)(3.1415926539);
42 |
43 | static void lsp_to_curve(float[] curve, int[] map, int n, int ln,
44 | float[] lsp, int m, float amp, float ampoffset){
45 | int i;
46 | float wdel=M_PI/ln;
47 | for(i=0; i=0x7f800000||(ix==0)){
83 | // 0,inf,nan
84 | }
85 | else{
86 | if(ix<0x00800000){ // subnormal
87 | q*=3.3554432000e+07; // 0x4c000000
88 | hx=Float.floatToIntBits(q);
89 | ix=0x7fffffff&hx;
90 | qexp=-25;
91 | }
92 | qexp+=((ix>>>23)-126);
93 | hx=(hx&0x807fffff)|0x3f000000;
94 | q=Float.intBitsToFloat(hx);
95 | }
96 |
97 | q=Lookup.fromdBlook(amp*Lookup.invsqlook(q)*Lookup.invsq2explook(qexp+m)
98 | -ampoffset);
99 |
100 | do{
101 | curve[i++]*=q;
102 | }
103 | while(i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class Mapping0 extends FuncMapping{
32 | static int seq=0;
33 |
34 | void free_info(Object imap){
35 | };
36 |
37 | void free_look(Object imap){
38 | }
39 |
40 | Object look(DspState vd, InfoMode vm, Object m){
41 | //System.err.println("Mapping0.look");
42 | Info vi=vd.vi;
43 | LookMapping0 look=new LookMapping0();
44 | InfoMapping0 info=look.map=(InfoMapping0)m;
45 | look.mode=vm;
46 |
47 | look.time_look=new Object[info.submaps];
48 | look.floor_look=new Object[info.submaps];
49 | look.residue_look=new Object[info.submaps];
50 |
51 | look.time_func=new FuncTime[info.submaps];
52 | look.floor_func=new FuncFloor[info.submaps];
53 | look.residue_func=new FuncResidue[info.submaps];
54 |
55 | for(int i=0; i1){
91 | opb.write(1, 1);
92 | opb.write(info.submaps-1, 4);
93 | }
94 | else{
95 | opb.write(0, 1);
96 | }
97 |
98 | if(info.coupling_steps>0){
99 | opb.write(1, 1);
100 | opb.write(info.coupling_steps-1, 8);
101 | for(int i=0; i1){
114 | for(int i=0; i=vi.channels
143 | ||testA>=vi.channels){
144 | //goto err_out;
145 | info.free();
146 | return (null);
147 | }
148 | }
149 | }
150 |
151 | if(opb.read(2)>0){ /* 2,3:reserved */
152 | info.free();
153 | return (null);
154 | }
155 |
156 | if(info.submaps>1){
157 | for(int i=0; i=info.submaps){
160 | info.free();
161 | return (null);
162 | }
163 | }
164 | }
165 |
166 | for(int i=0; i=vi.times){
169 | info.free();
170 | return (null);
171 | }
172 | info.floorsubmap[i]=opb.read(8);
173 | if(info.floorsubmap[i]>=vi.floors){
174 | info.free();
175 | return (null);
176 | }
177 | info.residuesubmap[i]=opb.read(8);
178 | if(info.residuesubmap[i]>=vi.residues){
179 | info.free();
180 | return (null);
181 | }
182 | }
183 | return info;
184 | }
185 |
186 | float[][] pcmbundle=null;
187 | int[] zerobundle=null;
188 | int[] nonzero=null;
189 | Object[] floormemo=null;
190 |
191 | synchronized int inverse(Block vb, Object l){
192 | DspState vd=vb.vd;
193 | Info vi=vd.vi;
194 | LookMapping0 look=(LookMapping0)l;
195 | InfoMapping0 info=look.map;
196 | InfoMode mode=look.mode;
197 | int n=vb.pcmend=vi.blocksizes[vb.W];
198 |
199 | float[] window=vd.window[vb.W][vb.lW][vb.nW][mode.windowtype];
200 | if(pcmbundle==null||pcmbundle.length=0; i--){
259 | float[] pcmM=vb.pcm[info.coupling_mag[i]];
260 | float[] pcmA=vb.pcm[info.coupling_ang[i]];
261 |
262 | for(int j=0; j0){
267 | if(ang>0){
268 | pcmM[j]=mag;
269 | pcmA[j]=mag-ang;
270 | }
271 | else{
272 | pcmA[j]=mag;
273 | pcmM[j]=mag+ang;
274 | }
275 | }
276 | else{
277 | if(ang>0){
278 | pcmM[j]=mag;
279 | pcmA[j]=mag+ang;
280 | }
281 | else{
282 | pcmA[j]=mag;
283 | pcmM[j]=mag-ang;
284 | }
285 | }
286 | }
287 | }
288 |
289 | // /* compute and apply spectral envelope */
290 |
291 | for(int i=0; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class Mdct{
30 |
31 | int n;
32 | int log2n;
33 |
34 | float[] trig;
35 | int[] bitrev;
36 |
37 | float scale;
38 |
39 | void init(int n){
40 | bitrev=new int[n/4];
41 | trig=new float[n+n/4];
42 |
43 | log2n=(int)Math.rint(Math.log(n)/Math.log(2));
44 | this.n=n;
45 |
46 | int AE=0;
47 | int AO=1;
48 | int BE=AE+n/2;
49 | int BO=BE+1;
50 | int CE=BE+n/2;
51 | int CO=CE+1;
52 | // trig lookups...
53 | for(int i=0; i>>j!=0; j++)
70 | if(((msb>>>j)&i)!=0)
71 | acc|=1<>>1;
99 | int n4=n>>>2;
100 | int n8=n>>>3;
101 |
102 | // rotate + step 1
103 | {
104 | int inO=1;
105 | int xO=0;
106 | int A=n2;
107 |
108 | int i;
109 | for(i=0; i>>(i+2);
184 | int k1=1<<(i+3);
185 | int wbase=n2-2;
186 |
187 | A=0;
188 | float[] temp;
189 |
190 | for(int r=0; r<(k0>>>2); r++){
191 | int w1=wbase;
192 | w2=w1-(k0>>1);
193 | float AEv=trig[A], wA;
194 | float AOv=trig[A+1], wB;
195 | wbase-=2;
196 |
197 | k0++;
198 | for(int s=0; s<(2<
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | // psychoacoustic setup
30 | class PsyInfo{
31 | int athp;
32 | int decayp;
33 | int smoothp;
34 | int noisefitp;
35 | int noisefit_subblock;
36 | float noisefit_threshdB;
37 |
38 | float ath_att;
39 |
40 | int tonemaskp;
41 | float[] toneatt_125Hz=new float[5];
42 | float[] toneatt_250Hz=new float[5];
43 | float[] toneatt_500Hz=new float[5];
44 | float[] toneatt_1000Hz=new float[5];
45 | float[] toneatt_2000Hz=new float[5];
46 | float[] toneatt_4000Hz=new float[5];
47 | float[] toneatt_8000Hz=new float[5];
48 |
49 | int peakattp;
50 | float[] peakatt_125Hz=new float[5];
51 | float[] peakatt_250Hz=new float[5];
52 | float[] peakatt_500Hz=new float[5];
53 | float[] peakatt_1000Hz=new float[5];
54 | float[] peakatt_2000Hz=new float[5];
55 | float[] peakatt_4000Hz=new float[5];
56 | float[] peakatt_8000Hz=new float[5];
57 |
58 | int noisemaskp;
59 | float[] noiseatt_125Hz=new float[5];
60 | float[] noiseatt_250Hz=new float[5];
61 | float[] noiseatt_500Hz=new float[5];
62 | float[] noiseatt_1000Hz=new float[5];
63 | float[] noiseatt_2000Hz=new float[5];
64 | float[] noiseatt_4000Hz=new float[5];
65 | float[] noiseatt_8000Hz=new float[5];
66 |
67 | float max_curve_dB;
68 |
69 | float attack_coeff;
70 | float decay_coeff;
71 |
72 | void free(){
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/PsyLook.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class PsyLook{
30 | int n;
31 | PsyInfo vi;
32 |
33 | float[][][] tonecurves;
34 | float[][] peakatt;
35 | float[][][] noisecurves;
36 |
37 | float[] ath;
38 | int[] octave;
39 |
40 | void init(PsyInfo vi, int n, int rate){
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Residue0.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class Residue0 extends FuncResidue{
32 | void pack(Object vr, Buffer opb){
33 | InfoResidue0 info=(InfoResidue0)vr;
34 | int acc=0;
35 | opb.write(info.begin, 24);
36 | opb.write(info.end, 24);
37 |
38 | opb.write(info.grouping-1, 24); /* residue vectors to group and
39 | code with a partitioned book */
40 | opb.write(info.partitions-1, 6); /* possible partition choices */
41 | opb.write(info.groupbook, 8); /* group huffman book */
42 |
43 | /* secondstages is a bitmask; as encoding progresses pass by pass, a
44 | bitmask of one indicates this partition class has bits to write
45 | this pass */
46 | for(int j=0; j3){
49 | /* yes, this is a minor hack due to not thinking ahead */
50 | opb.write(i, 3);
51 | opb.write(1, 1);
52 | opb.write(i>>>3, 5);
53 | }
54 | else{
55 | opb.write(i, 4); /* trailing zero */
56 | }
57 | acc+=Util.icount(i);
58 | }
59 | for(int j=0; j=vi.books){
87 | free_info(info);
88 | return (null);
89 | }
90 |
91 | for(int j=0; j=vi.books){
93 | free_info(info);
94 | return (null);
95 | }
96 | }
97 | return (info);
98 | }
99 |
100 | Object look(DspState vd, InfoMode vm, Object vr){
101 | InfoResidue0 info=(InfoResidue0)vr;
102 | LookResidue0 look=new LookResidue0();
103 | int acc=0;
104 | int dim;
105 | int maxstage=0;
106 | look.info=info;
107 | look.map=vm.mapping;
108 |
109 | look.parts=info.partitions;
110 | look.fullbooks=vd.fullbooks;
111 | look.phrasebook=vd.fullbooks[info.groupbook];
112 |
113 | dim=look.phrasebook.dim;
114 |
115 | look.partbooks=new int[look.parts][];
116 |
117 | for(int j=0; jmaxstage)
122 | maxstage=stages;
123 | look.partbooks[j]=new int[stages];
124 | for(int k=0; k
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class Residue1 extends Residue0{
30 |
31 | int inverse(Block vb, Object vl, float[][] in, int[] nonzero, int ch){
32 | int used=0;
33 | for(int i=0; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | class Residue2 extends Residue0{
30 |
31 | int inverse(Block vb, Object vl, float[][] in, int[] nonzero, int ch){
32 | int i=0;
33 | for(i=0; i
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class StaticCodeBook{
32 | int dim; // codebook dimensions (elements per vector)
33 | int entries; // codebook entries
34 | int[] lengthlist; // codeword lengths in bits
35 |
36 | // mapping
37 | int maptype; // 0=none
38 | // 1=implicitly populated values from map column
39 | // 2=listed arbitrary values
40 |
41 | // The below does a linear, single monotonic sequence mapping.
42 | int q_min; // packed 32 bit float; quant value 0 maps to minval
43 | int q_delta; // packed 32 bit float; val 1 - val 0 == delta
44 | int q_quant; // bits: 0 < quant <= 16
45 | int q_sequencep; // bitflag
46 |
47 | // additional information for log (dB) mapping; the linear mapping
48 | // is assumed to actually be values in dB. encodebias is used to
49 | // assign an error weight to 0 dB. We have two additional flags:
50 | // zeroflag indicates if entry zero is to represent -Inf dB; negflag
51 | // indicates if we're to represent negative linear values in a
52 | // mirror of the positive mapping.
53 |
54 | int[] quantlist; // map == 1: (int)(entries/dim) element column map
55 | // map == 2: list of dim*entries quantized entry vals
56 |
57 | StaticCodeBook(){
58 | }
59 |
60 | int pack(Buffer opb){
61 | int i;
62 | boolean ordered=false;
63 |
64 | opb.write(0x564342, 24);
65 | opb.write(dim, 16);
66 | opb.write(entries, 24);
67 |
68 | // pack the codewords. There are two packings; length ordered and
69 | // length random. Decide between the two now.
70 |
71 | for(i=1; i_last){
91 | for(int j=_last; j<_this; j++){
92 | opb.write(i-count, Util.ilog(entries-count));
93 | count=i;
94 | }
95 | }
96 | }
97 | opb.write(i-count, Util.ilog(entries-count));
98 | }
99 | else{
100 | // length random. Again, we don't code the codeword itself, just
101 | // the length. This time, though, we have to encode each length
102 | opb.write(0, 1); // unordered
103 |
104 | // algortihmic mapping has use for 'unused entries', which we tag
105 | // here. The algorithmic mapping happens as usual, but the unused
106 | // entry has no codeword.
107 | for(i=0; ientries/c->dim) quantized values for
159 | // building a full value list algorithmically (square lattice)
160 | quantvals=maptype1_quantvals();
161 | break;
162 | case 2:
163 | // every value (c->entries*c->dim total) specified explicitly
164 | quantvals=entries*dim;
165 | break;
166 | }
167 |
168 | // quantized values
169 | for(i=0; ibim <= b->entries
326 | // treat the above as an initial guess
327 | while(true){
328 | int acc=1;
329 | int acc1=1;
330 | for(int i=0; ientries){
335 | return (vals);
336 | }
337 | else{
338 | if(acc>entries){
339 | vals--;
340 | }
341 | else{
342 | vals++;
343 | }
344 | }
345 | }
346 | }
347 |
348 | void clear(){
349 | }
350 |
351 | // unpack the quantized list of values for encode/decode
352 | // we need to deal with two map types: in map type 1, the values are
353 | // generated algorithmically (each column of the vector counts through
354 | // the values in the quant vector). in map type 2, all the values came
355 | // in in an explicit list. Both value lists must be unpacked
356 | float[] unquantize(){
357 |
358 | if(maptype==1||maptype==2){
359 | int quantvals;
360 | float mindel=float32_unpack(q_min);
361 | float delta=float32_unpack(q_delta);
362 | float[] r=new float[entries*dim];
363 |
364 | // maptype 1 and 2 both use a quantized value vector, but
365 | // different sizes
366 | switch(maptype){
367 | case 1:
368 | // most of the time, entries%dimensions == 0, but we need to be
369 | // well defined. We define that the possible vales at each
370 | // scalar is values == entries/dim. If entries%dim != 0, we'll
371 | // have 'too few' values (values*dim "+val+" | ");}
395 | val=Math.abs(val)*delta+mindel+last;
396 | if(q_sequencep!=0)
397 | last=val;
398 | r[j*dim+k]=val;
399 | //if((j*dim+k)==0){System.err.println(" $ r[0] -> "+r[0]+" | ");}
400 | }
401 | }
402 | //System.err.println("\nr[0]="+r[0]);
403 | }
404 | return (r);
405 | }
406 | return (null);
407 | }
408 |
409 | // 32 bit float (not IEEE; nonnormalized mantissa +
410 | // biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm
411 | // Why not IEEE? It's just not that important here.
412 |
413 | static final int VQ_FEXP=10;
414 | static final int VQ_FMAN=21;
415 | static final int VQ_FEXP_BIAS=768; // bias toward values smaller than 1.
416 |
417 | // doesn't currently guard under/overflow
418 | static long float32_pack(float val){
419 | int sign=0;
420 | int exp;
421 | int mant;
422 | if(val<0){
423 | sign=0x80000000;
424 | val=-val;
425 | }
426 | exp=(int)Math.floor(Math.log(val)/Math.log(2));
427 | mant=(int)Math.rint(Math.pow(val, (VQ_FMAN-1)-exp));
428 | exp=(exp+VQ_FEXP_BIAS)<>>VQ_FMAN;
435 | if((val&0x80000000)!=0)
436 | mant=-mant;
437 | return (ldexp(mant, ((int)exp)-(VQ_FMAN-1)-VQ_FEXP_BIAS));
438 | }
439 |
440 | static float ldexp(float foo, int e){
441 | return (float)(foo*Math.pow(2, e));
442 | }
443 | }
444 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Time0.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /* JOrbis
3 | * Copyright (C) 2000 ymnk, JCraft,Inc.
4 | *
5 | * Written by: 2000 ymnk
6 | *
7 | * Many thanks to
8 | * Monty and
9 | * The XIPHOPHORUS Company http://www.xiph.org/ .
10 | * JOrbis has been based on their awesome works, Vorbis codec.
11 | *
12 | * This program is free software; you can redistribute it and/or
13 | * modify it under the terms of the GNU Library General Public License
14 | * as published by the Free Software Foundation; either version 2 of
15 | * the License, or (at your option) any later version.
16 |
17 | * This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Library General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Library General Public
23 | * License along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 | */
26 |
27 | package com.jcraft.jorbis;
28 |
29 | import com.jcraft.jogg.*;
30 |
31 | class Time0 extends FuncTime{
32 | void pack(Object i, Buffer opb){
33 | }
34 |
35 | Object unpack(Info vi, Buffer opb){
36 | return "";
37 | }
38 |
39 | Object look(DspState vd, InfoMode mi, Object i){
40 | return "";
41 | }
42 |
43 | void free_info(Object i){
44 | }
45 |
46 | void free_look(Object i){
47 | }
48 |
49 | int inverse(Block vb, Object i, float[] in, float[] out){
50 | return 0;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/player/src/com/jcraft/jorbis/Util.java:
--------------------------------------------------------------------------------
1 | package com.jcraft.jorbis;
2 |
3 | class Util{
4 | static int ilog(int v){
5 | int ret=0;
6 | while(v!=0){
7 | ret++;
8 | v>>>=1;
9 | }
10 | return (ret);
11 | }
12 |
13 | static int ilog2(int v){
14 | int ret=0;
15 | while(v>1){
16 | ret++;
17 | v>>>=1;
18 | }
19 | return (ret);
20 | }
21 |
22 | static int icount(int v){
23 | int ret=0;
24 | while(v!=0){
25 | ret+=(v&1);
26 | v>>>=1;
27 | }
28 | return (ret);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/player/src/net/droidlabs/audio/ogg/OggStreamPlayerCallback.java:
--------------------------------------------------------------------------------
1 | package net.droidlabs.audio.ogg;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | * User: Radek Piekarz
6 | * Date: 06.04.13
7 | * Time: 18:56
8 | */
9 | public interface OggStreamPlayerCallback
10 | {
11 | public void playerStarted();
12 |
13 | public void playerStopped();
14 |
15 | public void playerException(Throwable t);
16 | }
17 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | org.sonatype.oss
8 | oss-parent
9 | 7
10 |
11 |
12 | net.droidlabs.android.audio.ogg
13 | parent
14 | pom
15 | 1.0.1-SNAPSHOT
16 |
17 | Android Ogg Stream Player
18 | This library allows you to play Ogg Live Streams on any Android device. It is based on JOrbis so everything is written in Java code.
19 | http://droidlabs.net
20 | 2013
21 |
22 |
23 | player
24 | player-demo
25 |
26 |
27 |
28 | https://github.com/radzio/AndroidOggStreamPlayer
29 | scm:git:git://github.com/radzio/AndroidOggStreamPlayer.git
30 | scm:git:git@github.com:radzio/AndroidOggStreamPlayer.git
31 | 1.0.0
32 |
33 |
34 |
35 |
36 | Radek Piekarz
37 | contact@droidlabs.net
38 | radzio
39 | http://droidlabs.net
40 | +1
41 |
42 | developer
43 | owner
44 |
45 |
46 |
47 |
48 |
49 |
50 | Apache License Version 2.0
51 | http://www.apache.org/licenses/LICENSE-2.0.txt
52 | repo
53 |
54 |
55 |
56 |
57 | DroidLabs
58 | http://droidlabs.net
59 |
60 |
61 |
62 | GitHub Issues
63 | https://github.com/radzio/DroidLabs-Tools/issues
64 |
65 |
66 |
67 | UTF-8
68 | UTF-8
69 |
70 | 1.6
71 | 14
72 |
73 |
74 | 4.0.1.2
75 | r7
76 | 1.0.4
77 |
78 |
79 | 2.4.0
80 | 1.5
81 |
82 |
83 | 4.10
84 | 2.0M10
85 | 2.0-alpha-2
86 |
87 | AF617292
88 |
89 |
90 |
91 |
92 |
93 |
94 | com.google.android
95 | android
96 | ${android.version}
97 |
98 |
99 | com.google.android
100 | support-v4
101 | ${android-support.version}
102 |
103 |
104 | com.nineoldandroids
105 | library
106 | ${nineoldandroids.version}
107 |
108 |
109 | com.github.rtyley
110 | roboguice-sherlock
111 | ${roboguice-sherlock.version}
112 |
113 |
114 | junit
115 | junit
116 | ${junit.version}
117 |
118 |
119 | org.easytesting
120 | fest-assert-core
121 | ${fest.version}
122 |
123 |
124 | org.robolectric
125 | robolectric
126 | ${robolectric.version}
127 |
128 |
129 | com.squareup
130 | fest-android
131 | ${fest.android.version}
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | org.apache.maven.plugins
141 | maven-compiler-plugin
142 | 3.0
143 |
144 | ${java.version}
145 | ${java.version}
146 | true
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 | com.jayway.maven.plugins.android.generation2
155 | android-maven-plugin
156 | 3.5.3
157 |
158 | ignored
159 |
160 | ${android.platform}
161 |
162 |
163 |
164 |
165 |
166 | org.apache.maven.plugins
167 | maven-javadoc-plugin
168 | 2.9
169 |
170 |
171 |
172 | org.codehaus.mojo
173 | build-helper-maven-plugin
174 | 1.7
175 |
176 |
177 |
178 | org.holoeverywhere
179 | resbuilder
180 | 1.5.0
181 |
182 |
183 |
184 | com.google.code.maven-replacer-plugin
185 | maven-replacer-plugin
186 | 1.4.0
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 | com.jayway.maven.plugins.android.generation2
196 | android-maven-plugin
197 | true
198 | 3.5.0
199 |
200 |
201 | ${android.platform}
202 |
203 |
204 |
205 |
206 |
207 | org.apache.maven.plugins
208 | maven-release-plugin
209 | 2.4
210 |
211 | true
212 |
213 |
214 |
215 |
216 | org.apache.maven.plugins
217 | maven-gpg-plugin
218 |
219 |
220 | sign-artifacts
221 | verify
222 |
223 | sign
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 | org.apache.maven.plugins
233 | maven-source-plugin
234 |
235 |
236 | attach-sources
237 |
238 | jar
239 |
240 |
241 |
242 |
243 |
244 |
245 | org.apache.maven.plugins
246 | maven-javadoc-plugin
247 |
248 |
249 | attach-javadocs
250 |
251 | jar
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
--------------------------------------------------------------------------------