diff options
author | Björn Stenberg <bjorn@haxx.se> | 2007-01-08 23:53:00 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2007-01-08 23:53:00 +0000 |
commit | 7039a05147b8bbfc829babea1c65bd436450b505 (patch) | |
tree | 4ba555eb84ed97b72b0575034d5b0530a393713e /songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java | |
parent | 6d4c19707ef95942e323cbdc89fbbfdbe45e7cc5 (diff) | |
download | rockbox-7039a05147b8bbfc829babea1c65bd436450b505.tar.gz rockbox-7039a05147b8bbfc829babea1c65bd436450b505.zip |
Splitting out songdbj
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11953 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java')
-rw-r--r-- | songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java b/songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java deleted file mode 100644 index b1bc999947..0000000000 --- a/songdbj/de/jarnbjo/vorbis/VorbisAudioFileReader.java +++ /dev/null | |||
@@ -1,217 +0,0 @@ | |||
1 | package de.jarnbjo.vorbis; | ||
2 | |||
3 | /* | ||
4 | * $ProjectName$ | ||
5 | * $ProjectRevision$ | ||
6 | * ----------------------------------------------------------- | ||
7 | * $Id$ | ||
8 | * ----------------------------------------------------------- | ||
9 | * | ||
10 | * $Author$ | ||
11 | * | ||
12 | * Description: | ||
13 | * | ||
14 | * Copyright 2002-2003 Tor-Einar Jarnbjo | ||
15 | * ----------------------------------------------------------- | ||
16 | * | ||
17 | * Change History | ||
18 | * ----------------------------------------------------------- | ||
19 | * $Log$ | ||
20 | * Revision 1.1 2005/07/11 15:42:36 hcl | ||
21 | * Songdb java version, source. only 1.5 compatible | ||
22 | * | ||
23 | * Revision 1.2 2004/09/21 06:39:06 shred | ||
24 | * Importe reorganisiert, damit Eclipse Ruhe gibt. ;-) | ||
25 | * | ||
26 | * Revision 1.1.1.1 2004/04/04 22:09:12 shred | ||
27 | * First Import | ||
28 | * | ||
29 | * | ||
30 | */ | ||
31 | |||
32 | import java.io.File; | ||
33 | import java.io.IOException; | ||
34 | import java.io.InputStream; | ||
35 | import java.io.RandomAccessFile; | ||
36 | import java.net.URL; | ||
37 | import java.util.Collection; | ||
38 | |||
39 | import javax.sound.sampled.AudioFileFormat; | ||
40 | import javax.sound.sampled.AudioFormat; | ||
41 | import javax.sound.sampled.AudioInputStream; | ||
42 | import javax.sound.sampled.AudioSystem; | ||
43 | import javax.sound.sampled.UnsupportedAudioFileException; | ||
44 | import javax.sound.sampled.spi.AudioFileReader; | ||
45 | |||
46 | import de.jarnbjo.ogg.BasicStream; | ||
47 | import de.jarnbjo.ogg.EndOfOggStreamException; | ||
48 | import de.jarnbjo.ogg.FileStream; | ||
49 | import de.jarnbjo.ogg.LogicalOggStream; | ||
50 | import de.jarnbjo.ogg.OggFormatException; | ||
51 | import de.jarnbjo.ogg.PhysicalOggStream; | ||
52 | import de.jarnbjo.ogg.UncachedUrlStream; | ||
53 | |||
54 | public class VorbisAudioFileReader extends AudioFileReader { | ||
55 | |||
56 | public VorbisAudioFileReader() { | ||
57 | } | ||
58 | |||
59 | public AudioFileFormat getAudioFileFormat(File file) throws IOException, UnsupportedAudioFileException { | ||
60 | try { | ||
61 | return getAudioFileFormat(new FileStream(new RandomAccessFile(file, "r"))); | ||
62 | } | ||
63 | catch(OggFormatException e) { | ||
64 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public AudioFileFormat getAudioFileFormat(InputStream stream) throws IOException, UnsupportedAudioFileException { | ||
69 | try { | ||
70 | return getAudioFileFormat(new BasicStream(stream)); | ||
71 | } | ||
72 | catch(OggFormatException e) { | ||
73 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public AudioFileFormat getAudioFileFormat(URL url) throws IOException, UnsupportedAudioFileException { | ||
78 | try { | ||
79 | return getAudioFileFormat(new UncachedUrlStream(url)); | ||
80 | } | ||
81 | catch(OggFormatException e) { | ||
82 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | private AudioFileFormat getAudioFileFormat(PhysicalOggStream oggStream) throws IOException, UnsupportedAudioFileException { | ||
87 | try { | ||
88 | Collection streams=oggStream.getLogicalStreams(); | ||
89 | if(streams.size()!=1) { | ||
90 | throw new UnsupportedAudioFileException("Only Ogg files with one logical Vorbis stream are supported."); | ||
91 | } | ||
92 | |||
93 | LogicalOggStream los=(LogicalOggStream)streams.iterator().next(); | ||
94 | if(los.getFormat()!=LogicalOggStream.FORMAT_VORBIS) { | ||
95 | throw new UnsupportedAudioFileException("Only Ogg files with one logical Vorbis stream are supported."); | ||
96 | } | ||
97 | |||
98 | VorbisStream vs=new VorbisStream(los); | ||
99 | |||
100 | AudioFormat audioFormat=new AudioFormat( | ||
101 | (float)vs.getIdentificationHeader().getSampleRate(), | ||
102 | 16, | ||
103 | vs.getIdentificationHeader().getChannels(), | ||
104 | true, true); | ||
105 | |||
106 | return new AudioFileFormat(VorbisFormatType.getInstance(), audioFormat, AudioSystem.NOT_SPECIFIED); | ||
107 | } | ||
108 | catch(OggFormatException e) { | ||
109 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
110 | } | ||
111 | catch(VorbisFormatException e) { | ||
112 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | |||
117 | |||
118 | public AudioInputStream getAudioInputStream(File file) throws IOException, UnsupportedAudioFileException { | ||
119 | try { | ||
120 | return getAudioInputStream(new FileStream(new RandomAccessFile(file, "r"))); | ||
121 | } | ||
122 | catch(OggFormatException e) { | ||
123 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public AudioInputStream getAudioInputStream(InputStream stream) throws IOException, UnsupportedAudioFileException { | ||
128 | try { | ||
129 | return getAudioInputStream(new BasicStream(stream)); | ||
130 | } | ||
131 | catch(OggFormatException e) { | ||
132 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | public AudioInputStream getAudioInputStream(URL url) throws IOException, UnsupportedAudioFileException { | ||
137 | try { | ||
138 | return getAudioInputStream(new UncachedUrlStream(url)); | ||
139 | } | ||
140 | catch(OggFormatException e) { | ||
141 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | private AudioInputStream getAudioInputStream(PhysicalOggStream oggStream) throws IOException, UnsupportedAudioFileException { | ||
146 | try { | ||
147 | Collection streams=oggStream.getLogicalStreams(); | ||
148 | if(streams.size()!=1) { | ||
149 | throw new UnsupportedAudioFileException("Only Ogg files with one logical Vorbis stream are supported."); | ||
150 | } | ||
151 | |||
152 | LogicalOggStream los=(LogicalOggStream)streams.iterator().next(); | ||
153 | if(los.getFormat()!=LogicalOggStream.FORMAT_VORBIS) { | ||
154 | throw new UnsupportedAudioFileException("Only Ogg files with one logical Vorbis stream are supported."); | ||
155 | } | ||
156 | |||
157 | VorbisStream vs=new VorbisStream(los); | ||
158 | |||
159 | AudioFormat audioFormat=new AudioFormat( | ||
160 | (float)vs.getIdentificationHeader().getSampleRate(), | ||
161 | 16, | ||
162 | vs.getIdentificationHeader().getChannels(), | ||
163 | true, true); | ||
164 | |||
165 | return new AudioInputStream(new VorbisInputStream(vs), audioFormat, -1); | ||
166 | } | ||
167 | catch(OggFormatException e) { | ||
168 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
169 | } | ||
170 | catch(VorbisFormatException e) { | ||
171 | throw new UnsupportedAudioFileException(e.getMessage()); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | |||
176 | public static class VorbisFormatType extends AudioFileFormat.Type { | ||
177 | |||
178 | private static final VorbisFormatType instance=new VorbisFormatType(); | ||
179 | |||
180 | private VorbisFormatType() { | ||
181 | super("VORBIS", "ogg"); | ||
182 | } | ||
183 | |||
184 | public static AudioFileFormat.Type getInstance() { | ||
185 | return instance; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | public static class VorbisInputStream extends InputStream { | ||
190 | |||
191 | private VorbisStream source; | ||
192 | private byte[] buffer=new byte[8192]; | ||
193 | |||
194 | public VorbisInputStream(VorbisStream source) { | ||
195 | this.source=source; | ||
196 | } | ||
197 | |||
198 | public int read() throws IOException { | ||
199 | return 0; | ||
200 | } | ||
201 | |||
202 | public int read(byte[] buffer) throws IOException { | ||
203 | return read(buffer, 0, buffer.length); | ||
204 | } | ||
205 | |||
206 | public int read(byte[] buffer, int offset, int length) throws IOException { | ||
207 | try { | ||
208 | return source.readPcm(buffer, offset, length); | ||
209 | } | ||
210 | catch(EndOfOggStreamException e) { | ||
211 | return -1; | ||
212 | } | ||
213 | } | ||
214 | } | ||
215 | |||
216 | |||
217 | } \ No newline at end of file | ||