6502
|
1 |
/*
|
|
2 |
* Copyright (c) 2010, 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. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
/* @test
|
|
27 |
@summary Test SoftSynthesizer getPropertyInfo method */
|
|
28 |
|
|
29 |
import java.util.HashMap;
|
|
30 |
import java.util.Map;
|
|
31 |
|
|
32 |
import javax.sound.midi.MidiDevice;
|
|
33 |
import javax.sound.midi.MidiUnavailableException;
|
|
34 |
import javax.sound.midi.Patch;
|
|
35 |
import javax.sound.midi.Soundbank;
|
|
36 |
import javax.sound.sampled.*;
|
|
37 |
import javax.sound.sampled.AudioFormat.Encoding;
|
|
38 |
import javax.sound.midi.MidiDevice.Info;
|
|
39 |
|
|
40 |
import com.sun.media.sound.*;
|
|
41 |
|
|
42 |
public class GetPropertyInfo {
|
|
43 |
|
|
44 |
private static void assertTrue(boolean value) throws Exception {
|
|
45 |
if (!value)
|
|
46 |
throw new RuntimeException("assertTrue fails!");
|
|
47 |
}
|
|
48 |
|
|
49 |
public static void main(String[] args) throws Exception {
|
|
50 |
SoftSynthesizer synth = new SoftSynthesizer();
|
|
51 |
Map<String, Object> p = new HashMap<String, Object>();
|
|
52 |
p.put("format", "8000 HZ 24 BIT MONO UNSIGNED BIG-ENDIAN");
|
|
53 |
p.put("control rate", 125);
|
|
54 |
p.put("reverb", false);
|
|
55 |
p.put("auto gain control", "false");
|
|
56 |
AudioSynthesizerPropertyInfo[] ap = synth.getPropertyInfo(p);
|
|
57 |
for (int i = 0; i < ap.length; i++) {
|
|
58 |
if (ap[i].name.equals("control rate"))
|
|
59 |
assertTrue(Math.abs((Float) ap[i].value - 125.0) < 0.001);
|
|
60 |
if (ap[i].name.equals("reverb"))
|
|
61 |
assertTrue((Boolean) ap[i].value == false);
|
|
62 |
if (ap[i].name.equals("auto gain control"))
|
|
63 |
assertTrue((Boolean) ap[i].value == false);
|
|
64 |
if (ap[i].name.equals("format")) {
|
|
65 |
AudioFormat format = (AudioFormat) ap[i].value;
|
|
66 |
assertTrue(format.getChannels() == 1);
|
|
67 |
assertTrue(format.getSampleSizeInBits() == 24);
|
|
68 |
assertTrue(format.isBigEndian());
|
|
69 |
assertTrue(Math.abs(format.getSampleRate() - 8000) < 0.001);
|
|
70 |
assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
p = new HashMap<String, Object>();
|
|
74 |
p.put("format", "9000 Hz, 8 bit, 4 channels");
|
|
75 |
ap = synth.getPropertyInfo(p);
|
|
76 |
for (int i = 0; i < ap.length; i++) {
|
|
77 |
if (ap[i].name.equals("format")) {
|
|
78 |
AudioFormat format = (AudioFormat) ap[i].value;
|
|
79 |
assertTrue(format.getChannels() == 4);
|
|
80 |
assertTrue(format.getSampleSizeInBits() == 8);
|
|
81 |
assertTrue(!format.isBigEndian());
|
|
82 |
assertTrue(Math.abs(format.getSampleRate() - 9000) < 0.001);
|
|
83 |
assertTrue(format.getEncoding() == Encoding.PCM_SIGNED);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
p = new HashMap<String, Object>();
|
|
88 |
p.put("format", "PCM_UNSIGNED 44100.0 Hz, 16 bit, 3 channels, 6 bytes/frame, big-endian");
|
|
89 |
ap = synth.getPropertyInfo(p);
|
|
90 |
for (int i = 0; i < ap.length; i++) {
|
|
91 |
if (ap[i].name.equals("format")) {
|
|
92 |
AudioFormat format = (AudioFormat) ap[i].value;
|
|
93 |
assertTrue(format.getChannels() == 3);
|
|
94 |
assertTrue(format.getSampleSizeInBits() == 16);
|
|
95 |
assertTrue(format.isBigEndian());
|
|
96 |
assertTrue(Math.abs(format.getSampleRate() - 44100) < 0.001);
|
|
97 |
assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED);
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
}
|
|
103 |
}
|