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/org/tritonus/share/sampled/Encodings.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/org/tritonus/share/sampled/Encodings.java')
-rw-r--r-- | songdbj/org/tritonus/share/sampled/Encodings.java | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/songdbj/org/tritonus/share/sampled/Encodings.java b/songdbj/org/tritonus/share/sampled/Encodings.java deleted file mode 100644 index 6b880d24d9..0000000000 --- a/songdbj/org/tritonus/share/sampled/Encodings.java +++ /dev/null | |||
@@ -1,183 +0,0 @@ | |||
1 | /* | ||
2 | * Encodings.java | ||
3 | * | ||
4 | * This file is part of Tritonus: http://www.tritonus.org/ | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Copyright (c) 2000 by Florian Bomers <http://www.bomers.de> | ||
9 | * | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU Library General Public License as published | ||
13 | * by the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU Library General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Library General Public | ||
22 | * License along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | |||
28 | package org.tritonus.share.sampled; | ||
29 | |||
30 | import java.util.Iterator; | ||
31 | import javax.sound.sampled.AudioSystem; | ||
32 | import javax.sound.sampled.AudioFormat; | ||
33 | import org.tritonus.share.StringHashedSet; | ||
34 | import org.tritonus.share.TDebug; | ||
35 | |||
36 | /** | ||
37 | * This class is a proposal for generic handling of encodings. | ||
38 | * The main purpose is to provide a standardized way of | ||
39 | * implementing encoding types. Like this, encodings | ||
40 | * are only identified by their String name, and not, as currently, | ||
41 | * by their object instance. | ||
42 | * <p> | ||
43 | * A registry of standard encoding names will | ||
44 | * be maintained by the Tritonus team. | ||
45 | * <p> | ||
46 | * In a specification request to JavaSoft, the static method | ||
47 | * <code>getEncoding</code> should be integrated into | ||
48 | * <code>AudioFormat.Encoding(String name)</code> (possibly | ||
49 | * renamed to <code>getInstance(String name)</code>.<br> | ||
50 | * The static instances of ULAW, ALAW PCM_UNSIGNED and PCM_SIGNED | ||
51 | * encodings in that class should be retrieved using that function, | ||
52 | * too (internally).<br> | ||
53 | * At best, the protected constructor of that class | ||
54 | * should also be replaced to be a private constructor. | ||
55 | * Like this it will be prevented that developers create their own | ||
56 | * instances of Encoding, which causes problems with the | ||
57 | * equals method. In fact, the equals method should be redefined anyway | ||
58 | * so that it compares the names and not the objects. | ||
59 | * <p> | ||
60 | * Also, a specification request should be made to integrate | ||
61 | * <code>getEncodings()</code> into AudioSystem (this is | ||
62 | * especially annoying as the relevant methods already exist | ||
63 | * in the provider interfaces of file readers, file writers and | ||
64 | * converters). | ||
65 | * | ||
66 | * @author Florian Bomers | ||
67 | */ | ||
68 | public class Encodings extends AudioFormat.Encoding { | ||
69 | |||
70 | /** contains all known encodings */ | ||
71 | private static StringHashedSet encodings = new StringHashedSet(); | ||
72 | |||
73 | // initially add the standard encodings | ||
74 | static { | ||
75 | encodings.add(AudioFormat.Encoding.PCM_SIGNED); | ||
76 | encodings.add(AudioFormat.Encoding.PCM_UNSIGNED); | ||
77 | encodings.add(AudioFormat.Encoding.ULAW); | ||
78 | encodings.add(AudioFormat.Encoding.ALAW); | ||
79 | } | ||
80 | |||
81 | Encodings(String name) { | ||
82 | super(name); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Use this method for retrieving an instance of | ||
87 | * <code>AudioFormat.Encoding</code> of the specified | ||
88 | * name. A standard registry of encoding names will | ||
89 | * be maintained by the Tritonus team. | ||
90 | * <p> | ||
91 | * Every file reader, file writer, and format converter | ||
92 | * provider should exclusively use this method for | ||
93 | * retrieving instances of <code>AudioFormat.Encoding</code>. | ||
94 | */ | ||
95 | /* | ||
96 | MP2000/09/11: | ||
97 | perhaps it is not a good idea to allow user programs the creation of new | ||
98 | encodings. The problem with it is that a plain typo will produce an encoding | ||
99 | object that is not supported. Instead, some indication of an error should be | ||
100 | signaled to the user program. And, there should be a second interface for | ||
101 | service providers allowing them to register encodings supported by themselves. | ||
102 | |||
103 | $$fb2000/09/26: | ||
104 | The problem is what you see as second issue: it can never be assured | ||
105 | that this class knows all available encodings. So at the moment, there | ||
106 | is no choice than to allow users to create any Encoding they wish. | ||
107 | The encodings database will simplify things. | ||
108 | A problem with an interface to retrieve supported encodings (or API | ||
109 | function in spi.FormatConversionProvider) is that this requires | ||
110 | loading of all providers very early. Hmmm, maybe this is necessary in any | ||
111 | case when the user issues something like AudioSystem.isConversionSupported. | ||
112 | */ | ||
113 | public static AudioFormat.Encoding getEncoding(String name) { | ||
114 | AudioFormat.Encoding res=(AudioFormat.Encoding) encodings.get(name); | ||
115 | if (res==null) { | ||
116 | // it is not already in the string set. Create a new encoding instance. | ||
117 | res=new Encodings(name); | ||
118 | // and save it for the future | ||
119 | encodings.add(res); | ||
120 | } | ||
121 | return res; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * Tests for equality of 2 encodings. They are equal when their strings match. | ||
126 | * <p> | ||
127 | * This function should be AudioFormat.Encoding.equals and must | ||
128 | * be considered as a temporary work around until it flows into the | ||
129 | * JavaSound API. | ||
130 | */ | ||
131 | // IDEA: create a special "NOT_SPECIFIED" encoding | ||
132 | // and a AudioFormat.Encoding.matches method. | ||
133 | public static boolean equals(AudioFormat.Encoding e1, AudioFormat.Encoding e2) { | ||
134 | return e2.toString().equals(e1.toString()); | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Returns all "supported" encodings. | ||
140 | * Supported means that it is possible to read or | ||
141 | * write files with this encoding, or that a converter | ||
142 | * accepts this encoding as source or target format. | ||
143 | * <p> | ||
144 | * Currently, this method returns a best guess and | ||
145 | * the search algorithm is far from complete: with standard | ||
146 | * methods of AudioSystem, only the target encodings | ||
147 | * of the converters can be retrieved - neither | ||
148 | * the source encodings of converters nor the encodings | ||
149 | * of file readers and file writers cannot be retrieved. | ||
150 | */ | ||
151 | public static AudioFormat.Encoding[] getEncodings() { | ||
152 | StringHashedSet iteratedSources=new StringHashedSet(); | ||
153 | StringHashedSet retrievedTargets=new StringHashedSet(); | ||
154 | Iterator sourceFormats=encodings.iterator(); | ||
155 | while (sourceFormats.hasNext()) { | ||
156 | AudioFormat.Encoding source=(AudioFormat.Encoding) sourceFormats.next(); | ||
157 | iterateEncodings(source, iteratedSources, retrievedTargets); | ||
158 | } | ||
159 | return (AudioFormat.Encoding[]) retrievedTargets.toArray( | ||
160 | new AudioFormat.Encoding[retrievedTargets.size()]); | ||
161 | } | ||
162 | |||
163 | |||
164 | private static void iterateEncodings(AudioFormat.Encoding source, | ||
165 | StringHashedSet iteratedSources, | ||
166 | StringHashedSet retrievedTargets) { | ||
167 | if (!iteratedSources.contains(source)) { | ||
168 | iteratedSources.add(source); | ||
169 | AudioFormat.Encoding[] targets=AudioSystem.getTargetEncodings(source); | ||
170 | for (int i=0; i<targets.length; i++) { | ||
171 | AudioFormat.Encoding target=targets[i]; | ||
172 | if (retrievedTargets.add(target.toString())) { | ||
173 | iterateEncodings(target, iteratedSources,retrievedTargets); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | |||
181 | |||
182 | /*** Encodings.java ***/ | ||
183 | |||