Path: blob/master/test/jdk/javax/sound/sampled/Lines/16and32KHz/Has16and32KHz.java
41159 views
/*1* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.sampled.AudioFormat;24import javax.sound.sampled.AudioSystem;25import javax.sound.sampled.Clip;26import javax.sound.sampled.DataLine;27import javax.sound.sampled.Line;28import javax.sound.sampled.Mixer;29import javax.sound.sampled.SourceDataLine;30import javax.sound.sampled.TargetDataLine;3132/**33* @test34* @bug 447944135* @summary Verify that the lines report 16KHz and 32KHz capability36*/37public class Has16and32KHz {3839public static boolean ok32=false;40public static boolean ok16=false;4142public static void showMixerLines(Line.Info[] lineinfo) {43for (int j = 0; j < lineinfo.length; j++) {44boolean isSDL=false; // SourceDataLine45Line.Info thisInfo=lineinfo[j];46System.out.println(" " + thisInfo);47String impl="";48if (thisInfo.getLineClass().equals(SourceDataLine.class)) {49isSDL=true;50impl+="SourceDataLine";51}52if (thisInfo.getLineClass().equals(Clip.class)) {53impl+="Clip";54}55if (thisInfo.getLineClass().equals(DataLine.class)) {56impl+="DataLine";57}58if (thisInfo.getLineClass().equals(TargetDataLine.class)) {59impl+="TargetDataLine";60}61if (thisInfo.getLineClass().equals(Mixer.class)) {62impl+="Mixer";63}64System.out.println(" implements "+impl);65try {66AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();67for (int k = 0; k < formats.length; k++) {68System.out.println(" " + formats[k] + ", "+ formats[k].getFrameSize()+" bytes/frame");69if (isSDL) {70if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)71|| (formats[k].getSampleRate()==32000.0f)) {72ok32=true;73}74if ((formats[k].getSampleRate()==AudioSystem.NOT_SPECIFIED)75|| (formats[k].getSampleRate()==16000.0f)) {76ok16=true;77}78}79}80} catch (ClassCastException e) {81}82}83}8485public static void main(String[] args) throws Exception {86boolean res=true;8788Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();89System.out.println(mixerInfo.length+" mixers on system.");90if (mixerInfo.length == 0) {91System.out.println("Cannot execute test. Not Failed!");92} else {93for (int i = 0; i < mixerInfo.length; i++) {94Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);95System.out.println();96System.out.println(mixer+":");97showMixerLines(mixer.getSourceLineInfo());98showMixerLines(mixer.getTargetLineInfo());99100101}102res=ok16 && ok32;103}104if (res) {105System.out.println("Test passed");106} else {107System.out.println("Test failed");108throw new Exception("Test failed");109}110//ystem.exit(res?0:1);111}112}113114115