41905
|
1 |
/*
|
|
2 |
* Copyright (c) 2001, 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 javax.sound.sampled.AudioFormat;
|
|
25 |
import javax.sound.sampled.AudioSystem;
|
|
26 |
import javax.sound.sampled.Clip;
|
|
27 |
import javax.sound.sampled.DataLine;
|
|
28 |
import javax.sound.sampled.Line;
|
|
29 |
import javax.sound.sampled.Mixer;
|
|
30 |
import javax.sound.sampled.SourceDataLine;
|
|
31 |
import javax.sound.sampled.TargetDataLine;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* @test
|
|
35 |
* @bug 4479441
|
|
36 |
* @summary Verify that the lines report 16KHz and 32KHz capability
|
|
37 |
*/
|
|
38 |
public class Has16and32KHz {
|
|
39 |
|
|
40 |
public static boolean ok32=false;
|
|
41 |
public static boolean ok16=false;
|
|
42 |
|
|
43 |
public static void showMixerLines(Line.Info[] lineinfo) {
|
|
44 |
for (int j = 0; j < lineinfo.length; j++) {
|
|
45 |
boolean isSDL=false; // SourceDataLine
|
|
46 |
Line.Info thisInfo=lineinfo[j];
|
|
47 |
System.out.println(" " + thisInfo);
|
|
48 |
String impl="";
|
|
49 |
if (thisInfo.getLineClass().equals(SourceDataLine.class)) {
|
|
50 |
isSDL=true;
|
|
51 |
impl+="SourceDataLine";
|
|
52 |
}
|
|
53 |
if (thisInfo.getLineClass().equals(Clip.class)) {
|
|
54 |
impl+="Clip";
|
|
55 |
}
|
|
56 |
if (thisInfo.getLineClass().equals(DataLine.class)) {
|
|
57 |
impl+="DataLine";
|
|
58 |
}
|
|
59 |
if (thisInfo.getLineClass().equals(TargetDataLine.class)) {
|
|
60 |
impl+="TargetDataLine";
|
|
61 |
}
|
|
62 |
if (thisInfo.getLineClass().equals(Mixer.class)) {
|
|
63 |
impl+="Mixer";
|
|
64 |
}
|
|
65 |
System.out.println(" implements "+impl);
|
|
66 |
try {
|
|
67 |
AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();
|
|
68 |
for (int k = 0; k < formats.length; k++) {
|
|
69 |
System.out.println(" " + formats[k] + ", "+ formats[k].getFrameSize()+" bytes/frame");
|
|
70 |
if (isSDL) {
|
|
71 |
if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)
|
|
72 |
|| (formats[k].getSampleRate()==32000.0f)) {
|
|
73 |
ok32=true;
|
|
74 |
}
|
|
75 |
if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)
|
|
76 |
|| (formats[k].getSampleRate()==16000.0f)) {
|
|
77 |
ok16=true;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
}
|
|
81 |
} catch (ClassCastException e) {
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
public static void main(String[] args) throws Exception {
|
|
87 |
boolean res=true;
|
|
88 |
|
|
89 |
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
|
|
90 |
System.out.println(mixerInfo.length+" mixers on system.");
|
|
91 |
if (mixerInfo.length == 0) {
|
|
92 |
System.out.println("Cannot execute test. Not Failed!");
|
|
93 |
} else {
|
|
94 |
for (int i = 0; i < mixerInfo.length; i++) {
|
|
95 |
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
|
|
96 |
System.out.println();
|
|
97 |
System.out.println(mixer+":");
|
|
98 |
showMixerLines(mixer.getSourceLineInfo());
|
|
99 |
showMixerLines(mixer.getTargetLineInfo());
|
|
100 |
|
|
101 |
|
|
102 |
}
|
|
103 |
res=ok16 && ok32;
|
|
104 |
}
|
|
105 |
if (res) {
|
|
106 |
System.out.println("Test passed");
|
|
107 |
} else {
|
|
108 |
System.out.println("Test failed");
|
|
109 |
throw new Exception("Test failed");
|
|
110 |
}
|
|
111 |
//ystem.exit(res?0:1);
|
|
112 |
}
|
|
113 |
}
|