author | serb |
Sat, 06 May 2017 13:17:36 -0700 | |
changeset 45341 | b7cc7f639ecf |
parent 40718 | fe2adbe4d101 |
permissions | -rw-r--r-- |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
1 |
/* |
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
4 |
* |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
8 |
* |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
14 |
* |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
18 |
* |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
21 |
* questions. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
22 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
23 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
24 |
import java.io.ByteArrayInputStream; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
25 |
import java.io.ByteArrayOutputStream; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
26 |
import java.io.File; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
27 |
import java.io.IOException; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
28 |
import java.io.InputStream; |
40718 | 29 |
import java.nio.file.Files; |
30 |
import java.nio.file.Paths; |
|
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
32 |
import java.util.List; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
33 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
34 |
import javax.sound.sampled.AudioFileFormat; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
35 |
import javax.sound.sampled.AudioFormat; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
36 |
import javax.sound.sampled.AudioInputStream; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
37 |
import javax.sound.sampled.AudioSystem; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
38 |
import javax.sound.sampled.UnsupportedAudioFileException; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
39 |
import javax.sound.sampled.spi.AudioFileWriter; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
40 |
import javax.sound.sampled.spi.FormatConversionProvider; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
41 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
42 |
import static java.util.ServiceLoader.load; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
43 |
import static javax.sound.sampled.AudioFileFormat.Type.AIFC; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
44 |
import static javax.sound.sampled.AudioFileFormat.Type.AIFF; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
45 |
import static javax.sound.sampled.AudioFileFormat.Type.AU; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
46 |
import static javax.sound.sampled.AudioFileFormat.Type.SND; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
47 |
import static javax.sound.sampled.AudioFileFormat.Type.WAVE; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
48 |
import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
49 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
50 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
51 |
* @test |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
52 |
* @bug 8038139 |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
53 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
54 |
public final class FrameLengthAfterConversion { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
55 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
56 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
57 |
* We will try to use all formats, in this case all our providers will be |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
58 |
* covered by supported/unsupported formats. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
59 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
60 |
private static final List<AudioFormat> formats = new ArrayList<>(23000); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
61 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
62 |
private static final AudioFormat.Encoding[] encodings = { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
63 |
AudioFormat.Encoding.ALAW, AudioFormat.Encoding.ULAW, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
64 |
AudioFormat.Encoding.PCM_SIGNED, AudioFormat.Encoding.PCM_UNSIGNED, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
65 |
AudioFormat.Encoding.PCM_FLOAT, new AudioFormat.Encoding("Test") |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
66 |
}; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
67 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
68 |
private static final int[] sampleBits = { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
69 |
1, 4, 8, 11, 16, 20, 24, 32 |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
70 |
}; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
71 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
72 |
private static final int[] channels = { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
73 |
1, 2, 3, 4, 5 |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
74 |
}; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
75 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
76 |
private static final AudioFileFormat.Type[] types = { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
77 |
WAVE, AU, AIFF, AIFC, SND, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
78 |
new AudioFileFormat.Type("TestName", "TestExt") |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
79 |
}; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
80 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
81 |
private static final int FRAME_LENGTH = 10; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
82 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
83 |
static { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
84 |
for (final int sampleSize : sampleBits) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
85 |
for (final int channel : channels) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
86 |
for (final AudioFormat.Encoding enc : encodings) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
87 |
final int frameSize = ((sampleSize + 7) / 8) * channel; |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
88 |
formats.add(new AudioFormat(enc, 44100, sampleSize, channel, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
89 |
frameSize, 44100, true)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
90 |
formats.add(new AudioFormat(enc, 44100, sampleSize, channel, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
91 |
frameSize, 44100, false)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
92 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
93 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
94 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
95 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
96 |
|
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
97 |
public static void main(final String[] args) throws IOException { |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
98 |
for (final FormatConversionProvider fcp : load( |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
99 |
FormatConversionProvider.class)) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
100 |
System.out.println("fcp = " + fcp); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
101 |
for (final AudioFormat from : formats) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
102 |
for (final AudioFormat to : formats) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
103 |
testAfterConversion(fcp, to, getStream(from, true)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
104 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
105 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
106 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
107 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
108 |
for (final AudioFileWriter afw : load(AudioFileWriter.class)) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
109 |
System.out.println("afw = " + afw); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
110 |
for (final AudioFileFormat.Type type : types) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
111 |
for (final AudioFormat from : formats) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
112 |
testAfterSaveToStream(afw, type, getStream(from, true)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
113 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
114 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
115 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
116 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
117 |
for (final AudioFileWriter afw : load(AudioFileWriter.class)) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
118 |
System.out.println("afw = " + afw); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
119 |
for (final AudioFileFormat.Type type : types) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
120 |
for (final AudioFormat from : formats) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
121 |
testAfterSaveToFile(afw, type, getStream(from, true)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
122 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
123 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
124 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
125 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
126 |
for (final AudioFileWriter afw : load(AudioFileWriter.class)) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
127 |
System.out.println("afw = " + afw); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
128 |
for (final AudioFileFormat.Type type : types) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
129 |
for (final AudioFormat from : formats) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
130 |
testAfterSaveToFile(afw, type, getStream(from, false)); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
131 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
132 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
133 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
134 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
135 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
136 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
137 |
* Verifies the frame length after the stream was saved/read to/from |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
138 |
* stream. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
139 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
140 |
private static void testAfterSaveToStream(final AudioFileWriter afw, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
141 |
final AudioFileFormat.Type type, |
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
142 |
final AudioInputStream ais) |
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
143 |
throws IOException { |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
144 |
try { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
145 |
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
146 |
afw.write(ais, type, out); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
147 |
final InputStream input = new ByteArrayInputStream( |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
148 |
out.toByteArray()); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
149 |
validate(AudioSystem.getAudioInputStream(input).getFrameLength()); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
150 |
} catch (IllegalArgumentException | UnsupportedAudioFileException |
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
151 |
ignored) { |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
152 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
153 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
154 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
155 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
156 |
* Verifies the frame length after the stream was saved/read to/from file. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
157 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
158 |
private static void testAfterSaveToFile(final AudioFileWriter afw, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
159 |
final AudioFileFormat.Type type, |
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
160 |
AudioInputStream ais) |
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
161 |
throws IOException { |
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
162 |
final File temp = File.createTempFile("sound", ".tmp"); |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
163 |
try { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
164 |
afw.write(ais, type, temp); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
165 |
ais = AudioSystem.getAudioInputStream(temp); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
166 |
final long frameLength = ais.getFrameLength(); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
167 |
ais.close(); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
168 |
validate(frameLength); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
169 |
} catch (IllegalArgumentException | UnsupportedAudioFileException |
45341
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
170 |
ignored) { |
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
171 |
} finally { |
b7cc7f639ecf
8178383: Validation of FileIO in the tests for JavaSound should be stricter
serb
parents:
40718
diff
changeset
|
172 |
Files.delete(Paths.get(temp.getAbsolutePath())); |
36454
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
173 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
174 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
175 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
176 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
177 |
* Verifies the frame length after the stream was converted to other |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
178 |
* stream. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
179 |
* |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
180 |
* @see FormatConversionProvider#getAudioInputStream(AudioFormat, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
181 |
* AudioInputStream) |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
182 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
183 |
private static void testAfterConversion(final FormatConversionProvider fcp, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
184 |
final AudioFormat to, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
185 |
final AudioInputStream ais) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
186 |
if (fcp.isConversionSupported(to, ais.getFormat())) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
187 |
validate(fcp.getAudioInputStream(to, ais).getFrameLength()); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
188 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
189 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
190 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
191 |
/** |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
192 |
* Throws an exception if the frameLength is specified and is not equal to |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
193 |
* the gold value. |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
194 |
*/ |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
195 |
private static void validate(final long frameLength) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
196 |
if (frameLength != FRAME_LENGTH) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
197 |
System.err.println("Expected: " + FRAME_LENGTH); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
198 |
System.err.println("Actual: " + frameLength); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
199 |
throw new RuntimeException(); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
200 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
201 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
202 |
|
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
203 |
private static AudioInputStream getStream(final AudioFormat format, |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
204 |
final boolean frameLength) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
205 |
final int dataSize = FRAME_LENGTH * format.getFrameSize(); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
206 |
final InputStream in = new ByteArrayInputStream(new byte[dataSize]); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
207 |
if (frameLength) { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
208 |
return new AudioInputStream(in, format, FRAME_LENGTH); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
209 |
} else { |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
210 |
return new AudioInputStream(in, format, NOT_SPECIFIED); |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
211 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
212 |
} |
d2853d1fc614
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV
serb
parents:
diff
changeset
|
213 |
} |