GetPropertyInfo.java revision 12278:6fb5ee377870
1222613Snwhitehorn/* 2222613Snwhitehorn * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 3222613Snwhitehorn * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4222613Snwhitehorn * 5222613Snwhitehorn * This code is free software; you can redistribute it and/or modify it 6222613Snwhitehorn * under the terms of the GNU General Public License version 2 only, as 7222613Snwhitehorn * published by the Free Software Foundation. 8222613Snwhitehorn * 9222613Snwhitehorn * This code is distributed in the hope that it will be useful, but WITHOUT 10222613Snwhitehorn * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11222613Snwhitehorn * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12222613Snwhitehorn * version 2 for more details (a copy is included in the LICENSE file that 13222613Snwhitehorn * accompanied this code). 14222613Snwhitehorn * 15222613Snwhitehorn * You should have received a copy of the GNU General Public License version 16222613Snwhitehorn * 2 along with this work; if not, write to the Free Software Foundation, 17222613Snwhitehorn * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18222613Snwhitehorn * 19222613Snwhitehorn * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20222613Snwhitehorn * or visit www.oracle.com if you need additional information or have any 21222613Snwhitehorn * questions. 22222613Snwhitehorn */ 23222613Snwhitehorn 24222613Snwhitehorn/* @test 25222613Snwhitehorn @summary Test SoftSynthesizer getPropertyInfo method 26222613Snwhitehorn @modules java.desktop/com.sun.media.sound 27222613Snwhitehorn*/ 28222613Snwhitehorn 29222613Snwhitehornimport java.util.HashMap; 30222613Snwhitehornimport java.util.Map; 31222613Snwhitehorn 32222613Snwhitehornimport javax.sound.midi.MidiDevice; 33222613Snwhitehornimport javax.sound.midi.MidiUnavailableException; 34222613Snwhitehornimport javax.sound.midi.Patch; 35222613Snwhitehornimport javax.sound.midi.Soundbank; 36222613Snwhitehornimport javax.sound.sampled.*; 37222613Snwhitehornimport javax.sound.sampled.AudioFormat.Encoding; 38222613Snwhitehornimport javax.sound.midi.MidiDevice.Info; 39222613Snwhitehorn 40222613Snwhitehornimport com.sun.media.sound.*; 41222613Snwhitehorn 42222613Snwhitehornpublic class GetPropertyInfo { 43222613Snwhitehorn 44222613Snwhitehorn private static void assertTrue(boolean value) throws Exception { 45222613Snwhitehorn if (!value) 46222613Snwhitehorn throw new RuntimeException("assertTrue fails!"); 47222613Snwhitehorn } 48222613Snwhitehorn 49222613Snwhitehorn public static void main(String[] args) throws Exception { 50222613Snwhitehorn SoftSynthesizer synth = new SoftSynthesizer(); 51222613Snwhitehorn Map<String, Object> p = new HashMap<String, Object>(); 52222613Snwhitehorn p.put("format", "8000 HZ 24 BIT MONO UNSIGNED BIG-ENDIAN"); 53222613Snwhitehorn p.put("control rate", 125); 54222613Snwhitehorn p.put("reverb", false); 55222613Snwhitehorn p.put("auto gain control", "false"); 56222613Snwhitehorn AudioSynthesizerPropertyInfo[] ap = synth.getPropertyInfo(p); 57222613Snwhitehorn for (int i = 0; i < ap.length; i++) { 58222613Snwhitehorn if (ap[i].name.equals("control rate")) 59222613Snwhitehorn assertTrue(Math.abs((Float) ap[i].value - 125.0) < 0.001); 60222613Snwhitehorn if (ap[i].name.equals("reverb")) 61222613Snwhitehorn assertTrue((Boolean) ap[i].value == false); 62222613Snwhitehorn if (ap[i].name.equals("auto gain control")) 63222613Snwhitehorn assertTrue((Boolean) ap[i].value == false); 64222613Snwhitehorn if (ap[i].name.equals("format")) { 65222613Snwhitehorn AudioFormat format = (AudioFormat) ap[i].value; 66222613Snwhitehorn assertTrue(format.getChannels() == 1); 67222613Snwhitehorn assertTrue(format.getSampleSizeInBits() == 24); 68222613Snwhitehorn assertTrue(format.isBigEndian()); 69222613Snwhitehorn assertTrue(Math.abs(format.getSampleRate() - 8000) < 0.001); 70222613Snwhitehorn assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED); 71222613Snwhitehorn } 72222613Snwhitehorn } 73222613Snwhitehorn p = new HashMap<String, Object>(); 74222613Snwhitehorn p.put("format", "9000 Hz, 8 bit, 4 channels"); 75222613Snwhitehorn ap = synth.getPropertyInfo(p); 76222613Snwhitehorn for (int i = 0; i < ap.length; i++) { 77222613Snwhitehorn if (ap[i].name.equals("format")) { 78222613Snwhitehorn AudioFormat format = (AudioFormat) ap[i].value; 79222613Snwhitehorn assertTrue(format.getChannels() == 4); 80222613Snwhitehorn assertTrue(format.getSampleSizeInBits() == 8); 81222613Snwhitehorn assertTrue(!format.isBigEndian()); 82222613Snwhitehorn assertTrue(Math.abs(format.getSampleRate() - 9000) < 0.001); 83222613Snwhitehorn assertTrue(format.getEncoding() == Encoding.PCM_SIGNED); 84222613Snwhitehorn } 85222613Snwhitehorn } 86222613Snwhitehorn 87222613Snwhitehorn p = new HashMap<String, Object>(); 88222613Snwhitehorn p.put("format", "PCM_UNSIGNED 44100.0 Hz, 16 bit, 3 channels, 6 bytes/frame, big-endian"); 89222613Snwhitehorn ap = synth.getPropertyInfo(p); 90223485Snwhitehorn for (int i = 0; i < ap.length; i++) { 91223485Snwhitehorn if (ap[i].name.equals("format")) { 92223485Snwhitehorn AudioFormat format = (AudioFormat) ap[i].value; 93223485Snwhitehorn assertTrue(format.getChannels() == 3); 94223485Snwhitehorn assertTrue(format.getSampleSizeInBits() == 16); 95222613Snwhitehorn assertTrue(format.isBigEndian()); 96222613Snwhitehorn assertTrue(Math.abs(format.getSampleRate() - 44100) < 0.001); 97222613Snwhitehorn assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED); 98222613Snwhitehorn } 99222613Snwhitehorn } 100222613Snwhitehorn 101222613Snwhitehorn 102222613Snwhitehorn } 103222613Snwhitehorn} 104223485Snwhitehorn