Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/midi/Gervill/AudioFloatConverter/Bits8ToFromFloatArray.java
41155 views
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
*/
23
24
import java.util.Arrays;
25
26
import javax.sound.sampled.AudioFormat;
27
import javax.sound.sampled.AudioFormat.Encoding;
28
29
import com.sun.media.sound.AudioFloatConverter;
30
31
import static javax.sound.sampled.AudioFormat.Encoding.*;
32
33
/**
34
* @test
35
* @bug 8152501
36
* @modules java.desktop/com.sun.media.sound
37
*/
38
public final class Bits8ToFromFloatArray {
39
40
private static final int SIZE = 8;
41
42
private static final float[] FLOATS = {-1.0f, 0, 1.0f};
43
44
private static final byte[] SIGNED = {Byte.MIN_VALUE, 0, Byte.MAX_VALUE};
45
46
private static final byte[] UNSIGNED = {
47
0, (byte) (Byte.MAX_VALUE + 1), (byte) -1
48
};
49
50
public static void main(final String[] args) {
51
test(PCM_UNSIGNED, UNSIGNED);
52
test(PCM_SIGNED, SIGNED);
53
}
54
55
private static void test(final Encoding enc, final byte[] expected) {
56
AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
57
true);
58
byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
59
AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
60
61
conv.toByteArray(FLOATS, bytes);
62
63
if (!Arrays.equals(bytes, expected)) {
64
System.err.println("Actual: " + Arrays.toString(bytes));
65
System.err.println("Expected: " + Arrays.toString(expected));
66
throw new RuntimeException();
67
}
68
69
float[] floats = new float[bytes.length / af.getFrameSize()];
70
conv.toFloatArray(bytes, floats);
71
72
if (!Arrays.equals(floats, FLOATS)) {
73
System.err.println("Actual: " + Arrays.toString(floats));
74
System.err.println("Expected: " + Arrays.toString(FLOATS));
75
throw new RuntimeException();
76
}
77
}
78
}
79
80