1 /*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
77 WAVE, AU, AIFF, AIFC, SND,
78 new AudioFileFormat.Type("TestName", "TestExt")
79 };
80
81 private static final int FRAME_LENGTH = 10;
82
83 static {
84 for (final int sampleSize : sampleBits) {
85 for (final int channel : channels) {
86 for (final AudioFormat.Encoding enc : encodings) {
87 final int frameSize = ((sampleSize + 7) / 8) * channel;
88 formats.add(new AudioFormat(enc, 44100, sampleSize, channel,
89 frameSize, 44100, true));
90 formats.add(new AudioFormat(enc, 44100, sampleSize, channel,
91 frameSize, 44100, false));
92 }
93 }
94 }
95 }
96
97 public static void main(final String[] args) {
98 for (final FormatConversionProvider fcp : load(
99 FormatConversionProvider.class)) {
100 System.out.println("fcp = " + fcp);
101 for (final AudioFormat from : formats) {
102 for (final AudioFormat to : formats) {
103 testAfterConversion(fcp, to, getStream(from, true));
104 }
105 }
106 }
107
108 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
109 System.out.println("afw = " + afw);
110 for (final AudioFileFormat.Type type : types) {
111 for (final AudioFormat from : formats) {
112 testAfterSaveToStream(afw, type, getStream(from, true));
113 }
114 }
115 }
116
117 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
122 }
123 }
124 }
125
126 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
127 System.out.println("afw = " + afw);
128 for (final AudioFileFormat.Type type : types) {
129 for (final AudioFormat from : formats) {
130 testAfterSaveToFile(afw, type, getStream(from, false));
131 }
132 }
133 }
134 }
135
136 /**
137 * Verifies the frame length after the stream was saved/read to/from
138 * stream.
139 */
140 private static void testAfterSaveToStream(final AudioFileWriter afw,
141 final AudioFileFormat.Type type,
142 final AudioInputStream ais) {
143 try {
144 final ByteArrayOutputStream out = new ByteArrayOutputStream();
145 afw.write(ais, type, out);
146 final InputStream input = new ByteArrayInputStream(
147 out.toByteArray());
148 validate(AudioSystem.getAudioInputStream(input).getFrameLength());
149 } catch (IllegalArgumentException | UnsupportedAudioFileException
150 | IOException ignored) {
151 }
152 }
153
154 /**
155 * Verifies the frame length after the stream was saved/read to/from file.
156 */
157 private static void testAfterSaveToFile(final AudioFileWriter afw,
158 final AudioFileFormat.Type type,
159 AudioInputStream ais) {
160 try {
161 final File temp = File.createTempFile("sound", ".tmp");
162 temp.deleteOnExit();
163 afw.write(ais, type, temp);
164 ais = AudioSystem.getAudioInputStream(temp);
165 final long frameLength = ais.getFrameLength();
166 ais.close();
167 Files.delete(Paths.get(temp.getAbsolutePath()));
168 validate(frameLength);
169 } catch (IllegalArgumentException | UnsupportedAudioFileException
170 | IOException ignored) {
171 }
172 }
173
174 /**
175 * Verifies the frame length after the stream was converted to other
176 * stream.
177 *
178 * @see FormatConversionProvider#getAudioInputStream(AudioFormat,
179 * AudioInputStream)
180 */
181 private static void testAfterConversion(final FormatConversionProvider fcp,
182 final AudioFormat to,
183 final AudioInputStream ais) {
184 if (fcp.isConversionSupported(to, ais.getFormat())) {
185 validate(fcp.getAudioInputStream(to, ais).getFrameLength());
186 }
187 }
188
189 /**
190 * Throws an exception if the frameLength is specified and is not equal to
|
1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
77 WAVE, AU, AIFF, AIFC, SND,
78 new AudioFileFormat.Type("TestName", "TestExt")
79 };
80
81 private static final int FRAME_LENGTH = 10;
82
83 static {
84 for (final int sampleSize : sampleBits) {
85 for (final int channel : channels) {
86 for (final AudioFormat.Encoding enc : encodings) {
87 final int frameSize = ((sampleSize + 7) / 8) * channel;
88 formats.add(new AudioFormat(enc, 44100, sampleSize, channel,
89 frameSize, 44100, true));
90 formats.add(new AudioFormat(enc, 44100, sampleSize, channel,
91 frameSize, 44100, false));
92 }
93 }
94 }
95 }
96
97 public static void main(final String[] args) throws IOException {
98 for (final FormatConversionProvider fcp : load(
99 FormatConversionProvider.class)) {
100 System.out.println("fcp = " + fcp);
101 for (final AudioFormat from : formats) {
102 for (final AudioFormat to : formats) {
103 testAfterConversion(fcp, to, getStream(from, true));
104 }
105 }
106 }
107
108 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
109 System.out.println("afw = " + afw);
110 for (final AudioFileFormat.Type type : types) {
111 for (final AudioFormat from : formats) {
112 testAfterSaveToStream(afw, type, getStream(from, true));
113 }
114 }
115 }
116
117 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
122 }
123 }
124 }
125
126 for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
127 System.out.println("afw = " + afw);
128 for (final AudioFileFormat.Type type : types) {
129 for (final AudioFormat from : formats) {
130 testAfterSaveToFile(afw, type, getStream(from, false));
131 }
132 }
133 }
134 }
135
136 /**
137 * Verifies the frame length after the stream was saved/read to/from
138 * stream.
139 */
140 private static void testAfterSaveToStream(final AudioFileWriter afw,
141 final AudioFileFormat.Type type,
142 final AudioInputStream ais)
143 throws IOException {
144 try {
145 final ByteArrayOutputStream out = new ByteArrayOutputStream();
146 afw.write(ais, type, out);
147 final InputStream input = new ByteArrayInputStream(
148 out.toByteArray());
149 validate(AudioSystem.getAudioInputStream(input).getFrameLength());
150 } catch (IllegalArgumentException | UnsupportedAudioFileException
151 ignored) {
152 }
153 }
154
155 /**
156 * Verifies the frame length after the stream was saved/read to/from file.
157 */
158 private static void testAfterSaveToFile(final AudioFileWriter afw,
159 final AudioFileFormat.Type type,
160 AudioInputStream ais)
161 throws IOException {
162 final File temp = File.createTempFile("sound", ".tmp");
163 try {
164 afw.write(ais, type, temp);
165 ais = AudioSystem.getAudioInputStream(temp);
166 final long frameLength = ais.getFrameLength();
167 ais.close();
168 validate(frameLength);
169 } catch (IllegalArgumentException | UnsupportedAudioFileException
170 ignored) {
171 } finally {
172 Files.delete(Paths.get(temp.getAbsolutePath()));
173 }
174 }
175
176 /**
177 * Verifies the frame length after the stream was converted to other
178 * stream.
179 *
180 * @see FormatConversionProvider#getAudioInputStream(AudioFormat,
181 * AudioInputStream)
182 */
183 private static void testAfterConversion(final FormatConversionProvider fcp,
184 final AudioFormat to,
185 final AudioInputStream ais) {
186 if (fcp.isConversionSupported(to, ais.getFormat())) {
187 validate(fcp.getAudioInputStream(to, ais).getFrameLength());
188 }
189 }
190
191 /**
192 * Throws an exception if the frameLength is specified and is not equal to
|