Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/midi/Gervill/AudioFloatConverter/Bits64ToFromFloatArray.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.PCM_SIGNED;
32
import static javax.sound.sampled.AudioFormat.Encoding.PCM_UNSIGNED;
33
34
/**
35
* @test
36
* @bug 8152501
37
* @modules java.desktop/com.sun.media.sound
38
*/
39
public final class Bits64ToFromFloatArray {
40
41
private static final int SIZE = 64;
42
43
private static final float[] FLOATS = {-1.0f, 0, 1.0f};
44
45
private static long MID_U = (long) (Long.MAX_VALUE + 1);
46
private static long MAX_U = -1;
47
48
// BIG ENDIAN
49
private static final byte[] SIGNED_BIG = {
50
(byte) ((Long.MIN_VALUE >> 56) & 0xff),
51
(byte) ((Long.MIN_VALUE >> 48) & 0xff),
52
(byte) ((Long.MIN_VALUE >> 40) & 0xff),
53
(byte) ((Long.MIN_VALUE >> 32) & 0xff),
54
0, 0, 0, 0, // current javasound impl will ignore this
55
0, 0, 0, 0,
56
0, 0, 0, 0,
57
(byte) ((Long.MAX_VALUE >> 56) & 0xff),
58
(byte) ((Long.MAX_VALUE >> 48) & 0xff),
59
(byte) ((Long.MAX_VALUE >> 40) & 0xff),
60
(byte) ((Long.MAX_VALUE >> 32) & 0xff),
61
0, 0, 0, 0, // current javasound impl will ignore this
62
};
63
64
private static final byte[] UNSIGNED_BIG = {
65
0, 0, 0, 0,
66
0, 0, 0, 0,
67
(byte) ((MID_U >> 56) & 0xff),
68
(byte) ((MID_U >> 48) & 0xff),
69
(byte) ((MID_U >> 40) & 0xff),
70
(byte) ((MID_U >> 32) & 0xff),
71
0, 0, 0, 0, // current javasound impl will ignore this
72
(byte) ((MAX_U >> 56) & 0xff),
73
(byte) ((MAX_U >> 48) & 0xff),
74
(byte) ((MAX_U >> 40) & 0xff),
75
(byte) ((MAX_U >> 32) & 0xff),
76
0, 0, 0, 0, // current javasound impl will ignore this
77
};
78
79
// LITTLE ENDIAN
80
private static final byte[] SIGNED_LITTLE = {
81
0, 0, 0, 0, // current javasound impl will ignore this
82
(byte) ((Long.MIN_VALUE >> 32) & 0xff),
83
(byte) ((Long.MIN_VALUE >> 40) & 0xff),
84
(byte) ((Long.MIN_VALUE >> 48) & 0xff),
85
(byte) ((Long.MIN_VALUE >> 56) & 0xff),
86
0, 0, 0, 0,
87
0, 0, 0, 0,
88
0, 0, 0, 0, // current javasound impl will ignore this
89
(byte) ((Long.MAX_VALUE >> 32) & 0xff),
90
(byte) ((Long.MAX_VALUE >> 40) & 0xff),
91
(byte) ((Long.MAX_VALUE >> 48) & 0xff),
92
(byte) ((Long.MAX_VALUE >> 56) & 0xff),
93
};
94
95
private static final byte[] UNSIGNED_LITTLE = {
96
0, 0, 0, 0,
97
0, 0, 0, 0,
98
0, 0, 0, 0, // current javasound impl will ignore this
99
(byte) ((MID_U >> 32) & 0xff),
100
(byte) ((MID_U >> 40) & 0xff),
101
(byte) ((MID_U >> 48) & 0xff),
102
(byte) ((MID_U >> 56) & 0xff),
103
0, 0, 0, 0, // current javasound impl will ignore this
104
(byte) ((MAX_U >> 32) & 0xff),
105
(byte) ((MAX_U >> 40) & 0xff),
106
(byte) ((MAX_U >> 48) & 0xff),
107
(byte) ((MAX_U >> 56) & 0xff),
108
};
109
110
public static void main(final String[] args) {
111
test(PCM_UNSIGNED, UNSIGNED_BIG, true);
112
test(PCM_UNSIGNED, UNSIGNED_LITTLE, false);
113
test(PCM_SIGNED, SIGNED_LITTLE, false);
114
test(PCM_SIGNED, SIGNED_BIG, true);
115
}
116
117
private static void test(final Encoding enc, final byte[] expected,
118
boolean end) {
119
System.err.println(enc);
120
AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
121
end);
122
byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
123
AudioFloatConverter conv = AudioFloatConverter.getConverter(af);
124
125
conv.toByteArray(FLOATS, bytes);
126
127
if (!Arrays.equals(bytes, expected)) {
128
System.err.println("Actual: " + Arrays.toString(bytes));
129
System.err.println("Expected: " + Arrays.toString(expected));
130
throw new RuntimeException();
131
}
132
133
float[] floats = new float[bytes.length / af.getFrameSize()];
134
conv.toFloatArray(bytes, floats);
135
136
if (!Arrays.equals(floats, FLOATS)) {
137
System.err.println("Actual: " + Arrays.toString(floats));
138
System.err.println("Expected: " + Arrays.toString(FLOATS));
139
throw new RuntimeException();
140
}
141
}
142
}
143
144