Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/sampled/Mixers/DirectSoundRepeatingBuffer/DirectSoundRepeatingBuffer.java
41161 views
1
/*
2
* Copyright (c) 2004, 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.io.IOException;
25
26
import javax.sound.sampled.AudioFormat;
27
import javax.sound.sampled.AudioSystem;
28
import javax.sound.sampled.DataLine;
29
import javax.sound.sampled.LineUnavailableException;
30
import javax.sound.sampled.Mixer;
31
import javax.sound.sampled.SourceDataLine;
32
33
/**
34
* This is utility class for Test4997635.
35
*/
36
public class DirectSoundRepeatingBuffer {
37
38
static int sampleRate = 8000;
39
static double frequency = 1000.0;
40
static double RAD = 2.0 * Math.PI;
41
42
static byte[] audioData = new byte[sampleRate/8];
43
static DataLine.Info info;
44
static SourceDataLine source;
45
46
//static AudioInputStream ais = null;
47
static AudioFormat audioFormat;
48
//static String filename;
49
50
public static void print(String s) {
51
System.out.print(s);
52
}
53
public static void println(String s) {
54
System.out.println(s);
55
}
56
57
public static void key() {
58
println("");
59
print("Press ENTER to continue...");
60
try {
61
System.in.read();
62
} catch (IOException ioe) {
63
}
64
println("");
65
}
66
67
public static void play(Mixer mixer) {
68
int res = 0;
69
try {
70
println("Getting SDL from mixer...");
71
source = (SourceDataLine) mixer.getLine(info);
72
println("Opening SDL...");
73
source.open(audioFormat);
74
println("Writing data to SDL...");
75
source.write(audioData, 0, audioData.length);
76
println("Starting SDL...");
77
source.start();
78
println("Now open your ears:");
79
println("- you should have heard a short tone,");
80
println(" followed by silence.");
81
println("- if after a while you hear repeated tones,");
82
println(" the bug is NOT fixed.");
83
println("- if the program remains silent after the ");
84
println(" initial tone, the bug is fixed.");
85
key();
86
} catch (IllegalArgumentException iae) {
87
println("IllegalArgumentException: "+iae.getMessage());
88
println("Sound device cannot handle this audio format.");
89
println("ERROR: Test environment not correctly set up.");
90
if (source!=null) {
91
source.close();
92
source = null;
93
}
94
return;
95
} catch (LineUnavailableException lue) {
96
println("LineUnavailableException: "+lue.getMessage());
97
println("This is normal for some mixers.");
98
} catch (Exception e) {
99
println("Unexpected Exception: "+e.toString());
100
}
101
if (source != null) {
102
println("Stopping...");
103
source.stop();
104
println("Closing...");
105
source.close();
106
println("Closed.");
107
source = null;
108
}
109
}
110
111
public static void main(String[] args) throws Exception {
112
println("This is an interactive test for DirectAudio.");
113
println("If the tone repeats, the test is failed.");
114
println("");
115
println("Make sure that you have speakers connected");
116
println("and that the system mixer is not muted.");
117
println("");
118
println("Press a key to start the test.");
119
key();
120
Mixer.Info[] mixers=null;
121
122
println(" ...using self-generated sine wave for playback");
123
audioFormat = new AudioFormat((float)sampleRate, 8, 1, true, true);
124
for (int i=0; i<audioData.length; i++) {
125
audioData[i] = (byte)(Math.sin(RAD*frequency/sampleRate*i)*127.0);
126
}
127
info = new DataLine.Info(SourceDataLine.class, audioFormat);
128
129
mixers = AudioSystem.getMixerInfo();
130
int succMixers = 0;
131
for (int i=0; i<mixers.length; i++) {
132
println(""+mixers[i]+":");
133
if ((mixers[i].getName()+mixers[i].getDescription()+mixers[i].getVendor()).indexOf("Direct") < 0) {
134
println(" ->not a DirectAudio Mixer!");
135
} else {
136
try {
137
Mixer mixer = AudioSystem.getMixer(mixers[i]);
138
if (!mixer.isLineSupported(info)) {
139
println(" ->doesn't support SourceDataLine!");
140
} else {
141
succMixers++;
142
println(" -> is getting tested.");
143
play(mixer);
144
}
145
} catch (Exception e) {
146
println(" -> Exception occured: "+e);
147
e.printStackTrace();
148
}
149
}
150
}
151
if (succMixers == 0) {
152
println("No DirectAudio mixers available! ");
153
println("Cannot run test.");
154
}
155
}
156
}
157
158