001 /* Format conversion API
002 Copyright (C) 2005 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package javax.sound.sampled.spi;
040
041 import javax.sound.sampled.AudioFormat;
042 import javax.sound.sampled.AudioInputStream;
043
044 /**
045 * A format conversion provider supplies methods for converting between
046 * different audio formats. This abstract class defines the interface
047 * to this functionality; concrete subclasses will implement the methods
048 * declared here.
049 * @since 1.3
050 */
051 public abstract class FormatConversionProvider
052 {
053 /**
054 * Create a new format conversion provider.
055 */
056 public FormatConversionProvider()
057 {
058 }
059
060 /**
061 * Return an audio input stream given the desired target encoding and
062 * another audio input stream. The data in the given stream will be
063 * converted to the desired encoding.
064 * @param encoding the encoding
065 * @param source the source audio input stream
066 * @return a new audio input stream
067 * @throws IllegalArgumentException if the conversion is not supported
068 */
069 public abstract AudioInputStream getAudioInputStream(AudioFormat.Encoding encoding,
070 AudioInputStream source);
071
072 /**
073 * Return an audio input stream given the desired target format and
074 * another audio input stream. The data in the given stream will be
075 * converted to the desired format.
076 * @param format the format
077 * @param source the source audio input stream
078 * @return a new audio input stream
079 * @throws IllegalArgumentException if the conversion is not supported
080 */
081 public abstract AudioInputStream getAudioInputStream(AudioFormat format,
082 AudioInputStream source);
083
084 /**
085 * Return an array of all the source encodings supported by this conversion
086 * provider.
087 */
088 public abstract AudioFormat.Encoding[] getSourceEncodings();
089
090 /**
091 * Return an array of all the target encodings supported by this conversion
092 * provider.
093 */
094 public abstract AudioFormat.Encoding[] getTargetEncodings();
095
096 /**
097 * Return an array of all the target encodings that are available for a given
098 * source format.
099 * @param fmt the source format
100 * @return an array of supported target encodings
101 */
102 public abstract AudioFormat.Encoding[] getTargetEncodings(AudioFormat fmt);
103
104 /**
105 * Return a array of all the target formats that match given target encoding,
106 * and to which this provider can convert the source format.
107 * @param targ the target encoding to match
108 * @param src the source format
109 * @return an array of supported target formats
110 */
111 public abstract AudioFormat[] getTargetFormats(AudioFormat.Encoding targ,
112 AudioFormat src);
113
114 /**
115 * Return true if this provider supports conversion from the given
116 * source format to the given target encoding.
117 * @param targ the target encoding
118 * @param src the source format
119 * @return true if the conversion is supported
120 */
121 public boolean isConversionSupported(AudioFormat.Encoding targ,
122 AudioFormat src)
123 {
124 AudioFormat.Encoding[] encodings = getTargetEncodings(src);
125 for (int i = 0; i < encodings.length; ++i)
126 {
127 if (targ.equals(encodings[i]))
128 return true;
129 }
130 return false;
131 }
132
133 /**
134 * Return true if this provider supports conversions from the given
135 * source format to the given target format.
136 * @param targ the source format
137 * @param src the target format
138 * @return true if the conversion is supported
139 */
140 public boolean isConversionSupported(AudioFormat targ, AudioFormat src)
141 {
142 AudioFormat[] encodings = getTargetFormats(targ.getEncoding(), src);
143 return encodings.length > 0;
144 }
145
146 /**
147 * Return true if an encoding matching the argument is supported as a
148 * source encoding by this provider.
149 * @param src the source encoding
150 * @return true if it is supported
151 */
152 public boolean isSourceEncodingSupported(AudioFormat.Encoding src)
153 {
154 AudioFormat.Encoding[] srcs = getSourceEncodings();
155 for (int i = 0; i < srcs.length; ++i)
156 {
157 if (src.equals(srcs[i]))
158 return true;
159 }
160 return false;
161 }
162
163 /**
164 * Return true if an encoding matching the argument is supported as a
165 * target encoding by this provider.
166 * @param targ the target encoding
167 * @return true if it is supported
168 */
169 public boolean isTargetEncodingSupported(AudioFormat.Encoding targ)
170 {
171 AudioFormat.Encoding[] encodings = getTargetEncodings();
172 for (int i = 0; i < encodings.length; ++i)
173 {
174 if (targ.equals(encodings[i]))
175 return true;
176 }
177 return false;
178 }
179 }