summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java')
-rw-r--r--songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java182
1 files changed, 0 insertions, 182 deletions
diff --git a/songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java b/songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java
deleted file mode 100644
index 05dca90309..0000000000
--- a/songdbj/org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java
+++ /dev/null
@@ -1,182 +0,0 @@
1/*
2 * TMatrixFormatConversionProvider.java
3 */
4
5/*
6 * Copyright (c) 1999, 2000 by Matthias Pfisterer <Matthias.Pfisterer@gmx.de>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25
26package org.tritonus.share.sampled.convert;
27
28
29import java.util.Collection;
30import java.util.List;
31import java.util.Map;
32import java.util.Set;
33import java.util.HashMap;
34import java.util.ArrayList;
35import java.util.Iterator;
36
37import javax.sound.sampled.AudioFormat;
38import javax.sound.sampled.AudioInputStream;
39import javax.sound.sampled.spi.FormatConversionProvider;
40
41import org.tritonus.share.sampled.AudioFormats;
42import org.tritonus.share.ArraySet;
43
44/**
45 * Base class for arbitrary formatConversionProviders.
46 *
47 * @author Matthias Pfisterer
48 */
49
50
51public abstract class TMatrixFormatConversionProvider
52 extends TSimpleFormatConversionProvider
53{
54 /*
55 * keys: source AudioFormat
56 * values: collection of possible target encodings
57 *
58 * Note that accessing values with get() is not appropriate,
59 * since the equals() method in AudioFormat is not overloaded.
60 * The hashtable is just used as a convenient storage
61 * organization.
62 */
63 private Map m_targetEncodingsFromSourceFormat;
64
65
66 /*
67 * keys: source AudioFormat
68 * values: a Map that contains a mapping from target encodings
69 * (keys) to a collection of target formats (values).
70 *
71 * Note that accessing values with get() is not appropriate,
72 * since the equals() method in AudioFormat is not overloaded.
73 * The hashtable is just used as a convenient storage
74 * organization.
75 */
76 private Map m_targetFormatsFromSourceFormat;
77
78
79
80 protected TMatrixFormatConversionProvider(
81 List sourceFormats,
82 List targetFormats,
83 boolean[][] abConversionPossible)
84 {
85 super(sourceFormats,
86 targetFormats);
87 m_targetEncodingsFromSourceFormat = new HashMap();
88 m_targetFormatsFromSourceFormat = new HashMap();
89
90 for (int nSourceFormat = 0;
91 nSourceFormat < sourceFormats.size();
92 nSourceFormat++)
93 {
94 AudioFormat sourceFormat = (AudioFormat) sourceFormats.get(nSourceFormat);
95 List supportedTargetEncodings = new ArraySet();
96 m_targetEncodingsFromSourceFormat.put(sourceFormat, supportedTargetEncodings);
97 Map targetFormatsFromTargetEncodings = new HashMap();
98 m_targetFormatsFromSourceFormat.put(sourceFormat, targetFormatsFromTargetEncodings);
99 for (int nTargetFormat = 0;
100 nTargetFormat < targetFormats.size();
101 nTargetFormat++)
102 {
103 AudioFormat targetFormat = (AudioFormat) targetFormats.get(nTargetFormat);
104 if (abConversionPossible[nSourceFormat][nTargetFormat])
105 {
106 AudioFormat.Encoding targetEncoding = targetFormat.getEncoding();
107 supportedTargetEncodings.add(targetEncoding);
108 Collection supportedTargetFormats = (Collection) targetFormatsFromTargetEncodings.get(targetEncoding);
109 if (supportedTargetFormats == null)
110 {
111 supportedTargetFormats = new ArraySet();
112 targetFormatsFromTargetEncodings.put(targetEncoding, supportedTargetFormats);
113 }
114 supportedTargetFormats.add(targetFormat);
115 }
116 }
117 }
118 }
119
120
121
122 public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat)
123 {
124 Iterator iterator = m_targetEncodingsFromSourceFormat.entrySet().iterator();
125 while (iterator.hasNext())
126 {
127 Map.Entry entry = (Map.Entry) iterator.next();
128 AudioFormat format = (AudioFormat) entry.getKey();
129 if (AudioFormats.matches(format, sourceFormat))
130 {
131 Collection targetEncodings = (Collection) entry.getValue();
132 return (AudioFormat.Encoding[]) targetEncodings.toArray(EMPTY_ENCODING_ARRAY);
133 }
134
135 }
136 return EMPTY_ENCODING_ARRAY;
137 }
138
139
140
141 // TODO: this should work on the array returned by getTargetEncodings(AudioFormat)
142/*
143 public boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat)
144 {
145 return isAllowedSourceFormat(sourceFormat) &&
146 isTargetEncodingSupported(targetEncoding);
147 }
148*/
149
150
151
152 public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat)
153 {
154 Iterator iterator = m_targetFormatsFromSourceFormat.entrySet().iterator();
155 while (iterator.hasNext())
156 {
157 Map.Entry entry = (Map.Entry) iterator.next();
158 AudioFormat format = (AudioFormat) entry.getKey();
159 if (AudioFormats.matches(format, sourceFormat))
160 {
161 Map targetEncodings = (Map) entry.getValue();
162 Collection targetFormats = (Collection) targetEncodings.get(targetEncoding);
163 if (targetFormats != null)
164 {
165 return (AudioFormat[]) targetFormats.toArray(EMPTY_FORMAT_ARRAY);
166 }
167 else
168 {
169 return EMPTY_FORMAT_ARRAY;
170 }
171 }
172
173 }
174 return EMPTY_FORMAT_ARRAY;
175 }
176
177
178}
179
180
181
182/*** TMatrixFormatConversionProvider.java ***/